X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fstmf0%2Fao_arch_funcs.h;h=a0c6e08876cbb012e350b18dc585e02346db9c7c;hb=c4b8aff07d5366cef2c7209729f6cd22fa67de0c;hp=96c033f9712ce379f481c43d4fe621e52f663e2d;hpb=bc70f92966221f941b96177b401744a7aca24814;p=fw%2Faltos diff --git a/src/stmf0/ao_arch_funcs.h b/src/stmf0/ao_arch_funcs.h index 96c033f9..a0c6e088 100644 --- a/src/stmf0/ao_arch_funcs.h +++ b/src/stmf0/ao_arch_funcs.h @@ -168,8 +168,8 @@ ao_spi_try_get_mask(struct stm_gpio *reg, uint16_t mask, uint8_t bus, uint32_t s ao_spi_put(bus); \ } while (0) -#define ao_spi_get_bit(reg,bit,pin,bus,speed) ao_spi_get_mask(reg,(1<stack + AO_STACK_SIZE); + uint32_t *sp = &task->stack32[AO_STACK_SIZE >> 2]; uint32_t a = (uint32_t) start; int i; @@ -407,7 +407,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) { @@ -426,17 +426,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}"); @@ -450,6 +447,31 @@ static inline void ao_arch_restore_stack(void) { asm("pop {r0-r7,pc}\n"); } +static inline void ao_sleep_mode(void) { + + /* + WFI (Wait for Interrupt) or WFE (Wait for Event) while: + – Set SLEEPDEEP in Cortex ® -M0 System Control register + – Set PDDS bit in Power Control register (PWR_CR) + – Clear WUF bit in Power Control/Status register (PWR_CSR) + */ + + ao_arch_block_interrupts(); + + stm_scb.scr |= (1 << STM_SCB_SCR_SLEEPDEEP); + ao_arch_nop(); + stm_pwr.cr |= (1 << STM_PWR_CR_PDDS) | (1 << STM_PWR_CR_LPDS); + ao_arch_nop(); + stm_pwr.cr |= (1 << STM_PWR_CR_CWUF); + ao_arch_nop(); + ao_arch_nop(); + ao_arch_nop(); + ao_arch_nop(); + ao_arch_nop(); + asm("wfi"); + ao_arch_nop(); +} + #ifndef HAS_SAMPLE_PROFILE #define HAS_SAMPLE_PROFILE 0 #endif @@ -503,4 +525,9 @@ uint8_t ao_usb_write2(uint16_t len); #endif /* AO_USB_DIRECTIO */ +void start(void); + +void +ao_debug_out(char c); + #endif /* _AO_ARCH_FUNCS_H_ */