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