Repostiory containing DAPLink source code with Reset Pin workaround for HANI_IOT board.

Upstream: https://github.com/ARMmbed/DAPLink

Committer:
Pawel Zarembski
Date:
Tue Apr 07 12:55:42 2020 +0200
Revision:
0:01f31e923fe2
hani: DAPLink with reset workaround

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pawel Zarembski 0:01f31e923fe2 1 /**
Pawel Zarembski 0:01f31e923fe2 2 * @file RTX_lib.c
Pawel Zarembski 0:01f31e923fe2 3 * @brief
Pawel Zarembski 0:01f31e923fe2 4 *
Pawel Zarembski 0:01f31e923fe2 5 * DAPLink Interface Firmware
Pawel Zarembski 0:01f31e923fe2 6 * Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
Pawel Zarembski 0:01f31e923fe2 7 * SPDX-License-Identifier: Apache-2.0
Pawel Zarembski 0:01f31e923fe2 8 *
Pawel Zarembski 0:01f31e923fe2 9 * Licensed under the Apache License, Version 2.0 (the "License"); you may
Pawel Zarembski 0:01f31e923fe2 10 * not use this file except in compliance with the License.
Pawel Zarembski 0:01f31e923fe2 11 * You may obtain a copy of the License at
Pawel Zarembski 0:01f31e923fe2 12 *
Pawel Zarembski 0:01f31e923fe2 13 * http://www.apache.org/licenses/LICENSE-2.0
Pawel Zarembski 0:01f31e923fe2 14 *
Pawel Zarembski 0:01f31e923fe2 15 * Unless required by applicable law or agreed to in writing, software
Pawel Zarembski 0:01f31e923fe2 16 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
Pawel Zarembski 0:01f31e923fe2 17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Pawel Zarembski 0:01f31e923fe2 18 * See the License for the specific language governing permissions and
Pawel Zarembski 0:01f31e923fe2 19 * limitations under the License.
Pawel Zarembski 0:01f31e923fe2 20 */
Pawel Zarembski 0:01f31e923fe2 21
Pawel Zarembski 0:01f31e923fe2 22 #pragma thumb
Pawel Zarembski 0:01f31e923fe2 23 #pragma O3
Pawel Zarembski 0:01f31e923fe2 24
Pawel Zarembski 0:01f31e923fe2 25 /*----------------------------------------------------------------------------
Pawel Zarembski 0:01f31e923fe2 26 * Definitions
Pawel Zarembski 0:01f31e923fe2 27 *---------------------------------------------------------------------------*/
Pawel Zarembski 0:01f31e923fe2 28 #if (__TARGET_ARCH_6S_M || __TARGET_ARCH_7_M || __TARGET_ARCH_7E_M)
Pawel Zarembski 0:01f31e923fe2 29 #define __CM__ 1
Pawel Zarembski 0:01f31e923fe2 30 #elif (__TARGET_ARCH_7_R)
Pawel Zarembski 0:01f31e923fe2 31 #define __CR__ 1
Pawel Zarembski 0:01f31e923fe2 32 #else
Pawel Zarembski 0:01f31e923fe2 33 #define __ARM__ 1
Pawel Zarembski 0:01f31e923fe2 34 #endif
Pawel Zarembski 0:01f31e923fe2 35
Pawel Zarembski 0:01f31e923fe2 36 #if (__ARM__ || __CR__)
Pawel Zarembski 0:01f31e923fe2 37 #define runtask_id() os_tsk_self()
Pawel Zarembski 0:01f31e923fe2 38 #define mutex_init(m) os_mut_init(m)
Pawel Zarembski 0:01f31e923fe2 39 #endif
Pawel Zarembski 0:01f31e923fe2 40 #if (__CM__)
Pawel Zarembski 0:01f31e923fe2 41 #ifndef OS_TIMER
Pawel Zarembski 0:01f31e923fe2 42 #define OS_TIMER 0
Pawel Zarembski 0:01f31e923fe2 43 #endif
Pawel Zarembski 0:01f31e923fe2 44 #define runtask_id() rt_tsk_self()
Pawel Zarembski 0:01f31e923fe2 45 #define mutex_init(m) rt_mut_init(m)
Pawel Zarembski 0:01f31e923fe2 46 #endif
Pawel Zarembski 0:01f31e923fe2 47
Pawel Zarembski 0:01f31e923fe2 48 #define mutex_wait(m) os_mut_wait(m,0xFFFF)
Pawel Zarembski 0:01f31e923fe2 49 #define mutex_rel(m) os_mut_release(m)
Pawel Zarembski 0:01f31e923fe2 50
Pawel Zarembski 0:01f31e923fe2 51
Pawel Zarembski 0:01f31e923fe2 52 /*----------------------------------------------------------------------------
Pawel Zarembski 0:01f31e923fe2 53 * Global Variables
Pawel Zarembski 0:01f31e923fe2 54 *---------------------------------------------------------------------------*/
Pawel Zarembski 0:01f31e923fe2 55 U16 const os_maxtaskrun = OS_TASKCNT;
Pawel Zarembski 0:01f31e923fe2 56 U32 const os_stackinfo = (OS_STKCHECK<<24)| (OS_PRIVCNT<<16) | (OS_STKSIZE*4);
Pawel Zarembski 0:01f31e923fe2 57 U32 const os_rrobin = (OS_ROBIN << 16) | OS_ROBINTOUT;
Pawel Zarembski 0:01f31e923fe2 58 #if (__CM__)
Pawel Zarembski 0:01f31e923fe2 59 U32 const os_trv = OS_TRV;
Pawel Zarembski 0:01f31e923fe2 60 #endif
Pawel Zarembski 0:01f31e923fe2 61 #if (__CM__ || __CR__)
Pawel Zarembski 0:01f31e923fe2 62 U8 const os_flags = OS_RUNPRIV;
Pawel Zarembski 0:01f31e923fe2 63 #endif
Pawel Zarembski 0:01f31e923fe2 64
Pawel Zarembski 0:01f31e923fe2 65 /* Export following defines to uVision debugger. */
Pawel Zarembski 0:01f31e923fe2 66 U32 const os_clockrate __attribute__((used)) = OS_TICK;
Pawel Zarembski 0:01f31e923fe2 67 U32 const os_timernum __attribute__((used)) = (OS_TIMER << 16) | OS_TIMERCNT;
Pawel Zarembski 0:01f31e923fe2 68
Pawel Zarembski 0:01f31e923fe2 69 /* Memory pool for TCB allocation */
Pawel Zarembski 0:01f31e923fe2 70 _declare_box (mp_tcb, OS_TCB_SIZE, OS_TASKCNT);
Pawel Zarembski 0:01f31e923fe2 71 U16 const mp_tcb_size = sizeof(mp_tcb);
Pawel Zarembski 0:01f31e923fe2 72
Pawel Zarembski 0:01f31e923fe2 73 /* Memory pool for System stack allocation (+ os_idle_demon). */
Pawel Zarembski 0:01f31e923fe2 74 _declare_box8 (mp_stk, OS_STKSIZE*4, OS_TASKCNT-OS_PRIVCNT+1);
Pawel Zarembski 0:01f31e923fe2 75 U32 const mp_stk_size = sizeof(mp_stk);
Pawel Zarembski 0:01f31e923fe2 76
Pawel Zarembski 0:01f31e923fe2 77 #ifndef OS_FIFOSZ
Pawel Zarembski 0:01f31e923fe2 78 #define OS_FIFOSZ 16
Pawel Zarembski 0:01f31e923fe2 79 #endif
Pawel Zarembski 0:01f31e923fe2 80
Pawel Zarembski 0:01f31e923fe2 81 /* Fifo Queue buffer for ISR requests.*/
Pawel Zarembski 0:01f31e923fe2 82 U32 os_fifo[OS_FIFOSZ*2+1];
Pawel Zarembski 0:01f31e923fe2 83 U8 const os_fifo_size = OS_FIFOSZ;
Pawel Zarembski 0:01f31e923fe2 84
Pawel Zarembski 0:01f31e923fe2 85 /* An array of Active task pointers. */
Pawel Zarembski 0:01f31e923fe2 86 void *os_active_TCB[OS_TASKCNT];
Pawel Zarembski 0:01f31e923fe2 87
Pawel Zarembski 0:01f31e923fe2 88 #if (OS_TIMERCNT != 0)
Pawel Zarembski 0:01f31e923fe2 89 /* Memory pool for User Timer allocation */
Pawel Zarembski 0:01f31e923fe2 90 _declare_box (mp_tmr, OS_TMR_SIZE, OS_TIMERCNT);
Pawel Zarembski 0:01f31e923fe2 91 U16 const mp_tmr_size = sizeof(mp_tmr);
Pawel Zarembski 0:01f31e923fe2 92 U32 const *m_tmr = &mp_tmr[0];
Pawel Zarembski 0:01f31e923fe2 93 #else
Pawel Zarembski 0:01f31e923fe2 94 U32 const *m_tmr = NULL;
Pawel Zarembski 0:01f31e923fe2 95 U16 const mp_tmr_size = 0;
Pawel Zarembski 0:01f31e923fe2 96 #endif
Pawel Zarembski 0:01f31e923fe2 97
Pawel Zarembski 0:01f31e923fe2 98 #ifndef __MICROLIB
Pawel Zarembski 0:01f31e923fe2 99 /* A memory space for arm standard library. */
Pawel Zarembski 0:01f31e923fe2 100 static U32 std_libspace[OS_TASKCNT][96/4];
Pawel Zarembski 0:01f31e923fe2 101 static OS_MUT std_libmutex[OS_MUTEXCNT];
Pawel Zarembski 0:01f31e923fe2 102 static U32 nr_mutex;
Pawel Zarembski 0:01f31e923fe2 103 extern void *__libspace_start;
Pawel Zarembski 0:01f31e923fe2 104 #endif
Pawel Zarembski 0:01f31e923fe2 105
Pawel Zarembski 0:01f31e923fe2 106 /*----------------------------------------------------------------------------
Pawel Zarembski 0:01f31e923fe2 107 * Tick Timer configuration for ARM7/9, Cortex-R4
Pawel Zarembski 0:01f31e923fe2 108 *---------------------------------------------------------------------------*/
Pawel Zarembski 0:01f31e923fe2 109
Pawel Zarembski 0:01f31e923fe2 110 #if (__ARM__ || __CR__)
Pawel Zarembski 0:01f31e923fe2 111
Pawel Zarembski 0:01f31e923fe2 112 extern void os_clock_interrupt (void);
Pawel Zarembski 0:01f31e923fe2 113
Pawel Zarembski 0:01f31e923fe2 114 /*--------------------------- os_tmr_init -----------------------------------*/
Pawel Zarembski 0:01f31e923fe2 115
Pawel Zarembski 0:01f31e923fe2 116 #ifndef __OS_TMR_INIT
Pawel Zarembski 0:01f31e923fe2 117 void os_tmr_init (void) {
Pawel Zarembski 0:01f31e923fe2 118 /* Initialize hardware timer as system tick timer. */
Pawel Zarembski 0:01f31e923fe2 119 OS_TINIT();
Pawel Zarembski 0:01f31e923fe2 120 }
Pawel Zarembski 0:01f31e923fe2 121 #endif
Pawel Zarembski 0:01f31e923fe2 122
Pawel Zarembski 0:01f31e923fe2 123 /*--------------------------- os_tmr_reload ---------------------------------*/
Pawel Zarembski 0:01f31e923fe2 124
Pawel Zarembski 0:01f31e923fe2 125 #if (!defined(__OS_TMR_RELOAD) && defined(OS_TREL))
Pawel Zarembski 0:01f31e923fe2 126 void os_tmr_reload (void) {
Pawel Zarembski 0:01f31e923fe2 127 /* Reload system timer for next period. */
Pawel Zarembski 0:01f31e923fe2 128 OS_TREL();
Pawel Zarembski 0:01f31e923fe2 129 }
Pawel Zarembski 0:01f31e923fe2 130 #endif
Pawel Zarembski 0:01f31e923fe2 131
Pawel Zarembski 0:01f31e923fe2 132 /*--------------------------- os_tmr_force_irq ------------------------------*/
Pawel Zarembski 0:01f31e923fe2 133
Pawel Zarembski 0:01f31e923fe2 134 #ifndef __OS_TMR_FORCE_IRQ
Pawel Zarembski 0:01f31e923fe2 135 void os_tmr_force_irq (void) {
Pawel Zarembski 0:01f31e923fe2 136 /* Force a timer interrupt. */
Pawel Zarembski 0:01f31e923fe2 137 OS_TFIRQ();
Pawel Zarembski 0:01f31e923fe2 138 }
Pawel Zarembski 0:01f31e923fe2 139 #endif
Pawel Zarembski 0:01f31e923fe2 140
Pawel Zarembski 0:01f31e923fe2 141 /*--------------------------- os_tmr_inspect_cnt ----------------------------*/
Pawel Zarembski 0:01f31e923fe2 142
Pawel Zarembski 0:01f31e923fe2 143 #ifndef __OS_TMR_INSPECT_CNT
Pawel Zarembski 0:01f31e923fe2 144 U32 os_tmr_inspect_cnt (void) {
Pawel Zarembski 0:01f31e923fe2 145 /* Inspect current value of rtx timer. */
Pawel Zarembski 0:01f31e923fe2 146 return (OS_TVAL);
Pawel Zarembski 0:01f31e923fe2 147 }
Pawel Zarembski 0:01f31e923fe2 148 #endif
Pawel Zarembski 0:01f31e923fe2 149
Pawel Zarembski 0:01f31e923fe2 150 /*--------------------------- os_tmr_inspect_ovf ----------------------------*/
Pawel Zarembski 0:01f31e923fe2 151
Pawel Zarembski 0:01f31e923fe2 152 #ifndef __OS_TMR_INSPECT_OVF
Pawel Zarembski 0:01f31e923fe2 153 BOOL os_tmr_inspect_ovf (void) {
Pawel Zarembski 0:01f31e923fe2 154 /* Inspect current state of timer overflow flag. */
Pawel Zarembski 0:01f31e923fe2 155 return (OS_TOVF);
Pawel Zarembski 0:01f31e923fe2 156 }
Pawel Zarembski 0:01f31e923fe2 157 #endif
Pawel Zarembski 0:01f31e923fe2 158
Pawel Zarembski 0:01f31e923fe2 159 /*--------------------------- os_irq_ack_lock -------------------------------*/
Pawel Zarembski 0:01f31e923fe2 160
Pawel Zarembski 0:01f31e923fe2 161 #ifndef __OS_IRQ_ACK_LOCK
Pawel Zarembski 0:01f31e923fe2 162 void os_irq_ack_lock (void) {
Pawel Zarembski 0:01f31e923fe2 163 /* Acknowledge and disable a timer interrupt. */
Pawel Zarembski 0:01f31e923fe2 164 OS_TIACK();
Pawel Zarembski 0:01f31e923fe2 165 OS_LOCK();
Pawel Zarembski 0:01f31e923fe2 166 }
Pawel Zarembski 0:01f31e923fe2 167 #endif
Pawel Zarembski 0:01f31e923fe2 168
Pawel Zarembski 0:01f31e923fe2 169 /*--------------------------- tsk_lock --------------------------------------*/
Pawel Zarembski 0:01f31e923fe2 170
Pawel Zarembski 0:01f31e923fe2 171 #ifndef __TSK_LOCK
Pawel Zarembski 0:01f31e923fe2 172 void __swi(5) tsk_lock (void);
Pawel Zarembski 0:01f31e923fe2 173 void __SWI_5 (void) {
Pawel Zarembski 0:01f31e923fe2 174 /* Disable RTX System Tick Timer interrupts. */
Pawel Zarembski 0:01f31e923fe2 175 OS_LOCK();
Pawel Zarembski 0:01f31e923fe2 176 }
Pawel Zarembski 0:01f31e923fe2 177 #endif
Pawel Zarembski 0:01f31e923fe2 178
Pawel Zarembski 0:01f31e923fe2 179 /*--------------------------- tsk_unlock ------------------------------------*/
Pawel Zarembski 0:01f31e923fe2 180
Pawel Zarembski 0:01f31e923fe2 181 #ifndef __TSK_UNLOCK
Pawel Zarembski 0:01f31e923fe2 182 void tsk_unlock (void) {
Pawel Zarembski 0:01f31e923fe2 183 /* Enable RTX System Tick Timer Interrupts. */
Pawel Zarembski 0:01f31e923fe2 184 OS_UNLOCK();
Pawel Zarembski 0:01f31e923fe2 185 }
Pawel Zarembski 0:01f31e923fe2 186 #endif
Pawel Zarembski 0:01f31e923fe2 187
Pawel Zarembski 0:01f31e923fe2 188 #endif /* #if (__ARM__ || __CR__) */
Pawel Zarembski 0:01f31e923fe2 189
Pawel Zarembski 0:01f31e923fe2 190
Pawel Zarembski 0:01f31e923fe2 191 /*----------------------------------------------------------------------------
Pawel Zarembski 0:01f31e923fe2 192 * RT Agent interface for ARM7/9
Pawel Zarembski 0:01f31e923fe2 193 *---------------------------------------------------------------------------*/
Pawel Zarembski 0:01f31e923fe2 194
Pawel Zarembski 0:01f31e923fe2 195 #if (__ARM__ && __RTA_RTX_CONFIG)
Pawel Zarembski 0:01f31e923fe2 196
Pawel Zarembski 0:01f31e923fe2 197 #include "RT_Agent.h"
Pawel Zarembski 0:01f31e923fe2 198
Pawel Zarembski 0:01f31e923fe2 199 #if (__RTA_ENABLED && __RTA_RTX_TASK_SWITCHING)
Pawel Zarembski 0:01f31e923fe2 200 /*
Pawel Zarembski 0:01f31e923fe2 201 * RT Agent - Event Viewer Packing
Pawel Zarembski 0:01f31e923fe2 202 *
Pawel Zarembski 0:01f31e923fe2 203 * |---+---------+---------+------|
Pawel Zarembski 0:01f31e923fe2 204 * | 0 | os_time | hw_tick | t_id |
Pawel Zarembski 0:01f31e923fe2 205 * |---+---------+---------+------|
Pawel Zarembski 0:01f31e923fe2 206 * bit 31 ^ 7 0
Pawel Zarembski 0:01f31e923fe2 207 * +-- OS_TIME_SL
Pawel Zarembski 0:01f31e923fe2 208 *
Pawel Zarembski 0:01f31e923fe2 209 * value hw_tick is truncated by number of bits specified by OS_TVAL_SR
Pawel Zarembski 0:01f31e923fe2 210 * value os_time is shifted left by number of bits specified by OS_TIME_SL
Pawel Zarembski 0:01f31e923fe2 211 */
Pawel Zarembski 0:01f31e923fe2 212
Pawel Zarembski 0:01f31e923fe2 213 /* Define pack shift values depending on the tick time value OS_TICK. */
Pawel Zarembski 0:01f31e923fe2 214 /* Packing results in a time of ~1 second being represented, and an */
Pawel Zarembski 0:01f31e923fe2 215 /* accuracy of ~0.15us. (based on the hw tick timer accuracy. */
Pawel Zarembski 0:01f31e923fe2 216
Pawel Zarembski 0:01f31e923fe2 217 #if ((OS_TICK) < 0x80) // OS_TICK < 128us ==> tick 14 bits, timer 9
Pawel Zarembski 0:01f31e923fe2 218 #define OS_TIME_SL 17
Pawel Zarembski 0:01f31e923fe2 219 #elif ((OS_TICK) < 0x100) // OS_TICK < 256us ==> tick 13 bits, timer 10
Pawel Zarembski 0:01f31e923fe2 220 #define OS_TIME_SL 18
Pawel Zarembski 0:01f31e923fe2 221 #elif ((OS_TICK) < 0x200) // OS_TICK < 512us ==> tick 12 bits, timer 11
Pawel Zarembski 0:01f31e923fe2 222 #define OS_TIME_SL 19
Pawel Zarembski 0:01f31e923fe2 223 #elif ((OS_TICK) < 0x400) // OS_TICK < 1.024ms ==> tick 11 bits, timer 12
Pawel Zarembski 0:01f31e923fe2 224 #define OS_TIME_SL 20
Pawel Zarembski 0:01f31e923fe2 225 #elif ((OS_TICK) < 0x800) // OS_TICK < 2.048ms ==> tick 10 bits, timer 13
Pawel Zarembski 0:01f31e923fe2 226 #define OS_TIME_SL 21
Pawel Zarembski 0:01f31e923fe2 227 #elif ((OS_TICK) < 0x1000) // OS_TICK < 4.096ms ==> tick 9 bits, timer 14
Pawel Zarembski 0:01f31e923fe2 228 #define OS_TIME_SL 22
Pawel Zarembski 0:01f31e923fe2 229 #elif ((OS_TICK) < 0x2000) // OS_TICK < 8.192ms ==> tick 8 bits, timer 15
Pawel Zarembski 0:01f31e923fe2 230 #define OS_TIME_SL 23
Pawel Zarembski 0:01f31e923fe2 231 #elif ((OS_TICK) < 0x4000) // OS_TICK < 16.384ms ==> tick 7 bits, timer 16
Pawel Zarembski 0:01f31e923fe2 232 #define OS_TIME_SL 24
Pawel Zarembski 0:01f31e923fe2 233 #elif ((OS_TICK) < 0x8000) // OS_TICK < 32.768ms ==> tick 6 bits, timer 17
Pawel Zarembski 0:01f31e923fe2 234 #define OS_TIME_SL 25
Pawel Zarembski 0:01f31e923fe2 235 #elif ((OS_TICK) < 0x10000) // OS_TICK < 65.536ms ==> tick 5 bits, timer 18
Pawel Zarembski 0:01f31e923fe2 236 #define OS_TIME_SL 26
Pawel Zarembski 0:01f31e923fe2 237 #elif ((OS_TICK) < 0x20000) // OS_TICK < 131.070ms ==> tick 4 bits, timer 19
Pawel Zarembski 0:01f31e923fe2 238 #define OS_TIME_SL 27
Pawel Zarembski 0:01f31e923fe2 239 #elif ((OS_TICK) < 0x40000) // OS_TICK < 262.140ms ==> tick 3 bits, timer 20
Pawel Zarembski 0:01f31e923fe2 240 #define OS_TIME_SL 28
Pawel Zarembski 0:01f31e923fe2 241 #elif ((OS_TICK) < 0x80000) // OS_TICK < 524.280ms ==> tick 2 bits, timer 21
Pawel Zarembski 0:01f31e923fe2 242 #define OS_TIME_SL 29
Pawel Zarembski 0:01f31e923fe2 243 #else // OS_TICK >= 524.280ms ==> tick 1 bit, timer 22
Pawel Zarembski 0:01f31e923fe2 244 #define OS_TIME_SL 30
Pawel Zarembski 0:01f31e923fe2 245 #endif
Pawel Zarembski 0:01f31e923fe2 246
Pawel Zarembski 0:01f31e923fe2 247 /* Define hw_tick truncation depending on the timer reload value OS_TRV */
Pawel Zarembski 0:01f31e923fe2 248 #if ((OS_TRV) < 0x10)
Pawel Zarembski 0:01f31e923fe2 249 #define OS_TVAL_SR (12 - OS_TIME_SL)
Pawel Zarembski 0:01f31e923fe2 250 #elif ((OS_TRV) < 0x20)
Pawel Zarembski 0:01f31e923fe2 251 #define OS_TVAL_SR (13 - OS_TIME_SL)
Pawel Zarembski 0:01f31e923fe2 252 #elif ((OS_TRV) < 0x40)
Pawel Zarembski 0:01f31e923fe2 253 #define OS_TVAL_SR (14 - OS_TIME_SL)
Pawel Zarembski 0:01f31e923fe2 254 #elif ((OS_TRV) < 0x80)
Pawel Zarembski 0:01f31e923fe2 255 #define OS_TVAL_SR (15 - OS_TIME_SL)
Pawel Zarembski 0:01f31e923fe2 256 #elif ((OS_TRV) < 0x100)
Pawel Zarembski 0:01f31e923fe2 257 #define OS_TVAL_SR (16 - OS_TIME_SL)
Pawel Zarembski 0:01f31e923fe2 258 #elif ((OS_TRV) < 0x200)
Pawel Zarembski 0:01f31e923fe2 259 #define OS_TVAL_SR (17 - OS_TIME_SL)
Pawel Zarembski 0:01f31e923fe2 260 #elif ((OS_TRV) < 0x400)
Pawel Zarembski 0:01f31e923fe2 261 #define OS_TVAL_SR (18 - OS_TIME_SL)
Pawel Zarembski 0:01f31e923fe2 262 #elif ((OS_TRV) < 0x800)
Pawel Zarembski 0:01f31e923fe2 263 #define OS_TVAL_SR (19 - OS_TIME_SL)
Pawel Zarembski 0:01f31e923fe2 264 #elif ((OS_TRV) < 0x1000)
Pawel Zarembski 0:01f31e923fe2 265 #define OS_TVAL_SR (20 - OS_TIME_SL)
Pawel Zarembski 0:01f31e923fe2 266 #elif ((OS_TRV) < 0x2000)
Pawel Zarembski 0:01f31e923fe2 267 #define OS_TVAL_SR (21 - OS_TIME_SL)
Pawel Zarembski 0:01f31e923fe2 268 #elif ((OS_TRV) < 0x4000)
Pawel Zarembski 0:01f31e923fe2 269 #define OS_TVAL_SR (22 - OS_TIME_SL)
Pawel Zarembski 0:01f31e923fe2 270 #elif ((OS_TRV) < 0x8000)
Pawel Zarembski 0:01f31e923fe2 271 #define OS_TVAL_SR (23 - OS_TIME_SL)
Pawel Zarembski 0:01f31e923fe2 272 #elif ((OS_TRV) < 0x10000)
Pawel Zarembski 0:01f31e923fe2 273 #define OS_TVAL_SR (24 - OS_TIME_SL)
Pawel Zarembski 0:01f31e923fe2 274 #elif ((OS_TRV) < 0x20000)
Pawel Zarembski 0:01f31e923fe2 275 #define OS_TVAL_SR (25 - OS_TIME_SL)
Pawel Zarembski 0:01f31e923fe2 276 #elif ((OS_TRV) < 0x40000)
Pawel Zarembski 0:01f31e923fe2 277 #define OS_TVAL_SR (26 - OS_TIME_SL)
Pawel Zarembski 0:01f31e923fe2 278 #elif ((OS_TRV) < 0x80000)
Pawel Zarembski 0:01f31e923fe2 279 #define OS_TVAL_SR (27 - OS_TIME_SL)
Pawel Zarembski 0:01f31e923fe2 280 #elif ((OS_TRV) < 0x100000)
Pawel Zarembski 0:01f31e923fe2 281 #define OS_TVAL_SR (28 - OS_TIME_SL)
Pawel Zarembski 0:01f31e923fe2 282 #elif ((OS_TRV) < 0x200000)
Pawel Zarembski 0:01f31e923fe2 283 #define OS_TVAL_SR (29 - OS_TIME_SL)
Pawel Zarembski 0:01f31e923fe2 284 #elif ((OS_TRV) < 0x400000)
Pawel Zarembski 0:01f31e923fe2 285 #define OS_TVAL_SR (30 - OS_TIME_SL)
Pawel Zarembski 0:01f31e923fe2 286 #elif ((OS_TRV) < 0x800000)
Pawel Zarembski 0:01f31e923fe2 287 #define OS_TVAL_SR (31 - OS_TIME_SL)
Pawel Zarembski 0:01f31e923fe2 288 #elif ((OS_TRV) < 0x1000000)
Pawel Zarembski 0:01f31e923fe2 289 #define OS_TVAL_SR (32 - OS_TIME_SL)
Pawel Zarembski 0:01f31e923fe2 290 #elif ((OS_TRV) < 0x2000000)
Pawel Zarembski 0:01f31e923fe2 291 #define OS_TVAL_SR (33 - OS_TIME_SL)
Pawel Zarembski 0:01f31e923fe2 292 #elif ((OS_TRV) < 0x4000000)
Pawel Zarembski 0:01f31e923fe2 293 #define OS_TVAL_SR (34 - OS_TIME_SL)
Pawel Zarembski 0:01f31e923fe2 294 #elif ((OS_TRV) < 0x8000000)
Pawel Zarembski 0:01f31e923fe2 295 #define OS_TVAL_SR (35 - OS_TIME_SL)
Pawel Zarembski 0:01f31e923fe2 296 #else
Pawel Zarembski 0:01f31e923fe2 297 #define OS_TVAL_SR (36 - OS_TIME_SL)
Pawel Zarembski 0:01f31e923fe2 298 #endif
Pawel Zarembski 0:01f31e923fe2 299
Pawel Zarembski 0:01f31e923fe2 300 #if (OS_TVAL_SR < 0)
Pawel Zarembski 0:01f31e923fe2 301 #undef OS_TVAL_SR
Pawel Zarembski 0:01f31e923fe2 302 #define OS_TVAL_SR 0
Pawel Zarembski 0:01f31e923fe2 303 #endif
Pawel Zarembski 0:01f31e923fe2 304
Pawel Zarembski 0:01f31e923fe2 305 extern U32 os_time;
Pawel Zarembski 0:01f31e923fe2 306
Pawel Zarembski 0:01f31e923fe2 307 /* Export following defines to uVision debugger. */
Pawel Zarembski 0:01f31e923fe2 308 U8 const os_time_sl __attribute__((used)) = OS_TIME_SL;
Pawel Zarembski 0:01f31e923fe2 309 U32 const os_treload __attribute__((used)) = OS_TRV;
Pawel Zarembski 0:01f31e923fe2 310
Pawel Zarembski 0:01f31e923fe2 311 __weak extern void RTA_Task_Mon (unsigned int tsk);
Pawel Zarembski 0:01f31e923fe2 312
Pawel Zarembski 0:01f31e923fe2 313 #define RTA_CMD_RTX_TASK_INFO 0x0A
Pawel Zarembski 0:01f31e923fe2 314
Pawel Zarembski 0:01f31e923fe2 315 void rt_notify (U32 ptask, U32 create_tid) {
Pawel Zarembski 0:01f31e923fe2 316 /* Notify RTA user of a task creation/deletion. */
Pawel Zarembski 0:01f31e923fe2 317 U32 msg[2];
Pawel Zarembski 0:01f31e923fe2 318
Pawel Zarembski 0:01f31e923fe2 319 /* (BOOL)create << 8 | task_id - parameter packed in RTX library */
Pawel Zarembski 0:01f31e923fe2 320 msg[0] = create_tid;
Pawel Zarembski 0:01f31e923fe2 321 msg[1] = (U32)ptask;
Pawel Zarembski 0:01f31e923fe2 322 RTA_Msg (RTA_CMD_RTX_TASK_INFO, (U32 *)&msg, 2);
Pawel Zarembski 0:01f31e923fe2 323 }
Pawel Zarembski 0:01f31e923fe2 324
Pawel Zarembski 0:01f31e923fe2 325 /*--------------------------- rt_post_taskswitch ----------------------------*/
Pawel Zarembski 0:01f31e923fe2 326
Pawel Zarembski 0:01f31e923fe2 327 void rt_post_taskswitch (U32 task_id) {
Pawel Zarembski 0:01f31e923fe2 328 U32 tsk_event;
Pawel Zarembski 0:01f31e923fe2 329
Pawel Zarembski 0:01f31e923fe2 330 /* Add the current timer value (with bottom bits removed) */
Pawel Zarembski 0:01f31e923fe2 331 tsk_event = OS_TVAL >> OS_TVAL_SR;
Pawel Zarembski 0:01f31e923fe2 332 /* Shif timer value into place, add the task ID. */
Pawel Zarembski 0:01f31e923fe2 333 tsk_event = (tsk_event << 8) | task_id;
Pawel Zarembski 0:01f31e923fe2 334 /* Add the OS tick time. */
Pawel Zarembski 0:01f31e923fe2 335 tsk_event = tsk_event | (os_time << OS_TIME_SL);
Pawel Zarembski 0:01f31e923fe2 336 /* Mask off the top bit to indicate a task switch message. */
Pawel Zarembski 0:01f31e923fe2 337 tsk_event &= 0x7FFFFFFFU;
Pawel Zarembski 0:01f31e923fe2 338
Pawel Zarembski 0:01f31e923fe2 339 RTA_Task_Mon (tsk_event);
Pawel Zarembski 0:01f31e923fe2 340 }
Pawel Zarembski 0:01f31e923fe2 341
Pawel Zarembski 0:01f31e923fe2 342 #endif /* #if (__RTA_ENABLED && __RTA_RTX_TASK_SWITCHING) */
Pawel Zarembski 0:01f31e923fe2 343
Pawel Zarembski 0:01f31e923fe2 344 /*--------------------------- rt_init ---------------------------------------*/
Pawel Zarembski 0:01f31e923fe2 345
Pawel Zarembski 0:01f31e923fe2 346 void rt_init (void) {
Pawel Zarembski 0:01f31e923fe2 347 RTA_Init ();
Pawel Zarembski 0:01f31e923fe2 348 }
Pawel Zarembski 0:01f31e923fe2 349
Pawel Zarembski 0:01f31e923fe2 350
Pawel Zarembski 0:01f31e923fe2 351 #include "RT_Agent.c"
Pawel Zarembski 0:01f31e923fe2 352
Pawel Zarembski 0:01f31e923fe2 353 #endif /* #if (__ARM__ && __RTA_RTX_CONFIG) */
Pawel Zarembski 0:01f31e923fe2 354
Pawel Zarembski 0:01f31e923fe2 355
Pawel Zarembski 0:01f31e923fe2 356 /*----------------------------------------------------------------------------
Pawel Zarembski 0:01f31e923fe2 357 * RTX Optimizations (empty functions)
Pawel Zarembski 0:01f31e923fe2 358 *---------------------------------------------------------------------------*/
Pawel Zarembski 0:01f31e923fe2 359
Pawel Zarembski 0:01f31e923fe2 360 #if (__ARM__ || __CR__) && OS_ROBIN == 0
Pawel Zarembski 0:01f31e923fe2 361 void os_init_robin (void) {;}
Pawel Zarembski 0:01f31e923fe2 362 void os_chk_robin (void) {;}
Pawel Zarembski 0:01f31e923fe2 363 #endif
Pawel Zarembski 0:01f31e923fe2 364
Pawel Zarembski 0:01f31e923fe2 365 #if (__ARM__ || __CR__) && OS_STKCHECK == 0
Pawel Zarembski 0:01f31e923fe2 366 void os_stk_check (U32 stk) {;}
Pawel Zarembski 0:01f31e923fe2 367 #endif
Pawel Zarembski 0:01f31e923fe2 368
Pawel Zarembski 0:01f31e923fe2 369 #if (__CM__) && OS_ROBIN == 0
Pawel Zarembski 0:01f31e923fe2 370 void rt_init_robin (void) {;}
Pawel Zarembski 0:01f31e923fe2 371 void rt_chk_robin (void) {;}
Pawel Zarembski 0:01f31e923fe2 372 #endif
Pawel Zarembski 0:01f31e923fe2 373
Pawel Zarembski 0:01f31e923fe2 374 #if (__CM__) && OS_STKCHECK == 0
Pawel Zarembski 0:01f31e923fe2 375 void rt_stk_check (void) {;}
Pawel Zarembski 0:01f31e923fe2 376 #endif
Pawel Zarembski 0:01f31e923fe2 377
Pawel Zarembski 0:01f31e923fe2 378
Pawel Zarembski 0:01f31e923fe2 379 /*----------------------------------------------------------------------------
Pawel Zarembski 0:01f31e923fe2 380 * Standard Library multithreading interface
Pawel Zarembski 0:01f31e923fe2 381 *---------------------------------------------------------------------------*/
Pawel Zarembski 0:01f31e923fe2 382
Pawel Zarembski 0:01f31e923fe2 383 #ifndef __MICROLIB
Pawel Zarembski 0:01f31e923fe2 384
Pawel Zarembski 0:01f31e923fe2 385 /*--------------------------- __user_perthread_libspace ---------------------*/
Pawel Zarembski 0:01f31e923fe2 386
Pawel Zarembski 0:01f31e923fe2 387 void *__user_perthread_libspace (void) {
Pawel Zarembski 0:01f31e923fe2 388 /* Provide a separate libspace for each task. */
Pawel Zarembski 0:01f31e923fe2 389 U32 idx;
Pawel Zarembski 0:01f31e923fe2 390
Pawel Zarembski 0:01f31e923fe2 391 idx = runtask_id ();
Pawel Zarembski 0:01f31e923fe2 392 if (idx == 0) {
Pawel Zarembski 0:01f31e923fe2 393 /* RTX not running yet. */
Pawel Zarembski 0:01f31e923fe2 394 return (&__libspace_start);
Pawel Zarembski 0:01f31e923fe2 395 }
Pawel Zarembski 0:01f31e923fe2 396 return ((void *)&std_libspace[idx-1]);
Pawel Zarembski 0:01f31e923fe2 397 }
Pawel Zarembski 0:01f31e923fe2 398
Pawel Zarembski 0:01f31e923fe2 399 /*--------------------------- _mutex_initialize -----------------------------*/
Pawel Zarembski 0:01f31e923fe2 400
Pawel Zarembski 0:01f31e923fe2 401 int _mutex_initialize (OS_ID *mutex) {
Pawel Zarembski 0:01f31e923fe2 402 /* Allocate and initialize a system mutex. */
Pawel Zarembski 0:01f31e923fe2 403
Pawel Zarembski 0:01f31e923fe2 404 if (nr_mutex >= OS_MUTEXCNT) {
Pawel Zarembski 0:01f31e923fe2 405 /* If you are here, you need to increase the number OS_MUTEXCNT. */
Pawel Zarembski 0:01f31e923fe2 406 for (;;);
Pawel Zarembski 0:01f31e923fe2 407 }
Pawel Zarembski 0:01f31e923fe2 408 *mutex = &std_libmutex[nr_mutex++];
Pawel Zarembski 0:01f31e923fe2 409 mutex_init (*mutex);
Pawel Zarembski 0:01f31e923fe2 410 return (1);
Pawel Zarembski 0:01f31e923fe2 411 }
Pawel Zarembski 0:01f31e923fe2 412
Pawel Zarembski 0:01f31e923fe2 413
Pawel Zarembski 0:01f31e923fe2 414 /*--------------------------- _mutex_acquire --------------------------------*/
Pawel Zarembski 0:01f31e923fe2 415
Pawel Zarembski 0:01f31e923fe2 416 __used void _mutex_acquire (OS_ID *mutex) {
Pawel Zarembski 0:01f31e923fe2 417 /* Acquire a system mutex, lock stdlib resources. */
Pawel Zarembski 0:01f31e923fe2 418 if (runtask_id ()) {
Pawel Zarembski 0:01f31e923fe2 419 /* RTX running, acquire a mutex. */
Pawel Zarembski 0:01f31e923fe2 420 mutex_wait (*mutex);
Pawel Zarembski 0:01f31e923fe2 421 }
Pawel Zarembski 0:01f31e923fe2 422 }
Pawel Zarembski 0:01f31e923fe2 423
Pawel Zarembski 0:01f31e923fe2 424
Pawel Zarembski 0:01f31e923fe2 425 /*--------------------------- _mutex_release --------------------------------*/
Pawel Zarembski 0:01f31e923fe2 426
Pawel Zarembski 0:01f31e923fe2 427 __used void _mutex_release (OS_ID *mutex) {
Pawel Zarembski 0:01f31e923fe2 428 /* Release a system mutex, unlock stdlib resources. */
Pawel Zarembski 0:01f31e923fe2 429 if (runtask_id ()) {
Pawel Zarembski 0:01f31e923fe2 430 /* RTX runnning, release a mutex. */
Pawel Zarembski 0:01f31e923fe2 431 mutex_rel (*mutex);
Pawel Zarembski 0:01f31e923fe2 432 }
Pawel Zarembski 0:01f31e923fe2 433 }
Pawel Zarembski 0:01f31e923fe2 434
Pawel Zarembski 0:01f31e923fe2 435 #endif
Pawel Zarembski 0:01f31e923fe2 436
Pawel Zarembski 0:01f31e923fe2 437 /*----------------------------------------------------------------------------
Pawel Zarembski 0:01f31e923fe2 438 * end of file
Pawel Zarembski 0:01f31e923fe2 439 *---------------------------------------------------------------------------*/
Pawel Zarembski 0:01f31e923fe2 440