先附上一张CMSIS的结构图
对于基于CMSIS的设备驱动框架开发涉及的文件有CMSIS目录下的,对外设驱动做了统一的驱动模型封装
/**
\brief Access structure of the SPI Driver.
*/
typedef struct _ARM_DRIVER_SPI {ARM_DRIVER_VERSION (*GetVersion) (void); ///< Pointer to \ref ARM_SPI_GetVersion : Get driver version.ARM_SPI_CAPABILITIES (*GetCapabilities) (void); ///< Pointer to \ref ARM_SPI_GetCapabilities : Get driver capabilities.int32_t (*Initialize) (ARM_SPI_SignalEvent_t cb_event); ///< Pointer to \ref ARM_SPI_Initialize : Initialize SPI Interface.int32_t (*Uninitialize) (void); ///< Pointer to \ref ARM_SPI_Uninitialize : De-initialize SPI Interface.int32_t (*PowerControl) (ARM_POWER_STATE state); ///< Pointer to \ref ARM_SPI_PowerControl : Control SPI Interface Power.int32_t (*Send) (const void *data, uint32_t num); ///< Pointer to \ref ARM_SPI_Send : Start sending data to SPI Interface.int32_t (*Receive) ( void *data, uint32_t num); ///< Pointer to \ref ARM_SPI_Receive : Start receiving data from SPI Interface.int32_t (*Transfer) (const void *data_out,void *data_in,uint32_t num); ///< Pointer to \ref ARM_SPI_Transfer : Start sending/receiving data to/from SPI.uint32_t (*GetDataCount) (void); ///< Pointer to \ref ARM_SPI_GetDataCount : Get transferred data count.int32_t (*Control) (uint32_t control, uint32_t arg); ///< Pointer to \ref ARM_SPI_Control : Control SPI Interface.ARM_SPI_STATUS (*GetStatus) (void); ///< Pointer to \ref ARM_SPI_GetStatus : Get SPI status.
} const ARM_DRIVER_SPI;
下的DriverTemplates目录下只是做了驱动模型的壳子
我们要与Driver_SPI.h对接的驱动文件在安装的芯片软件包里
#if (RTE_SSP1)
static int32_t SSP1_Initialize (ARM_SPI_SignalEvent_t pSignalEvent) { return SSPx_Initialize (pSignalEvent, &SSP1_Resources); }
static int32_t SSP1_Uninitialize (void) { return SSPx_Uninitialize (&SSP1_Resources); }
static int32_t SSP1_PowerControl (ARM_POWER_STATE state) { return SSPx_PowerControl (state, &SSP1_Resources); }
static int32_t SSP1_Send (const void *data, uint32_t num) { return SSPx_Send (data, num, &SSP1_Resources); }
static int32_t SSP1_Receive (void *data, uint32_t num) { return SSPx_Receive (data, num, &SSP1_Resources); }
static int32_t SSP1_Transfer (const void *data_out, void *data_in, uint32_t num) { return SSPx_Transfer (data_out, data_in, num, &SSP1_Resources); }
static uint32_t SSP1_GetDataCount (void) { return SSPx_GetDataCount (&SSP1_Resources); }
static int32_t SSP1_Control (uint32_t control, uint32_t arg) { return SSPx_Control (control, arg, &SSP1_Resources); }
static ARM_SPI_STATUS SSP1_GetStatus (void) { return SSPx_GetStatus (&SSP1_Resources); }void SSP1_GPDMA_Tx_SignalEvent(uint32_t event) { SSPx_GPDMA_Tx_SignalEvent(event, &SSP1_Resources); }void SSP1_GPDMA_Rx_SignalEvent(uint32_t event) { SSPx_GPDMA_Rx_SignalEvent(event, &SSP1_Resources); }void SSP1_IRQHandler (void) { SSPx_IRQHandler (&SSP1_Resources); }// SPI1 Driver Control Block
ARM_DRIVER_SPI Driver_SPI1 = {SSP_GetVersion,SSP_GetCapabilities,SSP1_Initialize,SSP1_Uninitialize,SSP1_PowerControl,SSP1_Send,SSP1_Receive,SSP1_Transfer,SSP1_GetDataCount,SSP1_Control,SSP1_GetStatus
};
#endif
这里就把我们上面的驱动接口对接到具体的实现函数
对于外设配置的相关驱动对接的引脚再
文件RTE_Device.h里
// <e> SSP0 (Synchronous Serial Port 0) [Driver_SPI0]
// <i> Configuration settings for Driver_SPI0 in component ::Drivers:SPI
#define RTE_SSP0 0// <h> Pin Configuration
// <o> SSP0_SSEL <0=>Not used <1=>P0_16 <2=>P1_21
// <i> Slave Select for SSP0
#define RTE_SSP0_SSEL_PIN_SEL 1
#if (RTE_SSP0_SSEL_PIN_SEL == 0)
#define RTE_SSP0_SSEL_PIN_EN 0
#elif (RTE_SSP0_SSEL_PIN_SEL == 1)#define RTE_SSP0_SSEL_PORT 0#define RTE_SSP0_SSEL_BIT 16#define RTE_SSP0_SSEL_FUNC 2
#elif (RTE_SSP0_SSEL_PIN_SEL == 2)#define RTE_SSP0_SSEL_PORT 1#define RTE_SSP0_SSEL_BIT 21#define RTE_SSP0_SSEL_FUNC 3
#else#error "Invalid SSP0 SSP0_SSEL Pin Configuration!"
#endif
#ifndef RTE_SSP0_SSEL_PIN_EN
#define RTE_SSP0_SSEL_PIN_EN 1
#endif// <o> SSP0_SCK <0=>P0_15 <1=>P1_20
// <i> Serial clock for SSP0
#define RTE_SSP0_SCK_PIN_SEL 0
#if (RTE_SSP0_SCK_PIN_SEL == 0)#define RTE_SSP0_SCK_PORT 0#define RTE_SSP0_SCK_BIT 15#define RTE_SSP0_SCK_FUNC 2
#elif (RTE_SSP0_SCK_PIN_SEL == 1)#define RTE_SSP0_SCK_PORT 1#define RTE_SSP0_SCK_BIT 20#define RTE_SSP0_SCK_FUNC 3
#else#error "Invalid SSP0 SSP0_SCK Pin Configuration!"
#endif// <o> SSP0_MISO <0=>Not used <1=>P0_17 <2=>P1_23
// <i> Master In Slave Out for SSP0
#define RTE_SSP0_MISO_PIN_SEL 0
#if (RTE_SSP0_MISO_PIN_SEL == 0)#define RTE_SSP0_MISO_PIN_EN 0
#elif (RTE_SSP0_MISO_PIN_SEL == 1)#define RTE_SSP0_MISO_PORT 0#define RTE_SSP0_MISO_BIT 17#define RTE_SSP0_MISO_FUNC 2
#elif (RTE_SSP0_MISO_PIN_SEL == 2)#define RTE_SSP0_MISO_PORT 1#define RTE_SSP0_MISO_BIT 23#define RTE_SSP0_MISO_FUNC 3
#else#error "Invalid SSP0 SSP0_MISO Pin Configuration!"
#endif
#ifndef RTE_SSP0_MISO_PIN_EN
#define RTE_SSP0_MISO_PIN_EN 1
#endif// <o> SSP0_MOSI <0=>Not used <1=>P0_18 <2=>P1_24
// <i> Master Out Slave In for SSP0
#define RTE_SSP0_MOSI_PIN_SEL 0
#if (RTE_SSP0_MOSI_PIN_SEL == 0)#define RTE_SSP0_MOSI_PIN_EN 0
#elif (RTE_SSP0_MOSI_PIN_SEL == 1)#define RTE_SSP0_MOSI_PORT 0#define RTE_SSP0_MOSI_BIT 18#define RTE_SSP0_MOSI_FUNC 2
#elif (RTE_SSP0_MOSI_PIN_SEL == 2)#define RTE_SSP0_MOSI_PORT 1#define RTE_SSP0_MOSI_BIT 24#define RTE_SSP0_MOSI_FUNC 3
#else#error "Invalid SSP0 SSP0_MOSI Pin Configuration!"
#endif
#ifndef RTE_SSP0_MOSI_PIN_EN
#define RTE_SSP0_MOSI_PIN_EN 1
#endif
对此基于CMSIS驱动框架的大致结构就是如此。