in OS_TSK, rename run as tsk_run and new as tsk_new.

Committer:
jonathonfletcher
Date:
Sun Sep 02 03:24:20 2012 +0000
Revision:
0:5f46ebd8588e
in OS_TSK, rename run as tsk_run and new as tsk_new.

Who changed what in which revision?

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