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