This section gives an overview of the general operation of CMSIS-Drivers. It explains the Common Driver Functions that are common in all CMSIS-Drivers along with the Function Call Sequence. The topic Data Transfer Functions describes how data read/write operations to the peripheral are implemented.
Each CMSIS-Driver defines an Access Struct for calling the various driver functions and each peripheral (that is accessed via a CMSIS-Driver) has one Driver Instance.
Common Driver FunctionsEach CMSIS-Driver contains these functions:
ARM_POWER_FULL:
Peripheral is turned on and fully operational. The driver initializes the peripheral registers, interrupts, and (optionally) DMA.ARM_POWER_LOW:
(optional) Peripheral is in low power mode and partially operational; usually, it can detect external events and wake-up.ARM_POWER_OFF:
Peripheral is turned off and not operational (pending operations are terminated). This is the state after device reset.The section Function Call Sequence contains more information on the operation of each function. Additional functions are specific to each driver interface and are described in the individual sections of each driver.
Cortex-M Processor ModeThe CMSIS-Driver functions access peripherals and interrupts and are designed to execute in Privileged mode. When calling CMSIS-Driver functions from RTOS threads, it should be ensure that these threads execute in Privileged mode.
Function Call SequenceFor normal operation of the driver, the API functions GetVersion, GetCapabilities, Initialize, PowerControl, Uninitialize are called in the following order:
The functions GetVersion and GetCapabilities can be called any time to obtain the required information from the driver. These functions return always the same information.
Start SequenceTo start working with a peripheral the functions Initialize and PowerControl need to be called in this order:
ARM_POWER_FULL
) sets the peripheral registers including interrupt (NVIC) and optionally DMA. The function can be called multiple times; if the registers are already set it performs no operation and just returns with ARM_DRIVER_OK.To stop working with a peripheral the functions PowerControl and Uninitialize need to be called in this order:
The functions PowerControl and Uninitialize always execute and can be used to put the peripheral into a Safe State, for example after any data transmission errors. To restart the peripheral in a error condition, you should first execute the Stop Sequence and then the Start Sequence.
ARM_POWER_OFF
) terminates any pending data transfers with the peripheral, disables the peripheral and leaves it in a defined mode (typically the reset state).
All CMSIS-Driver provide a Start Sequence and Stop Sequence. Therefore two different drivers can share the same I/O pins, for example UART1 and SPI1 can have overlapping I/O pins. In this case the communication channels can be used as shown below:
SPI1drv->Initialize (...);
...
SPI1drv->Uninitialize ();
...
USART1drv->Initialize (...);
...
USART1drv->Uninitialize ();
Data Transfer FunctionsA CMSIS-Driver implements non-blocking functions to transfer data to a peripheral. This means that the driver configures the read or write access to the peripheral and instantly returns to the calling application. The function names for data transfer end with:
During a data transfer, the application can query the number of transferred data items using functions named GetxxxCount. On completion of a data transfer, the driver calls a callback function with a specific event code.
During the data exchange with the peripheral, the application can decide to:
The following diagram shows the basic communication flow when using the _Send function in an application.
Non-blocking Send Function
Access StructA CMSIS-Driver publishes an Access Struct with the data type name ARM_DRIVER_xxxx that gives to access the driver functions.
Code Example: Function Access of the SPI driver
typedef struct _ARM_DRIVER_SPI {
int32_t (*Uninitialize) (void);
int32_t (*Send) (const void *data, uint32_t num);
int32_t (*Receive) ( void *data, uint32_t num);
int32_t (*Transfer) (const void *data_out, void *data_in, uint32_t num);
uint32_t (*GetDataCount) (void);
int32_t (*Control) (uint32_t control, uint32_t arg);
Driver InstancesA device may offer several peripherals of the same type. For such devices, the CMSIS-Driver publishes multiple instances of the Access Struct. The name of each driver instance reflects the names of the peripheral available in the device.
Code Example: Access Struct for three SPIs in a microcontroller device.
The access functions can be passed to middleware to specify the driver instance that the middleware should use for communication.
Naming Convention
The access structs need to follow this naming convention: the keyword "Driver" followed by an underscore "_", the interface name "IFNAME" (usually in upper case letters), and the instance number "n". Here's the full list of access struct names for all drivers (n to be replaced with the actual instance number):
Driver_CANn
Driver_ETH_MACn
Driver_ETH_PHYn
Driver_Flashn
Driver_I2Cn
Driver_MCIn
Driver_NANDn
Driver_SAIn
Driver_SPIn
Driver_Storagen
Driver_USARTn
Driver_USBDn
Driver_USBHn
Driver_WiFin
Example:
\\ inside the middleware the SPI driver functions are called with:
\\ Drv_spi->function (...);
\\ setup middleware
init_middleware (&Driver_SPI1);
:
init_middleware (&Driver_SPI2);
Driver ConfigurationFor a device family, the drivers may be configurable. The Reference Implementation stores configuration options in a central file with the name RTE_Device.h. However, the configuration of the drivers itself is not part of the CMSIS-Driver specification.
Code ExampleThe following example code shows the usage of the SPI interface.
#include "cmsis_os.h"
void mySPI_Thread(void const *argument);
osThreadId tid_mySPI_Thread;
void mySPI_callback(uint32_t event)
{
switch (event)
{
osSignalSet(tid_mySPI_Thread, 0x01);
break;
__breakpoint(0);
break;
__breakpoint(0);
break;
}
}
const uint8_t testdata_out[8] = { 0, 1, 2, 3, 4, 5, 6, 7 };
uint8_t testdata_in [8];
void mySPI_Thread(void const* arg)
{
osEvent evt;
#ifdef DEBUG
if(version.
api< 0x200)
{
return;
}
{
return;
}
#endif
while (1)
{
SPIdrv->
Send(testdata_out,
sizeof(testdata_out));
evt = osSignalWait(0x01, 100);
if (evt.status == osEventTimeout) {
__breakpoint(0);
}
evt = osSignalWait(0x01, 100);
if (evt.status == osEventTimeout) {
__breakpoint(0);
}
}
}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4