1 /******************************************************************************
2 * @brief provide generic high-level routines for ARM Cortex M0/M0+ processors.
3 *
4 *******************************************************************************/
5 
6 #include "common.h"
7 
8 /***********************************************************************/
9 /*
10  * Configures the ARM system control register for STOP (deep sleep) mode
11  * and then executes the WFI instruction to enter the mode.
12  *
13  * Parameters:
14  * none
15  *
16  * Note: Might want to change this later to allow for passing in a parameter
17  *       to optionally set the sleep on exit bit.
18  */
19 
stop(void)20 void stop (void)
21 {
22 	/* Set the SLEEPDEEP bit to enable deep sleep mode (STOP) */
23 	SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
24 
25 	/* WFI instruction will start entry into STOP mode */
26 #ifndef KEIL
27         // If not using KEIL's uVision use the standard assembly command
28 	asm("WFI");
29 #else
30         // If using KEIL's uVision, use the CMSIS intrinsic
31 	__wfi();
32 #endif
33 }
34 /***********************************************************************/
35 /*
36  * Configures the ARM system control register for WAIT (sleep) mode
37  * and then executes the WFI instruction to enter the mode.
38  *
39  * Parameters:
40  * none
41  *
42  * Note: Might want to change this later to allow for passing in a parameter
43  *       to optionally set the sleep on exit bit.
44  */
45 
wait(void)46 void wait (void)
47 {
48 	/* Clear the SLEEPDEEP bit to make sure we go into WAIT (sleep) mode instead
49 	 * of deep sleep.
50 	 */
51 	SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
52 
53 	/* WFI instruction will start entry into WAIT mode */
54 #ifndef KEIL
55         // If not using KEIL's uVision use the standard assembly command
56 	asm("WFI");
57 #else
58         // If using KEIL's uVision, use the CMSIS intrinsic
59     __wfi();
60 #endif
61 }
62 /***********************************************************************/
63 /*
64  * Change the value of the vector table offset register to the specified value.
65  *
66  * Parameters:
67  * vtor     new value to write to the VTOR
68  */
69 
write_vtor(int vtor)70 void write_vtor (int vtor)
71 {
72         /* Write the VTOR with the new value */
73         SCB->VTOR = vtor;
74 }
75 
76 /***********************************************************************/
77 
78