1、SPIdriverIMPLv01 SPI Driver ImplementationTianjin UniversityInfineon Automotive Electronic Joint LaboratoryState Key Laboratory of EnginesTianJin University, ChinaRevision historyVersionByModificationsV0.1, 10th Sep 2007Nenghui ZhouCreationV0.11 7th November 2008Change document name to Contents1 Int
2、roduction 41.1 Overview 41.2 Reference 42. Type definition 53 Global Variable 64 Function Definitions 74.1 OCSPI_InitSync 74.2 OCSPI_DeInitSync 84.3 OCSPI_ReadAsync 94.4 OCSPI_WriteAsync 114.5 OCSPI_SuspendAsync 134.6 OCSPI_Notification 144.7 OCSPI Interrupt Functions. 155 Resources Configuration 17
3、5.1 Periperal Config 175.2 Interrupt Config 176 Compile Environment 181 Introduction1.1 OverviewThis document describes the implementations of the SPI driver to be developed in the frame of the GEMS-K1 project. The SPI driver configures the microcontroller internal peripherals, so that transmission
4、and reception of data is possible using serial synchronous communication. The microcontroller acts as the master of the communication, and it is connected to several slave devices.Note: 1. This driver is specified for master mode only.2. A channel is a SW logical entity which is mapped to a hardware
5、 chip select signal.3. Errors (Transmit, Receive, phase and baud rate) are not handled by the driver.1.2 Reference1 SPI driver specification document2 TC1766_um_v1.1_2005_08.pdf document2. Type definitionTypeDescriptionRangeOCSPI_ErrorTypeRecommended type: 16 bit unsigned value. Numbers from 0 to 15
6、 are reserved for the HIS IO Library itself, numbers between 16 and 63 are defined in the HIS IO Driver document. Error codes from 64 to 127 are for driver specific error codes not defined in the HIS IO Driver document and numbers starting from 128 are reserved for future use.OCSPI_R_OK OCSPI_R_BUSY
7、OCSPI_R_INVALID_CHANNEL OCSPI_ChannelTypeType to specify a channel from a channel devices. Fix type: 16 bit unsigned value.0 , 7OCSPI_MemPtrTypeType to hold the address to a memory location.0x00000000 to 0xFFFFFFFFOCSPI_SizeTypeType to hold info about the size of an object.0x0000 to 0xFFFFOCSPI_Noti
8、fType16 bit unsigned value.OCSPI_N_READYOCSPI_N_SUSPENDED3 Global VariableThis chapter describes the global variable used by scheduler.VarialbesTypeDescriptionSPI_MODULE_STATUSOCSPI_NotifType SPI module status: busy or idleSPI_MODULE_READ_ADDRESSOCSPI_MemPtrTypeRead data starting from “address”SPI_M
9、ODULE_WRITE_ADDRESSOCSPI_MemPtrTypeWrite data starting from “address”SPI_MODULE_MODEOCSPI_NotifTypeSPI module: read or writeSPI_MODULE_SIZEOCSPI_NotifTypethe number of words to be received or transimit.SPI_MODULE_PLAYLOADOCSPI_SizeTypethe number of SPI received wordsSPI_MODULE_CHANNELOCSPI_ChannelTy
10、peSPI current channel4 Function Definitions4.1 OCSPI_InitSyncSyntaxOCSPI_ErrorType OCSPI_InitSync(void)ParametersnoneReturnOCSPI_R_OK: initialization was successful.NotificationDescriptionInitializes global and module configuration. In details the driver should: Enable module clock. For MRST: Select
11、 option A or B (if available), select alternate input mode and pull device. For SCLK, MTSR and used chip select: Select option A or B (if available), alternate output mode and driver strength. Set active channels invalid. Receive interrupt: disable SRN (SRE=0), clear interrupt request flag (CLRR=1)
12、and set priority. ReentrancyNoRemarks4.2 OCSPI_DeInitSyncSyntaxOCSPI_ErrorType OCSPI_DeInitSync(void)ParametersNoneReturnOCSPI_R_OK: de-initialization was successful.NotificationDescriptionResets all SPI registers. ReentrancyNoRemarks4.3 OCSPI_ReadAsyncSyntaxOCSPI_ErrorType OCSPI_ReadAsync(OCSPI_Cha
13、nnelType channel, OCSPI_MemPtrType address, OCSPI_SizeType size)Parameterschannel: the 16 bit channel identification numberaddress: the address where the received data is writtensize: specifies the number of words to be received.ReturnOCSPI_R_OK: Reading of message is successful.OCSPI_R_BUSY: SPI bu
14、s not idle.OCSPI_R_INVALID_CHANNEL: not configured channel has been called.NotificationOCSPI_N_READY, OCSPI_N_SUSPENDEDDescriptionThe function allows the reception of “size” words, which are to be stored starting from “address”.If the SPI bus is not idle, the function returns with OCSPI_R_BUSY.When
15、all words have been received the notification function is called with OCSPI_N_READY.To be able to handle the transfer asynchronously the SPI will switch on the required interrupts. They will be switched off when all words have been received or when the channel is suspended.ReentrancyNoRemarksThe SPI
16、 transmits dummy data to receive the wanted data.4.4 OCSPI_WriteAsyncSyntaxOCSPI_ErrorType OCSPI_WriteAsync(OCSPI_ChannelType channel, OCSPI_MemPtrType address, OCSPI_SizeType size)Parameterschannel: the 16 bit channel identification numberaddress: the address with the words to writesize: specifies
17、the number of words to be received.ReturnOCSPI_R_OK: Reading of message is successful.OCSPI_R_BUSY: SPI bus not idle.OCSPI_R_INVALID_CHANNEL: not configured channel has been called.NotificationOCSPI_N_READY, OCSPI_N_SUSPENDEDDescriptionThe function allows the transmission of “size” words, which are
18、stored starting from “address”.If the SPI bus is not idle, the function returns with OCSPI_R_BUSY.When all words have been transmitted the notification function is called with OCSPI_N_READY.To be able to handle the transfer asynchronously the SPI will switch on the required interrupts. They will be
19、switched off when all words have been received or when the channel is suspended.ReentrancyNoRemarks4.5 OCSPI_SuspendAsyncSyntaxOCSPI_ErrorType OCSPI_SuspendAsync(OCSPI_ChannelType channel)Parameterschannel: the 16 bit channel identification numberReturnOCSPI_R_OK: function executedOCSPI_R_INVALID_CH
20、ANNEL: not configured channel has been called.NotificationOCSPI_N_SUSPENDEDDescriptionSuspends any asynchronous transfer on the SPI bus.ReentrancyYesRemarks4.6 OCSPI_NotificationSyntaxvoid OCSPI_Notification (OCSPI_ChannelType channel, OCSPI_NotifType notifType, OCSPI_SizeType size)Parameterschannel
21、: the 16 bit channel identification numbernotifType: OCSPI_N_READY, OCSPI_N_SUSPENDEDsize : number of words that have been transmitted / receivedReturnNotificationDescriptionThis is the function prototype for the notification callback function. The implementation is TBD.ReentrancyYesRemarks4.7 OCSPI
22、 Interrupt Functions.4.7.1 Receive Interrupt4.7.2 Configure Channel4.7.3 CheckInit5 Resources ConfigurationThe resource used by SPI driver5.1 Periperal ConfigSourceDescriptionSSC0As SPI hardware interfaceSLSO7:0Slave selection outputs 5.2 Interrupt ConfigSourceSRNTOSPriorityNameDescriptionSSC0SSC0_RSRCCPU3SSC0_viRxDispose receive affairs6 Compile EnvironmentCompile Tool: Tasking for Tricore
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2