Repostiory containing DAPLink source code with Reset Pin workaround for HANI_IOT board.
Upstream: https://github.com/ARMmbed/DAPLink
source/rtos/rt_Event.c@0:01f31e923fe2, 2020-04-07 (annotated)
- Committer:
- Pawel Zarembski
- Date:
- Tue Apr 07 12:55:42 2020 +0200
- Revision:
- 0:01f31e923fe2
hani: DAPLink with reset workaround
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Pawel Zarembski |
0:01f31e923fe2 | 1 | /** |
Pawel Zarembski |
0:01f31e923fe2 | 2 | * @file rt_Event.c |
Pawel Zarembski |
0:01f31e923fe2 | 3 | * @brief |
Pawel Zarembski |
0:01f31e923fe2 | 4 | * |
Pawel Zarembski |
0:01f31e923fe2 | 5 | * DAPLink Interface Firmware |
Pawel Zarembski |
0:01f31e923fe2 | 6 | * Copyright (c) 2009-2016, ARM Limited, All Rights Reserved |
Pawel Zarembski |
0:01f31e923fe2 | 7 | * SPDX-License-Identifier: Apache-2.0 |
Pawel Zarembski |
0:01f31e923fe2 | 8 | * |
Pawel Zarembski |
0:01f31e923fe2 | 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
Pawel Zarembski |
0:01f31e923fe2 | 10 | * not use this file except in compliance with the License. |
Pawel Zarembski |
0:01f31e923fe2 | 11 | * You may obtain a copy of the License at |
Pawel Zarembski |
0:01f31e923fe2 | 12 | * |
Pawel Zarembski |
0:01f31e923fe2 | 13 | * http://www.apache.org/licenses/LICENSE-2.0 |
Pawel Zarembski |
0:01f31e923fe2 | 14 | * |
Pawel Zarembski |
0:01f31e923fe2 | 15 | * Unless required by applicable law or agreed to in writing, software |
Pawel Zarembski |
0:01f31e923fe2 | 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
Pawel Zarembski |
0:01f31e923fe2 | 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Pawel Zarembski |
0:01f31e923fe2 | 18 | * See the License for the specific language governing permissions and |
Pawel Zarembski |
0:01f31e923fe2 | 19 | * limitations under the License. |
Pawel Zarembski |
0:01f31e923fe2 | 20 | */ |
Pawel Zarembski |
0:01f31e923fe2 | 21 | |
Pawel Zarembski |
0:01f31e923fe2 | 22 | #include "rt_TypeDef.h" |
Pawel Zarembski |
0:01f31e923fe2 | 23 | #include "RTX_Config.h" |
Pawel Zarembski |
0:01f31e923fe2 | 24 | #include "rt_System.h" |
Pawel Zarembski |
0:01f31e923fe2 | 25 | #include "rt_Event.h" |
Pawel Zarembski |
0:01f31e923fe2 | 26 | #include "rt_List.h" |
Pawel Zarembski |
0:01f31e923fe2 | 27 | #include "rt_Task.h" |
Pawel Zarembski |
0:01f31e923fe2 | 28 | |
Pawel Zarembski |
0:01f31e923fe2 | 29 | |
Pawel Zarembski |
0:01f31e923fe2 | 30 | /*---------------------------------------------------------------------------- |
Pawel Zarembski |
0:01f31e923fe2 | 31 | * Functions |
Pawel Zarembski |
0:01f31e923fe2 | 32 | *---------------------------------------------------------------------------*/ |
Pawel Zarembski |
0:01f31e923fe2 | 33 | |
Pawel Zarembski |
0:01f31e923fe2 | 34 | |
Pawel Zarembski |
0:01f31e923fe2 | 35 | /*--------------------------- rt_evt_wait -----------------------------------*/ |
Pawel Zarembski |
0:01f31e923fe2 | 36 | |
Pawel Zarembski |
0:01f31e923fe2 | 37 | OS_RESULT rt_evt_wait (U16 wait_flags, U16 timeout, BOOL and_wait) { |
Pawel Zarembski |
0:01f31e923fe2 | 38 | /* Wait for one or more event flags with optional time-out. */ |
Pawel Zarembski |
0:01f31e923fe2 | 39 | /* "wait_flags" identifies the flags to wait for. */ |
Pawel Zarembski |
0:01f31e923fe2 | 40 | /* "timeout" is the time-out limit in system ticks (0xffff if no time-out) */ |
Pawel Zarembski |
0:01f31e923fe2 | 41 | /* "and_wait" specifies the AND-ing of "wait_flags" as condition to be met */ |
Pawel Zarembski |
0:01f31e923fe2 | 42 | /* to complete the wait. (OR-ing if set to 0). */ |
Pawel Zarembski |
0:01f31e923fe2 | 43 | U32 block_state; |
Pawel Zarembski |
0:01f31e923fe2 | 44 | |
Pawel Zarembski |
0:01f31e923fe2 | 45 | if (and_wait) { |
Pawel Zarembski |
0:01f31e923fe2 | 46 | /* Check for AND-connected events */ |
Pawel Zarembski |
0:01f31e923fe2 | 47 | if ((os_tsk.run->events & wait_flags) == wait_flags) { |
Pawel Zarembski |
0:01f31e923fe2 | 48 | os_tsk.run->events &= ~wait_flags; |
Pawel Zarembski |
0:01f31e923fe2 | 49 | return (OS_R_EVT); |
Pawel Zarembski |
0:01f31e923fe2 | 50 | } |
Pawel Zarembski |
0:01f31e923fe2 | 51 | block_state = WAIT_AND; |
Pawel Zarembski |
0:01f31e923fe2 | 52 | } |
Pawel Zarembski |
0:01f31e923fe2 | 53 | else { |
Pawel Zarembski |
0:01f31e923fe2 | 54 | /* Check for OR-connected events */ |
Pawel Zarembski |
0:01f31e923fe2 | 55 | if (os_tsk.run->events & wait_flags) { |
Pawel Zarembski |
0:01f31e923fe2 | 56 | os_tsk.run->waits = os_tsk.run->events & wait_flags; |
Pawel Zarembski |
0:01f31e923fe2 | 57 | os_tsk.run->events &= ~wait_flags; |
Pawel Zarembski |
0:01f31e923fe2 | 58 | return (OS_R_EVT); |
Pawel Zarembski |
0:01f31e923fe2 | 59 | } |
Pawel Zarembski |
0:01f31e923fe2 | 60 | block_state = WAIT_OR; |
Pawel Zarembski |
0:01f31e923fe2 | 61 | } |
Pawel Zarembski |
0:01f31e923fe2 | 62 | /* Task has to wait */ |
Pawel Zarembski |
0:01f31e923fe2 | 63 | os_tsk.run->waits = wait_flags; |
Pawel Zarembski |
0:01f31e923fe2 | 64 | rt_block (timeout, (U8)block_state); |
Pawel Zarembski |
0:01f31e923fe2 | 65 | return (OS_R_TMO); |
Pawel Zarembski |
0:01f31e923fe2 | 66 | } |
Pawel Zarembski |
0:01f31e923fe2 | 67 | |
Pawel Zarembski |
0:01f31e923fe2 | 68 | |
Pawel Zarembski |
0:01f31e923fe2 | 69 | /*--------------------------- rt_evt_set ------------------------------------*/ |
Pawel Zarembski |
0:01f31e923fe2 | 70 | |
Pawel Zarembski |
0:01f31e923fe2 | 71 | void rt_evt_set (U16 event_flags, OS_TID task_id) { |
Pawel Zarembski |
0:01f31e923fe2 | 72 | /* Set one or more event flags of a selectable task. */ |
Pawel Zarembski |
0:01f31e923fe2 | 73 | P_TCB p_tcb; |
Pawel Zarembski |
0:01f31e923fe2 | 74 | |
Pawel Zarembski |
0:01f31e923fe2 | 75 | p_tcb = os_active_TCB[task_id-1]; |
Pawel Zarembski |
0:01f31e923fe2 | 76 | if (p_tcb == NULL) { |
Pawel Zarembski |
0:01f31e923fe2 | 77 | return; |
Pawel Zarembski |
0:01f31e923fe2 | 78 | } |
Pawel Zarembski |
0:01f31e923fe2 | 79 | p_tcb->events |= event_flags; |
Pawel Zarembski |
0:01f31e923fe2 | 80 | event_flags = p_tcb->waits; |
Pawel Zarembski |
0:01f31e923fe2 | 81 | /* If the task is not waiting for an event, it should not be put */ |
Pawel Zarembski |
0:01f31e923fe2 | 82 | /* to ready state. */ |
Pawel Zarembski |
0:01f31e923fe2 | 83 | if (p_tcb->state == WAIT_AND) { |
Pawel Zarembski |
0:01f31e923fe2 | 84 | /* Check for AND-connected events */ |
Pawel Zarembski |
0:01f31e923fe2 | 85 | if ((p_tcb->events & event_flags) == event_flags) { |
Pawel Zarembski |
0:01f31e923fe2 | 86 | goto wkup; |
Pawel Zarembski |
0:01f31e923fe2 | 87 | } |
Pawel Zarembski |
0:01f31e923fe2 | 88 | } |
Pawel Zarembski |
0:01f31e923fe2 | 89 | if (p_tcb->state == WAIT_OR) { |
Pawel Zarembski |
0:01f31e923fe2 | 90 | /* Check for OR-connected events */ |
Pawel Zarembski |
0:01f31e923fe2 | 91 | if (p_tcb->events & event_flags) { |
Pawel Zarembski |
0:01f31e923fe2 | 92 | p_tcb->waits &= p_tcb->events; |
Pawel Zarembski |
0:01f31e923fe2 | 93 | wkup: p_tcb->events &= ~event_flags; |
Pawel Zarembski |
0:01f31e923fe2 | 94 | rt_rmv_dly (p_tcb); |
Pawel Zarembski |
0:01f31e923fe2 | 95 | p_tcb->events &= ~event_flags; |
Pawel Zarembski |
0:01f31e923fe2 | 96 | p_tcb->state = READY; |
Pawel Zarembski |
0:01f31e923fe2 | 97 | p_tcb->ret_val = OS_R_EVT; |
Pawel Zarembski |
0:01f31e923fe2 | 98 | rt_dispatch (p_tcb); |
Pawel Zarembski |
0:01f31e923fe2 | 99 | } |
Pawel Zarembski |
0:01f31e923fe2 | 100 | } |
Pawel Zarembski |
0:01f31e923fe2 | 101 | } |
Pawel Zarembski |
0:01f31e923fe2 | 102 | |
Pawel Zarembski |
0:01f31e923fe2 | 103 | |
Pawel Zarembski |
0:01f31e923fe2 | 104 | /*--------------------------- rt_evt_clr ------------------------------------*/ |
Pawel Zarembski |
0:01f31e923fe2 | 105 | |
Pawel Zarembski |
0:01f31e923fe2 | 106 | void rt_evt_clr (U16 clear_flags, OS_TID task_id) { |
Pawel Zarembski |
0:01f31e923fe2 | 107 | /* Clear one or more event flags (identified by "clear_flags") of a */ |
Pawel Zarembski |
0:01f31e923fe2 | 108 | /* selectable task (identified by "task"). */ |
Pawel Zarembski |
0:01f31e923fe2 | 109 | P_TCB task = os_active_TCB[task_id-1]; |
Pawel Zarembski |
0:01f31e923fe2 | 110 | |
Pawel Zarembski |
0:01f31e923fe2 | 111 | if (task == NULL) { |
Pawel Zarembski |
0:01f31e923fe2 | 112 | return; |
Pawel Zarembski |
0:01f31e923fe2 | 113 | } |
Pawel Zarembski |
0:01f31e923fe2 | 114 | task->events &= ~clear_flags; |
Pawel Zarembski |
0:01f31e923fe2 | 115 | } |
Pawel Zarembski |
0:01f31e923fe2 | 116 | |
Pawel Zarembski |
0:01f31e923fe2 | 117 | |
Pawel Zarembski |
0:01f31e923fe2 | 118 | /*--------------------------- isr_evt_set -----------------------------------*/ |
Pawel Zarembski |
0:01f31e923fe2 | 119 | |
Pawel Zarembski |
0:01f31e923fe2 | 120 | void isr_evt_set (U16 event_flags, OS_TID task_id) { |
Pawel Zarembski |
0:01f31e923fe2 | 121 | /* Same function as "os_evt_set", but to be called by ISRs. */ |
Pawel Zarembski |
0:01f31e923fe2 | 122 | P_TCB p_tcb = os_active_TCB[task_id-1]; |
Pawel Zarembski |
0:01f31e923fe2 | 123 | |
Pawel Zarembski |
0:01f31e923fe2 | 124 | if (p_tcb == NULL) { |
Pawel Zarembski |
0:01f31e923fe2 | 125 | return; |
Pawel Zarembski |
0:01f31e923fe2 | 126 | } |
Pawel Zarembski |
0:01f31e923fe2 | 127 | rt_psq_enq (p_tcb, event_flags); |
Pawel Zarembski |
0:01f31e923fe2 | 128 | rt_psh_req (); |
Pawel Zarembski |
0:01f31e923fe2 | 129 | } |
Pawel Zarembski |
0:01f31e923fe2 | 130 | |
Pawel Zarembski |
0:01f31e923fe2 | 131 | |
Pawel Zarembski |
0:01f31e923fe2 | 132 | /*--------------------------- rt_evt_get ------------------------------------*/ |
Pawel Zarembski |
0:01f31e923fe2 | 133 | |
Pawel Zarembski |
0:01f31e923fe2 | 134 | U16 rt_evt_get (void) { |
Pawel Zarembski |
0:01f31e923fe2 | 135 | /* Get events of a running task after waiting for OR connected events. */ |
Pawel Zarembski |
0:01f31e923fe2 | 136 | return (os_tsk.run->waits); |
Pawel Zarembski |
0:01f31e923fe2 | 137 | } |
Pawel Zarembski |
0:01f31e923fe2 | 138 | |
Pawel Zarembski |
0:01f31e923fe2 | 139 | |
Pawel Zarembski |
0:01f31e923fe2 | 140 | /*--------------------------- rt_evt_psh ------------------------------------*/ |
Pawel Zarembski |
0:01f31e923fe2 | 141 | |
Pawel Zarembski |
0:01f31e923fe2 | 142 | void rt_evt_psh (P_TCB p_CB, U16 set_flags) { |
Pawel Zarembski |
0:01f31e923fe2 | 143 | /* Check if task has to be waken up */ |
Pawel Zarembski |
0:01f31e923fe2 | 144 | U16 event_flags; |
Pawel Zarembski |
0:01f31e923fe2 | 145 | |
Pawel Zarembski |
0:01f31e923fe2 | 146 | p_CB->events |= set_flags; |
Pawel Zarembski |
0:01f31e923fe2 | 147 | event_flags = p_CB->waits; |
Pawel Zarembski |
0:01f31e923fe2 | 148 | if (p_CB->state == WAIT_AND) { |
Pawel Zarembski |
0:01f31e923fe2 | 149 | /* Check for AND-connected events */ |
Pawel Zarembski |
0:01f31e923fe2 | 150 | if ((p_CB->events & event_flags) == event_flags) { |
Pawel Zarembski |
0:01f31e923fe2 | 151 | goto rdy; |
Pawel Zarembski |
0:01f31e923fe2 | 152 | } |
Pawel Zarembski |
0:01f31e923fe2 | 153 | } |
Pawel Zarembski |
0:01f31e923fe2 | 154 | if (p_CB->state == WAIT_OR) { |
Pawel Zarembski |
0:01f31e923fe2 | 155 | /* Check for OR-connected events */ |
Pawel Zarembski |
0:01f31e923fe2 | 156 | if (p_CB->events & event_flags) { |
Pawel Zarembski |
0:01f31e923fe2 | 157 | p_CB->waits &= p_CB->events; |
Pawel Zarembski |
0:01f31e923fe2 | 158 | rdy: p_CB->events &= ~event_flags; |
Pawel Zarembski |
0:01f31e923fe2 | 159 | rt_rmv_dly (p_CB); |
Pawel Zarembski |
0:01f31e923fe2 | 160 | p_CB->state = READY; |
Pawel Zarembski |
0:01f31e923fe2 | 161 | p_CB->ret_val = OS_R_EVT; |
Pawel Zarembski |
0:01f31e923fe2 | 162 | rt_put_prio (&os_rdy, p_CB); |
Pawel Zarembski |
0:01f31e923fe2 | 163 | } |
Pawel Zarembski |
0:01f31e923fe2 | 164 | } |
Pawel Zarembski |
0:01f31e923fe2 | 165 | } |
Pawel Zarembski |
0:01f31e923fe2 | 166 | |
Pawel Zarembski |
0:01f31e923fe2 | 167 | /*---------------------------------------------------------------------------- |
Pawel Zarembski |
0:01f31e923fe2 | 168 | * end of file |
Pawel Zarembski |
0:01f31e923fe2 | 169 | *---------------------------------------------------------------------------*/ |