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_CM0.C
mkersh3 0:e7ca326e76ee 5 * Purpose: Hardware Abstraction Layer for Cortex-M0
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 BNE PrivilegedE
mkersh3 0:e7ca326e76ee 74 MOVS R0,#0x03 ; Unprivileged Thread mode, use PSP
mkersh3 0:e7ca326e76ee 75 MSR CONTROL,R0
mkersh3 0:e7ca326e76ee 76 BX LR
mkersh3 0:e7ca326e76ee 77 PrivilegedE
mkersh3 0:e7ca326e76ee 78 MOVS R0,#0x02 ; Privileged Thread mode, use PSP
mkersh3 0:e7ca326e76ee 79 MSR CONTROL,R0
mkersh3 0:e7ca326e76ee 80 BX LR
mkersh3 0:e7ca326e76ee 81
mkersh3 0:e7ca326e76ee 82 ALIGN
mkersh3 0:e7ca326e76ee 83 }
mkersh3 0:e7ca326e76ee 84
mkersh3 0:e7ca326e76ee 85
mkersh3 0:e7ca326e76ee 86 /*--------------------------- _alloc_box ------------------------------------*/
mkersh3 0:e7ca326e76ee 87
mkersh3 0:e7ca326e76ee 88 __asm void *_alloc_box (void *box_mem) {
mkersh3 0:e7ca326e76ee 89 /* Function wrapper for Unprivileged/Privileged mode. */
mkersh3 0:e7ca326e76ee 90 LDR R3,=__cpp(rt_alloc_box)
mkersh3 0:e7ca326e76ee 91 MOV R12,R3
mkersh3 0:e7ca326e76ee 92 MRS R3,IPSR
mkersh3 0:e7ca326e76ee 93 LSLS R3,#24
mkersh3 0:e7ca326e76ee 94 BNE PrivilegedA
mkersh3 0:e7ca326e76ee 95 MRS R3,CONTROL
mkersh3 0:e7ca326e76ee 96 LSLS R3,#31
mkersh3 0:e7ca326e76ee 97 BEQ PrivilegedA
mkersh3 0:e7ca326e76ee 98 SVC 0
mkersh3 0:e7ca326e76ee 99 BX LR
mkersh3 0:e7ca326e76ee 100 PrivilegedA
mkersh3 0:e7ca326e76ee 101 BX R12
mkersh3 0:e7ca326e76ee 102
mkersh3 0:e7ca326e76ee 103 ALIGN
mkersh3 0:e7ca326e76ee 104 }
mkersh3 0:e7ca326e76ee 105
mkersh3 0:e7ca326e76ee 106
mkersh3 0:e7ca326e76ee 107 /*--------------------------- _free_box -------------------------------------*/
mkersh3 0:e7ca326e76ee 108
mkersh3 0:e7ca326e76ee 109 __asm int _free_box (void *box_mem, void *box) {
mkersh3 0:e7ca326e76ee 110 /* Function wrapper for Unprivileged/Privileged mode. */
mkersh3 0:e7ca326e76ee 111 LDR R3,=__cpp(rt_free_box)
mkersh3 0:e7ca326e76ee 112 MOV R12,R3
mkersh3 0:e7ca326e76ee 113 MRS R3,IPSR
mkersh3 0:e7ca326e76ee 114 LSLS R3,#24
mkersh3 0:e7ca326e76ee 115 BNE PrivilegedF
mkersh3 0:e7ca326e76ee 116 MRS R3,CONTROL
mkersh3 0:e7ca326e76ee 117 LSLS R3,#31
mkersh3 0:e7ca326e76ee 118 BEQ PrivilegedF
mkersh3 0:e7ca326e76ee 119 SVC 0
mkersh3 0:e7ca326e76ee 120 BX LR
mkersh3 0:e7ca326e76ee 121 PrivilegedF
mkersh3 0:e7ca326e76ee 122 BX R12
mkersh3 0:e7ca326e76ee 123
mkersh3 0:e7ca326e76ee 124 ALIGN
mkersh3 0:e7ca326e76ee 125 }
mkersh3 0:e7ca326e76ee 126
mkersh3 0:e7ca326e76ee 127
mkersh3 0:e7ca326e76ee 128 /*-------------------------- SVC_Handler ------------------------------------*/
mkersh3 0:e7ca326e76ee 129
mkersh3 0:e7ca326e76ee 130 __asm void SVC_Handler (void) {
mkersh3 0:e7ca326e76ee 131 PRESERVE8
mkersh3 0:e7ca326e76ee 132
mkersh3 0:e7ca326e76ee 133 IMPORT SVC_Count
mkersh3 0:e7ca326e76ee 134 IMPORT SVC_Table
mkersh3 0:e7ca326e76ee 135 IMPORT rt_stk_check
mkersh3 0:e7ca326e76ee 136
mkersh3 0:e7ca326e76ee 137 MRS R0,PSP ; Read PSP
mkersh3 0:e7ca326e76ee 138 LDR R1,[R0,#24] ; Read Saved PC from Stack
mkersh3 0:e7ca326e76ee 139 SUBS R1,R1,#2 ; Point to SVC Instruction
mkersh3 0:e7ca326e76ee 140 LDRB R1,[R1] ; Load SVC Number
mkersh3 0:e7ca326e76ee 141 CMP R1,#0
mkersh3 0:e7ca326e76ee 142 BNE SVC_User ; User SVC Number > 0
mkersh3 0:e7ca326e76ee 143
mkersh3 0:e7ca326e76ee 144 MOV LR,R4
mkersh3 0:e7ca326e76ee 145 LDMIA R0,{R0-R3,R4} ; Read R0-R3,R12 from stack
mkersh3 0:e7ca326e76ee 146 MOV R12,R4
mkersh3 0:e7ca326e76ee 147 MOV R4,LR
mkersh3 0:e7ca326e76ee 148 BLX R12 ; Call SVC Function
mkersh3 0:e7ca326e76ee 149
mkersh3 0:e7ca326e76ee 150 MRS R3,PSP ; Read PSP
mkersh3 0:e7ca326e76ee 151 STMIA R3!,{R0-R2} ; Store return values
mkersh3 0:e7ca326e76ee 152
mkersh3 0:e7ca326e76ee 153 LDR R3,=__cpp(&os_tsk)
mkersh3 0:e7ca326e76ee 154 LDMIA R3!,{R1,R2} ; os_tsk.run, os_tsk.new
mkersh3 0:e7ca326e76ee 155 CMP R1,R2
mkersh3 0:e7ca326e76ee 156 BEQ SVC_Exit ; no task switch
mkersh3 0:e7ca326e76ee 157
mkersh3 0:e7ca326e76ee 158 SUBS R3,#8
mkersh3 0:e7ca326e76ee 159 CMP R1,#0 ; Runtask deleted?
mkersh3 0:e7ca326e76ee 160 BEQ SVC_Next
mkersh3 0:e7ca326e76ee 161
mkersh3 0:e7ca326e76ee 162 MRS R0,PSP ; Read PSP
mkersh3 0:e7ca326e76ee 163 SUBS R0,R0,#32 ; Adjust Start Address
mkersh3 0:e7ca326e76ee 164 STR R0,[R1,#TCB_TSTACK] ; Update os_tsk.run->tsk_stack
mkersh3 0:e7ca326e76ee 165 STMIA R0!,{R4-R7} ; Save old context (R4-R7)
mkersh3 0:e7ca326e76ee 166 MOV R4,R8
mkersh3 0:e7ca326e76ee 167 MOV R5,R9
mkersh3 0:e7ca326e76ee 168 MOV R6,R10
mkersh3 0:e7ca326e76ee 169 MOV R7,R11
mkersh3 0:e7ca326e76ee 170 STMIA R0!,{R4-R7} ; Save old context (R8-R11)
mkersh3 0:e7ca326e76ee 171
mkersh3 0:e7ca326e76ee 172 PUSH {R2,R3}
mkersh3 0:e7ca326e76ee 173 BL rt_stk_check ; Check for Stack overflow
mkersh3 0:e7ca326e76ee 174 POP {R2,R3}
mkersh3 0:e7ca326e76ee 175
mkersh3 0:e7ca326e76ee 176 SVC_Next
mkersh3 0:e7ca326e76ee 177 STR R2,[R3] ; os_tsk.run = os_tsk.new
mkersh3 0:e7ca326e76ee 178
mkersh3 0:e7ca326e76ee 179 LDR R0,[R2,#TCB_TSTACK] ; os_tsk.new->tsk_stack
mkersh3 0:e7ca326e76ee 180 ADDS R0,R0,#16 ; Adjust Start Address
mkersh3 0:e7ca326e76ee 181 LDMIA R0!,{R4-R7} ; Restore new Context (R8-R11)
mkersh3 0:e7ca326e76ee 182 MOV R8,R4
mkersh3 0:e7ca326e76ee 183 MOV R9,R5
mkersh3 0:e7ca326e76ee 184 MOV R10,R6
mkersh3 0:e7ca326e76ee 185 MOV R11,R7
mkersh3 0:e7ca326e76ee 186 MSR PSP,R0 ; Write PSP
mkersh3 0:e7ca326e76ee 187 SUBS R0,R0,#32 ; Adjust Start Address
mkersh3 0:e7ca326e76ee 188 LDMIA R0!,{R4-R7} ; Restore new Context (R4-R7)
mkersh3 0:e7ca326e76ee 189
mkersh3 0:e7ca326e76ee 190 SVC_Exit
mkersh3 0:e7ca326e76ee 191 MOVS R0,#:NOT:0xFFFFFFFD ; Set EXC_RETURN value
mkersh3 0:e7ca326e76ee 192 MVNS R0,R0
mkersh3 0:e7ca326e76ee 193 BX R0 ; RETI to Thread Mode, use PSP
mkersh3 0:e7ca326e76ee 194
mkersh3 0:e7ca326e76ee 195 /*------------------- User SVC ------------------------------*/
mkersh3 0:e7ca326e76ee 196
mkersh3 0:e7ca326e76ee 197 SVC_User
mkersh3 0:e7ca326e76ee 198 PUSH {R4,LR} ; Save Registers
mkersh3 0:e7ca326e76ee 199 LDR R2,=SVC_Count
mkersh3 0:e7ca326e76ee 200 LDR R2,[R2]
mkersh3 0:e7ca326e76ee 201 CMP R1,R2
mkersh3 0:e7ca326e76ee 202 BHI SVC_Done ; Overflow
mkersh3 0:e7ca326e76ee 203
mkersh3 0:e7ca326e76ee 204 LDR R4,=SVC_Table-4
mkersh3 0:e7ca326e76ee 205 LSLS R1,R1,#2
mkersh3 0:e7ca326e76ee 206 LDR R4,[R4,R1] ; Load SVC Function Address
mkersh3 0:e7ca326e76ee 207 MOV LR,R4
mkersh3 0:e7ca326e76ee 208
mkersh3 0:e7ca326e76ee 209 LDMIA R0,{R0-R3,R4} ; Read R0-R3,R12 from stack
mkersh3 0:e7ca326e76ee 210 MOV R12,R4
mkersh3 0:e7ca326e76ee 211 BLX LR ; Call SVC Function
mkersh3 0:e7ca326e76ee 212
mkersh3 0:e7ca326e76ee 213 MRS R4,PSP ; Read PSP
mkersh3 0:e7ca326e76ee 214 STMIA R4!,{R0-R3} ; Function return values
mkersh3 0:e7ca326e76ee 215 SVC_Done
mkersh3 0:e7ca326e76ee 216 POP {R4,PC} ; RETI
mkersh3 0:e7ca326e76ee 217
mkersh3 0:e7ca326e76ee 218 ALIGN
mkersh3 0:e7ca326e76ee 219 }
mkersh3 0:e7ca326e76ee 220
mkersh3 0:e7ca326e76ee 221
mkersh3 0:e7ca326e76ee 222 /*-------------------------- PendSV_Handler ---------------------------------*/
mkersh3 0:e7ca326e76ee 223
mkersh3 0:e7ca326e76ee 224 __asm void PendSV_Handler (void) {
mkersh3 0:e7ca326e76ee 225 PRESERVE8
mkersh3 0:e7ca326e76ee 226
mkersh3 0:e7ca326e76ee 227 BL __cpp(rt_pop_req)
mkersh3 0:e7ca326e76ee 228
mkersh3 0:e7ca326e76ee 229 Sys_Switch
mkersh3 0:e7ca326e76ee 230 LDR R3,=__cpp(&os_tsk)
mkersh3 0:e7ca326e76ee 231 LDMIA R3!,{R1,R2} ; os_tsk.run, os_tsk.new
mkersh3 0:e7ca326e76ee 232 CMP R1,R2
mkersh3 0:e7ca326e76ee 233 BEQ Sys_Exit ; no task switch
mkersh3 0:e7ca326e76ee 234
mkersh3 0:e7ca326e76ee 235 SUBS R3,#8
mkersh3 0:e7ca326e76ee 236
mkersh3 0:e7ca326e76ee 237 MRS R0,PSP ; Read PSP
mkersh3 0:e7ca326e76ee 238 SUBS R0,R0,#32 ; Adjust Start Address
mkersh3 0:e7ca326e76ee 239 STR R0,[R1,#TCB_TSTACK] ; Update os_tsk.run->tsk_stack
mkersh3 0:e7ca326e76ee 240 STMIA R0!,{R4-R7} ; Save old context (R4-R7)
mkersh3 0:e7ca326e76ee 241 MOV R4,R8
mkersh3 0:e7ca326e76ee 242 MOV R5,R9
mkersh3 0:e7ca326e76ee 243 MOV R6,R10
mkersh3 0:e7ca326e76ee 244 MOV R7,R11
mkersh3 0:e7ca326e76ee 245 STMIA R0!,{R4-R7} ; Save old context (R8-R11)
mkersh3 0:e7ca326e76ee 246
mkersh3 0:e7ca326e76ee 247 PUSH {R2,R3}
mkersh3 0:e7ca326e76ee 248 BL rt_stk_check ; Check for Stack overflow
mkersh3 0:e7ca326e76ee 249 POP {R2,R3}
mkersh3 0:e7ca326e76ee 250
mkersh3 0:e7ca326e76ee 251 STR R2,[R3] ; os_tsk.run = os_tsk.new
mkersh3 0:e7ca326e76ee 252
mkersh3 0:e7ca326e76ee 253 LDR R0,[R2,#TCB_TSTACK] ; os_tsk.new->tsk_stack
mkersh3 0:e7ca326e76ee 254 ADDS R0,R0,#16 ; Adjust Start Address
mkersh3 0:e7ca326e76ee 255 LDMIA R0!,{R4-R7} ; Restore new Context (R8-R11)
mkersh3 0:e7ca326e76ee 256 MOV R8,R4
mkersh3 0:e7ca326e76ee 257 MOV R9,R5
mkersh3 0:e7ca326e76ee 258 MOV R10,R6
mkersh3 0:e7ca326e76ee 259 MOV R11,R7
mkersh3 0:e7ca326e76ee 260 MSR PSP,R0 ; Write PSP
mkersh3 0:e7ca326e76ee 261 SUBS R0,R0,#32 ; Adjust Start Address
mkersh3 0:e7ca326e76ee 262 LDMIA R0!,{R4-R7} ; Restore new Context (R4-R7)
mkersh3 0:e7ca326e76ee 263
mkersh3 0:e7ca326e76ee 264 Sys_Exit
mkersh3 0:e7ca326e76ee 265 MOVS R0,#:NOT:0xFFFFFFFD ; Set EXC_RETURN value
mkersh3 0:e7ca326e76ee 266 MVNS R0,R0
mkersh3 0:e7ca326e76ee 267 BX R0 ; RETI to Thread Mode, use PSP
mkersh3 0:e7ca326e76ee 268
mkersh3 0:e7ca326e76ee 269 ALIGN
mkersh3 0:e7ca326e76ee 270 }
mkersh3 0:e7ca326e76ee 271
mkersh3 0:e7ca326e76ee 272
mkersh3 0:e7ca326e76ee 273 /*-------------------------- SysTick_Handler --------------------------------*/
mkersh3 0:e7ca326e76ee 274
mkersh3 0:e7ca326e76ee 275 __asm void SysTick_Handler (void) {
mkersh3 0:e7ca326e76ee 276 PRESERVE8
mkersh3 0:e7ca326e76ee 277
mkersh3 0:e7ca326e76ee 278 BL __cpp(rt_systick)
mkersh3 0:e7ca326e76ee 279 B Sys_Switch
mkersh3 0:e7ca326e76ee 280
mkersh3 0:e7ca326e76ee 281 ALIGN
mkersh3 0:e7ca326e76ee 282 }
mkersh3 0:e7ca326e76ee 283
mkersh3 0:e7ca326e76ee 284
mkersh3 0:e7ca326e76ee 285 /*-------------------------- OS_Tick_Handler --------------------------------*/
mkersh3 0:e7ca326e76ee 286
mkersh3 0:e7ca326e76ee 287 __asm void OS_Tick_Handler (void) {
mkersh3 0:e7ca326e76ee 288 PRESERVE8
mkersh3 0:e7ca326e76ee 289
mkersh3 0:e7ca326e76ee 290 BL __cpp(os_tick_irqack)
mkersh3 0:e7ca326e76ee 291 BL __cpp(rt_systick)
mkersh3 0:e7ca326e76ee 292 B Sys_Switch
mkersh3 0:e7ca326e76ee 293
mkersh3 0:e7ca326e76ee 294 ALIGN
mkersh3 0:e7ca326e76ee 295 }
mkersh3 0:e7ca326e76ee 296
mkersh3 0:e7ca326e76ee 297
mkersh3 0:e7ca326e76ee 298 /*----------------------------------------------------------------------------
mkersh3 0:e7ca326e76ee 299 * end of file
mkersh3 0:e7ca326e76ee 300 *---------------------------------------------------------------------------*/
mkersh3 0:e7ca326e76ee 301