arm_cm0.c 2.1 KB

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