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