NRF: receive, ntp, Data to Sd-card working

Dependencies:   F7_Ethernet mbed BSP_DISCO_F746NG Test_Mainboard SDFileSystem RF24

Committer:
lowlowry
Date:
Sun Jun 20 13:48:06 2021 +0000
Revision:
4:5ecb71f149bf
Parent:
0:d984976f1f1c
NRF: receive, ntp, Data to Sd-card working

Who changed what in which revision?

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