Modified by Osama Ashaikh

Fork of mbed-rtos by mbed official

Committer:
<>
Date:
Thu Sep 01 15:13:42 2016 +0100
Revision:
122:3da5f554d8bf
Parent:
80:2dab120a94c2
RTOS rev121

Compatible with the mbed library v125

Changes:
- K64F: Revert to hardcoded stack pointer in RTX.
- Adding NCS36510 support.
- Add MAX32620 target support.
- Fix implicit declaration of function 'atexit'.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 80:2dab120a94c2 1 /*----------------------------------------------------------------------------
mbed_official 80:2dab120a94c2 2 * RL-ARM - RTX
mbed_official 80:2dab120a94c2 3 *----------------------------------------------------------------------------
mbed_official 80:2dab120a94c2 4 * Name: RT_EVENT.C
mbed_official 80:2dab120a94c2 5 * Purpose: Implements waits and wake-ups for event flags
mbed_official 80:2dab120a94c2 6 * Rev.: V4.60
mbed_official 80:2dab120a94c2 7 *----------------------------------------------------------------------------
mbed_official 80:2dab120a94c2 8 *
mbed_official 80:2dab120a94c2 9 * Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH
mbed_official 80:2dab120a94c2 10 * All rights reserved.
mbed_official 80:2dab120a94c2 11 * Redistribution and use in source and binary forms, with or without
mbed_official 80:2dab120a94c2 12 * modification, are permitted provided that the following conditions are met:
mbed_official 80:2dab120a94c2 13 * - Redistributions of source code must retain the above copyright
mbed_official 80:2dab120a94c2 14 * notice, this list of conditions and the following disclaimer.
mbed_official 80:2dab120a94c2 15 * - Redistributions in binary form must reproduce the above copyright
mbed_official 80:2dab120a94c2 16 * notice, this list of conditions and the following disclaimer in the
mbed_official 80:2dab120a94c2 17 * documentation and/or other materials provided with the distribution.
mbed_official 80:2dab120a94c2 18 * - Neither the name of ARM nor the names of its contributors may be used
mbed_official 80:2dab120a94c2 19 * to endorse or promote products derived from this software without
mbed_official 80:2dab120a94c2 20 * specific prior written permission.
mbed_official 80:2dab120a94c2 21 *
mbed_official 80:2dab120a94c2 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 80:2dab120a94c2 23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 80:2dab120a94c2 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
mbed_official 80:2dab120a94c2 25 * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
mbed_official 80:2dab120a94c2 26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
mbed_official 80:2dab120a94c2 27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
mbed_official 80:2dab120a94c2 28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
mbed_official 80:2dab120a94c2 29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
mbed_official 80:2dab120a94c2 30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
mbed_official 80:2dab120a94c2 31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
mbed_official 80:2dab120a94c2 32 * POSSIBILITY OF SUCH DAMAGE.
mbed_official 80:2dab120a94c2 33 *---------------------------------------------------------------------------*/
mbed_official 80:2dab120a94c2 34
mbed_official 80:2dab120a94c2 35 #include "rt_TypeDef.h"
mbed_official 80:2dab120a94c2 36 #include "RTX_Conf.h"
mbed_official 80:2dab120a94c2 37 #include "rt_System.h"
mbed_official 80:2dab120a94c2 38 #include "rt_Event.h"
mbed_official 80:2dab120a94c2 39 #include "rt_List.h"
mbed_official 80:2dab120a94c2 40 #include "rt_Task.h"
mbed_official 80:2dab120a94c2 41 #include "rt_HAL_CM.h"
mbed_official 80:2dab120a94c2 42
mbed_official 80:2dab120a94c2 43
mbed_official 80:2dab120a94c2 44 /*----------------------------------------------------------------------------
mbed_official 80:2dab120a94c2 45 * Functions
mbed_official 80:2dab120a94c2 46 *---------------------------------------------------------------------------*/
mbed_official 80:2dab120a94c2 47
mbed_official 80:2dab120a94c2 48
mbed_official 80:2dab120a94c2 49 /*--------------------------- rt_evt_wait -----------------------------------*/
mbed_official 80:2dab120a94c2 50
mbed_official 80:2dab120a94c2 51 OS_RESULT rt_evt_wait (U16 wait_flags, U16 timeout, BOOL and_wait) {
mbed_official 80:2dab120a94c2 52 /* Wait for one or more event flags with optional time-out. */
mbed_official 80:2dab120a94c2 53 /* "wait_flags" identifies the flags to wait for. */
mbed_official 80:2dab120a94c2 54 /* "timeout" is the time-out limit in system ticks (0xffff if no time-out) */
mbed_official 80:2dab120a94c2 55 /* "and_wait" specifies the AND-ing of "wait_flags" as condition to be met */
mbed_official 80:2dab120a94c2 56 /* to complete the wait. (OR-ing if set to 0). */
mbed_official 80:2dab120a94c2 57 U32 block_state;
mbed_official 80:2dab120a94c2 58
mbed_official 80:2dab120a94c2 59 if (and_wait) {
mbed_official 80:2dab120a94c2 60 /* Check for AND-connected events */
mbed_official 80:2dab120a94c2 61 if ((os_tsk.run->events & wait_flags) == wait_flags) {
mbed_official 80:2dab120a94c2 62 os_tsk.run->events &= ~wait_flags;
mbed_official 80:2dab120a94c2 63 return (OS_R_EVT);
mbed_official 80:2dab120a94c2 64 }
mbed_official 80:2dab120a94c2 65 block_state = WAIT_AND;
mbed_official 80:2dab120a94c2 66 }
mbed_official 80:2dab120a94c2 67 else {
mbed_official 80:2dab120a94c2 68 /* Check for OR-connected events */
mbed_official 80:2dab120a94c2 69 if (os_tsk.run->events & wait_flags) {
mbed_official 80:2dab120a94c2 70 os_tsk.run->waits = os_tsk.run->events & wait_flags;
mbed_official 80:2dab120a94c2 71 os_tsk.run->events &= ~wait_flags;
mbed_official 80:2dab120a94c2 72 return (OS_R_EVT);
mbed_official 80:2dab120a94c2 73 }
mbed_official 80:2dab120a94c2 74 block_state = WAIT_OR;
mbed_official 80:2dab120a94c2 75 }
mbed_official 80:2dab120a94c2 76 /* Task has to wait */
mbed_official 80:2dab120a94c2 77 os_tsk.run->waits = wait_flags;
mbed_official 80:2dab120a94c2 78 rt_block (timeout, (U8)block_state);
mbed_official 80:2dab120a94c2 79 return (OS_R_TMO);
mbed_official 80:2dab120a94c2 80 }
mbed_official 80:2dab120a94c2 81
mbed_official 80:2dab120a94c2 82
mbed_official 80:2dab120a94c2 83 /*--------------------------- rt_evt_set ------------------------------------*/
mbed_official 80:2dab120a94c2 84
mbed_official 80:2dab120a94c2 85 void rt_evt_set (U16 event_flags, OS_TID task_id) {
mbed_official 80:2dab120a94c2 86 /* Set one or more event flags of a selectable task. */
mbed_official 80:2dab120a94c2 87 P_TCB p_tcb;
mbed_official 80:2dab120a94c2 88
mbed_official 80:2dab120a94c2 89 p_tcb = os_active_TCB[task_id-1];
mbed_official 80:2dab120a94c2 90 if (p_tcb == NULL) {
mbed_official 80:2dab120a94c2 91 return;
mbed_official 80:2dab120a94c2 92 }
mbed_official 80:2dab120a94c2 93 p_tcb->events |= event_flags;
mbed_official 80:2dab120a94c2 94 event_flags = p_tcb->waits;
mbed_official 80:2dab120a94c2 95 /* If the task is not waiting for an event, it should not be put */
mbed_official 80:2dab120a94c2 96 /* to ready state. */
mbed_official 80:2dab120a94c2 97 if (p_tcb->state == WAIT_AND) {
mbed_official 80:2dab120a94c2 98 /* Check for AND-connected events */
mbed_official 80:2dab120a94c2 99 if ((p_tcb->events & event_flags) == event_flags) {
mbed_official 80:2dab120a94c2 100 goto wkup;
mbed_official 80:2dab120a94c2 101 }
mbed_official 80:2dab120a94c2 102 }
mbed_official 80:2dab120a94c2 103 if (p_tcb->state == WAIT_OR) {
mbed_official 80:2dab120a94c2 104 /* Check for OR-connected events */
mbed_official 80:2dab120a94c2 105 if (p_tcb->events & event_flags) {
mbed_official 80:2dab120a94c2 106 p_tcb->waits &= p_tcb->events;
mbed_official 80:2dab120a94c2 107 wkup: p_tcb->events &= ~event_flags;
mbed_official 80:2dab120a94c2 108 rt_rmv_dly (p_tcb);
mbed_official 80:2dab120a94c2 109 p_tcb->state = READY;
mbed_official 80:2dab120a94c2 110 #ifdef __CMSIS_RTOS
mbed_official 80:2dab120a94c2 111 rt_ret_val2(p_tcb, 0x08/*osEventSignal*/, p_tcb->waits);
mbed_official 80:2dab120a94c2 112 #else
mbed_official 80:2dab120a94c2 113 rt_ret_val (p_tcb, OS_R_EVT);
mbed_official 80:2dab120a94c2 114 #endif
mbed_official 80:2dab120a94c2 115 rt_dispatch (p_tcb);
mbed_official 80:2dab120a94c2 116 }
mbed_official 80:2dab120a94c2 117 }
mbed_official 80:2dab120a94c2 118 }
mbed_official 80:2dab120a94c2 119
mbed_official 80:2dab120a94c2 120
mbed_official 80:2dab120a94c2 121 /*--------------------------- rt_evt_clr ------------------------------------*/
mbed_official 80:2dab120a94c2 122
mbed_official 80:2dab120a94c2 123 void rt_evt_clr (U16 clear_flags, OS_TID task_id) {
mbed_official 80:2dab120a94c2 124 /* Clear one or more event flags (identified by "clear_flags") of a */
mbed_official 80:2dab120a94c2 125 /* selectable task (identified by "task"). */
mbed_official 80:2dab120a94c2 126 P_TCB task = os_active_TCB[task_id-1];
mbed_official 80:2dab120a94c2 127
mbed_official 80:2dab120a94c2 128 if (task == NULL) {
mbed_official 80:2dab120a94c2 129 return;
mbed_official 80:2dab120a94c2 130 }
mbed_official 80:2dab120a94c2 131 task->events &= ~clear_flags;
mbed_official 80:2dab120a94c2 132 }
mbed_official 80:2dab120a94c2 133
mbed_official 80:2dab120a94c2 134
mbed_official 80:2dab120a94c2 135 /*--------------------------- isr_evt_set -----------------------------------*/
mbed_official 80:2dab120a94c2 136
mbed_official 80:2dab120a94c2 137 void isr_evt_set (U16 event_flags, OS_TID task_id) {
mbed_official 80:2dab120a94c2 138 /* Same function as "os_evt_set", but to be called by ISRs. */
mbed_official 80:2dab120a94c2 139 P_TCB p_tcb = os_active_TCB[task_id-1];
mbed_official 80:2dab120a94c2 140
mbed_official 80:2dab120a94c2 141 if (p_tcb == NULL) {
mbed_official 80:2dab120a94c2 142 return;
mbed_official 80:2dab120a94c2 143 }
mbed_official 80:2dab120a94c2 144 rt_psq_enq (p_tcb, event_flags);
mbed_official 80:2dab120a94c2 145 rt_psh_req ();
mbed_official 80:2dab120a94c2 146 }
mbed_official 80:2dab120a94c2 147
mbed_official 80:2dab120a94c2 148
mbed_official 80:2dab120a94c2 149 /*--------------------------- rt_evt_get ------------------------------------*/
mbed_official 80:2dab120a94c2 150
mbed_official 80:2dab120a94c2 151 U16 rt_evt_get (void) {
mbed_official 80:2dab120a94c2 152 /* Get events of a running task after waiting for OR connected events. */
mbed_official 80:2dab120a94c2 153 return (os_tsk.run->waits);
mbed_official 80:2dab120a94c2 154 }
mbed_official 80:2dab120a94c2 155
mbed_official 80:2dab120a94c2 156
mbed_official 80:2dab120a94c2 157 /*--------------------------- rt_evt_psh ------------------------------------*/
mbed_official 80:2dab120a94c2 158
mbed_official 80:2dab120a94c2 159 void rt_evt_psh (P_TCB p_CB, U16 set_flags) {
mbed_official 80:2dab120a94c2 160 /* Check if task has to be waken up */
mbed_official 80:2dab120a94c2 161 U16 event_flags;
mbed_official 80:2dab120a94c2 162
mbed_official 80:2dab120a94c2 163 p_CB->events |= set_flags;
mbed_official 80:2dab120a94c2 164 event_flags = p_CB->waits;
mbed_official 80:2dab120a94c2 165 if (p_CB->state == WAIT_AND) {
mbed_official 80:2dab120a94c2 166 /* Check for AND-connected events */
mbed_official 80:2dab120a94c2 167 if ((p_CB->events & event_flags) == event_flags) {
mbed_official 80:2dab120a94c2 168 goto rdy;
mbed_official 80:2dab120a94c2 169 }
mbed_official 80:2dab120a94c2 170 }
mbed_official 80:2dab120a94c2 171 if (p_CB->state == WAIT_OR) {
mbed_official 80:2dab120a94c2 172 /* Check for OR-connected events */
mbed_official 80:2dab120a94c2 173 if (p_CB->events & event_flags) {
mbed_official 80:2dab120a94c2 174 p_CB->waits &= p_CB->events;
mbed_official 80:2dab120a94c2 175 rdy: p_CB->events &= ~event_flags;
mbed_official 80:2dab120a94c2 176 rt_rmv_dly (p_CB);
mbed_official 80:2dab120a94c2 177 p_CB->state = READY;
mbed_official 80:2dab120a94c2 178 #ifdef __CMSIS_RTOS
mbed_official 80:2dab120a94c2 179 rt_ret_val2(p_CB, 0x08/*osEventSignal*/, p_CB->waits);
mbed_official 80:2dab120a94c2 180 #else
mbed_official 80:2dab120a94c2 181 rt_ret_val (p_CB, OS_R_EVT);
mbed_official 80:2dab120a94c2 182 #endif
mbed_official 80:2dab120a94c2 183 rt_put_prio (&os_rdy, p_CB);
mbed_official 80:2dab120a94c2 184 }
mbed_official 80:2dab120a94c2 185 }
mbed_official 80:2dab120a94c2 186 }
mbed_official 80:2dab120a94c2 187
mbed_official 80:2dab120a94c2 188 /*----------------------------------------------------------------------------
mbed_official 80:2dab120a94c2 189 * end of file
mbed_official 80:2dab120a94c2 190 *---------------------------------------------------------------------------*/