CMSIS-like headers for sensors and peripherals

In one of our previous blog posts, we explained how arm standardized core modules access by implementing CMSIS not only for the core components but also for the micro-controller peripherals.

At Andustria, we are using this approach not only for micro-controllers but also for sensors and connected peripherals like transceivers or memory modules that are configurable and accessed via internal registers. The concept is simple enough, we have defines for each field in each register with the available options. As an example, we are using the AT86RF215 transceiver from Microchip which is controlled via its internal registers. To follow the CMSIS rules, we have defined each register and its fields like this: 

#define REGISTER                      // the register address
#define REGISTER_FIELD_OPTION_Pos     // the bit or field starting position 
#define REGISTER_FIELD_OPTION_Msk     // the bit of field mask 
#define REGISTER_FIELD_OPTION         // a more user friendly name for the bit or field

For example, on page 39 we can find the bit contents of the BBCn_IRQM register, so we define the registers and the bits like so: 

/******************  Address definition for BBC0_IRQM register  ********************/
#define BBC0_IRQM			0x0300

/******************  Bit definition for BBC0_IRQM register  ********************/
#define BBC0_IRQM_RXFS_Pos		(0U)
#define BBC0_IRQM_RXFS_Msk		(0x1U << BBC0_IRQM_RXFS_Pos)
#define BBC0_IRQM_RXFS			BBC0_IRQM_RXFS_Msk
#define BBC0_IRQM_RXFE_Pos		(1U)
#define BBC0_IRQM_RXFE_Msk		(0x1U << BBC0_IRQM_RXFE_Pos)
#define BBC0_IRQM_RXFE			BBC0_IRQM_RXFE_Msk
#define BBC0_IRQM_RXAM_Pos		(2U)
#define BBC0_IRQM_RXAM_Msk		(0x1U << BBC0_IRQM_RXAM_Pos)
#define BBC0_IRQM_RXAM			BBC0_IRQM_RXAM_Msk
#define BBC0_IRQM_RXEM_Pos		(3U)
#define BBC0_IRQM_RXEM_Msk		(0x1U << BBC0_IRQM_RXEM_Pos)
#define BBC0_IRQM_RXEM			BBC0_IRQM_RXEM_Msk
#define BBC0_IRQM_TXFE_Pos		(4U)
#define BBC0_IRQM_TXFE_Msk		(0x1U << BBC0_IRQM_TXFE_Pos)
#define BBC0_IRQM_TXFE			BBC0_IRQM_TXFE_Msk
#define BBC0_IRQM_AGCH_Pos		(5U)
#define BBC0_IRQM_AGCH_Msk		(0x1U << BBC0_IRQM_AGCH_Pos)
#define BBC0_IRQM_AGCH			BBC0_IRQM_AGCH_Msk
#define BBC0_IRQM_AGCR_Pos		(6U)
#define BBC0_IRQM_AGCR_Msk		(0x1U << BBC0_IRQM_AGCR_Pos)
#define BBC0_IRQM_AGCR			BBC0_IRQM_AGCR_Msk
#define BBC0_IRQM_FBLI_Pos		(7U)
#define BBC0_IRQM_FBLI_Msk		(0x1U << BBC0_IRQM_FBLI_Pos)
#define BBC0_IRQM_FBLI			BBC0_IRQM_FBLI_Msk

Datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-42415-WIRELESS-AT86RF215_Datasheet.pdf

Another example is the register bit and field definitions for the ams CCS811 gas sensor. On page 18 in datasheet, we can find the register bit and field definitions for the STATUS register. The defines for this register look as follows:

/******************  Address definition for STATUS register  ********************/
#define STATUS				0x00

/******************  Bit definition for STATUS register  ********************/
#define STATUS_ERROR_Pos		(0U)
#define STATUS_ERROR_Msk		(0x1U << STATUS_ERROR_Pos)
#define STATUS_ERROR			STATUS_ERROR_Msk
#define STATUS_DATA_READY_Pos		(3U)
#define STATUS_DATA_READY_Msk		(0x1U << STATUS_DATA_READY_Pos)
#define STATUS_DATA_READY		STATUS_DATA_READY_Msk
#define STATUS_APP_VALID_Pos		(4U)
#define STATUS_APP_VALID_Msk		(0x1U << STATUS_APP_VALID_Pos)
#define STATUS_APP_VALID		STATUS_APP_VALID_Msk
#define STATUS_APP_VERIFY_Pos		(5U)
#define STATUS_APP_VERIFY_Msk		(0x1U << STATUS_APP_VERIFY_Pos)
#define STATUS_APP_VERIFY		STATUS_APP_VERIFY_Msk
#define STATUS_APP_ERASE_Pos		(6U)
#define STATUS_APP_ERASE_Msk		(0x1U << STATUS_APP_ERASE_Pos)
#define STATUS_APP_ERASE		STATUS_APP_ERASE_Msk
#define STATUS_FW_MODE_Pos		(7U)
#define STATUS_FW_MODE_Msk		(0x1U << STATUS_FW_MODE_Pos)
#define STATUS_FW_MODE			STATUS_FW_MODE_Msk

Datasheet: https://ams.com/documents/20143/36005/CCS811_DS000459_7-00.pdf

This way we can have a standardized approach for register bits and fields not only for the micro-controllers, but also for the connected peripherals.

You may also like...

Popular Posts

Leave a Reply