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

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?

UserRevisionLine numberNew contents of line
mkersh3 0:e7ca326e76ee 1 /*----------------------------------------------------------------------------
mkersh3 0:e7ca326e76ee 2 * RL-ARM - RTX
mkersh3 0:e7ca326e76ee 3 *----------------------------------------------------------------------------
mkersh3 0:e7ca326e76ee 4 * Name: RT_SEMAPHORE.C
mkersh3 0:e7ca326e76ee 5 * Purpose: Implements binary and counting semaphores
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_List.h"
mkersh3 0:e7ca326e76ee 39 #include "rt_Task.h"
mkersh3 0:e7ca326e76ee 40 #include "rt_Semaphore.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_sem_init -----------------------------------*/
mkersh3 0:e7ca326e76ee 50
mkersh3 0:e7ca326e76ee 51 void rt_sem_init (OS_ID semaphore, U16 token_count) {
mkersh3 0:e7ca326e76ee 52 /* Initialize a semaphore */
mkersh3 0:e7ca326e76ee 53 P_SCB p_SCB = semaphore;
mkersh3 0:e7ca326e76ee 54
mkersh3 0:e7ca326e76ee 55 p_SCB->cb_type = SCB;
mkersh3 0:e7ca326e76ee 56 p_SCB->p_lnk = NULL;
mkersh3 0:e7ca326e76ee 57 p_SCB->tokens = token_count;
mkersh3 0:e7ca326e76ee 58 }
mkersh3 0:e7ca326e76ee 59
mkersh3 0:e7ca326e76ee 60
mkersh3 0:e7ca326e76ee 61 /*--------------------------- rt_sem_delete ---------------------------------*/
mkersh3 0:e7ca326e76ee 62 OS_RESULT rt_sem_delete (OS_ID semaphore) {
mkersh3 0:e7ca326e76ee 63 /* Delete semaphore */
mkersh3 0:e7ca326e76ee 64 P_SCB p_SCB = semaphore;
mkersh3 0:e7ca326e76ee 65 P_TCB p_TCB;
mkersh3 0:e7ca326e76ee 66
mkersh3 0:e7ca326e76ee 67 while (p_SCB->p_lnk != NULL) {
mkersh3 0:e7ca326e76ee 68 /* A task is waiting for token */
mkersh3 0:e7ca326e76ee 69 p_TCB = rt_get_first ((P_XCB)p_SCB);
mkersh3 0:e7ca326e76ee 70 rt_ret_val(p_TCB, 0);
mkersh3 0:e7ca326e76ee 71 rt_rmv_dly(p_TCB);
mkersh3 0:e7ca326e76ee 72 p_TCB->state = READY;
mkersh3 0:e7ca326e76ee 73 rt_put_prio (&os_rdy, p_TCB);
mkersh3 0:e7ca326e76ee 74 }
mkersh3 0:e7ca326e76ee 75
mkersh3 0:e7ca326e76ee 76 if (os_rdy.p_lnk && (os_rdy.p_lnk->prio > os_tsk.run->prio)) {
mkersh3 0:e7ca326e76ee 77 /* preempt running task */
mkersh3 0:e7ca326e76ee 78 rt_put_prio (&os_rdy, os_tsk.run);
mkersh3 0:e7ca326e76ee 79 os_tsk.run->state = READY;
mkersh3 0:e7ca326e76ee 80 rt_dispatch (NULL);
mkersh3 0:e7ca326e76ee 81 }
mkersh3 0:e7ca326e76ee 82
mkersh3 0:e7ca326e76ee 83 p_SCB->cb_type = 0;
mkersh3 0:e7ca326e76ee 84
mkersh3 0:e7ca326e76ee 85 return (OS_R_OK);
mkersh3 0:e7ca326e76ee 86 }
mkersh3 0:e7ca326e76ee 87
mkersh3 0:e7ca326e76ee 88 /*--------------------------- rt_sem_send -----------------------------------*/
mkersh3 0:e7ca326e76ee 89
mkersh3 0:e7ca326e76ee 90 OS_RESULT rt_sem_send (OS_ID semaphore) {
mkersh3 0:e7ca326e76ee 91 /* Return a token to semaphore */
mkersh3 0:e7ca326e76ee 92 P_SCB p_SCB = semaphore;
mkersh3 0:e7ca326e76ee 93 P_TCB p_TCB;
mkersh3 0:e7ca326e76ee 94
mkersh3 0:e7ca326e76ee 95 if (p_SCB->p_lnk != NULL) {
mkersh3 0:e7ca326e76ee 96 /* A task is waiting for token */
mkersh3 0:e7ca326e76ee 97 p_TCB = rt_get_first ((P_XCB)p_SCB);
mkersh3 0:e7ca326e76ee 98 rt_ret_val(p_TCB, 1);
mkersh3 0:e7ca326e76ee 99 rt_rmv_dly (p_TCB);
mkersh3 0:e7ca326e76ee 100 rt_dispatch (p_TCB);
mkersh3 0:e7ca326e76ee 101 }
mkersh3 0:e7ca326e76ee 102 else {
mkersh3 0:e7ca326e76ee 103 /* Store token. */
mkersh3 0:e7ca326e76ee 104 p_SCB->tokens++;
mkersh3 0:e7ca326e76ee 105 }
mkersh3 0:e7ca326e76ee 106 return (OS_R_OK);
mkersh3 0:e7ca326e76ee 107 }
mkersh3 0:e7ca326e76ee 108
mkersh3 0:e7ca326e76ee 109
mkersh3 0:e7ca326e76ee 110 /*--------------------------- rt_sem_wait -----------------------------------*/
mkersh3 0:e7ca326e76ee 111
mkersh3 0:e7ca326e76ee 112 OS_RESULT rt_sem_wait (OS_ID semaphore, U16 timeout) {
mkersh3 0:e7ca326e76ee 113 /* Obtain a token; possibly wait for it */
mkersh3 0:e7ca326e76ee 114 P_SCB p_SCB = semaphore;
mkersh3 0:e7ca326e76ee 115
mkersh3 0:e7ca326e76ee 116 if (p_SCB->tokens) {
mkersh3 0:e7ca326e76ee 117 p_SCB->tokens--;
mkersh3 0:e7ca326e76ee 118 return (OS_R_OK);
mkersh3 0:e7ca326e76ee 119 }
mkersh3 0:e7ca326e76ee 120 /* No token available: wait for one */
mkersh3 0:e7ca326e76ee 121 if (timeout == 0) {
mkersh3 0:e7ca326e76ee 122 return (OS_R_TMO);
mkersh3 0:e7ca326e76ee 123 }
mkersh3 0:e7ca326e76ee 124 if (p_SCB->p_lnk != NULL) {
mkersh3 0:e7ca326e76ee 125 rt_put_prio ((P_XCB)p_SCB, os_tsk.run);
mkersh3 0:e7ca326e76ee 126 }
mkersh3 0:e7ca326e76ee 127 else {
mkersh3 0:e7ca326e76ee 128 p_SCB->p_lnk = os_tsk.run;
mkersh3 0:e7ca326e76ee 129 os_tsk.run->p_lnk = NULL;
mkersh3 0:e7ca326e76ee 130 os_tsk.run->p_rlnk = (P_TCB)p_SCB;
mkersh3 0:e7ca326e76ee 131 }
mkersh3 0:e7ca326e76ee 132 rt_block(timeout, WAIT_SEM);
mkersh3 0:e7ca326e76ee 133 return (OS_R_TMO);
mkersh3 0:e7ca326e76ee 134 }
mkersh3 0:e7ca326e76ee 135
mkersh3 0:e7ca326e76ee 136
mkersh3 0:e7ca326e76ee 137 /*--------------------------- isr_sem_send ----------------------------------*/
mkersh3 0:e7ca326e76ee 138
mkersh3 0:e7ca326e76ee 139 void isr_sem_send (OS_ID semaphore) {
mkersh3 0:e7ca326e76ee 140 /* Same function as "os_sem"send", but to be called by ISRs */
mkersh3 0:e7ca326e76ee 141 P_SCB p_SCB = semaphore;
mkersh3 0:e7ca326e76ee 142
mkersh3 0:e7ca326e76ee 143 rt_psq_enq (p_SCB, 0);
mkersh3 0:e7ca326e76ee 144 rt_psh_req ();
mkersh3 0:e7ca326e76ee 145 }
mkersh3 0:e7ca326e76ee 146
mkersh3 0:e7ca326e76ee 147
mkersh3 0:e7ca326e76ee 148 /*--------------------------- rt_sem_psh ------------------------------------*/
mkersh3 0:e7ca326e76ee 149
mkersh3 0:e7ca326e76ee 150 void rt_sem_psh (P_SCB p_CB) {
mkersh3 0:e7ca326e76ee 151 /* Check if task has to be waken up */
mkersh3 0:e7ca326e76ee 152 P_TCB p_TCB;
mkersh3 0:e7ca326e76ee 153
mkersh3 0:e7ca326e76ee 154 if (p_CB->p_lnk != NULL) {
mkersh3 0:e7ca326e76ee 155 /* A task is waiting for token */
mkersh3 0:e7ca326e76ee 156 p_TCB = rt_get_first ((P_XCB)p_CB);
mkersh3 0:e7ca326e76ee 157 rt_rmv_dly (p_TCB);
mkersh3 0:e7ca326e76ee 158 p_TCB->state = READY;
mkersh3 0:e7ca326e76ee 159 rt_ret_val(p_TCB, 1);
mkersh3 0:e7ca326e76ee 160 rt_put_prio (&os_rdy, p_TCB);
mkersh3 0:e7ca326e76ee 161 }
mkersh3 0:e7ca326e76ee 162 else {
mkersh3 0:e7ca326e76ee 163 /* Store token */
mkersh3 0:e7ca326e76ee 164 p_CB->tokens++;
mkersh3 0:e7ca326e76ee 165 }
mkersh3 0:e7ca326e76ee 166 }
mkersh3 0:e7ca326e76ee 167
mkersh3 0:e7ca326e76ee 168 /*----------------------------------------------------------------------------
mkersh3 0:e7ca326e76ee 169 * end of file
mkersh3 0:e7ca326e76ee 170 *---------------------------------------------------------------------------*/
mkersh3 0:e7ca326e76ee 171