CMSIS-Core (Cortex-A)  
CMSIS-Core support for Cortex-A processor-based devices
 
Loading...
Searching...
No Matches
Basic CMSIS Example

A typical example for using the CMSIS layer is provided below. The example is based on an unspecific Cortex-A9 Device.

#include <ARMCA9.h> // File name depends on device used
static const uint32_t TICK_RATE_HZ = 1000U;
uint32_t volatile msTicks; // Counter for millisecond Interval
static void SysTick_Handler( void )
{
msTicks++; // Increment Counter
}
// We use the Private Tiemer (PTIM) of the Cortex-A9 FVP Model here.
// In general the available Timers are highly vendor specific for Cortex-A processors.
void private_timer_init(void) {
PTIM_SetLoadValue ((SystemCoreClock/TICK_RATE_HZ) - 1U);
/* Install SysTick_Handler as the interrupt function for PTIM */
IRQ_SetHandler((IRQn_ID_t)PrivTimer_IRQn, SysTick_Handler);
/* Determine number of implemented priority bits */
/* Set lowest priority -1 */
IRQ_SetPriority ((IRQn_ID_t)PrivTimer_IRQn, GIC_GetPriority((IRQn_ID_t)PrivTimer_IRQn)-1);
/* Enable IRQ */
IRQ_Enable ((IRQn_ID_t)PrivTimer_IRQn);
}
/* Delay execution for given amount of ticks */
void Delay(uint32_t ticks) {
uint32_t tgtTicks = msTicks + ticks; // target tick count to delay execution to
while (msTicks == tgtTicks) {
__WFE (); // Power-Down until next Event/Interrupt
}
}
/* main function */
int main(void)
{
/* Initialize device HAL here */
private_timer_init();
static uint8_t ledState = 0;
/* Infinite loop */
while (1)
{
/* Add application code here */
ledState = !ledState;
Delay(500);
}
}
#define __WFE
Wait For Event.
__STATIC_INLINE uint32_t GIC_GetPriority(IRQn_Type IRQn)
Read the current interrupt priority from GIC's IPRIORITYR register.
Definition: core_ca.h:1668
__STATIC_INLINE void PTIM_SetLoadValue(uint32_t value)
Set the load value to timers LOAD register.
Definition: core_ca.h:1949
__STATIC_INLINE uint32_t PTIM_GetControl(void)
Definition: core_ca.h:1988
__STATIC_INLINE void PTIM_SetControl(uint32_t value)
Configure the timer using its CONTROL register.
Definition: core_ca.h:1980
int32_t IRQ_Enable(IRQn_ID_t irqn)
Enable interrupt.
int32_t IRQ_SetPriority(IRQn_ID_t irqn, uint32_t priority)
Set interrupt priority value.
int32_t IRQ_SetHandler(IRQn_ID_t irqn, IRQHandler_t handler)
Register interrupt handler.
#define IRQ_PRIORITY_Msk
Interrupt priority value bit-mask.
uint32_t SystemCoreClock
Variable to hold the system core clock value.
Definition: Ref_SystemAndClock.txt:67
int32_t IRQn_ID_t
Interrupt ID number data type.
Definition: irq_ctrl.h:45

CMSIS-Pack provides the #define CMSIS_header_file in RTE_Components.h which gives you access to the device.h file of a project. This allows you to generate generic software components that use the device selected in a project.

#include "RTE_Components.h" // include information about project configuration
#include CMSIS_device_header // include <device>.h file