cpu_c.c
上传用户:yj_qqy
上传日期:2017-01-28
资源大小:2911k
文件大小:28k
源码类别:

uCOS

开发平台:

C/C++

  1. /*
  2. *********************************************************************************************************
  3. *                                               uC/CPU
  4. *                                    CPU CONFIGURATION & PORT LAYER
  5. *
  6. *                          (c) Copyright 2004-2008; Micrium, Inc.; Weston, FL
  7. *
  8. *               All rights reserved.  Protected by international copyright laws.
  9. *
  10. *               uC/CPU is provided in source form for FREE evaluation, for educational
  11. *               use or peaceful research.  If you plan on using uC/CPU in a commercial
  12. *               product you need to contact Micrium to properly license its use in your
  13. *               product.  We provide ALL the source code for your convenience and to
  14. *               help you experience uC/CPU.  The fact that the source code is provided
  15. *               does NOT mean that you can use it without paying a licensing fee.
  16. *
  17. *               Knowledge of the source code may NOT be used to develop a similar product.
  18. *
  19. *               Please help us continue to provide the Embedded community with the finest
  20. *               software available.  Your honesty is greatly appreciated.
  21. *********************************************************************************************************
  22. */
  23. /*
  24. *********************************************************************************************************
  25. *
  26. *                                            CPU PORT FILE
  27. *
  28. *                                            ARM-Cortex-M3
  29. *                                      RealView Development Suite
  30. *                            RealView Microcontroller Development Kit (MDK)
  31. *                                       ARM Developer Suite (ADS)
  32. *                                            Keil uVision
  33. *
  34. * Filename      : cpu_c.c
  35. * Version       : V1.19
  36. * Programmer(s) : JJL
  37. *                 BAN
  38. *********************************************************************************************************
  39. */
  40. /*
  41. *********************************************************************************************************
  42. *                                              INCLUDE FILES
  43. *********************************************************************************************************
  44. */
  45. #include  <cpu.h>
  46. #include  <lib_def.h>
  47. /*
  48. *********************************************************************************************************
  49. *                                              LOCAL DEFINES
  50. *********************************************************************************************************
  51. */
  52. #define  CPU_INT_SRC_POS_MAX      ((((CPU_REG_NVIC_NVIC + 1) & 0x1F) * 32) + 1)
  53. #define  CPU_BIT_BAND_SRAM_REG_LO       0x20000000
  54. #define  CPU_BIT_BAND_SRAM_REG_HI       0x200FFFFF
  55. #define  CPU_BIT_BAND_SRAM_BASE         0x22000000
  56. #define  CPU_BIT_BAND_PERIPH_REG_LO     0x40000000
  57. #define  CPU_BIT_BAND_PERIPH_REG_HI     0x400FFFFF
  58. #define  CPU_BIT_BAND_PERIPH_BASE       0x42000000
  59. /*
  60. *********************************************************************************************************
  61. *                                             LOCAL CONSTANTS
  62. *********************************************************************************************************
  63. */
  64. /*
  65. *********************************************************************************************************
  66. *                                            LOCAL DATA TYPES
  67. *********************************************************************************************************
  68. */
  69. /*
  70. *********************************************************************************************************
  71. *                                              LOCAL TABLES
  72. *********************************************************************************************************
  73. */
  74. /*
  75. *********************************************************************************************************
  76. *                                         LOCAL GLOBAL VARIABLES
  77. *********************************************************************************************************
  78. */
  79. /*
  80. *********************************************************************************************************
  81. *                                        LOCAL FUNCTION PROTOTYPES
  82. *********************************************************************************************************
  83. */
  84. /*
  85. *********************************************************************************************************
  86. *                                       LOCAL CONFIGURATION ERRORS
  87. *********************************************************************************************************
  88. */
  89. /*
  90. *********************************************************************************************************
  91. *                                           CPU_BitBandClr()
  92. *
  93. * Description : Clear bit in bit-band region.
  94. *
  95. * Argument(s) : addr            Byte address in memory space.
  96. *
  97. *               bit_nbr         Bit number in byte.
  98. *
  99. * Return(s)   : none.
  100. *
  101. * Caller(s)   : Application.
  102. *
  103. * Note(s)     : none.
  104. *********************************************************************************************************
  105. */
  106. void  CPU_BitBandClr (CPU_ADDR    addr,
  107.                       CPU_INT08U  bit_nbr)
  108. {
  109.     CPU_ADDR  bit_word_off;
  110.     CPU_ADDR  bit_word_addr;
  111.     if ((addr >= CPU_BIT_BAND_SRAM_REG_LO) &&
  112.         (addr <= CPU_BIT_BAND_SRAM_REG_HI)) {
  113.         bit_word_off  = ((addr - CPU_BIT_BAND_SRAM_REG_LO) * 32) + (bit_nbr * 4);
  114.         bit_word_addr = CPU_BIT_BAND_SRAM_BASE + bit_word_off;
  115.        *(volatile CPU_INT32U *)(bit_word_addr) = 0;
  116.     } else if ((addr >= CPU_BIT_BAND_PERIPH_REG_LO) &&
  117.                (addr <= CPU_BIT_BAND_PERIPH_REG_HI)) {
  118.         bit_word_off  = ((addr - CPU_BIT_BAND_PERIPH_REG_LO) * 32) + (bit_nbr * 4);
  119.         bit_word_addr = CPU_BIT_BAND_PERIPH_BASE + bit_word_off;
  120.        *(volatile CPU_INT32U *)(bit_word_addr) = 0;
  121.     }
  122. }
  123. /*
  124. *********************************************************************************************************
  125. *                                           CPU_BitBandClr()
  126. *
  127. * Description : Set bit in bit-band region.
  128. *
  129. * Argument(s) : addr            Byte address in memory space.
  130. *
  131. *               bit_nbr         Bit number in byte.
  132. *
  133. * Return(s)   : none.
  134. *
  135. * Caller(s)   : Application.
  136. *
  137. * Note(s)     : none.
  138. *********************************************************************************************************
  139. */
  140. void  CPU_BitBandSet (CPU_ADDR    addr,
  141.                       CPU_INT08U  bit_nbr)
  142. {
  143.     CPU_ADDR  bit_word_off;
  144.     CPU_ADDR  bit_word_addr;
  145.     if ((addr >= CPU_BIT_BAND_SRAM_REG_LO) &&
  146.         (addr <= CPU_BIT_BAND_SRAM_REG_HI)) {
  147.         bit_word_off  = ((addr - CPU_BIT_BAND_SRAM_REG_LO) * 32) + (bit_nbr * 4);
  148.         bit_word_addr = CPU_BIT_BAND_SRAM_BASE + bit_word_off;
  149.        *(volatile CPU_INT32U *)(bit_word_addr) = 1;
  150.     } else if ((addr >= CPU_BIT_BAND_PERIPH_REG_LO) &&
  151.                (addr <= CPU_BIT_BAND_PERIPH_REG_HI)) {
  152.         bit_word_off  = ((addr - CPU_BIT_BAND_PERIPH_REG_LO) * 32) + (bit_nbr * 4);
  153.         bit_word_addr = CPU_BIT_BAND_PERIPH_BASE + bit_word_off;
  154.        *(volatile CPU_INT32U *)(bit_word_addr) = 1;
  155.     }
  156. }
  157. /*
  158. *********************************************************************************************************
  159. *                                           CPU_IntSrcDis()
  160. *
  161. * Description : Disable an interrupt source.
  162. *
  163. * Argument(s) : pos     Position of interrupt vector in interrupt table :
  164. *
  165. *                           0       Invalid (see Note #1a).
  166. *                           1       Invalid (see Note #1b).
  167. *                           2       Non-maskable interrupt.
  168. *                           3       Hard Fault.
  169. *                           4       Memory Management.
  170. *                           5       Bus Fault.
  171. *                           6       Usage Fault.
  172. *                           7-10    Reserved.
  173. *                           11      SVCall
  174. *                           12      Debug monitor.
  175. *                           13      Reserved
  176. *                           14      PendSV.
  177. *                           15      SysTick.
  178. *                           16+     External Interrupt.
  179. *
  180. * Return(s)   : none.
  181. *
  182. * Caller(s)   : Application.
  183. *
  184. * Note(s)     : (1) Several table positions do not contain interrupt sources :
  185. *
  186. *                   (a) Position 0 contains the stack pointer.
  187. *                   (b) Positions 7-10, 13 are reserved.
  188. *
  189. *               (2) Several interrupts cannot be disabled/enabled :
  190. *
  191. *                   (a) Reset.
  192. *                   (b) NMI.
  193. *                   (c) Hard fault.
  194. *                   (d) SVCall.
  195. *                   (e) Debug monitor.
  196. *                   (f) PendSV.
  197. *
  198. *               (3) The maximum Cortex-M3 table position is 256.  A particular Cortex-M3 may have fewer
  199. *                   than 240 external exceptions and, consequently, fewer than 256 table positions.
  200. *                   This function assumes that the specified table position is valid if the interrupt
  201. *                   controller type register's INTLINESNUM field is large enough so that the position
  202. *                   COULD be valid.
  203. *********************************************************************************************************
  204. */
  205. void  CPU_IntSrcDis (CPU_INT08U  pos)
  206. {
  207. #if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
  208.     CPU_SR      cpu_sr;
  209. #endif
  210.     CPU_INT08U  group;
  211.     CPU_INT08U  pos_max;
  212.     CPU_INT08U  nbr;
  213.     switch (pos) {
  214.         case CPU_INT_STK_PTR:                                   /* ---------------- INVALID OR RESERVED --------------- */
  215.         case CPU_INT_RSVD_07:
  216.         case CPU_INT_RSVD_08:
  217.         case CPU_INT_RSVD_09:
  218.         case CPU_INT_RSVD_10:
  219.         case CPU_INT_RSVD_13:
  220.              break;
  221.                                                                 /* ----------------- SYSTEM EXCEPTIONS ---------------- */
  222.         case CPU_INT_RESET:                                     /* Reset (see Note #2).                                 */
  223.         case CPU_INT_NMI:                                       /* Non-maskable interrupt (see Note #2).                */
  224.         case CPU_INT_HFAULT:                                    /* Hard fault (see Note #2).                            */
  225.         case CPU_INT_SVCALL:                                    /* SVCall (see Note #2).                                */
  226.         case CPU_INT_DBGMON:                                    /* Debug monitor (see Note #2).                         */
  227.         case CPU_INT_PENDSV:                                    /* PendSV (see Note #2).                                */
  228.              break;
  229.         case CPU_INT_MEM:                                       /* Memory management.                                   */
  230.              CPU_CRITICAL_ENTER();
  231.              CPU_REG_NVIC_SHCSR &= ~CPU_REG_NVIC_SHCSR_MEMFAULTENA;
  232.              CPU_CRITICAL_EXIT();
  233.              break;
  234.         case CPU_INT_BUSFAULT:                                  /* Bus fault.                                           */
  235.              CPU_CRITICAL_ENTER();
  236.              CPU_REG_NVIC_SHCSR &= ~CPU_REG_NVIC_SHCSR_BUSFAULTENA;
  237.              CPU_CRITICAL_EXIT();
  238.              break;
  239.         case CPU_INT_USAGEFAULT:                                /* Usage fault.                                         */
  240.              CPU_CRITICAL_ENTER();
  241.              CPU_REG_NVIC_SHCSR &= ~CPU_REG_NVIC_SHCSR_USGFAULTENA;
  242.              CPU_CRITICAL_EXIT();
  243.              break;
  244.         case CPU_INT_SYSTICK:                                   /* SysTick.                                             */
  245.              CPU_CRITICAL_ENTER();
  246.              CPU_REG_NVIC_ST_CTRL &= ~CPU_REG_NVIC_ST_CTRL_ENABLE;
  247.              CPU_CRITICAL_EXIT();
  248.              break;
  249.                                                                 /* ---------------- EXTERNAL INTERRUPT ---------------- */
  250.         default:
  251.             pos_max = CPU_INT_SRC_POS_MAX;
  252.             if (pos < pos_max) {                                /* See Note #3.                                         */
  253.                  group = (pos - 16) / 32;
  254.                  nbr   = (pos - 16) % 32;
  255.                  CPU_CRITICAL_ENTER();
  256.                  CPU_REG_NVIC_CLREN(group) = DEF_BIT(nbr);
  257.                  CPU_CRITICAL_EXIT();
  258.              }
  259.              break;
  260.     }
  261. }
  262. /*
  263. *********************************************************************************************************
  264. *                                           CPU_IntSrcEn()
  265. *
  266. * Description : Enable an interrupt source.
  267. *
  268. * Argument(s) : pos     Position of interrupt vector in interrupt table (see 'CPU_IntSrcDis()').
  269. *
  270. * Return(s)   : none.
  271. *
  272. * Caller(s)   : Application.
  273. *
  274. * Note(s)     : (1) See 'CPU_IntSrcDis() Note #1'.
  275. *
  276. *               (2) See 'CPU_IntSrcDis() Note #2'.
  277. *
  278. *               (3) See 'CPU_IntSrcDis() Note #3'.
  279. *********************************************************************************************************
  280. */
  281. void  CPU_IntSrcEn (CPU_INT08U  pos)
  282. {
  283. #if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
  284.     CPU_SR      cpu_sr;
  285. #endif
  286.     CPU_INT08U  group;
  287.     CPU_INT08U  nbr;
  288.     CPU_INT08U  pos_max;
  289.     switch (pos) {
  290.         case CPU_INT_STK_PTR:                                   /* ---------------- INVALID OR RESERVED --------------- */
  291.         case CPU_INT_RSVD_07:
  292.         case CPU_INT_RSVD_08:
  293.         case CPU_INT_RSVD_09:
  294.         case CPU_INT_RSVD_10:
  295.         case CPU_INT_RSVD_13:
  296.              break;
  297.                                                                 /* ----------------- SYSTEM EXCEPTIONS ---------------- */
  298.         case CPU_INT_RESET:                                     /* Reset (see Note #2).                                 */
  299.         case CPU_INT_NMI:                                       /* Non-maskable interrupt (see Note #2).                */
  300.         case CPU_INT_HFAULT:                                    /* Hard fault (see Note #2).                            */
  301.         case CPU_INT_SVCALL:                                    /* SVCall (see Note #2).                                */
  302.         case CPU_INT_DBGMON:                                    /* Debug monitor (see Note #2).                         */
  303.         case CPU_INT_PENDSV:                                    /* PendSV (see Note #2).                                */
  304.              break;
  305.         case CPU_INT_MEM:                                       /* Memory management.                                   */
  306.              CPU_CRITICAL_ENTER();
  307.              CPU_REG_NVIC_SHCSR |= CPU_REG_NVIC_SHCSR_MEMFAULTENA;
  308.              CPU_CRITICAL_EXIT();
  309.              break;
  310.         case CPU_INT_BUSFAULT:                                  /* Bus fault.                                           */
  311.              CPU_CRITICAL_ENTER();
  312.              CPU_REG_NVIC_SHCSR |= CPU_REG_NVIC_SHCSR_BUSFAULTENA;
  313.              CPU_CRITICAL_EXIT();
  314.              break;
  315.         case CPU_INT_USAGEFAULT:                                /* Usage fault.                                         */
  316.              CPU_CRITICAL_ENTER();
  317.              CPU_REG_NVIC_SHCSR |= CPU_REG_NVIC_SHCSR_USGFAULTENA;
  318.              CPU_CRITICAL_EXIT();
  319.              break;
  320.         case CPU_INT_SYSTICK:                                   /* SysTick.                                             */
  321.              CPU_CRITICAL_ENTER();
  322.              CPU_REG_NVIC_ST_CTRL |= CPU_REG_NVIC_ST_CTRL_ENABLE;
  323.              CPU_CRITICAL_EXIT();
  324.              break;
  325.                                                                 /* ---------------- EXTERNAL INTERRUPT ---------------- */
  326.         default:
  327.             pos_max = CPU_INT_SRC_POS_MAX;
  328.             if (pos < pos_max) {                                /* See Note #3.                                         */
  329.                  group = (pos - 16) / 32;
  330.                  nbr   = (pos - 16) % 32;
  331.                  CPU_CRITICAL_ENTER();
  332.                  CPU_REG_NVIC_SETEN(group) = DEF_BIT(nbr);
  333.                  CPU_CRITICAL_EXIT();
  334.              }
  335.              break;
  336.     }
  337. }
  338. /*
  339. *********************************************************************************************************
  340. *                                           CPU_IntSrcPrioSet()
  341. *
  342. * Description : Set priority of an interrupt source.
  343. *
  344. * Argument(s) : pos     Position of interrupt vector in interrupt table (see 'CPU_IntSrcDis()').
  345. *
  346. *               prio    Priority.  Use a lower priority number for a higher priority.
  347. *
  348. * Return(s)   : none.
  349. *
  350. * Caller(s)   : Application.
  351. *
  352. * Note(s)     : (1) See 'CPU_IntSrcDis() Note #1'.
  353. *
  354. *               (2) Several interrupts priorities CANNOT be set :
  355. *
  356. *                   (a) Reset (always -3).
  357. *                   (b) NMI (always -2).
  358. *                   (c) Hard fault (always -1).
  359. *
  360. *               (3) See 'CPU_IntSrcDis() Note #3'.
  361. *********************************************************************************************************
  362. */
  363. void  CPU_IntSrcPrioSet (CPU_INT08U  pos,
  364.                          CPU_INT08U  prio)
  365. {
  366. #if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
  367.     CPU_SR      cpu_sr;
  368. #endif
  369.     CPU_INT08U  group;
  370.     CPU_INT08U  nbr;
  371.     CPU_INT08U  pos_max;
  372.     CPU_INT32U  prio_32;
  373.     CPU_INT32U  temp;
  374.     prio_32 = CPU_RevBits((CPU_INT08U)prio);
  375.     prio    = (CPU_INT08U)(prio_32 >> (3 * DEF_OCTET_NBR_BITS));
  376.     switch (pos) {
  377.         case CPU_INT_STK_PTR:                                   /* ---------------- INVALID OR RESERVED --------------- */
  378.         case CPU_INT_RSVD_07:
  379.         case CPU_INT_RSVD_08:
  380.         case CPU_INT_RSVD_09:
  381.         case CPU_INT_RSVD_10:
  382.         case CPU_INT_RSVD_13:
  383.              break;
  384.                                                                 /* ----------------- SYSTEM EXCEPTIONS ---------------- */
  385.         case CPU_INT_RESET:                                     /* Reset (see Note #2).                                 */
  386.         case CPU_INT_NMI:                                       /* Non-maskable interrupt (see Note #2).                */
  387.         case CPU_INT_HFAULT:                                    /* Hard fault (see Note #2).                            */
  388.              break;
  389.         case CPU_INT_MEM:                                       /* Memory management.                                   */
  390.              CPU_CRITICAL_ENTER();
  391.              temp                 = CPU_REG_NVIC_SHPRI1;
  392.              temp                &= ~(DEF_OCTET_MASK << (0 * DEF_OCTET_NBR_BITS));
  393.              temp                |=  (prio           << (0 * DEF_OCTET_NBR_BITS));
  394.              CPU_REG_NVIC_SHPRI1  = temp;
  395.              CPU_CRITICAL_EXIT();
  396.              break;
  397.         case CPU_INT_BUSFAULT:                                  /* Bus fault.                                           */
  398.              CPU_CRITICAL_ENTER();
  399.              temp                 = CPU_REG_NVIC_SHPRI1;
  400.              temp                &= ~(DEF_OCTET_MASK << (1 * DEF_OCTET_NBR_BITS));
  401.              temp                |=  (prio           << (1 * DEF_OCTET_NBR_BITS));
  402.              CPU_REG_NVIC_SHPRI1  = temp;
  403.              CPU_CRITICAL_EXIT();
  404.              break;
  405.         case CPU_INT_USAGEFAULT:                                /* Usage fault.                                         */
  406.              CPU_CRITICAL_ENTER();
  407.              temp                 = CPU_REG_NVIC_SHPRI1;
  408.              temp                &= ~(DEF_OCTET_MASK << (2 * DEF_OCTET_NBR_BITS));
  409.              temp                |=  (prio           << (2 * DEF_OCTET_NBR_BITS));
  410.              CPU_REG_NVIC_SHPRI1  = temp;
  411.              CPU_CRITICAL_EXIT();
  412.              break;
  413.         case CPU_INT_SVCALL:                                    /* SVCall.                                              */
  414.              CPU_CRITICAL_ENTER();
  415.              temp                 = CPU_REG_NVIC_SHPRI2;
  416.              temp                &= ~((CPU_INT32U)DEF_OCTET_MASK << (3 * DEF_OCTET_NBR_BITS));
  417.              temp                |=  (prio                       << (3 * DEF_OCTET_NBR_BITS));
  418.              CPU_REG_NVIC_SHPRI2  = temp;
  419.              CPU_CRITICAL_EXIT();
  420.              break;
  421.         case CPU_INT_DBGMON:                                    /* Debug monitor.                                       */
  422.              CPU_CRITICAL_ENTER();
  423.              temp                = CPU_REG_NVIC_SHPRI3;
  424.              temp                &= ~(DEF_OCTET_MASK << (0 * DEF_OCTET_NBR_BITS));
  425.              temp                |=  (prio           << (0 * DEF_OCTET_NBR_BITS));
  426.              CPU_REG_NVIC_SHPRI3  = temp;
  427.              CPU_CRITICAL_EXIT();
  428.              break;
  429.         case CPU_INT_PENDSV:                                    /* PendSV.                                              */
  430.              CPU_CRITICAL_ENTER();
  431.              temp                 = CPU_REG_NVIC_SHPRI3;
  432.              temp                &= ~(DEF_OCTET_MASK << (2 * DEF_OCTET_NBR_BITS));
  433.              temp                |=  (prio           << (2 * DEF_OCTET_NBR_BITS));
  434.              CPU_REG_NVIC_SHPRI3  = temp;
  435.              CPU_CRITICAL_EXIT();
  436.              break;
  437.         case CPU_INT_SYSTICK:                                   /* SysTick.                                             */
  438.              CPU_CRITICAL_ENTER();
  439.              temp                 = CPU_REG_NVIC_SHPRI3;
  440.              temp                &= ~((CPU_INT32U)DEF_OCTET_MASK << (3 * DEF_OCTET_NBR_BITS));
  441.              temp                |=  (prio                       << (3 * DEF_OCTET_NBR_BITS));
  442.              CPU_REG_NVIC_SHPRI3  = temp;
  443.              CPU_CRITICAL_EXIT();
  444.              break;
  445.                                                                 /* ---------------- EXTERNAL INTERRUPT ---------------- */
  446.         default:
  447.             pos_max = CPU_INT_SRC_POS_MAX;
  448.             if (pos < pos_max) {                                /* See Note #3.                                         */
  449.                  group                    = (pos - 16) / 4;
  450.                  nbr                      = (pos - 16) % 4;
  451.                  CPU_CRITICAL_ENTER();
  452.                  temp                     = CPU_REG_NVIC_PRIO(group);
  453.                  temp                    &= ~(DEF_OCTET_MASK << (nbr * DEF_OCTET_NBR_BITS));
  454.                  temp                    |=  (prio           << (nbr * DEF_OCTET_NBR_BITS));
  455.                  CPU_REG_NVIC_PRIO(group) = temp;
  456.                  CPU_CRITICAL_EXIT();
  457.              }
  458.              break;
  459.     }
  460. }
  461. /*
  462. *********************************************************************************************************
  463. *                                           CPU_IntSrcPrioGet()
  464. *
  465. * Description : Get priority of an interrupt source.
  466. *
  467. * Argument(s) : pos     Position of interrupt vector in interrupt table (see 'CPU_IntSrcDis()').
  468. *
  469. * Return(s)   : Priority of interrupt source.  If the interrupt source specified is invalid, then
  470. *               DEF_INT_16S_MIN_VAL is returned.
  471. *
  472. * Caller(s)   : Application.
  473. *
  474. * Note(s)     : (1) See 'CPU_IntSrcDis() Note #1'.
  475. *
  476. *               (2) See 'CPU_IntSrcPrioSet() Note #2'.
  477. *
  478. *               (3) See 'CPU_IntSrcDis() Note #3'.
  479. *********************************************************************************************************
  480. */
  481. CPU_INT16S  CPU_IntSrcPrioGet (CPU_INT08U  pos)
  482. {
  483. #if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
  484.     CPU_SR      cpu_sr;
  485. #endif
  486.     CPU_INT08U  group;
  487.     CPU_INT08U  nbr;
  488.     CPU_INT08U  pos_max;
  489.     CPU_INT16S  prio;
  490.     CPU_INT32U  prio_32;
  491.     CPU_INT32U  temp;
  492.     switch (pos) {
  493.         case CPU_INT_STK_PTR:                                   /* ---------------- INVALID OR RESERVED --------------- */
  494.         case CPU_INT_RSVD_07:
  495.         case CPU_INT_RSVD_08:
  496.         case CPU_INT_RSVD_09:
  497.         case CPU_INT_RSVD_10:
  498.         case CPU_INT_RSVD_13:
  499.              prio = DEF_INT_16S_MIN_VAL;
  500.              break;
  501.                                                                 /* ----------------- SYSTEM EXCEPTIONS ---------------- */
  502.         case CPU_INT_RESET:                                     /* Reset (see Note #2).                                 */
  503.              prio = -3;
  504.              break;
  505.         case CPU_INT_NMI:                                       /* Non-maskable interrupt (see Note #2).                */
  506.              prio = -2;
  507.              break;
  508.         case CPU_INT_HFAULT:                                    /* Hard fault (see Note #2).                            */
  509.              prio = -1;
  510.              break;
  511.         case CPU_INT_MEM:                                       /* Memory management.                                   */
  512.              CPU_CRITICAL_ENTER();
  513.              temp = CPU_REG_NVIC_SHPRI1;
  514.              prio = (temp >> (0 * DEF_OCTET_NBR_BITS)) & DEF_OCTET_MASK;
  515.              CPU_CRITICAL_EXIT();
  516.              break;
  517.         case CPU_INT_BUSFAULT:                                  /* Bus fault.                                           */
  518.              CPU_CRITICAL_ENTER();
  519.              temp = CPU_REG_NVIC_SHPRI1;
  520.              prio = (temp >> (1 * DEF_OCTET_NBR_BITS)) & DEF_OCTET_MASK;
  521.              CPU_CRITICAL_EXIT();
  522.              break;
  523.         case CPU_INT_USAGEFAULT:                                /* Usage fault.                                         */
  524.              CPU_CRITICAL_ENTER();
  525.              temp = CPU_REG_NVIC_SHPRI1;
  526.              prio = (temp >> (2 * DEF_OCTET_NBR_BITS)) & DEF_OCTET_MASK;
  527.              break;
  528.         case CPU_INT_SVCALL:                                    /* SVCall.                                              */
  529.              CPU_CRITICAL_ENTER();
  530.              temp = CPU_REG_NVIC_SHPRI2;
  531.              prio = (temp >> (3 * DEF_OCTET_NBR_BITS)) & DEF_OCTET_MASK;
  532.              CPU_CRITICAL_EXIT();
  533.              break;
  534.         case CPU_INT_DBGMON:                                    /* Debug monitor.                                       */
  535.              CPU_CRITICAL_ENTER();
  536.              temp = CPU_REG_NVIC_SHPRI3;
  537.              prio = (temp >> (0 * DEF_OCTET_NBR_BITS)) & DEF_OCTET_MASK;
  538.              CPU_CRITICAL_EXIT();
  539.              break;
  540.         case CPU_INT_PENDSV:                                    /* PendSV.                                              */
  541.              CPU_CRITICAL_ENTER();
  542.              temp = CPU_REG_NVIC_SHPRI3;
  543.              prio = (temp >> (2 * DEF_OCTET_NBR_BITS)) & DEF_OCTET_MASK;
  544.              CPU_CRITICAL_EXIT();
  545.              break;
  546.         case CPU_INT_SYSTICK:                                   /* SysTick.                                             */
  547.              CPU_CRITICAL_ENTER();
  548.              temp = CPU_REG_NVIC_SHPRI3;
  549.              prio = (temp >> (3 * DEF_OCTET_NBR_BITS)) & DEF_OCTET_MASK;
  550.              CPU_CRITICAL_EXIT();
  551.              break;
  552.                                                                 /* ---------------- EXTERNAL INTERRUPT ---------------- */
  553.         default:
  554.             pos_max = CPU_INT_SRC_POS_MAX;
  555.             if (pos < pos_max) {                                /* See Note #3.                                         */
  556.                  group = (pos - 16) / 4;
  557.                  nbr   = (pos - 16) % 4;
  558.                  CPU_CRITICAL_ENTER();
  559.                  temp  = CPU_REG_NVIC_PRIO(group);
  560.                  CPU_CRITICAL_EXIT();
  561.                  prio  = (temp >> (nbr * DEF_OCTET_NBR_BITS)) & DEF_OCTET_MASK;
  562.              } else {
  563.                  prio  = DEF_INT_16S_MIN_VAL;
  564.              }
  565.              break;
  566.     }
  567.     if (prio >= 0) {
  568.         prio_32 = CPU_RevBits((CPU_INT32U)prio);
  569.         prio    = (CPU_INT16S)(prio_32 >> (3 * DEF_OCTET_NBR_BITS));
  570.     }
  571.     return (prio);
  572. }