From e09e35471e788b88909ff01037fb8e0e4eabcd7d Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 15 Jun 2012 22:40:30 -0700 Subject: [PATCH] altos: Start making cc1120 radio work RDF tones and radio calibration work now. Signed-off-by: Keith Packard --- src/drivers/ao_cc1120.c | 31 ++++++++++++++++++++++++----- src/drivers/ao_cc1120.h | 1 + src/drivers/ao_cc1120_CC1120.h | 5 +---- src/megametrum-v0.1/Makefile | 2 +- src/megametrum-v0.1/ao_megametrum.c | 18 +---------------- src/megametrum-v0.1/ao_pins.h | 9 ++++++++- 6 files changed, 38 insertions(+), 28 deletions(-) diff --git a/src/drivers/ao_cc1120.c b/src/drivers/ao_cc1120.c index 68f7e736..a1d78d9c 100644 --- a/src/drivers/ao_cc1120.c +++ b/src/drivers/ao_cc1120.c @@ -106,7 +106,7 @@ ao_radio_strobe(uint8_t addr) ao_radio_duplex(&addr, &in, 1); ao_radio_deselect(); #if CC1120_DEBUG - printf("%02x\n", in); + printf("%02x\n", in); flush(); #endif return in; } @@ -254,15 +254,33 @@ ao_radio_rdf(uint8_t len) ao_radio_abort = 0; for (i = 0; i < sizeof (rdf_setup) / sizeof (rdf_setup[0]); i += 2) ao_radio_reg_write(rdf_setup[i], rdf_setup[i+1]); - ao_radio_reg_write(CC1120_PKT_LEN, len); + +#if 0 int_pin ("Before CFG"); ao_radio_reg_write(CC1120_IOCFG2, CC1120_IOCFG_GPIO_CFG_RX0TX1_CFG); int_pin ("After CFG"); +#endif + + ao_radio_fifo_write_fixed(ao_radio_rdf_value, len); + + ao_radio_reg_write(CC1120_PKT_LEN, len); + + printf ("packet length: %d\n", ao_radio_reg_read(CC1120_PKT_LEN)); + ao_radio_strobe(CC1120_STX); + + for (i = 0; i < 20; i++) { + printf ("%d ", i); flush(); + printf ("Status %02x ", ao_radio_status()); flush(); + printf ("num_tx_bytes %d ", ao_radio_reg_read(CC1120_NUM_TXBYTES)); flush(); + printf ("marc status %x\n", ao_radio_marc_status()); flush(); + ao_delay(AO_MS_TO_TICKS(50)); + } + +#if 0 ao_exti_enable(&AO_CC1120_INT_PORT, AO_CC1120_INT_PIN); int_pin ("After strobe"); ao_delay(AO_MS_TO_TICKS(100)); - ao_radio_fifo_write_fixed(ao_radio_rdf_value, len); int_pin ("After delay"); cli(); for (i = 0; i < 20; i++) { @@ -278,11 +296,14 @@ ao_radio_rdf(uint8_t len) #endif } sei(); +#endif printf ("num_tx_bytes %d marc status %x\n", ao_radio_reg_read(CC1120_NUM_TXBYTES), ao_radio_marc_status()); +#if 0 if (!ao_radio_tx_done()) ao_radio_idle(); +#endif ao_radio_set_packet(); ao_radio_put(); } @@ -488,8 +509,8 @@ ao_radio_setup(void) ao_radio_reg_write(CC1120_IOCFG2, CC1120_IOCFG_GPIO_CFG_MARC_MCU_WAKEUP); /* Enable the EXTI interrupt for the appropriate pin */ - ao_enable_port(AO_CC1120_INT_PORT); - ao_exti_setup(&AO_CC1120_INT_PORT, AO_CC1120_INT_PIN, AO_EXTI_MODE_FALLING, ao_radio_isr); +// ao_enable_port(AO_CC1120_INT_PORT); +// ao_exti_setup(&AO_CC1120_INT_PORT, AO_CC1120_INT_PIN, AO_EXTI_MODE_FALLING, ao_radio_isr); ao_radio_set_packet(); ao_radio_configured = 1; diff --git a/src/drivers/ao_cc1120.h b/src/drivers/ao_cc1120.h index 0f03f2c7..5822a21a 100644 --- a/src/drivers/ao_cc1120.h +++ b/src/drivers/ao_cc1120.h @@ -281,6 +281,7 @@ #define CC1120_PKT_CFG1_APPEND_STATUS 0 #define CC1120_PKT_CFG0 0x28 +#define CC1120_PKT_CFG0_RESERVED7 7 #define CC1120_PKT_CFG0_LENGTH_CONFIG 5 #define CC1120_PKT_CFG0_LENGTH_CONFIG_FIXED 0 #define CC1120_PKT_CFG0_LENGTH_CONFIG_VARIABLE 1 diff --git a/src/drivers/ao_cc1120_CC1120.h b/src/drivers/ao_cc1120_CC1120.h index 1799c274..f86fd384 100644 --- a/src/drivers/ao_cc1120_CC1120.h +++ b/src/drivers/ao_cc1120_CC1120.h @@ -68,7 +68,7 @@ CC1120_PKT_CFG2, 0x04, /* Packet Configuration, Reg 2 */ CC1120_PKT_CFG1, 0x45, /* Packet Configuration, Reg 1 */ #endif - CC1120_PKT_CFG0, 0x20, /* Packet Configuration, Reg 0 */ + CC1120_PKT_CFG0, 0x00, /* Packet Configuration, Reg 0 */ CC1120_RFEND_CFG1, 0x0f, /* RFEND Configuration, Reg 1 */ CC1120_RFEND_CFG0, 0x00, /* RFEND Configuration, Reg 0 */ CC1120_PA_CFG2, 0x3f, /* Power Amplifier Configuration, Reg 2 */ @@ -87,9 +87,6 @@ CC1120_RCCAL_OFFSET, 0x00, /* RC Oscillator Calibration Clock Offset */ CC1120_FREQOFF1, 0x00, /* Frequency Offset (MSB) */ CC1120_FREQOFF0, 0x00, /* Frequency Offset (LSB) */ - CC1120_FREQ2, 0x6c, /* Frequency Configuration [23:16] */ - CC1120_FREQ1, 0xa3, /* Frequency Configuration [15:8] */ - CC1120_FREQ0, 0x33, /* Frequency Configuration [7:0] */ CC1120_IF_ADC2, 0x02, /* Analog to Digital Converter Configuration, Reg 2 */ CC1120_IF_ADC1, 0xa6, /* Analog to Digital Converter Configuration, Reg 1 */ CC1120_IF_ADC0, 0x04, /* Analog to Digital Converter Configuration, Reg 0 */ diff --git a/src/megametrum-v0.1/Makefile b/src/megametrum-v0.1/Makefile index a07b25ee..5761fed7 100644 --- a/src/megametrum-v0.1/Makefile +++ b/src/megametrum-v0.1/Makefile @@ -24,7 +24,6 @@ INC = \ # Common AltOS sources # -# ao_cc1120.c \ # ao_packet.c \ # ao_packet_slave.c \ @@ -45,6 +44,7 @@ ALTOS_SRC = \ ao_freq.c \ ao_dma_stm.c \ ao_spi_stm.c \ + ao_cc1120.c \ ao_ms5607.c \ ao_adc_stm.c \ ao_beep_stm.c \ diff --git a/src/megametrum-v0.1/ao_megametrum.c b/src/megametrum-v0.1/ao_megametrum.c index 19746d37..628c5538 100644 --- a/src/megametrum-v0.1/ao_megametrum.c +++ b/src/megametrum-v0.1/ao_megametrum.c @@ -21,21 +21,6 @@ #include #include -void -beep(void) -{ - ao_beep(AO_BEEP_MID); - printf ("Hit a character to stop..."); flush(); - getchar(); - putchar('\n'); - ao_beep(0); -} - -const struct ao_cmds ao_mm_cmds[] = { - { beep, "b\0Beep" }, - { 0, NULL }, -}; - int main(void) { @@ -55,7 +40,7 @@ main(void) ao_storage_init(); ao_usb_init(); ao_exti_init(); -// ao_radio_init(); + ao_radio_init(); ao_i2c_init(); ao_hmc5883_init(); ao_mpu6000_init(); @@ -64,7 +49,6 @@ main(void) ao_report_init(); ao_config_init(); - ao_cmd_register(&ao_mm_cmds[0]); ao_start_scheduler(); return 0; } diff --git a/src/megametrum-v0.1/ao_pins.h b/src/megametrum-v0.1/ao_pins.h index d6394d9b..5121ad58 100644 --- a/src/megametrum-v0.1/ao_pins.h +++ b/src/megametrum-v0.1/ao_pins.h @@ -65,6 +65,7 @@ #define USE_INTERNAL_FLASH 0 #define HAS_USB 1 #define HAS_BEEP 1 +#define HAS_RADIO 1 #define HAS_SPI_1 1 #define SPI_1_PA5_PA6_PA7 1 @@ -74,6 +75,10 @@ #define HAS_SPI_2 1 #define SPI_2_PB13_PB14_PB15 1 #define SPI_2_PD1_PD3_PD4 0 +#define SPI_2_GPIO stm_gpiob +#define SPI_2_SCK 13 +#define SPI_2_MISO 14 +#define SPI_2_MOSI 15 #define HAS_I2C_1 1 #define I2C_1_PB8_PB9 1 @@ -81,7 +86,7 @@ #define HAS_I2C_2 1 #define I2C_2_PB10_PB11 1 -#define PACKET_HAS_SLAVE 1 +#define PACKET_HAS_SLAVE 0 #define LOW_LEVEL_DEBUG 1 @@ -251,4 +256,6 @@ struct ao_adc { #define HAS_HIGHG_ACCEL 1 +#define NUM_CMDS 16 + #endif /* _AO_PINS_H_ */ -- 2.30.2