X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Favr%2Fao_arch.h;h=d626e830ee97bf4bdb7bf760ef2832fff698853a;hb=77dc89ed5b7bf8f5b3fa3b6131660f1a98f583ea;hp=c189ccba08438d825348e874749917552520abb3;hpb=f1573a752425121d4c6a14285f1eb0fef3a8bea5;p=fw%2Faltos diff --git a/src/avr/ao_arch.h b/src/avr/ao_arch.h index c189ccba..d626e830 100644 --- a/src/avr/ao_arch.h +++ b/src/avr/ao_arch.h @@ -37,7 +37,9 @@ * AVR definitions and code fragments for AltOS */ +#ifndef AO_STACK_SIZE #define AO_STACK_SIZE 116 +#endif /* Various definitions to make GCC look more like SDCC */ @@ -67,7 +69,11 @@ extern void putchar(char c); extern char getchar(void); extern void ao_avr_stdio_init(void); -extern const uint16_t ao_serial_number; +#define AO_ROMCONFIG_VERSION 2 + +#define AO_ROMCONFIG_SYMBOL(a) const + +extern AO_ROMCONFIG_SYMBOL(0) uint16_t ao_serial_number; #define AVR_PUSH8(stack, val) (*((stack)--) = (val)) @@ -105,9 +111,7 @@ extern uint8_t ao_cpu_sleep_disable; asm("push r14" "\n\t" "push r13" "\n\t" "push r12" "\n\t" "push r11" "\n\t" "push r10"); \ asm("push r9" "\n\t" "push r8" "\n\t" "push r7" "\n\t" "push r6" "\n\t" "push r5"); \ asm("push r4" "\n\t" "push r3" "\n\t" "push r2" "\n\t" "push r1" "\n\t" "push r0"); \ - cli(); \ asm("in r0, __SREG__" "\n\t" "push r0"); \ - sei(); \ } while (0) #define ao_arch_save_stack() do { \ @@ -119,16 +123,28 @@ extern uint8_t ao_cpu_sleep_disable; #define ao_arch_isr_stack() /* nothing */ -#define ao_arch_cpu_idle() do { \ - if (!ao_cpu_sleep_disable) \ +/* Idle the CPU (if possible) waiting for an interrupt. Enabling + * interrupts and sleeping the CPU must be adjacent to eliminate race + * conditions. In all cases, we execute a single nop with interrupts + * enabled + */ +#define ao_arch_wait_interrupt() do { \ + if (!ao_cpu_sleep_disable) { \ + sleep_enable(); \ + sei(); \ sleep_cpu(); \ + sleep_disable(); \ + } else { \ + sei(); \ + } \ + ao_arch_nop(); \ + cli(); \ } while (0) #define ao_arch_restore_stack() do { \ uint8_t sp_l, sp_h; \ sp_l = (uint16_t) ao_cur_task->sp; \ sp_h = ((uint16_t) ao_cur_task->sp) >> 8; \ - cli(); \ asm("out __SP_H__,%0" : : "r" (sp_h) ); \ asm("out __SP_L__,%0" : : "r" (sp_l) ); \ asm("pop r0" "\n\t" \ @@ -145,14 +161,10 @@ extern uint8_t ao_cpu_sleep_disable; #define ao_arch_critical(b) do { cli(); do { b } while (0); sei(); } while (0) -#define AO_TELESCIENCE_NUM_ADC 12 - -struct ao_adc { - uint16_t tick; /* tick when the sample was read */ - uint16_t adc[AO_TELESCIENCE_NUM_ADC]; /* samples */ -}; +#define ao_arch_block_interrupts() cli() +#define ao_arch_release_interrupts() sei() -#define AO_ADC_RING 16 +#define AO_TELESCIENCE_NUM_ADC 12 #endif /* _AO_ARCH_H_ */