my version

Dependents:   aps_so_c2

Fork of mbed-rtos by mbed official

Committer:
mbed_official
Date:
Thu Nov 06 13:00:11 2014 +0000
Revision:
49:77c8e4604045
Child:
112:53ace74b190c
Synchronized with git revision 7b90c2ba137baaf9769219e0e8a7b8e8d1299c4f

Full URL: https://github.com/mbedmicro/mbed/commit/7b90c2ba137baaf9769219e0e8a7b8e8d1299c4f/

This target is not yet tested, so it can't be released as part of the official
SDK build for now.

Who changed what in which revision?

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