altos/lpc: Add casts to reduce -Wconversion warnings
[fw/altos] / src / lpc / ao_arch_funcs.h
index 345108aeb42c1b3f4887b02365cea4200e32e2a2..e88b0141f9ad7c37ea8785e448d9a59411b142f7 100644 (file)
@@ -23,7 +23,7 @@
 #define ao_spi_put_bit(reg,bit,bus) ao_spi_put_mask(reg,(1<<bit),bus)
 
 #define ao_enable_port(port) (lpc_scb.sysahbclkctrl |= (1 << LPC_SCB_SYSAHBCLKCTRL_GPIO))
-#define ao_disable_port(port) (lpc_scb.sysahbclkctrl &= ~(1 << LPC_SCB_SYSAHBCLKCTRL_GPIO))
+#define ao_disable_port(port) (lpc_scb.sysahbclkctrl &= ~(1UL << LPC_SCB_SYSAHBCLKCTRL_GPIO))
 
 #define lpc_all_bit(port,bit)  (((port) << 5) | (bit))
 
@@ -65,7 +65,7 @@ static inline void lpc_set_gpio(int port, int bit) {
 #define ao_enable_input(port,bit,mode) do {                            \
                ao_enable_port(port);                                   \
                lpc_set_gpio(port,bit);                                 \
-               lpc_gpio.dir[port] &= ~(1 << bit);                      \
+               lpc_gpio.dir[port] &= ~(1UL << bit);                    \
                ao_gpio_set_mode(port,bit,mode);                        \
        } while (0)
 
@@ -80,7 +80,7 @@ static inline void lpc_set_gpio(int port, int bit) {
 
 #define ao_enable_analog(port,bit,id) do {                             \
                ao_enable_port(port);                                   \
-               lpc_gpio.dir[port] &= ~(1 << bit);                      \
+               lpc_gpio.dir[port] &= ~(1UL << bit);                    \
                lpc_ioconf.analog_reg(port,bit) = ((analog_func(id) << LPC_IOCONF_FUNC) | \
                                                   (0 << LPC_IOCONF_ADMODE)); \
        } while (0)
@@ -107,9 +107,8 @@ ao_arch_memory_barrier(void) {
 
 #if HAS_TASK
 static inline void
-ao_arch_init_stack(struct ao_task *task, void *start)
+ao_arch_init_stack(struct ao_task *task, uint32_t *sp, void *start)
 {
-       uint32_t        *sp = (uint32_t *) (void *) (task->stack + AO_STACK_SIZE);
        uint32_t        a = (uint32_t) start;
        int             i;
 
@@ -127,7 +126,7 @@ ao_arch_init_stack(struct ao_task *task, void *start)
        /* PRIMASK with interrupts enabled */
        ARM_PUSH32(sp, 0);
 
-       task->sp = sp;
+       task->sp32 = sp;
 }
 
 static inline void ao_arch_save_regs(void) {
@@ -146,17 +145,14 @@ static inline void ao_arch_save_regs(void) {
 static inline void ao_arch_save_stack(void) {
        uint32_t        *sp;
        asm("mov %0,sp" : "=&r" (sp) );
-       ao_cur_task->sp = (sp);
-       if ((uint8_t *) sp < &ao_cur_task->stack[0])
+       ao_cur_task->sp32 = (sp);
+       if (sp < &ao_cur_task->stack32[0])
                ao_panic (AO_PANIC_STACK);
 }
 
 static inline void ao_arch_restore_stack(void) {
-       uint32_t        sp;
-       sp = (uint32_t) ao_cur_task->sp;
-
        /* Switch stacks */
-       asm("mov sp, %0" : : "r" (sp) );
+       asm("mov sp, %0" : : "r" (ao_cur_task->sp32) );
 
        /* Restore PRIMASK */
        asm("pop {r0}");