X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=src%2Fkernel%2Fao.h;h=dddcd9cb5afd6d8a4079d96eacac2842933b466a;hp=f44b0e9e380c260941580465f86c9c336cc97903;hb=HEAD;hpb=3058ecdeafdee959b1103965f3df4ffcd59683e4 diff --git a/src/kernel/ao.h b/src/kernel/ao.h index f44b0e9e..b3f780f5 100644 --- a/src/kernel/ao.h +++ b/src/kernel/ao.h @@ -40,8 +40,18 @@ extern char ao_getchar(void); #define HAS_TASK 1 #endif +#ifndef AO_GPIO_TYPE +#define AO_GPIO_TYPE void * +#endif + +typedef AO_GPIO_TYPE ao_gpio_t; typedef AO_PORT_TYPE ao_port_t; +#ifndef AO_TICK_TYPE +#define AO_TICK_TYPE uint32_t +#define AO_TICK_SIGNED int32_t +#endif + #if HAS_TASK #include #else @@ -81,7 +91,7 @@ typedef AO_PORT_TYPE ao_port_t; /* Stop the operating system, beeping and blinking the reason */ void -ao_panic(uint8_t reason); +ao_panic(uint8_t reason) __attribute__((noreturn)); /* * ao_romconfig.c @@ -100,11 +110,6 @@ extern AO_ROMCONFIG_SYMBOL uint32_t ao_radio_cal; * ao_timer.c */ -#ifndef AO_TICK_TYPE -#define AO_TICK_TYPE uint32_t -#define AO_TICK_SIGNED int32_t -#endif - extern volatile AO_TICK_TYPE ao_tick_count; /* Our timer runs at 100Hz */ @@ -112,7 +117,8 @@ extern volatile AO_TICK_TYPE ao_tick_count; #define AO_HERTZ 100 #endif #define AO_MS_TO_TICKS(ms) ((ms) / (1000 / AO_HERTZ)) -#define AO_SEC_TO_TICKS(s) ((s) * AO_HERTZ) +#define AO_SEC_TO_TICKS(s) ((AO_TICK_TYPE) (s) * AO_HERTZ) +#define AO_NS_TO_TICKS(ns) ((ns) / (1000000000L / AO_HERTZ)) /* Returns the current time in ticks */ AO_TICK_TYPE @@ -124,7 +130,7 @@ ao_time_ns(void); /* Suspend the current task until ticks time has passed */ void -ao_delay(uint16_t ticks); +ao_delay(AO_TICK_TYPE ticks); /* Set the ADC interval */ void @@ -389,7 +395,8 @@ ao_spi_slave(void); #define AO_GPS_NEW_TRACKING 2 extern uint8_t ao_gps_new; -extern uint16_t ao_gps_tick; +extern AO_TICK_TYPE ao_gps_tick; +extern AO_TICK_TYPE ao_gps_utc_tick; extern uint8_t ao_gps_mutex; extern struct ao_telemetry_location ao_gps_data; extern struct ao_telemetry_satellite ao_gps_tracking_data; @@ -531,7 +538,7 @@ struct ao_telemetry_tiny_recv { * for reporting RSSI. So, now we use these values everywhere */ #define AO_RSSI_FROM_RADIO(radio) ((int16_t) ((int8_t) (radio) >> 1) - 74) -#define AO_RADIO_FROM_RSSI(rssi) (((int8_t) (rssi) + 74) << 1) +#define AO_RADIO_FROM_RSSI(rssi) ((uint8_t) (((rssi) + 74) << 1)) /* * ao_radio_recv tacks on rssi and status bytes @@ -603,7 +610,7 @@ ao_radio_send(const void *d, uint8_t size); #if HAS_RADIO_RECV uint8_t -ao_radio_recv(void *d, uint8_t size, uint8_t timeout); +ao_radio_recv(void *d, uint8_t size, AO_TICK_TYPE timeout); void ao_radio_recv_abort(void); @@ -724,8 +731,8 @@ struct ao_stdio { }; extern struct ao_stdio ao_stdios[]; -extern int8_t ao_cur_stdio; -extern int8_t ao_num_stdios; +extern uint8_t ao_cur_stdio; +extern uint8_t ao_num_stdios; void flush(void); @@ -735,7 +742,7 @@ extern uint8_t ao_stdin_ready; uint8_t ao_echo(void); -int8_t +uint8_t ao_add_stdio(int (*pollchar)(void), void (*putchar)(char) , void (*flush)(void)); @@ -828,15 +835,15 @@ struct ao_fifo { char fifo[AO_FIFO_SIZE]; }; -#define ao_fifo_insert(f,c) do { \ - (f).fifo[(f).insert] = (c); \ - (f).insert = ((f).insert + 1) & (AO_FIFO_SIZE-1); \ -} while(0) +#define ao_fifo_insert(f,c) do { \ + (f).fifo[(f).insert] = (char) (c); \ + (f).insert = ((f).insert + 1) & (AO_FIFO_SIZE-1); \ + } while(0) -#define ao_fifo_remove(f,c) do {\ - c = (f).fifo[(f).remove]; \ - (f).remove = ((f).remove + 1) & (AO_FIFO_SIZE-1); \ -} while(0) +#define ao_fifo_remove(f,c) do { \ + c = (f).fifo[(f).remove]; \ + (f).remove = ((f).remove + 1) & (AO_FIFO_SIZE-1); \ + } while(0) #define ao_fifo_full(f) ((((f).insert + 1) & (AO_FIFO_SIZE-1)) == (f).remove) #define ao_fifo_mostly(f) ((((f).insert - (f).remove) & (AO_FIFO_SIZE-1)) >= (AO_FIFO_SIZE * 3 / 4)) @@ -965,7 +972,7 @@ ao_sqrt(uint32_t op); * ao_freq.c */ -int32_t ao_freq_to_set(int32_t freq, int32_t cal); +uint32_t ao_freq_to_set(uint32_t freq, uint32_t cal); /* * ao_ms5607.c