mbed client on ethernet with LWIP

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Fork of mbed-client-classic-example-lwip by sandbox

Committer:
mbedAustin
Date:
Thu Jun 09 17:08:36 2016 +0000
Revision:
11:cada08fc8a70
Commit for public Consumption

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedAustin 11:cada08fc8a70 1 /*----------------------------------------------------------------------------
mbedAustin 11:cada08fc8a70 2 * RL-ARM - RTX
mbedAustin 11:cada08fc8a70 3 *----------------------------------------------------------------------------
mbedAustin 11:cada08fc8a70 4 * Name: HAL_CM.C
mbedAustin 11:cada08fc8a70 5 * Purpose: Hardware Abstraction Layer for ARM7TDMI
mbedAustin 11:cada08fc8a70 6 * Rev.: V1.0
mbedAustin 11:cada08fc8a70 7 *----------------------------------------------------------------------------
mbedAustin 11:cada08fc8a70 8 *
mbedAustin 11:cada08fc8a70 9 * Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH
mbedAustin 11:cada08fc8a70 10 * All rights reserved.
mbedAustin 11:cada08fc8a70 11 * Redistribution and use in source and binary forms, with or without
mbedAustin 11:cada08fc8a70 12 * modification, are permitted provided that the following conditions are met:
mbedAustin 11:cada08fc8a70 13 * - Redistributions of source code must retain the above copyright
mbedAustin 11:cada08fc8a70 14 * notice, this list of conditions and the following disclaimer.
mbedAustin 11:cada08fc8a70 15 * - Redistributions in binary form must reproduce the above copyright
mbedAustin 11:cada08fc8a70 16 * notice, this list of conditions and the following disclaimer in the
mbedAustin 11:cada08fc8a70 17 * documentation and/or other materials provided with the distribution.
mbedAustin 11:cada08fc8a70 18 * - Neither the name of ARM nor the names of its contributors may be used
mbedAustin 11:cada08fc8a70 19 * to endorse or promote products derived from this software without
mbedAustin 11:cada08fc8a70 20 * specific prior written permission.
mbedAustin 11:cada08fc8a70 21 *
mbedAustin 11:cada08fc8a70 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbedAustin 11:cada08fc8a70 23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbedAustin 11:cada08fc8a70 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
mbedAustin 11:cada08fc8a70 25 * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
mbedAustin 11:cada08fc8a70 26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
mbedAustin 11:cada08fc8a70 27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
mbedAustin 11:cada08fc8a70 28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
mbedAustin 11:cada08fc8a70 29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
mbedAustin 11:cada08fc8a70 30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
mbedAustin 11:cada08fc8a70 31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
mbedAustin 11:cada08fc8a70 32 * POSSIBILITY OF SUCH DAMAGE.
mbedAustin 11:cada08fc8a70 33 *---------------------------------------------------------------------------*/
mbedAustin 11:cada08fc8a70 34
mbedAustin 11:cada08fc8a70 35 #include "rt_TypeDef.h"
mbedAustin 11:cada08fc8a70 36 #include "RTX_Conf.h"
mbedAustin 11:cada08fc8a70 37 #include "rt_HAL_CM.h"
mbedAustin 11:cada08fc8a70 38
mbedAustin 11:cada08fc8a70 39
mbedAustin 11:cada08fc8a70 40 /*----------------------------------------------------------------------------
mbedAustin 11:cada08fc8a70 41 * Global Variables
mbedAustin 11:cada08fc8a70 42 *---------------------------------------------------------------------------*/
mbedAustin 11:cada08fc8a70 43
mbedAustin 11:cada08fc8a70 44 #ifdef DBG_MSG
mbedAustin 11:cada08fc8a70 45 BIT dbg_msg;
mbedAustin 11:cada08fc8a70 46 #endif
mbedAustin 11:cada08fc8a70 47
mbedAustin 11:cada08fc8a70 48 /*----------------------------------------------------------------------------
mbedAustin 11:cada08fc8a70 49 * Functions
mbedAustin 11:cada08fc8a70 50 *---------------------------------------------------------------------------*/
mbedAustin 11:cada08fc8a70 51
mbedAustin 11:cada08fc8a70 52
mbedAustin 11:cada08fc8a70 53 /*--------------------------- rt_init_stack ---------------------------------*/
mbedAustin 11:cada08fc8a70 54
mbedAustin 11:cada08fc8a70 55 void rt_init_stack (P_TCB p_TCB, FUNCP task_body) {
mbedAustin 11:cada08fc8a70 56 /* Prepare TCB and saved context for a first time start of a task. */
mbedAustin 11:cada08fc8a70 57 U32 *stk,i,size;
mbedAustin 11:cada08fc8a70 58
mbedAustin 11:cada08fc8a70 59 /* Prepare a complete interrupt frame for first task start */
mbedAustin 11:cada08fc8a70 60 size = p_TCB->priv_stack >> 2;
mbedAustin 11:cada08fc8a70 61
mbedAustin 11:cada08fc8a70 62 /* Write to the top of stack. */
mbedAustin 11:cada08fc8a70 63 stk = &p_TCB->stack[size];
mbedAustin 11:cada08fc8a70 64
mbedAustin 11:cada08fc8a70 65 /* Auto correct to 8-byte ARM stack alignment. */
mbedAustin 11:cada08fc8a70 66 if ((U32)stk & 0x04) {
mbedAustin 11:cada08fc8a70 67 stk--;
mbedAustin 11:cada08fc8a70 68 }
mbedAustin 11:cada08fc8a70 69
mbedAustin 11:cada08fc8a70 70 stk -= 16;
mbedAustin 11:cada08fc8a70 71
mbedAustin 11:cada08fc8a70 72 /* Default xPSR and initial PC */
mbedAustin 11:cada08fc8a70 73 stk[15] = (U32)task_body + 4; /* add 4 byte offset because SUB PC, LR - 4 */
mbedAustin 11:cada08fc8a70 74 stk[0] = INITIAL_xPSR;
mbedAustin 11:cada08fc8a70 75
mbedAustin 11:cada08fc8a70 76 /* Clear R0-R13/LR registers. */
mbedAustin 11:cada08fc8a70 77 for (i = 1; i < 14; i++) {
mbedAustin 11:cada08fc8a70 78 stk[i] = 0;
mbedAustin 11:cada08fc8a70 79 }
mbedAustin 11:cada08fc8a70 80
mbedAustin 11:cada08fc8a70 81 /* Assign a void pointer to R0. */
mbedAustin 11:cada08fc8a70 82 stk[TCB_STACK_R0_OFFSET_DWORDS] = (U32)p_TCB->msg;
mbedAustin 11:cada08fc8a70 83
mbedAustin 11:cada08fc8a70 84 /* Initial Task stack pointer. */
mbedAustin 11:cada08fc8a70 85 p_TCB->tsk_stack = (U32)stk;
mbedAustin 11:cada08fc8a70 86
mbedAustin 11:cada08fc8a70 87 /* Task entry point. */
mbedAustin 11:cada08fc8a70 88 p_TCB->ptask = task_body;
mbedAustin 11:cada08fc8a70 89
mbedAustin 11:cada08fc8a70 90 /* Set a magic word for checking of stack overflow.
mbedAustin 11:cada08fc8a70 91 For the main thread (ID: 0x01) the stack is in a memory area shared with the
mbedAustin 11:cada08fc8a70 92 heap, therefore the last word of the stack is a moving target.
mbedAustin 11:cada08fc8a70 93 We want to do stack/heap collision detection instead.
mbedAustin 11:cada08fc8a70 94 */
mbedAustin 11:cada08fc8a70 95 if (p_TCB->task_id != 0x01)
mbedAustin 11:cada08fc8a70 96 p_TCB->stack[0] = MAGIC_WORD;
mbedAustin 11:cada08fc8a70 97 }
mbedAustin 11:cada08fc8a70 98
mbedAustin 11:cada08fc8a70 99
mbedAustin 11:cada08fc8a70 100 /*--------------------------- rt_ret_val ----------------------------------*/
mbedAustin 11:cada08fc8a70 101
mbedAustin 11:cada08fc8a70 102 static __inline U32 *rt_ret_regs (P_TCB p_TCB) {
mbedAustin 11:cada08fc8a70 103 /* Get pointer to task return value registers (R0..R3) in Stack */
mbedAustin 11:cada08fc8a70 104
mbedAustin 11:cada08fc8a70 105 /* Stack Frame: CPSR,R0-R13,PC */
mbedAustin 11:cada08fc8a70 106 return (U32 *)(p_TCB->tsk_stack + TCB_STACK_R0_OFFSET_BYTES);
mbedAustin 11:cada08fc8a70 107 }
mbedAustin 11:cada08fc8a70 108
mbedAustin 11:cada08fc8a70 109 void rt_ret_val (P_TCB p_TCB, U32 v0) {
mbedAustin 11:cada08fc8a70 110 U32 *ret;
mbedAustin 11:cada08fc8a70 111
mbedAustin 11:cada08fc8a70 112 ret = rt_ret_regs(p_TCB);
mbedAustin 11:cada08fc8a70 113 ret[0] = v0;
mbedAustin 11:cada08fc8a70 114 }
mbedAustin 11:cada08fc8a70 115
mbedAustin 11:cada08fc8a70 116 void rt_ret_val2(P_TCB p_TCB, U32 v0, U32 v1) {
mbedAustin 11:cada08fc8a70 117 U32 *ret;
mbedAustin 11:cada08fc8a70 118
mbedAustin 11:cada08fc8a70 119 ret = rt_ret_regs(p_TCB);
mbedAustin 11:cada08fc8a70 120 ret[0] = v0;
mbedAustin 11:cada08fc8a70 121 ret[1] = v1;
mbedAustin 11:cada08fc8a70 122 }
mbedAustin 11:cada08fc8a70 123
mbedAustin 11:cada08fc8a70 124
mbedAustin 11:cada08fc8a70 125 /*--------------------------- dbg_init --------------------------------------*/
mbedAustin 11:cada08fc8a70 126
mbedAustin 11:cada08fc8a70 127 #ifdef DBG_MSG
mbedAustin 11:cada08fc8a70 128 void dbg_init (void) {
mbedAustin 11:cada08fc8a70 129 if ((DEMCR & DEMCR_TRCENA) &&
mbedAustin 11:cada08fc8a70 130 (ITM_CONTROL & ITM_ITMENA) &&
mbedAustin 11:cada08fc8a70 131 (ITM_ENABLE & (1UL << 31))) {
mbedAustin 11:cada08fc8a70 132 dbg_msg = __TRUE;
mbedAustin 11:cada08fc8a70 133 }
mbedAustin 11:cada08fc8a70 134 }
mbedAustin 11:cada08fc8a70 135 #endif
mbedAustin 11:cada08fc8a70 136
mbedAustin 11:cada08fc8a70 137 /*--------------------------- dbg_task_notify -------------------------------*/
mbedAustin 11:cada08fc8a70 138
mbedAustin 11:cada08fc8a70 139 #ifdef DBG_MSG
mbedAustin 11:cada08fc8a70 140 void dbg_task_notify (P_TCB p_tcb, BOOL create) {
mbedAustin 11:cada08fc8a70 141 while (ITM_PORT31_U32 == 0);
mbedAustin 11:cada08fc8a70 142 ITM_PORT31_U32 = (U32)p_tcb->ptask;
mbedAustin 11:cada08fc8a70 143 while (ITM_PORT31_U32 == 0);
mbedAustin 11:cada08fc8a70 144 ITM_PORT31_U16 = (create << 8) | p_tcb->task_id;
mbedAustin 11:cada08fc8a70 145 }
mbedAustin 11:cada08fc8a70 146 #endif
mbedAustin 11:cada08fc8a70 147
mbedAustin 11:cada08fc8a70 148 /*--------------------------- dbg_task_switch -------------------------------*/
mbedAustin 11:cada08fc8a70 149
mbedAustin 11:cada08fc8a70 150 #ifdef DBG_MSG
mbedAustin 11:cada08fc8a70 151 void dbg_task_switch (U32 task_id) {
mbedAustin 11:cada08fc8a70 152 while (ITM_PORT31_U32 == 0);
mbedAustin 11:cada08fc8a70 153 ITM_PORT31_U8 = task_id;
mbedAustin 11:cada08fc8a70 154 }
mbedAustin 11:cada08fc8a70 155 #endif
mbedAustin 11:cada08fc8a70 156
mbedAustin 11:cada08fc8a70 157
mbedAustin 11:cada08fc8a70 158 /*----------------------------------------------------------------------------
mbedAustin 11:cada08fc8a70 159 * end of file
mbedAustin 11:cada08fc8a70 160 *---------------------------------------------------------------------------*/
mbedAustin 11:cada08fc8a70 161