mbed client lightswitch demo

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Fork of mbed-client-classic-example-lwip by Austin Blackstone

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: RT_HAL_CA.H
mbedAustin 11:cada08fc8a70 5 * Purpose: Hardware Abstraction Layer for Cortex-A definitions
mbedAustin 11:cada08fc8a70 6 * Rev.: 14th Jan 2014
mbedAustin 11:cada08fc8a70 7 *----------------------------------------------------------------------------
mbedAustin 11:cada08fc8a70 8 *
mbedAustin 11:cada08fc8a70 9 * Copyright (c) 1999-2009 KEIL, 2009-2013 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 /* Definitions */
mbedAustin 11:cada08fc8a70 36 #define INIT_CPSR_SYS 0x4000001F
mbedAustin 11:cada08fc8a70 37 #define INIT_CPSR_USER 0x40000010
mbedAustin 11:cada08fc8a70 38
mbedAustin 11:cada08fc8a70 39 #define CPSR_T_BIT 0x20
mbedAustin 11:cada08fc8a70 40 #define CPSR_I_BIT 0x80
mbedAustin 11:cada08fc8a70 41 #define CPSR_F_BIT 0x40
mbedAustin 11:cada08fc8a70 42
mbedAustin 11:cada08fc8a70 43 #define MODE_USR 0x10
mbedAustin 11:cada08fc8a70 44 #define MODE_FIQ 0x11
mbedAustin 11:cada08fc8a70 45 #define MODE_IRQ 0x12
mbedAustin 11:cada08fc8a70 46 #define MODE_SVC 0x13
mbedAustin 11:cada08fc8a70 47 #define MODE_ABT 0x17
mbedAustin 11:cada08fc8a70 48 #define MODE_UND 0x1B
mbedAustin 11:cada08fc8a70 49 #define MODE_SYS 0x1F
mbedAustin 11:cada08fc8a70 50
mbedAustin 11:cada08fc8a70 51 #define MAGIC_WORD 0xE25A2EA5
mbedAustin 11:cada08fc8a70 52
mbedAustin 11:cada08fc8a70 53 #include "core_ca9.h"
mbedAustin 11:cada08fc8a70 54
mbedAustin 11:cada08fc8a70 55 #if defined (__CC_ARM) /* ARM Compiler */
mbedAustin 11:cada08fc8a70 56
mbedAustin 11:cada08fc8a70 57 #if ((__TARGET_ARCH_7_M || __TARGET_ARCH_7E_M || __TARGET_ARCH_7_A) && !defined(NO_EXCLUSIVE_ACCESS))
mbedAustin 11:cada08fc8a70 58 #define __USE_EXCLUSIVE_ACCESS
mbedAustin 11:cada08fc8a70 59 #else
mbedAustin 11:cada08fc8a70 60 #undef __USE_EXCLUSIVE_ACCESS
mbedAustin 11:cada08fc8a70 61 #endif
mbedAustin 11:cada08fc8a70 62
mbedAustin 11:cada08fc8a70 63 #elif defined (__GNUC__) /* GNU Compiler */
mbedAustin 11:cada08fc8a70 64
mbedAustin 11:cada08fc8a70 65 #undef __USE_EXCLUSIVE_ACCESS
mbedAustin 11:cada08fc8a70 66
mbedAustin 11:cada08fc8a70 67 #if defined (__VFP_FP__) && !defined(__SOFTFP__)
mbedAustin 11:cada08fc8a70 68 #define __TARGET_FPU_VFP 1
mbedAustin 11:cada08fc8a70 69 #else
mbedAustin 11:cada08fc8a70 70 #define __TARGET_FPU_VFP 0
mbedAustin 11:cada08fc8a70 71 #endif
mbedAustin 11:cada08fc8a70 72
mbedAustin 11:cada08fc8a70 73 #define __inline inline
mbedAustin 11:cada08fc8a70 74 #define __weak __attribute__((weak))
mbedAustin 11:cada08fc8a70 75
mbedAustin 11:cada08fc8a70 76 #elif defined (__ICCARM__) /* IAR Compiler */
mbedAustin 11:cada08fc8a70 77
mbedAustin 11:cada08fc8a70 78 #endif
mbedAustin 11:cada08fc8a70 79
mbedAustin 11:cada08fc8a70 80 static U8 priority = 0xff;
mbedAustin 11:cada08fc8a70 81
mbedAustin 11:cada08fc8a70 82 extern const U32 GICDistributor_BASE;
mbedAustin 11:cada08fc8a70 83 extern const U32 GICInterface_BASE;
mbedAustin 11:cada08fc8a70 84
mbedAustin 11:cada08fc8a70 85 /* GIC registers - Distributor */
mbedAustin 11:cada08fc8a70 86 #define GICD_ICDICER0 (*((volatile U32 *)(GICDistributor_BASE + 0x180))) /* - RW - Interrupt Clear-Enable Registers */
mbedAustin 11:cada08fc8a70 87 #define GICD_ICDISER0 (*((volatile U32 *)(GICDistributor_BASE + 0x100))) /* - RW - Interrupt Set-Enable Registers */
mbedAustin 11:cada08fc8a70 88 #define GICD_ICDIPR0 (*((volatile U32 *)(GICDistributor_BASE + 0x400))) /* - RW - Interrupt Priority Registers */
mbedAustin 11:cada08fc8a70 89 #define GICD_ICDSGIR (*((volatile U32 *)(GICDistributor_BASE + 0xf00))) /* - RW - Interrupt Software Interrupt Register */
mbedAustin 11:cada08fc8a70 90 #define GICD_ICDICERx(irq) *(volatile U32 *)(&GICD_ICDICER0 + irq/32)
mbedAustin 11:cada08fc8a70 91 #define GICD_ICDISERx(irq) *(volatile U32 *)(&GICD_ICDISER0 + irq/32)
mbedAustin 11:cada08fc8a70 92
mbedAustin 11:cada08fc8a70 93 /* GIC register - CPU Interface */
mbedAustin 11:cada08fc8a70 94 #define GICI_ICCPMR (*((volatile U32 *)(GICInterface_BASE + 0x004))) /* - RW - Interrupt Priority Mask Register */
mbedAustin 11:cada08fc8a70 95
mbedAustin 11:cada08fc8a70 96 #define SGI_PENDSV 0 /* SGI0 */
mbedAustin 11:cada08fc8a70 97 #define SGI_PENDSV_BIT ((U32)(1 << (SGI_PENDSV & 0xf)))
mbedAustin 11:cada08fc8a70 98
mbedAustin 11:cada08fc8a70 99 //Increase priority filter to prevent timer and PendSV interrupts signaling. Guarantees that interrupts will not be forwarded.
mbedAustin 11:cada08fc8a70 100 #if defined (__ICCARM__)
mbedAustin 11:cada08fc8a70 101 #define OS_LOCK() int irq_dis = __disable_irq_iar();\
mbedAustin 11:cada08fc8a70 102 priority = GICI_ICCPMR; \
mbedAustin 11:cada08fc8a70 103 GICI_ICCPMR = 0xff; \
mbedAustin 11:cada08fc8a70 104 GICI_ICCPMR = GICI_ICCPMR - 1; \
mbedAustin 11:cada08fc8a70 105 __DSB();\
mbedAustin 11:cada08fc8a70 106 if(!irq_dis) __enable_irq(); \
mbedAustin 11:cada08fc8a70 107
mbedAustin 11:cada08fc8a70 108 #else
mbedAustin 11:cada08fc8a70 109 #define OS_LOCK() int irq_dis = __disable_irq();\
mbedAustin 11:cada08fc8a70 110 priority = GICI_ICCPMR; \
mbedAustin 11:cada08fc8a70 111 GICI_ICCPMR = 0xff; \
mbedAustin 11:cada08fc8a70 112 GICI_ICCPMR = GICI_ICCPMR - 1; \
mbedAustin 11:cada08fc8a70 113 __DSB();\
mbedAustin 11:cada08fc8a70 114 if(!irq_dis) __enable_irq(); \
mbedAustin 11:cada08fc8a70 115
mbedAustin 11:cada08fc8a70 116 #endif
mbedAustin 11:cada08fc8a70 117
mbedAustin 11:cada08fc8a70 118 //Restore priority filter. Re-enable timer and PendSV signaling
mbedAustin 11:cada08fc8a70 119 #define OS_UNLOCK() __DSB(); \
mbedAustin 11:cada08fc8a70 120 GICI_ICCPMR = priority; \
mbedAustin 11:cada08fc8a70 121
mbedAustin 11:cada08fc8a70 122 #define OS_PEND_IRQ() GICD_ICDSGIR = 0x0010000 | SGI_PENDSV
mbedAustin 11:cada08fc8a70 123 #define OS_PEND(fl,p) if(p) OS_PEND_IRQ();
mbedAustin 11:cada08fc8a70 124 #define OS_UNPEND(fl)
mbedAustin 11:cada08fc8a70 125
mbedAustin 11:cada08fc8a70 126 /* HW initialization needs to be done in os_tick_init (void) -RTX_Conf_CM.c-
mbedAustin 11:cada08fc8a70 127 * OS_X_INIT enables the IRQ n in the GIC */
mbedAustin 11:cada08fc8a70 128 #define OS_X_INIT(n) volatile char *reg; \
mbedAustin 11:cada08fc8a70 129 reg = (char *)(&GICD_ICDIPR0 + n / 4); \
mbedAustin 11:cada08fc8a70 130 reg += n % 4; \
mbedAustin 11:cada08fc8a70 131 *reg = (char)0xff; \
mbedAustin 11:cada08fc8a70 132 *reg = *reg - 1; \
mbedAustin 11:cada08fc8a70 133 GICD_ICDISERx(n) = (U32)(1 << n % 32);
mbedAustin 11:cada08fc8a70 134 #define OS_X_LOCK(n) OS_LOCK()
mbedAustin 11:cada08fc8a70 135 #define OS_X_UNLOCK(n) OS_UNLOCK()
mbedAustin 11:cada08fc8a70 136 #define OS_X_PEND_IRQ() OS_PEND_IRQ()
mbedAustin 11:cada08fc8a70 137 #define OS_X_PEND(fl,p) if(p) OS_X_PEND_IRQ();
mbedAustin 11:cada08fc8a70 138 #define OS_X_UNPEND(fl)
mbedAustin 11:cada08fc8a70 139
mbedAustin 11:cada08fc8a70 140
mbedAustin 11:cada08fc8a70 141 /* Functions */
mbedAustin 11:cada08fc8a70 142 #ifdef __USE_EXCLUSIVE_ACCESS
mbedAustin 11:cada08fc8a70 143 #define rt_inc(p) while(__strex((__ldrex(p)+1),p))
mbedAustin 11:cada08fc8a70 144 #define rt_dec(p) while(__strex((__ldrex(p)-1),p))
mbedAustin 11:cada08fc8a70 145 #else
mbedAustin 11:cada08fc8a70 146 #if defined (__ICCARM__)
mbedAustin 11:cada08fc8a70 147 #define rt_inc(p) { int irq_dis = __disable_irq_iar();(*p)++;if(!irq_dis) __enable_irq(); }
mbedAustin 11:cada08fc8a70 148 #define rt_dec(p) { int irq_dis = __disable_irq_iar();(*p)--;if(!irq_dis) __enable_irq(); }
mbedAustin 11:cada08fc8a70 149 #else
mbedAustin 11:cada08fc8a70 150 #define rt_inc(p) { int irq_dis = __disable_irq();(*p)++;if(!irq_dis) __enable_irq(); }
mbedAustin 11:cada08fc8a70 151 #define rt_dec(p) { int irq_dis = __disable_irq();(*p)--;if(!irq_dis) __enable_irq(); }
mbedAustin 11:cada08fc8a70 152 #endif /* __ICCARM__ */
mbedAustin 11:cada08fc8a70 153 #endif /* __USE_EXCLUSIVE_ACCESS */
mbedAustin 11:cada08fc8a70 154
mbedAustin 11:cada08fc8a70 155 __inline static U32 rt_inc_qi (U32 size, U8 *count, U8 *first) {
mbedAustin 11:cada08fc8a70 156 U32 cnt,c2;
mbedAustin 11:cada08fc8a70 157 #ifdef __USE_EXCLUSIVE_ACCESS
mbedAustin 11:cada08fc8a70 158 do {
mbedAustin 11:cada08fc8a70 159 if ((cnt = __ldrex(count)) == size) {
mbedAustin 11:cada08fc8a70 160 __clrex();
mbedAustin 11:cada08fc8a70 161 return (cnt); }
mbedAustin 11:cada08fc8a70 162 } while (__strex(cnt+1, count));
mbedAustin 11:cada08fc8a70 163 do {
mbedAustin 11:cada08fc8a70 164 c2 = (cnt = __ldrex(first)) + 1;
mbedAustin 11:cada08fc8a70 165 if (c2 == size) c2 = 0;
mbedAustin 11:cada08fc8a70 166 } while (__strex(c2, first));
mbedAustin 11:cada08fc8a70 167 #else
mbedAustin 11:cada08fc8a70 168 int irq_dis;
mbedAustin 11:cada08fc8a70 169 #if defined (__ICCARM__)
mbedAustin 11:cada08fc8a70 170 irq_dis = __disable_irq_iar();
mbedAustin 11:cada08fc8a70 171 #else
mbedAustin 11:cada08fc8a70 172 irq_dis = __disable_irq();
mbedAustin 11:cada08fc8a70 173 #endif /* __ICCARM__ */
mbedAustin 11:cada08fc8a70 174 if ((cnt = *count) < size) {
mbedAustin 11:cada08fc8a70 175 *count = cnt+1;
mbedAustin 11:cada08fc8a70 176 c2 = (cnt = *first) + 1;
mbedAustin 11:cada08fc8a70 177 if (c2 == size) c2 = 0;
mbedAustin 11:cada08fc8a70 178 *first = c2;
mbedAustin 11:cada08fc8a70 179 }
mbedAustin 11:cada08fc8a70 180 if(!irq_dis) __enable_irq ();
mbedAustin 11:cada08fc8a70 181 #endif
mbedAustin 11:cada08fc8a70 182 return (cnt);
mbedAustin 11:cada08fc8a70 183 }
mbedAustin 11:cada08fc8a70 184
mbedAustin 11:cada08fc8a70 185 __inline static void rt_systick_init (void) {
mbedAustin 11:cada08fc8a70 186 /* Cortex-A doesn't have a Systick. User needs to provide an alternative timer using RTX_Conf_CM configuration */
mbedAustin 11:cada08fc8a70 187 /* HW initialization needs to be done in os_tick_init (void) -RTX_Conf_CM.c- */
mbedAustin 11:cada08fc8a70 188 }
mbedAustin 11:cada08fc8a70 189
mbedAustin 11:cada08fc8a70 190 __inline static U32 rt_systick_val (void) {
mbedAustin 11:cada08fc8a70 191 /* Cortex-A doesn't have a Systick. User needs to provide an alternative timer using RTX_Conf_CM configuration */
mbedAustin 11:cada08fc8a70 192 /* HW initialization needs to be done in os_tick_init (void) -RTX_Conf_CM.c- */
mbedAustin 11:cada08fc8a70 193 return 0;
mbedAustin 11:cada08fc8a70 194 }
mbedAustin 11:cada08fc8a70 195
mbedAustin 11:cada08fc8a70 196 __inline static U32 rt_systick_ovf (void) {
mbedAustin 11:cada08fc8a70 197 /* Cortex-A doesn't have a Systick. User needs to provide an alternative timer using RTX_Conf_CM configuration */
mbedAustin 11:cada08fc8a70 198 /* HW initialization needs to be done in os_tick_init (void) -RTX_Conf_CM.c- */
mbedAustin 11:cada08fc8a70 199 return 0;
mbedAustin 11:cada08fc8a70 200 }
mbedAustin 11:cada08fc8a70 201
mbedAustin 11:cada08fc8a70 202 __inline static void rt_svc_init (void) {
mbedAustin 11:cada08fc8a70 203 /* Register pendSV - through SGI */
mbedAustin 11:cada08fc8a70 204 volatile char *reg;
mbedAustin 11:cada08fc8a70 205
mbedAustin 11:cada08fc8a70 206 reg = (char *)(&GICD_ICDIPR0 + SGI_PENDSV/4);
mbedAustin 11:cada08fc8a70 207 reg += SGI_PENDSV % 4;
mbedAustin 11:cada08fc8a70 208 /* Write 0xff to read priority level */
mbedAustin 11:cada08fc8a70 209 *reg = (char)0xff;
mbedAustin 11:cada08fc8a70 210 /* Read priority level and set the lowest possible*/
mbedAustin 11:cada08fc8a70 211 *reg = *reg - 1;
mbedAustin 11:cada08fc8a70 212
mbedAustin 11:cada08fc8a70 213 GICD_ICDISERx(SGI_PENDSV) = (U32)SGI_PENDSV_BIT;
mbedAustin 11:cada08fc8a70 214 }
mbedAustin 11:cada08fc8a70 215
mbedAustin 11:cada08fc8a70 216 extern void rt_set_PSP (U32 stack);
mbedAustin 11:cada08fc8a70 217 extern U32 rt_get_PSP (void);
mbedAustin 11:cada08fc8a70 218 extern void os_set_env (P_TCB p_TCB);
mbedAustin 11:cada08fc8a70 219 extern void *_alloc_box (void *box_mem);
mbedAustin 11:cada08fc8a70 220 extern int _free_box (void *box_mem, void *box);
mbedAustin 11:cada08fc8a70 221
mbedAustin 11:cada08fc8a70 222 extern void rt_init_stack (P_TCB p_TCB, FUNCP task_body);
mbedAustin 11:cada08fc8a70 223 extern void rt_ret_val (P_TCB p_TCB, U32 v0);
mbedAustin 11:cada08fc8a70 224 extern void rt_ret_val2 (P_TCB p_TCB, U32 v0, U32 v1);
mbedAustin 11:cada08fc8a70 225
mbedAustin 11:cada08fc8a70 226 extern void dbg_init (void);
mbedAustin 11:cada08fc8a70 227 extern void dbg_task_notify (P_TCB p_tcb, BOOL create);
mbedAustin 11:cada08fc8a70 228 extern void dbg_task_switch (U32 task_id);
mbedAustin 11:cada08fc8a70 229
mbedAustin 11:cada08fc8a70 230 #define DBG_INIT()
mbedAustin 11:cada08fc8a70 231 #define DBG_TASK_NOTIFY(p_tcb,create)
mbedAustin 11:cada08fc8a70 232 #define DBG_TASK_SWITCH(task_id)
mbedAustin 11:cada08fc8a70 233
mbedAustin 11:cada08fc8a70 234 /*----------------------------------------------------------------------------
mbedAustin 11:cada08fc8a70 235 * end of file
mbedAustin 11:cada08fc8a70 236 *---------------------------------------------------------------------------*/
mbedAustin 11:cada08fc8a70 237