Final 350 project

Dependencies:   uzair Camera_LS_Y201 F7_Ethernet LCD_DISCO_F746NG NetworkAPI SDFileSystem mbed

Committer:
shoaib_ahmed
Date:
Mon Jul 31 09:16:35 2017 +0000
Revision:
0:791a779d6220
final project;

Who changed what in which revision?

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