Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rt_HAL_CA.h 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*----------------------------------------------------------------------------
  2. * RL-ARM - RTX
  3. *----------------------------------------------------------------------------
  4. * Name: RT_HAL_CM.H
  5. * Purpose: Hardware Abstraction Layer for Cortex-A definitions
  6. * Rev.: 21 Aug 2013
  7. *----------------------------------------------------------------------------
  8. *
  9. * Copyright (c) 1999-2009 KEIL, 2009-2013 ARM Germany GmbH
  10. * All rights reserved.
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. * - Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. * - Neither the name of ARM nor the names of its contributors may be used
  19. * to endorse or promote products derived from this software without
  20. * specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. *---------------------------------------------------------------------------*/
  34. /* Definitions */
  35. #define INIT_CPSR_SYS 0x4000001F
  36. #define INIT_CPSR_USER 0x40000010
  37. #define CPSR_T_BIT 0x20
  38. #define CPSR_I_BIT 0x80
  39. #define CPSR_F_BIT 0x40
  40. #define MODE_USR 0x10
  41. #define MODE_FIQ 0x11
  42. #define MODE_IRQ 0x12
  43. #define MODE_SVC 0x13
  44. #define MODE_ABT 0x17
  45. #define MODE_UND 0x1B
  46. #define MODE_SYS 0x1F
  47. #define MAGIC_WORD 0xE25A2EA5
  48. #include "core_ca9.h"
  49. #if defined (__CC_ARM) /* ARM Compiler */
  50. #if ((__TARGET_ARCH_7_M || __TARGET_ARCH_7E_M || __TARGET_ARCH_7_A) && !defined(NO_EXCLUSIVE_ACCESS))
  51. #define __USE_EXCLUSIVE_ACCESS
  52. #else
  53. #undef __USE_EXCLUSIVE_ACCESS
  54. #endif
  55. #elif defined (__GNUC__) /* GNU Compiler */
  56. #undef __USE_EXCLUSIVE_ACCESS
  57. #if defined (__VFP_FP__) && !defined(__SOFTFP__)
  58. #define __TARGET_FPU_VFP 1
  59. #else
  60. #define __TARGET_FPU_VFP 0
  61. #endif
  62. #define __inline inline
  63. #define __weak __attribute__((weak))
  64. #elif defined (__ICCARM__) /* IAR Compiler */
  65. #error IAR Compiler support not implemented for Cortex-A
  66. #endif
  67. static U8 priority = 0xff;
  68. extern const U32 GICDistributor_BASE;
  69. extern const U32 GICInterface_BASE;
  70. /* GIC registers - Distributor */
  71. #define GICD_ICDICER0 (*((volatile U32 *)(GICDistributor_BASE + 0x180))) /* - RW - Interrupt Clear-Enable Registers */
  72. #define GICD_ICDISER0 (*((volatile U32 *)(GICDistributor_BASE + 0x100))) /* - RW - Interrupt Set-Enable Registers */
  73. #define GICD_ICDIPR0 (*((volatile U32 *)(GICDistributor_BASE + 0x400))) /* - RW - Interrupt Priority Registers */
  74. #define GICD_ICDSGIR (*((volatile U32 *)(GICDistributor_BASE + 0xf00))) /* - RW - Interrupt Software Interrupt Register */
  75. #define GICD_ICDICERx(irq) *(volatile U32 *)(&GICD_ICDICER0 + irq/32)
  76. #define GICD_ICDISERx(irq) *(volatile U32 *)(&GICD_ICDISER0 + irq/32)
  77. /* GIC register - CPU Interface */
  78. #define GICI_ICCPMR (*((volatile U32 *)(GICInterface_BASE + 0x004))) /* - RW - Interrupt Priority Mask Register */
  79. #define SGI_PENDSV 0 /* SGI0 */
  80. #define SGI_PENDSV_BIT ((U32)(1 << (SGI_PENDSV & 0xf)))
  81. //Increase priority filter to prevent timer and PendSV interrupts signaling. Guarantees that interrupts will not be forwarded.
  82. #define OS_LOCK() int irq_dis = __disable_irq();\
  83. priority = GICI_ICCPMR; \
  84. GICI_ICCPMR = 0xff; \
  85. GICI_ICCPMR = GICI_ICCPMR - 1; \
  86. __DSB();\
  87. if(!irq_dis) __enable_irq(); \
  88. //Restore priority filter. Re-enable timer and PendSV signaling
  89. #define OS_UNLOCK() __DSB(); \
  90. GICI_ICCPMR = priority; \
  91. #define OS_PEND_IRQ() GICD_ICDSGIR = 0x0010000 | SGI_PENDSV
  92. #define OS_PEND(fl,p) if(p) OS_PEND_IRQ();
  93. #define OS_UNPEND(fl)
  94. /* HW initialization needs to be done in os_tick_init (void) -RTX_Conf_CM.c-
  95. * OS_X_INIT enables the IRQ n in the GIC */
  96. #define OS_X_INIT(n) volatile char *reg; \
  97. reg = (char *)(&GICD_ICDIPR0 + n / 4); \
  98. reg += n % 4; \
  99. *reg = (char)0xff; \
  100. *reg = *reg - 1; \
  101. GICD_ICDISERx(n) = (U32)(1 << n % 32);
  102. #define OS_X_LOCK(n) OS_LOCK()
  103. #define OS_X_UNLOCK(n) OS_UNLOCK()
  104. #define OS_X_PEND_IRQ() OS_PEND_IRQ()
  105. #define OS_X_PEND(fl,p) if(p) OS_X_PEND_IRQ();
  106. #define OS_X_UNPEND(fl)
  107. /* Functions */
  108. #ifdef __USE_EXCLUSIVE_ACCESS
  109. #define rt_inc(p) while(__strex((__ldrex(p)+1),p))
  110. #define rt_dec(p) while(__strex((__ldrex(p)-1),p))
  111. #else
  112. #define rt_inc(p) { int irq_dis = __disable_irq();(*p)++;if(!irq_dis) __enable_irq(); }
  113. #define rt_dec(p) { int irq_dis = __disable_irq();(*p)--;if(!irq_dis) __enable_irq(); }
  114. #endif
  115. __inline static U32 rt_inc_qi (U32 size, U8 *count, U8 *first) {
  116. U32 cnt,c2;
  117. #ifdef __USE_EXCLUSIVE_ACCESS
  118. do {
  119. if ((cnt = __ldrex(count)) == size) {
  120. __clrex();
  121. return (cnt); }
  122. } while (__strex(cnt+1, count));
  123. do {
  124. c2 = (cnt = __ldrex(first)) + 1;
  125. if (c2 == size) c2 = 0;
  126. } while (__strex(c2, first));
  127. #else
  128. int irq_dis;
  129. irq_dis = __disable_irq();
  130. if ((cnt = *count) < size) {
  131. *count = cnt+1;
  132. c2 = (cnt = *first) + 1;
  133. if (c2 == size) c2 = 0;
  134. *first = c2;
  135. }
  136. if(!irq_dis) __enable_irq ();
  137. #endif
  138. return (cnt);
  139. }
  140. __inline static void rt_systick_init (void) {
  141. /* Cortex-A doesn't have a Systick. User needs to provide an alternative timer using RTX_Conf_CM configuration */
  142. /* HW initialization needs to be done in os_tick_init (void) -RTX_Conf_CM.c- */
  143. }
  144. __inline static void rt_svc_init (void) {
  145. /* Register pendSV - through SGI */
  146. volatile char *reg;
  147. reg = (char *)(&GICD_ICDIPR0 + SGI_PENDSV/4);
  148. reg += SGI_PENDSV % 4;
  149. /* Write 0xff to read priority level */
  150. *reg = (char)0xff;
  151. /* Read priority level and set the lowest possible*/
  152. *reg = *reg - 1;
  153. GICD_ICDISERx(SGI_PENDSV) = (U32)SGI_PENDSV_BIT;
  154. }
  155. extern void rt_set_PSP (U32 stack);
  156. extern U32 rt_get_PSP (void);
  157. extern void os_set_env (P_TCB p_TCB);
  158. extern void *_alloc_box (void *box_mem);
  159. extern int _free_box (void *box_mem, void *box);
  160. extern void rt_init_stack (P_TCB p_TCB, FUNCP task_body);
  161. extern void rt_ret_val (P_TCB p_TCB, U32 v0);
  162. extern void rt_ret_val2 (P_TCB p_TCB, U32 v0, U32 v1);
  163. extern void dbg_init (void);
  164. extern void dbg_task_notify (P_TCB p_tcb, BOOL create);
  165. extern void dbg_task_switch (U32 task_id);
  166. #define DBG_INIT()
  167. #define DBG_TASK_NOTIFY(p_tcb,create)
  168. #define DBG_TASK_SWITCH(task_id)
  169. /*----------------------------------------------------------------------------
  170. * end of file
  171. *---------------------------------------------------------------------------*/