ソースの整理中ですが、利用はできます。

Dependencies:   EthernetInterface HttpServer TextLCD mbed-rpc mbed-rtos mbed Socket lwip-eth lwip-sys lwip

Committer:
yueee_yt
Date:
Wed Mar 12 04:39:15 2014 +0000
Revision:
2:14b689a85306
Parent:
0:7766f6712673
bug fix

Who changed what in which revision?

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