]> begriffs open source - cmsis/blob - CMSIS/DoxyGen/Core_A/src/Using.txt
Release preparation: Aligned version information and updated change histories.
[cmsis] / CMSIS / DoxyGen / Core_A / src / Using.txt
1 /** 
2 \page using_pg Using CMSIS in Embedded Applications
3
4
5 \details 
6
7 To use the CMSIS-Core-A the following files are added to the embedded application:
8  - \ref startup_c_pg with reset handler and exception vectors.
9  - \ref system_c_pg with general device configuration (i.e. for clock and bus setup).
10  - \ref device_h_pg gives access to processor core and all peripherals.
11  - \ref mem_h_pg contains basic memory configurations.
12  - \ref mmu_c_pg contains the memory management unit setup.
13  
14 \note The files \ref startup_c_pg, \ref system_c_pg, \ref mem_h_pg, and \ref mmu_c_pg may require application specific adaptations and therefore should be copied 
15       into the application project folder prior configuration. The \ref device_h_pg is included in all source files that need device access 
16       and can be stored on a central include folder that is generic for all projects.
17
18 The \ref Reset_Handler defined in \ref startup_c_pg is executed after reset. 
19 The default initialization sequence is
20  - set the vector base address register (\ref __set_VBAR),
21  - set stacks for each exception mode (\ref __set_mode, \ref __set_SP),
22  - call \ref SystemInit.
23
24 After the system initialization control is transferred to the C/C++ run-time
25 library which performs initialization and calls the \b main function in the user code. In addition the \ref startup_c_pg contains a weak default handler
26 implementation for every exception. It may also contain stack and heap configurations for the user application.
27
28 The \ref system_c_pg performs the setup for the processor clock and the initialization of memory caches, memory management unit, generic interrupt interface
29 and floating point unit. The variable \ref SystemCoreClock indicates the CPU clock speed.
30 \ref system_init_gr describes the minimum feature set. In addition the file may contain functions for the memory bus setup and clock re-configuration. 
31
32 The \ref device_h_pg is the central include file that the application programmer is using in the C/C++ source code. It provides the following features:
33  - \ref peripheral_gr provides a standardized register layout for all peripherals. Optionally functions for device-specific peripherals may be available.
34  - \ref GIC_functions can be accessed with standardized symbols and functions for the General Interrupt Controller (GIC) are provided.
35  - \ref CMSIS_Core_InstructionInterface allow to access special instructions, for example for activating sleep mode or the NOP instruction.
36  - \ref PL1_timer_functions "Generic" and \ref PTM_timer_functions "Private" Timer functions to configure and start a periodic timer interrupt.
37  - \ref L1_cache_functions "Level 1" and \ref L2_cache_functions "Level 2" Cache controller functions to enable, disable, clean and invalidate caches.
38
39 \image html "CMSIS_CORE_A_Files_user.png" "CMSIS-Core-A User Files"
40
41 The CMSIS-Core-A user files are device specific. In addition, the \ref startup_c_pg is also compiler vendor specific. 
42 The various compiler vendor tool chains may provide folders that contain the CMSIS files for each supported device.
43   
44 \note The silicon vendors create these device-specific CMSIS-Core-A files based on \ref templates_pg provide by ARM.
45
46 Thereafter, the functions described under <a href="Modules.html">\b Reference </a> can be used in the application.
47
48 \b Examples
49  - \subpage using_CMSIS is a simple example that shows the usage of the CMSIS layer.
50  - \subpage using_ARM_pg explains how to use CMSIS-Core-M for ARM processors.
51
52
53 \page using_CMSIS Basic CMSIS Example
54
55 A typical example for using the CMSIS layer is provided below. The example is based on an unspecific Cortex-A9 Device. 
56     
57 \code
58 #include <ARMCA9.h>                              // File name depends on device used
59  
60 static const uint32_t TICK_RATE_HZ = 1000U;
61  
62 uint32_t volatile msTicks;                       // Counter for millisecond Interval
63  
64 static void SysTick_Handler( void )
65 {
66   msTicks++;                                     // Increment Counter
67 }
68  
69 // We use the Private Tiemer (PTIM) of the Cortex-A9 FVP Model here.
70 // In general the available Timers are highly vendor specific for Cortex-A processors.
71 void private_timer_init(void) {
72  
73   PTIM_SetLoadValue ((SystemCoreClock/TICK_RATE_HZ) - 1U);
74   PTIM_SetControl (PTIM_GetControl() | 7U);
75
76   /* Install SysTick_Handler as the interrupt function for PTIM */
77   IRQ_SetHandler((IRQn_ID_t)PrivTimer_IRQn, SysTick_Handler);
78  
79   /* Determine number of implemented priority bits */
80   IRQ_SetPriority ((IRQn_ID_t)PrivTimer_IRQn, IRQ_PRIORITY_Msk);
81  
82   /* Set lowest priority -1 */
83   IRQ_SetPriority ((IRQn_ID_t)PrivTimer_IRQn, GIC_GetPriority((IRQn_ID_t)PrivTimer_IRQn)-1);
84  
85   /* Enable IRQ */
86   IRQ_Enable ((IRQn_ID_t)PrivTimer_IRQn);
87 }
88
89 /* Delay execution for given amount of ticks */
90 void Delay(uint32_t ticks)  {
91   uint32_t tgtTicks = msTicks + ticks;             // target tick count to delay execution to
92   while (msTicks == tgtTicks)  {
93     __WFE ();                                      // Power-Down until next Event/Interrupt
94   }
95 }
96  
97 /* main function */
98 int main(void)
99 {
100   /* Initialize device HAL here */
101   private_timer_init();
102  
103   static uint8_t ledState = 0;
104  
105   /* Infinite loop */
106   while (1)
107   {
108     /* Add application code here */
109     ledState = !ledState;
110     Delay(500);
111   }
112 }
113 \endcode
114     
115 \page using_ARM_pg Using CMSIS with generic ARM Processors
116
117 ARM provides CMSIS-Core-A files for the supported ARM Processors and for various compiler vendors. 
118 These files can be used when standard ARM processors should be used in a project.
119 The table below lists the folder and device names of the ARM processors.
120   
121 <table class="cmtable">
122   <tr>
123     <th>Folder</th>
124     <th>Processor</th>
125     <th>Description</th>
126   </tr>
127   <tr>
128     <td>".\Device\ARM\ARMCA5"</td>
129     <td>Cortex-A5</td>
130     <td>Contains \b Include and \b Source template files configured for the Cortex-A5 processor.
131         The device name is ARMCA5 and the name of the \ref device_h_pg is <ARMCA5.h>.
132     </td>
133   </tr>
134   <tr>
135     <td>".\Device\ARM\ARMCA7"</td>
136     <td>Cortex-A7</td>
137     <td>Contains \b Include and \b Source template files configured for the Cortex-A7 processor.
138         The device name is ARMCA7 and the name of the \ref device_h_pg is <ARMCA7.h>.
139     </td>
140   </tr>
141   <tr>
142     <td>".\Device\ARM\ARMCA9"</td>
143     <td>Cortex-A9</td>
144     <td>Contains \b Include and \b Source template files configured for the Cortex-A9 processor.
145         The device name is ARMCA9 and the name of the \ref device_h_pg is <ARMCA9.h>.
146     </td>
147   </tr>
148 </table>
149
150 */