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.

HAL_CA.c 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*----------------------------------------------------------------------------
  2. * RL-ARM - RTX
  3. *----------------------------------------------------------------------------
  4. * Name: HAL_CA.C
  5. * Purpose: Hardware Abstraction Layer for Cortex-A
  6. * Rev.:
  7. *----------------------------------------------------------------------------
  8. *
  9. * Copyright (c) 2012 ARM Limited
  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. #include "rt_TypeDef.h"
  35. #include "RTX_Config.h"
  36. #include "rt_HAL_CA.h"
  37. /*--------------------------- os_init_context -------------------------------*/
  38. void rt_init_stack (P_TCB p_TCB, FUNCP task_body) {
  39. /* Prepare TCB and saved context for a first time start of a task. */
  40. U32 *stk,i,size;
  41. /* Prepare a complete interrupt frame for first task start */
  42. size = p_TCB->priv_stack >> 2;
  43. if (size == 0) {
  44. size = (U16)os_stackinfo >> 2;
  45. }
  46. /* Write to the top of stack. */
  47. stk = &p_TCB->stack[size];
  48. /* Auto correct to 8-byte ARM stack alignment. */
  49. if ((U32)stk & 0x04) {
  50. stk--;
  51. }
  52. stk -= 16;
  53. /* Initial PC and default CPSR */
  54. stk[14] = (U32)task_body;
  55. /* Task run mode is inherited from the startup file. */
  56. /* (non-privileged USER or privileged SYSTEM mode) */
  57. stk[15] = (os_flags & 1) ? INIT_CPSR_SYS : INIT_CPSR_USER;
  58. /* Set T-bit if task function in Thumb mode. */
  59. if ((U32)task_body & 1) {
  60. stk[15] |= CPSR_T_BIT;
  61. }
  62. /* Assign a void pointer to R0. */
  63. stk[8] = (U32)p_TCB->msg;
  64. /* Clear R1-R12,LR registers. */
  65. for (i = 0; i < 8; i++) {
  66. stk[i] = 0;
  67. }
  68. for (i = 9; i < 14; i++) {
  69. stk[i] = 0;
  70. }
  71. /* Initial Task stack pointer. */
  72. p_TCB->tsk_stack = (U32)stk;
  73. /* Task entry point. */
  74. p_TCB->ptask = task_body;
  75. /* Set a magic word for checking of stack overflow. */
  76. p_TCB->stack[0] = MAGIC_WORD;
  77. }
  78. /*--------------------------- rt_ret_val ----------------------------------*/
  79. static __inline U32 *rt_ret_regs (P_TCB p_TCB) {
  80. /* Get pointer to task return value registers (R0..R3) in Stack */
  81. #if (__TARGET_FPU_VFP)
  82. if (p_TCB->stack_frame & 0x2) {
  83. /* Extended Stack Frame: S0-31,FPSCR,Reserved,R4-R11,R0-R3,R12,LR,PC,xPSR */
  84. return (U32 *)(p_TCB->tsk_stack + 8*4 + 34*4);
  85. } else {
  86. /* Basic Stack Frame: R4-R11,R0-R3,R12,LR,PC,xPSR */
  87. return (U32 *)(p_TCB->tsk_stack + 8*4);
  88. }
  89. #else
  90. /* Stack Frame: R4-R11,R0-R3,R12,LR,PC,xPSR */
  91. return (U32 *)(p_TCB->tsk_stack + 8*4);
  92. #endif
  93. }
  94. void rt_ret_val (P_TCB p_TCB, U32 v0) {
  95. U32 *ret;
  96. ret = rt_ret_regs(p_TCB);
  97. ret[0] = v0;
  98. }
  99. void rt_ret_val2(P_TCB p_TCB, U32 v0, U32 v1) {
  100. U32 *ret;
  101. ret = rt_ret_regs(p_TCB);
  102. ret[0] = v0;
  103. ret[1] = v1;
  104. }
  105. /*----------------------------------------------------------------------------
  106. * end of file
  107. *---------------------------------------------------------------------------*/