Greg Steiert / pegasus_dev

Dependents:   blinky_max32630fthr

Committer:
switches
Date:
Fri Nov 11 20:59:50 2016 +0000
Revision:
0:5c4d7b2438d3
Initial commit

Who changed what in which revision?

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