驱动框架——CMSIS第一部分 RTE驱动框架介绍

一、介绍CMISIS

什么是CMSIS(cortex microcontrol software interface standard一种软件标准接口),官网地址:https://arm-software.github.io/CMSIS_6/latest/General/index.html

包含的core、driver、RTOS、dsp、nn等部分,这些源码文件的编写有的是ARM官方编写,有的是半导体厂商编写,标准是ARM联合这些半导体厂商联合制定的。

二、CMSIS-core部分介绍

一般工程都需要包含CMSIS-core部分文件,包括启动文件,系统初始化文件还有头文件等

启动文件:

系统初始化和一些头文件:

c 复制代码
system_stm32f10x.c 

至于其作用,解释几个头文件,stm32f10x.h是stm32f10x系列单片机寄存器定义的头文件,core_cm3.h 是ARM对cortex-M3系列单片机做出的统一标准等,至此就是对CMSIS-core部分的大致介绍。

三、CMSIS RTE框架的介绍

一些重要或者有必要了解的头文件:

c 复制代码
RTE_Device.h				管理外设驱动
RTE_Components.h			组件管理

驱动源文件,有的需要配合标准库或者HAL库来使用

里面的函数整合在ARM的CMSIS框架中

以spi为例子Driver_SPI.h中提供的框架

c 复制代码
/**
\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;

在SPI_STM32F10x.c中的使用

c 复制代码
// SPI1
#ifdef MX_SPI1
static int32_t        SPI1_Initialize          (ARM_SPI_SignalEvent_t pSignalEvent)                { return SPI_Initialize (pSignalEvent, &SPI1_Resources); }
static int32_t        SPI1_Uninitialize        (void)                                              { return SPI_Uninitialize (&SPI1_Resources); }
static int32_t        SPI1_PowerControl        (ARM_POWER_STATE state)                             { return SPI_PowerControl (state, &SPI1_Resources); }
static int32_t        SPI1_Send                (const void *data, uint32_t num)                    { return SPI_Send (data, num, &SPI1_Resources); }
static int32_t        SPI1_Receive             (void *data, uint32_t num)                          { return SPI_Receive (data, num, &SPI1_Resources); }
static int32_t        SPI1_Transfer            (const void *data_out, void *data_in, uint32_t num) { return SPI_Transfer (data_out, data_in, num, &SPI1_Resources); }
static uint32_t       SPI1_GetDataCount        (void)                                              { return SPI_GetDataCount (&SPI1_Resources); }
static int32_t        SPI1_Control             (uint32_t control, uint32_t arg)                    { return SPI_Control (control, arg, &SPI1_Resources); }
static ARM_SPI_STATUS SPI1_GetStatus           (void)                                              { return SPI_GetStatus (&SPI1_Resources); }
       void           SPI1_IRQHandler          (void)                                              {        SPI_IRQHandler (&SPI1_Resources); }

#ifdef MX_SPI1_TX_DMA_Instance
      void            SPI1_TX_DMA_Handler      (uint32_t events)                                   {        SPI_TX_DMA_Complete (events, &SPI1_Resources); }
#endif
#ifdef MX_SPI1_RX_DMA_Instance
      void            SPI1_RX_DMA_Handler      (uint32_t events)                                   {        SPI_RX_DMA_Complete (events, &SPI1_Resources); }
#endif

ARM_DRIVER_SPI Driver_SPI1 = {
  SPIX_GetVersion,
  SPIX_GetCapabilities,
  SPI1_Initialize,
  SPI1_Uninitialize,
  SPI1_PowerControl,
  SPI1_Send,
  SPI1_Receive,
  SPI1_Transfer,
  SPI1_GetDataCount,
  SPI1_Control,
  SPI1_GetStatus
};
#endif

先记录到这里,这里要注意一个分层次的关系,后续还会引入RTOS依次会设计的层次是软件层->RTOS层->设备层->驱动层->寄存器层。

相关推荐
阿川!1 天前
嵌入式软件--stm32 DAY7 I2C通讯上
stm32·单片机·嵌入式硬件·mcu
公子无缘1 天前
【嵌入式】记一次解决VScode+PlatformIO安装卡死的经历
vscode·stm32·单片机·mcu·platformio
光芒Shine3 天前
【嵌入式开发-SPI】
mcu
YHPsophie5 天前
MCU存储系统架构解析
mcu·存储器·亿胜盈科
时光の尘10 天前
FreeRTOS菜鸟入门(十)·消息队列
c语言·stm32·单片机·嵌入式硬件·mcu·物联网·嵌入式实时数据库
ZeroOne电平浪客10 天前
AUTOSAR_BSW_从入门到精通学习笔记系列_EcuM
笔记·mcu·学习·汽车·autosar·普华小满
mftang11 天前
Zephyr RTOS架构下的固件升级
mcu·zephyr架构蓝牙应用笔记
Mr zhua12 天前
(七)ASCLIN_UART模块串口+DMA+环形缓存区
单片机·mcu·英飞凌·tc334
攻城狮-鹏哥13 天前
DRV8301 三相电机驱动芯片的硬件参数与应用设计
驱动开发·单片机·嵌入式硬件·mcu·硬件架构·dsp开发·pcb工艺
YHPsophie14 天前
MCU片上存储器的类型与特性
mcu·ram·亿胜盈科