diff options
Diffstat (limited to 'src/cc1111')
| -rw-r--r-- | src/cc1111/ao_adc.c | 19 | ||||
| -rw-r--r-- | src/cc1111/ao_arch.h | 19 | ||||
| -rw-r--r-- | src/cc1111/ao_dbg.c | 63 | ||||
| -rw-r--r-- | src/cc1111/ao_radio.c | 27 | ||||
| -rw-r--r-- | src/cc1111/ao_serial.c | 26 | ||||
| -rw-r--r-- | src/cc1111/ao_usb.c | 16 |
6 files changed, 94 insertions, 76 deletions
diff --git a/src/cc1111/ao_adc.c b/src/cc1111/ao_adc.c index f7b52281..ed76179b 100644 --- a/src/cc1111/ao_adc.c +++ b/src/cc1111/ao_adc.c @@ -20,6 +20,10 @@ volatile __xdata struct ao_data ao_data_ring[AO_DATA_RING]; volatile __data uint8_t ao_data_head; +#ifndef AO_ADC_FIRST_PIN +#define AO_ADC_FIRST_PIN 0 +#endif + void ao_adc_poll(void) { @@ -29,7 +33,7 @@ ao_adc_poll(void) # ifdef TELENANO_V_0_1 ADCCON3 = ADCCON3_EREF_VDD | ADCCON3_EDIV_512 | 1; # else - ADCCON3 = ADCCON3_EREF_VDD | ADCCON3_EDIV_512 | 0; + ADCCON3 = ADCCON3_EREF_VDD | ADCCON3_EDIV_512 | AO_ADC_FIRST_PIN; # endif #endif } @@ -52,7 +56,7 @@ ao_adc_isr(void) __interrupt 1 uint8_t __xdata *a; sequence = (ADCCON2 & ADCCON2_SCH_MASK) >> ADCCON2_SCH_SHIFT; -#if TELEMETRUM_V_0_1 || TELEMETRUM_V_0_2 || TELEMETRUM_V_1_0 || TELEMETRUM_V_1_1 || TELEMETRUM_V_1_2 || TELELAUNCH_V_0_1 +#if TELEMETRUM_V_0_1 || TELEMETRUM_V_0_2 || TELEMETRUM_V_1_0 || TELEMETRUM_V_1_1 || TELEMETRUM_V_1_2 || TELELAUNCH_V_0_1 || TELEBALLOON_V_1_1 /* TeleMetrum readings */ #if HAS_ACCEL_REF if (sequence == 2) { @@ -141,7 +145,7 @@ ao_adc_isr(void) __interrupt 1 #endif /* telemini || telenano */ #ifdef TELEFIRE_V_0_1 - a = (uint8_t __xdata *) (&ao_data_ring[ao_data_head].adc.sense[0] + sequence); + a = (uint8_t __xdata *) (&ao_data_ring[ao_data_head].adc.sense[0] + sequence - AO_ADC_FIRST_PIN); a[0] = ADCL; a[1] = ADCH; if (sequence < 5) @@ -149,6 +153,15 @@ ao_adc_isr(void) __interrupt 1 #define GOT_ADC #endif /* TELEFIRE_V_0_1 */ +#ifdef TELEBT_V_1_0 + a = (uint8_t __xdata *) (&ao_data_ring[ao_data_head].adc.batt); + a[0] = ADCL; + a[1] = ADCH; + if (0) + ; +#define GOT_ADC +#endif + #ifndef GOT_ADC #error No known ADC configuration set #endif diff --git a/src/cc1111/ao_arch.h b/src/cc1111/ao_arch.h index 7fdfad80..9097557f 100644 --- a/src/cc1111/ao_arch.h +++ b/src/cc1111/ao_arch.h @@ -112,9 +112,7 @@ extern AO_ROMCONFIG_SYMBOL(0x00a6) uint32_t ao_radio_cal; /* Push ACC first, as when restoring the context it must be restored \ * last (it is used to set the IE register). */ \ push ACC \ - /* Store the IE register then enable interrupts. */ \ push _IEN0 \ - setb _EA \ push DPL \ push DPH \ push b \ @@ -147,11 +145,18 @@ extern AO_ROMCONFIG_SYMBOL(0x00a6) uint32_t ao_radio_cal; while (--stack_len); \ } -#define ao_arch_isr_stack() \ - /* Empty the stack; might as well let interrupts have the whole thing */ \ - (SP = AO_STACK_START - 1) +/* Empty the stack; might as well let interrupts have the whole thing */ +#define ao_arch_isr_stack() (SP = AO_STACK_START - 1) -#define ao_arch_cpu_idle() (PCON = PCON_IDLE) +#define ao_arch_block_interrupts() __asm clr _EA __endasm +#define ao_arch_release_interrupts() __asm setb _EA __endasm + +/* Idle the CPU, waking when an interrupt occurs */ +#define ao_arch_wait_interrupt() do { \ + ao_arch_release_interrupts(); \ + (PCON = PCON_IDLE); \ + ao_arch_block_interrupts(); \ + } while (0) #define ao_arch_restore_stack() { \ uint8_t stack_len; \ @@ -192,7 +197,7 @@ extern AO_ROMCONFIG_SYMBOL(0x00a6) uint32_t ao_radio_cal; 0098$: \ SETB _EA \ 0099$: \ - /* Finally pop off the ACC, which was the first register saved. */ \ + /* Finally restore ACC, which was the first register saved. */ \ pop ACC \ ret \ __endasm; \ diff --git a/src/cc1111/ao_dbg.c b/src/cc1111/ao_dbg.c index 847b5aaf..4e534697 100644 --- a/src/cc1111/ao_dbg.c +++ b/src/cc1111/ao_dbg.c @@ -193,54 +193,39 @@ ao_dbg_long_delay(void) #define AO_RESET_LOW_DELAY AO_MS_TO_TICKS(100) #define AO_RESET_HIGH_DELAY AO_MS_TO_TICKS(100) -void -ao_dbg_debug_mode(void) +static void +ao_dbg_send_bits_delay(uint8_t msk, uint8_t val) { - ao_dbg_set_pins(); ao_dbg_long_delay(); - ao_dbg_send_bits(DBG_CLOCK|DBG_DATA|DBG_RESET_N, DBG_CLOCK|DBG_DATA|DBG_RESET_N); - ao_dbg_long_delay(); - ao_dbg_send_bits(DBG_CLOCK|DBG_DATA|DBG_RESET_N, 0 |DBG_DATA| 0 ); - ao_delay(AO_RESET_LOW_DELAY); - ao_dbg_send_bits(DBG_CLOCK|DBG_DATA|DBG_RESET_N, DBG_CLOCK|DBG_DATA| 0 ); - ao_dbg_long_delay(); - ao_dbg_send_bits(DBG_CLOCK|DBG_DATA|DBG_RESET_N, 0 |DBG_DATA| 0 ); - ao_dbg_long_delay(); - ao_dbg_send_bits(DBG_CLOCK|DBG_DATA|DBG_RESET_N, DBG_CLOCK|DBG_DATA| 0 ); - ao_dbg_long_delay(); - ao_dbg_send_bits(DBG_CLOCK|DBG_DATA|DBG_RESET_N, 0 |DBG_DATA|DBG_RESET_N); - ao_delay(AO_RESET_HIGH_DELAY); + ao_dbg_send_bits(msk, val); } void -ao_dbg_reset(void) +ao_dbg_do_reset(uint8_t clock_up) { ao_dbg_set_pins(); - ao_dbg_long_delay(); - ao_dbg_send_bits(DBG_CLOCK|DBG_DATA|DBG_RESET_N, DBG_CLOCK|DBG_DATA|DBG_RESET_N); - ao_dbg_long_delay(); - ao_dbg_send_bits(DBG_CLOCK|DBG_DATA|DBG_RESET_N, DBG_CLOCK|DBG_DATA| 0 ); + ao_dbg_send_bits_delay(DBG_CLOCK|DBG_DATA|DBG_RESET_N, DBG_CLOCK|DBG_DATA|DBG_RESET_N); + ao_dbg_send_bits_delay(DBG_CLOCK|DBG_DATA|DBG_RESET_N, clock_up |DBG_DATA| 0 ); ao_delay(AO_RESET_LOW_DELAY); - ao_dbg_send_bits(DBG_CLOCK|DBG_DATA|DBG_RESET_N, DBG_CLOCK|DBG_DATA| 0 ); - ao_dbg_long_delay(); - ao_dbg_send_bits(DBG_CLOCK|DBG_DATA|DBG_RESET_N, DBG_CLOCK|DBG_DATA| 0 ); - ao_dbg_long_delay(); - ao_dbg_send_bits(DBG_CLOCK|DBG_DATA|DBG_RESET_N, DBG_CLOCK|DBG_DATA| 0 ); - ao_dbg_long_delay(); - ao_dbg_send_bits(DBG_CLOCK|DBG_DATA|DBG_RESET_N, DBG_CLOCK|DBG_DATA|DBG_RESET_N); + ao_dbg_send_bits (DBG_CLOCK|DBG_DATA|DBG_RESET_N, DBG_CLOCK|DBG_DATA| 0 ); + ao_dbg_send_bits_delay(DBG_CLOCK|DBG_DATA|DBG_RESET_N, clock_up |DBG_DATA| 0 ); + ao_dbg_send_bits_delay(DBG_CLOCK|DBG_DATA|DBG_RESET_N, DBG_CLOCK|DBG_DATA| 0 ); + ao_dbg_send_bits_delay(DBG_CLOCK|DBG_DATA|DBG_RESET_N, clock_up |DBG_DATA|DBG_RESET_N); ao_delay(AO_RESET_HIGH_DELAY); } static void debug_enable(void) { - ao_dbg_debug_mode(); + /* toggle clock line while holding reset low */ + ao_dbg_do_reset(0); } static void debug_reset(void) { - ao_dbg_reset(); + /* hold clock high while holding reset low */ + ao_dbg_do_reset(DBG_CLOCK); } static void @@ -281,22 +266,6 @@ debug_get(void) putchar('\n'); } -static uint8_t -getnibble(void) -{ - __pdata char c; - - c = getchar(); - if ('0' <= c && c <= '9') - return c - '0'; - if ('a' <= c && c <= 'f') - return c - ('a' - 10); - if ('A' <= c && c <= 'F') - return c - ('A' - 10); - ao_cmd_status = ao_cmd_lex_error; - return 0; -} - static void debug_input(void) { @@ -338,8 +307,8 @@ debug_output(void) return; ao_dbg_start_transfer(addr); while (count--) { - b = getnibble() << 4; - b |= getnibble(); + b = ao_getnibble() << 4; + b |= ao_getnibble(); if (ao_cmd_status != ao_cmd_success) return; ao_dbg_write_byte(b); diff --git a/src/cc1111/ao_radio.c b/src/cc1111/ao_radio.c index cb2c2fdd..88b8f686 100644 --- a/src/cc1111/ao_radio.c +++ b/src/cc1111/ao_radio.c @@ -187,7 +187,7 @@ static __code uint8_t radio_setup[] = { RF_BSCFG_BS_POST_KI_PRE_KI| RF_BSCFG_BS_POST_KP_PRE_KP| RF_BSCFG_BS_LIMIT_0), - RF_AGCCTRL2_OFF, 0x43, + RF_AGCCTRL2_OFF, 0x03, RF_AGCCTRL1_OFF, 0x40, RF_AGCCTRL0_OFF, 0x91, @@ -249,6 +249,18 @@ __xdata uint8_t ao_radio_done; __xdata uint8_t ao_radio_abort; __xdata uint8_t ao_radio_mutex; +#if PACKET_HAS_MASTER || HAS_AES +#define NEED_RADIO_RSSI 1 +#endif + +#ifndef NEED_RADIO_RSSI +#define NEED_RADIO_RSSI 0 +#endif + +#if NEED_RADIO_RSSI +__xdata int8_t ao_radio_rssi; +#endif + void ao_radio_general_isr(void) __interrupt 16 { @@ -322,7 +334,7 @@ ao_radio_send(__xdata void *packet, uint8_t size) __reentrant } uint8_t -ao_radio_recv(__xdata void *packet, uint8_t size) __reentrant +ao_radio_recv(__xdata void *packet, uint8_t size, uint8_t timeout) __reentrant { ao_radio_abort = 0; ao_radio_get(size - 2); @@ -342,9 +354,13 @@ ao_radio_recv(__xdata void *packet, uint8_t size) __reentrant /* Wait for DMA to be done, for the radio receive process to * get aborted or for a receive timeout to fire */ + if (timeout) + ao_alarm(timeout); __critical while (!ao_radio_dma_done && !ao_radio_abort) if (ao_sleep(&ao_radio_dma_done)) break; + if (timeout) + ao_clear_alarm(); /* If recv was aborted, clean up by stopping the DMA engine * and idling the radio @@ -352,7 +368,14 @@ ao_radio_recv(__xdata void *packet, uint8_t size) __reentrant if (!ao_radio_dma_done) { ao_dma_abort(ao_radio_dma); ao_radio_idle(); +#if NEED_RADIO_RSSI + ao_radio_rssi = 0; +#endif } +#if NEED_RADIO_RSSI + else + ao_radio_rssi = AO_RSSI_FROM_RADIO(((uint8_t *)packet)[size - 1]); +#endif ao_radio_put(); return ao_radio_dma_done; } diff --git a/src/cc1111/ao_serial.c b/src/cc1111/ao_serial.c index 48383802..81727836 100644 --- a/src/cc1111/ao_serial.c +++ b/src/cc1111/ao_serial.c @@ -34,8 +34,14 @@ const __code struct ao_serial_speed ao_serial_speeds[] = { /* .baud = */ 59, /* .gcr = */ (11 << UxGCR_BAUD_E_SHIFT) | UxGCR_ORDER_LSB }, + /* [AO_SERIAL_SPEED_115200] = */ { + /* .baud = */ 59, + /* .gcr = */ (12 << UxGCR_BAUD_E_SHIFT) | UxGCR_ORDER_LSB + }, }; +#define AO_SERIAL_SPEED_MAX AO_SERIAL_SPEED_115200 + #if HAS_SERIAL_0 volatile __xdata struct ao_fifo ao_serial0_rx_fifo; @@ -85,10 +91,10 @@ ao_serial0_getchar(void) __critical } #if USE_SERIAL_0_STDIN -char -ao_serial0_pollchar(void) __critical +int +_ao_serial0_pollchar(void) { - char c; + uint8_t c; if (ao_fifo_empty(ao_serial0_rx_fifo)) return AO_READ_AGAIN; ao_fifo_remove(ao_serial0_rx_fifo,c); @@ -116,7 +122,7 @@ void ao_serial0_set_speed(uint8_t speed) { ao_serial0_drain(); - if (speed > AO_SERIAL_SPEED_57600) + if (speed > AO_SERIAL_SPEED_MAX) return; U0UCR |= UxUCR_FLUSH; U0BAUD = ao_serial_speeds[speed].baud; @@ -173,10 +179,10 @@ ao_serial1_getchar(void) __critical } #if USE_SERIAL_1_STDIN -char -ao_serial1_pollchar(void) __critical +int +_ao_serial1_pollchar(void) { - char c; + uint8_t c; if (ao_fifo_empty(ao_serial1_rx_fifo)) return AO_READ_AGAIN; ao_fifo_remove(ao_serial1_rx_fifo,c); @@ -204,7 +210,7 @@ void ao_serial1_set_speed(uint8_t speed) { ao_serial1_drain(); - if (speed > AO_SERIAL_SPEED_57600) + if (speed > AO_SERIAL_SPEED_MAX) return; U1UCR |= UxUCR_FLUSH; U1BAUD = ao_serial_speeds[speed].baud; @@ -265,7 +271,7 @@ ao_serial_init(void) IEN0 |= IEN0_URX0IE; IEN2 |= IEN2_UTX0IE; #if USE_SERIAL_0_STDIN && !DELAY_SERIAL_0_STDIN - ao_add_stdio(ao_serial0_pollchar, + ao_add_stdio(_ao_serial0_pollchar, ao_serial0_putchar, NULL); #endif @@ -321,7 +327,7 @@ ao_serial_init(void) IEN2 |= IEN2_UTX1IE; #if USE_SERIAL_1_STDIN && !DELAY_SERIAL_1_STDIN - ao_add_stdio(ao_serial1_pollchar, + ao_add_stdio(_ao_serial1_pollchar, ao_serial1_putchar, NULL); #endif diff --git a/src/cc1111/ao_usb.c b/src/cc1111/ao_usb.c index ce26e808..8bd2efdf 100644 --- a/src/cc1111/ao_usb.c +++ b/src/cc1111/ao_usb.c @@ -382,10 +382,10 @@ ao_usb_putchar(char c) __critical __reentrant ao_usb_in_send(); } -char -ao_usb_pollchar(void) __critical +int +_ao_usb_pollchar(void) { - char c; + uint8_t c; if (ao_usb_out_bytes == 0) { USBINDEX = AO_USB_OUT_EP; if ((USBCSOL & USBCSOL_OUTPKT_RDY) == 0) @@ -407,12 +407,14 @@ ao_usb_pollchar(void) __critical } char -ao_usb_getchar(void) __critical +ao_usb_getchar(void) { - char c; + int c; - while ((c = ao_usb_pollchar()) == AO_READ_AGAIN) + ao_arch_block_interrupts(); + while ((c = _ao_usb_pollchar()) == AO_READ_AGAIN) ao_sleep(&ao_stdin_ready); + ao_arch_release_interrupts(); return c; } @@ -459,5 +461,5 @@ ao_usb_init(void) ao_usb_enable(); ao_add_task(&ao_usb_task, ao_usb_ep0, "usb"); - ao_add_stdio(ao_usb_pollchar, ao_usb_putchar, ao_usb_flush); + ao_add_stdio(_ao_usb_pollchar, ao_usb_putchar, ao_usb_flush); } |
