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: HAL_CM3.C
mkersh3 0:e7ca326e76ee 5 * Purpose: Hardware Abstraction Layer for Cortex-M3
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_HAL_CM.h"
mkersh3 0:e7ca326e76ee 39 #include "rt_Task.h"
mkersh3 0:e7ca326e76ee 40 #include "rt_MemBox.h"
mkersh3 0:e7ca326e76ee 41
mkersh3 0:e7ca326e76ee 42
mkersh3 0:e7ca326e76ee 43 /*----------------------------------------------------------------------------
mkersh3 0:e7ca326e76ee 44 * Functions
mkersh3 0:e7ca326e76ee 45 *---------------------------------------------------------------------------*/
mkersh3 0:e7ca326e76ee 46
mkersh3 0:e7ca326e76ee 47
mkersh3 0:e7ca326e76ee 48 /*--------------------------- rt_set_PSP ------------------------------------*/
mkersh3 0:e7ca326e76ee 49
mkersh3 0:e7ca326e76ee 50 __asm void rt_set_PSP (U32 stack) {
mkersh3 0:e7ca326e76ee 51 MSR PSP,R0
mkersh3 0:e7ca326e76ee 52 BX LR
mkersh3 0:e7ca326e76ee 53 }
mkersh3 0:e7ca326e76ee 54
mkersh3 0:e7ca326e76ee 55
mkersh3 0:e7ca326e76ee 56 /*--------------------------- rt_get_PSP ------------------------------------*/
mkersh3 0:e7ca326e76ee 57
mkersh3 0:e7ca326e76ee 58 __asm U32 rt_get_PSP (void) {
mkersh3 0:e7ca326e76ee 59 MRS R0,PSP
mkersh3 0:e7ca326e76ee 60 BX LR
mkersh3 0:e7ca326e76ee 61 }
mkersh3 0:e7ca326e76ee 62
mkersh3 0:e7ca326e76ee 63
mkersh3 0:e7ca326e76ee 64 /*--------------------------- os_set_env ------------------------------------*/
mkersh3 0:e7ca326e76ee 65
mkersh3 0:e7ca326e76ee 66 __asm void os_set_env (void) {
mkersh3 0:e7ca326e76ee 67 /* Switch to Unprivileged/Privileged Thread mode, use PSP. */
mkersh3 0:e7ca326e76ee 68 MOV R0,SP ; PSP = MSP
mkersh3 0:e7ca326e76ee 69 MSR PSP,R0
mkersh3 0:e7ca326e76ee 70 LDR R0,=__cpp(&os_flags)
mkersh3 0:e7ca326e76ee 71 LDRB R0,[R0]
mkersh3 0:e7ca326e76ee 72 LSLS R0,#31
mkersh3 0:e7ca326e76ee 73 MOVNE R0,#0x02 ; Privileged Thread mode, use PSP
mkersh3 0:e7ca326e76ee 74 MOVEQ R0,#0x03 ; Unprivileged Thread mode, use PSP
mkersh3 0:e7ca326e76ee 75 MSR CONTROL,R0
mkersh3 0:e7ca326e76ee 76 BX LR
mkersh3 0:e7ca326e76ee 77
mkersh3 0:e7ca326e76ee 78 ALIGN
mkersh3 0:e7ca326e76ee 79 }
mkersh3 0:e7ca326e76ee 80
mkersh3 0:e7ca326e76ee 81
mkersh3 0:e7ca326e76ee 82 /*--------------------------- _alloc_box ------------------------------------*/
mkersh3 0:e7ca326e76ee 83
mkersh3 0:e7ca326e76ee 84 __asm void *_alloc_box (void *box_mem) {
mkersh3 0:e7ca326e76ee 85 /* Function wrapper for Unprivileged/Privileged mode. */
mkersh3 0:e7ca326e76ee 86 LDR R12,=__cpp(rt_alloc_box)
mkersh3 0:e7ca326e76ee 87 MRS R3,IPSR
mkersh3 0:e7ca326e76ee 88 LSLS R3,#24
mkersh3 0:e7ca326e76ee 89 BXNE R12
mkersh3 0:e7ca326e76ee 90 MRS R3,CONTROL
mkersh3 0:e7ca326e76ee 91 LSLS R3,#31
mkersh3 0:e7ca326e76ee 92 BXEQ R12
mkersh3 0:e7ca326e76ee 93 SVC 0
mkersh3 0:e7ca326e76ee 94 BX LR
mkersh3 0:e7ca326e76ee 95
mkersh3 0:e7ca326e76ee 96 ALIGN
mkersh3 0:e7ca326e76ee 97 }
mkersh3 0:e7ca326e76ee 98
mkersh3 0:e7ca326e76ee 99
mkersh3 0:e7ca326e76ee 100 /*--------------------------- _free_box -------------------------------------*/
mkersh3 0:e7ca326e76ee 101
mkersh3 0:e7ca326e76ee 102 __asm int _free_box (void *box_mem, void *box) {
mkersh3 0:e7ca326e76ee 103 /* Function wrapper for Unprivileged/Privileged mode. */
mkersh3 0:e7ca326e76ee 104 LDR R12,=__cpp(rt_free_box)
mkersh3 0:e7ca326e76ee 105 MRS R3,IPSR
mkersh3 0:e7ca326e76ee 106 LSLS R3,#24
mkersh3 0:e7ca326e76ee 107 BXNE R12
mkersh3 0:e7ca326e76ee 108 MRS R3,CONTROL
mkersh3 0:e7ca326e76ee 109 LSLS R3,#31
mkersh3 0:e7ca326e76ee 110 BXEQ R12
mkersh3 0:e7ca326e76ee 111 SVC 0
mkersh3 0:e7ca326e76ee 112 BX LR
mkersh3 0:e7ca326e76ee 113
mkersh3 0:e7ca326e76ee 114 ALIGN
mkersh3 0:e7ca326e76ee 115 }
mkersh3 0:e7ca326e76ee 116
mkersh3 0:e7ca326e76ee 117
mkersh3 0:e7ca326e76ee 118 /*-------------------------- SVC_Handler ------------------------------------*/
mkersh3 0:e7ca326e76ee 119
mkersh3 0:e7ca326e76ee 120 __asm void SVC_Handler (void) {
mkersh3 0:e7ca326e76ee 121 PRESERVE8
mkersh3 0:e7ca326e76ee 122
mkersh3 0:e7ca326e76ee 123 IMPORT SVC_Count
mkersh3 0:e7ca326e76ee 124 IMPORT SVC_Table
mkersh3 0:e7ca326e76ee 125 IMPORT rt_stk_check
mkersh3 0:e7ca326e76ee 126
mkersh3 0:e7ca326e76ee 127 MRS R0,PSP ; Read PSP
mkersh3 0:e7ca326e76ee 128 LDR R1,[R0,#24] ; Read Saved PC from Stack
mkersh3 0:e7ca326e76ee 129 LDRB R1,[R1,#-2] ; Load SVC Number
mkersh3 0:e7ca326e76ee 130 CBNZ R1,SVC_User
mkersh3 0:e7ca326e76ee 131
mkersh3 0:e7ca326e76ee 132 LDM R0,{R0-R3,R12} ; Read R0-R3,R12 from stack
mkersh3 0:e7ca326e76ee 133 BLX R12 ; Call SVC Function
mkersh3 0:e7ca326e76ee 134
mkersh3 0:e7ca326e76ee 135 MRS R12,PSP ; Read PSP
mkersh3 0:e7ca326e76ee 136 STM R12,{R0-R2} ; Store return values
mkersh3 0:e7ca326e76ee 137
mkersh3 0:e7ca326e76ee 138 LDR R3,=__cpp(&os_tsk)
mkersh3 0:e7ca326e76ee 139 LDM R3,{R1,R2} ; os_tsk.run, os_tsk.new
mkersh3 0:e7ca326e76ee 140 CMP R1,R2
mkersh3 0:e7ca326e76ee 141 BEQ SVC_Exit ; no task switch
mkersh3 0:e7ca326e76ee 142
mkersh3 0:e7ca326e76ee 143 CBZ R1,SVC_Next ; Runtask deleted?
mkersh3 0:e7ca326e76ee 144 STMDB R12!,{R4-R11} ; Save Old context
mkersh3 0:e7ca326e76ee 145 STR R12,[R1,#TCB_TSTACK] ; Update os_tsk.run->tsk_stack
mkersh3 0:e7ca326e76ee 146
mkersh3 0:e7ca326e76ee 147 PUSH {R2,R3}
mkersh3 0:e7ca326e76ee 148 BL rt_stk_check ; Check for Stack overflow
mkersh3 0:e7ca326e76ee 149 POP {R2,R3}
mkersh3 0:e7ca326e76ee 150
mkersh3 0:e7ca326e76ee 151 SVC_Next
mkersh3 0:e7ca326e76ee 152 STR R2,[R3] ; os_tsk.run = os_tsk.new
mkersh3 0:e7ca326e76ee 153
mkersh3 0:e7ca326e76ee 154 LDR R12,[R2,#TCB_TSTACK] ; os_tsk.new->tsk_stack
mkersh3 0:e7ca326e76ee 155 LDMIA R12!,{R4-R11} ; Restore New Context
mkersh3 0:e7ca326e76ee 156 MSR PSP,R12 ; Write PSP
mkersh3 0:e7ca326e76ee 157
mkersh3 0:e7ca326e76ee 158 SVC_Exit
mkersh3 0:e7ca326e76ee 159 MVN LR,#:NOT:0xFFFFFFFD ; set EXC_RETURN value
mkersh3 0:e7ca326e76ee 160 BX LR
mkersh3 0:e7ca326e76ee 161
mkersh3 0:e7ca326e76ee 162 /*------------------- User SVC ------------------------------*/
mkersh3 0:e7ca326e76ee 163
mkersh3 0:e7ca326e76ee 164 SVC_User
mkersh3 0:e7ca326e76ee 165 PUSH {R4,LR} ; Save Registers
mkersh3 0:e7ca326e76ee 166 LDR R2,=SVC_Count
mkersh3 0:e7ca326e76ee 167 LDR R2,[R2]
mkersh3 0:e7ca326e76ee 168 CMP R1,R2
mkersh3 0:e7ca326e76ee 169 BHI SVC_Done ; Overflow
mkersh3 0:e7ca326e76ee 170
mkersh3 0:e7ca326e76ee 171 LDR R4,=SVC_Table-4
mkersh3 0:e7ca326e76ee 172 LDR R4,[R4,R1,LSL #2] ; Load SVC Function Address
mkersh3 0:e7ca326e76ee 173
mkersh3 0:e7ca326e76ee 174 LDM R0,{R0-R3,R12} ; Read R0-R3,R12 from stack
mkersh3 0:e7ca326e76ee 175 BLX R4 ; Call SVC Function
mkersh3 0:e7ca326e76ee 176
mkersh3 0:e7ca326e76ee 177 MRS R12,PSP
mkersh3 0:e7ca326e76ee 178 STM R12,{R0-R3} ; Function return values
mkersh3 0:e7ca326e76ee 179 SVC_Done
mkersh3 0:e7ca326e76ee 180 POP {R4,PC} ; RETI
mkersh3 0:e7ca326e76ee 181
mkersh3 0:e7ca326e76ee 182 ALIGN
mkersh3 0:e7ca326e76ee 183 }
mkersh3 0:e7ca326e76ee 184
mkersh3 0:e7ca326e76ee 185
mkersh3 0:e7ca326e76ee 186 /*-------------------------- PendSV_Handler ---------------------------------*/
mkersh3 0:e7ca326e76ee 187
mkersh3 0:e7ca326e76ee 188 __asm void PendSV_Handler (void) {
mkersh3 0:e7ca326e76ee 189 PRESERVE8
mkersh3 0:e7ca326e76ee 190
mkersh3 0:e7ca326e76ee 191 BL __cpp(rt_pop_req)
mkersh3 0:e7ca326e76ee 192
mkersh3 0:e7ca326e76ee 193 Sys_Switch
mkersh3 0:e7ca326e76ee 194 LDR R3,=__cpp(&os_tsk)
mkersh3 0:e7ca326e76ee 195 LDM R3,{R1,R2} ; os_tsk.run, os_tsk.new
mkersh3 0:e7ca326e76ee 196 CMP R1,R2
mkersh3 0:e7ca326e76ee 197 BEQ Sys_Exit
mkersh3 0:e7ca326e76ee 198
mkersh3 0:e7ca326e76ee 199 MRS R12,PSP ; Read PSP
mkersh3 0:e7ca326e76ee 200 STMDB R12!,{R4-R11} ; Save Old context
mkersh3 0:e7ca326e76ee 201 STR R12,[R1,#TCB_TSTACK] ; Update os_tsk.run->tsk_stack
mkersh3 0:e7ca326e76ee 202
mkersh3 0:e7ca326e76ee 203 PUSH {R2,R3}
mkersh3 0:e7ca326e76ee 204 BL rt_stk_check ; Check for Stack overflow
mkersh3 0:e7ca326e76ee 205 POP {R2,R3}
mkersh3 0:e7ca326e76ee 206
mkersh3 0:e7ca326e76ee 207 STR R2,[R3] ; os_tsk.run = os_tsk.new
mkersh3 0:e7ca326e76ee 208
mkersh3 0:e7ca326e76ee 209 LDR R12,[R2,#TCB_TSTACK] ; os_tsk.new->tsk_stack
mkersh3 0:e7ca326e76ee 210 LDMIA R12!,{R4-R11} ; Restore New Context
mkersh3 0:e7ca326e76ee 211 MSR PSP,R12 ; Write PSP
mkersh3 0:e7ca326e76ee 212
mkersh3 0:e7ca326e76ee 213 Sys_Exit
mkersh3 0:e7ca326e76ee 214 MVN LR,#:NOT:0xFFFFFFFD ; set EXC_RETURN value
mkersh3 0:e7ca326e76ee 215 BX LR ; Return to Thread Mode
mkersh3 0:e7ca326e76ee 216
mkersh3 0:e7ca326e76ee 217 ALIGN
mkersh3 0:e7ca326e76ee 218 }
mkersh3 0:e7ca326e76ee 219
mkersh3 0:e7ca326e76ee 220
mkersh3 0:e7ca326e76ee 221 /*-------------------------- SysTick_Handler --------------------------------*/
mkersh3 0:e7ca326e76ee 222
mkersh3 0:e7ca326e76ee 223 __asm void SysTick_Handler (void) {
mkersh3 0:e7ca326e76ee 224 PRESERVE8
mkersh3 0:e7ca326e76ee 225
mkersh3 0:e7ca326e76ee 226 BL __cpp(rt_systick)
mkersh3 0:e7ca326e76ee 227 B Sys_Switch
mkersh3 0:e7ca326e76ee 228
mkersh3 0:e7ca326e76ee 229 ALIGN
mkersh3 0:e7ca326e76ee 230 }
mkersh3 0:e7ca326e76ee 231
mkersh3 0:e7ca326e76ee 232
mkersh3 0:e7ca326e76ee 233 /*-------------------------- OS_Tick_Handler --------------------------------*/
mkersh3 0:e7ca326e76ee 234
mkersh3 0:e7ca326e76ee 235 __asm void OS_Tick_Handler (void) {
mkersh3 0:e7ca326e76ee 236 PRESERVE8
mkersh3 0:e7ca326e76ee 237
mkersh3 0:e7ca326e76ee 238 BL __cpp(os_tick_irqack)
mkersh3 0:e7ca326e76ee 239 BL __cpp(rt_systick)
mkersh3 0:e7ca326e76ee 240 B Sys_Switch
mkersh3 0:e7ca326e76ee 241
mkersh3 0:e7ca326e76ee 242 ALIGN
mkersh3 0:e7ca326e76ee 243 }
mkersh3 0:e7ca326e76ee 244
mkersh3 0:e7ca326e76ee 245
mkersh3 0:e7ca326e76ee 246 /*----------------------------------------------------------------------------
mkersh3 0:e7ca326e76ee 247 * end of file
mkersh3 0:e7ca326e76ee 248 *---------------------------------------------------------------------------*/
mkersh3 0:e7ca326e76ee 249