Skip to content

Commit

Permalink
Put unused DWM to sleep at boot time
Browse files Browse the repository at this point in the history
  • Loading branch information
hedgecrw committed Oct 9, 2023
1 parent 13113ba commit 7841528
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 17 deletions.
2 changes: 1 addition & 1 deletion software/firmware/.cproject
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@
</target>
<target name="UID" path="tests" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>${cross_make}</buildCommand>
<buildArguments>ID=c0:98:e5:42:05:51</buildArguments>
<buildArguments>ID=c0:98:e5:42:05:52</buildArguments>
<buildTarget>UID</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>false</useDefaultCommand>
Expand Down
2 changes: 1 addition & 1 deletion software/firmware/launchConfigs/TestBluetooth.launch
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
</listAttribute>
<stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#10;&lt;memoryBlockExpressionList context=&quot;Context string&quot;/&gt;&#10;"/>
<stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;memoryBlockExpressionList context=&quot;Context string&quot;/&gt;&#13;&#10;"/>
<stringAttribute key="process_factory_id" value="org.eclipse.cdt.dsf.gdb.GdbProcessFactory"/>
</launchConfiguration>
2 changes: 2 additions & 0 deletions software/firmware/src/boards/revL/pinout.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#define PIN_RADIO_SPI_MISO_FUNCTION AM_HAL_PIN_33_M3MISO
#define PIN_RADIO_SPI_MOSI_FUNCTION AM_HAL_PIN_32_M3MOSI
#define PIN_RADIO_SPI_CS_FUNCTION AM_HAL_PIN_29_NCE29
#define PIN_RADIO_SPI_CS2_FUNCTION AM_HAL_PIN_24_NCE24
#define PIN_RADIO_SPI_CS3_FUNCTION AM_HAL_PIN_25_NCE25

// IMU
#define IMU_I2C_NUMBER 1
Expand Down
2 changes: 2 additions & 0 deletions software/firmware/src/boards/revM/pinout.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#define PIN_RADIO_SPI_MISO_FUNCTION AM_HAL_PIN_33_M3MISO
#define PIN_RADIO_SPI_MOSI_FUNCTION AM_HAL_PIN_32_M3MOSI
#define PIN_RADIO_SPI_CS_FUNCTION AM_HAL_PIN_29_NCE29
#define PIN_RADIO_SPI_CS2_FUNCTION AM_HAL_PIN_24_NCE24
#define PIN_RADIO_SPI_CS3_FUNCTION AM_HAL_PIN_25_NCE25

// IMU
#define IMU_I2C_NUMBER 1
Expand Down
72 changes: 59 additions & 13 deletions software/firmware/src/peripherals/src/ranging.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ void ranging_radio_init(uint8_t *uid)
configASSERT0(am_hal_gpio_pinconfig(PIN_RADIO_ANTENNA_SELECT2, am_hal_gpio_pincfg_output));
am_hal_gpio_output_clear(PIN_RADIO_ANTENNA_SELECT2);
#else
configASSERT0(am_hal_gpio_pinconfig(PIN_RADIO_SPI_CS, am_hal_gpio_pincfg_output));
am_hal_gpio_output_set(PIN_RADIO_SPI_CS);
configASSERT0(am_hal_gpio_pinconfig(PIN_RADIO_SPI_CS2, am_hal_gpio_pincfg_output));
am_hal_gpio_output_set(PIN_RADIO_SPI_CS2);
configASSERT0(am_hal_gpio_pinconfig(PIN_RADIO_SPI_CS3, am_hal_gpio_pincfg_output));
Expand All @@ -185,14 +187,13 @@ void ranging_radio_init(uint8_t *uid)
radio_interrupt_pin = PIN_RADIO_INTERRUPT2;
configASSERT0(am_hal_gpio_pinconfig(PIN_RADIO_INTERRUPT2, interrupt_pin_config));
configASSERT0(am_hal_gpio_interrupt_control(AM_HAL_GPIO_INT_CHANNEL_0, AM_HAL_GPIO_INT_CTRL_INDV_ENABLE, &radio_interrupt_pin));
// TODO: Enable interrupts from other DWM modules at some point
//NVIC_SetPriority(GPIO0_001F_IRQn + GPIO_NUM2IDX(PIN_RADIO_INTERRUPT2), NVIC_configMAX_SYSCALL_INTERRUPT_PRIORITY);
//NVIC_EnableIRQ(GPIO0_001F_IRQn + GPIO_NUM2IDX(PIN_RADIO_INTERRUPT2));
NVIC_SetPriority(GPIO0_001F_IRQn + GPIO_NUM2IDX(PIN_RADIO_INTERRUPT2), NVIC_configMAX_SYSCALL_INTERRUPT_PRIORITY);
NVIC_EnableIRQ(GPIO0_001F_IRQn + GPIO_NUM2IDX(PIN_RADIO_INTERRUPT2));
radio_interrupt_pin = PIN_RADIO_INTERRUPT3;
configASSERT0(am_hal_gpio_pinconfig(PIN_RADIO_INTERRUPT3, interrupt_pin_config));
configASSERT0(am_hal_gpio_interrupt_control(AM_HAL_GPIO_INT_CHANNEL_0, AM_HAL_GPIO_INT_CTRL_INDV_ENABLE, &radio_interrupt_pin));
//NVIC_SetPriority(GPIO0_001F_IRQn + GPIO_NUM2IDX(PIN_RADIO_INTERRUPT3), NVIC_configMAX_SYSCALL_INTERRUPT_PRIORITY);
//NVIC_EnableIRQ(GPIO0_001F_IRQn + GPIO_NUM2IDX(PIN_RADIO_INTERRUPT3));
NVIC_SetPriority(GPIO0_001F_IRQn + GPIO_NUM2IDX(PIN_RADIO_INTERRUPT3), NVIC_configMAX_SYSCALL_INTERRUPT_PRIORITY);
NVIC_EnableIRQ(GPIO0_001F_IRQn + GPIO_NUM2IDX(PIN_RADIO_INTERRUPT3));
#endif

// Initialize the SPI module and enable all relevant SPI pins
Expand All @@ -209,16 +210,50 @@ void ranging_radio_init(uint8_t *uid)
configASSERT0(am_hal_gpio_pinconfig(PIN_RADIO_SPI_SCK, sck_config));
configASSERT0(am_hal_gpio_pinconfig(PIN_RADIO_SPI_MISO, miso_config));
configASSERT0(am_hal_gpio_pinconfig(PIN_RADIO_SPI_MOSI, mosi_config));
configASSERT0(am_hal_gpio_pinconfig(PIN_RADIO_SPI_CS, cs_config));
ranging_radio_spi_fast();

// TODO: Reset the extra DWMs and put them into deep-sleep mode
// Put all DWMs into reset mode
am_hal_gpio_output_tristate_enable(PIN_RADIO_RESET);
am_hal_delay_us(1);
am_hal_gpio_output_tristate_disable(PIN_RADIO_RESET);
am_hal_delay_us(2000);
#if REVISION_ID >= REVISION_M
am_hal_gpio_output_tristate_enable(PIN_RADIO_RESET2);
am_hal_delay_us(1);
am_hal_gpio_output_tristate_disable(PIN_RADIO_RESET2);
am_hal_delay_us(2000);
am_hal_gpio_output_tristate_enable(PIN_RADIO_RESET3);
am_hal_delay_us(1);
am_hal_gpio_output_tristate_disable(PIN_RADIO_RESET3);
am_hal_delay_us(2000);
#endif

// Reset the extra DWMs and put them into deep-sleep mode
#if REVISION_ID >= REVISION_L
cs_config.GP.cfg_b.uFuncSel = PIN_RADIO_SPI_CS2_FUNCTION;
configASSERT0(am_hal_gpio_pinconfig(PIN_RADIO_SPI_CS2, cs_config));
ranging_radio_spi_slow();
ranging_radio_reset();
ranging_radio_sleep(true);
while (am_hal_iom_disable(spi_handle) != AM_HAL_STATUS_SUCCESS);
configASSERT0(am_hal_gpio_pinconfig(PIN_RADIO_SPI_CS2, am_hal_gpio_pincfg_output));
am_hal_gpio_output_set(PIN_RADIO_SPI_CS2);
cs_config.GP.cfg_b.uFuncSel = PIN_RADIO_SPI_CS3_FUNCTION;
configASSERT0(am_hal_gpio_pinconfig(PIN_RADIO_SPI_CS3, cs_config));
ranging_radio_spi_slow();
ranging_radio_reset();
ranging_radio_sleep(true);
while (am_hal_iom_disable(spi_handle) != AM_HAL_STATUS_SUCCESS);
configASSERT0(am_hal_gpio_pinconfig(PIN_RADIO_SPI_CS3, am_hal_gpio_pincfg_output));
am_hal_gpio_output_set(PIN_RADIO_SPI_CS3);
cs_config.GP.cfg_b.uFuncSel = PIN_RADIO_SPI_CS_FUNCTION;
#endif

// Reset and initialize the DW3000 radio
configASSERT0(am_hal_gpio_pinconfig(PIN_RADIO_SPI_CS, cs_config));
ranging_radio_spi_slow();
ranging_radio_reset();
dwt_setcallbacks(NULL, NULL, NULL, NULL, NULL, ranging_radio_spi_ready, NULL);
ranging_radio_spi_fast();
}

void ranging_radio_deinit(void)
Expand All @@ -231,17 +266,28 @@ void ranging_radio_deinit(void)
// Disable all radio-based interrupts
uint32_t radio_interrupt_pin = PIN_RADIO_INTERRUPT;
NVIC_DisableIRQ(GPIO0_001F_IRQn + GPIO_NUM2IDX(PIN_RADIO_INTERRUPT));
am_hal_gpio_interrupt_register(AM_HAL_GPIO_INT_CHANNEL_0, radio_interrupt_pin, NULL, (void*)radio_interrupt_pin);
am_hal_gpio_interrupt_register(AM_HAL_GPIO_INT_CHANNEL_0, PIN_RADIO_INTERRUPT, NULL, NULL);
am_hal_gpio_interrupt_control(AM_HAL_GPIO_INT_CHANNEL_0, AM_HAL_GPIO_INT_CTRL_INDV_DISABLE, &radio_interrupt_pin);
#if REVISION_ID >= REVISION_L
radio_interrupt_pin = PIN_RADIO_INTERRUPT2;
NVIC_DisableIRQ(GPIO0_001F_IRQn + GPIO_NUM2IDX(PIN_RADIO_INTERRUPT2));
am_hal_gpio_interrupt_register(AM_HAL_GPIO_INT_CHANNEL_0, PIN_RADIO_INTERRUPT2, NULL, NULL);
am_hal_gpio_interrupt_control(AM_HAL_GPIO_INT_CHANNEL_0, AM_HAL_GPIO_INT_CTRL_INDV_DISABLE, &radio_interrupt_pin);
radio_interrupt_pin = PIN_RADIO_INTERRUPT3;
NVIC_DisableIRQ(GPIO0_001F_IRQn + GPIO_NUM2IDX(PIN_RADIO_INTERRUPT3));
am_hal_gpio_interrupt_register(AM_HAL_GPIO_INT_CHANNEL_0, PIN_RADIO_INTERRUPT3, NULL, NULL);
am_hal_gpio_interrupt_control(AM_HAL_GPIO_INT_CHANNEL_0, AM_HAL_GPIO_INT_CTRL_INDV_DISABLE, &radio_interrupt_pin);
#endif
}

void ranging_radio_reset(void)
{
// Assert the DW3000 reset pin for 1us to manually reset the device
am_hal_gpio_output_tristate_enable(PIN_RADIO_RESET);
am_hal_delay_us(1);
am_hal_gpio_output_tristate_disable(PIN_RADIO_RESET);
am_hal_delay_us(2000);
// TODO: SOMEHOW CLEAN ALL THIS UP ONCE THE HW STOPS CHANGING
//am_hal_gpio_output_tristate_enable(PIN_RADIO_RESET);
//am_hal_delay_us(1);
//am_hal_gpio_output_tristate_disable(PIN_RADIO_RESET);
//am_hal_delay_us(2000);

// Initialize the DW3000 driver and transceiver
while (dwt_probe((struct dwt_probe_s*)&driver_interface) != DWT_SUCCESS)
Expand Down
4 changes: 2 additions & 2 deletions software/firmware/tests/peripherals/test_ranging_radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ void deep_sleep_test(void)
void delayed_write_test(void)
{
// Create a test packet for sending
static schedule_packet_t packet = (schedule_packet_t){ .header = { .frameCtrl = { 0x41, 0xC8 }, .seqNum = 0,
schedule_packet_t packet = (schedule_packet_t){ .header = { .frameCtrl = { 0x41, 0xC8 }, .seqNum = 0,
.panID = { MODULE_PANID & 0xFF, MODULE_PANID >> 8 }, .destAddr = { 0xFF, 0xFF }, .sourceAddr = { 0 } },
.message_type = SCHEDULE_PACKET, .epoch_time_unix = 12345678, .num_devices = 0,
.schedule = { 0 }, .footer = { { 0 } } };
static uint16_t packet_size = sizeof(packet);
uint16_t packet_size = sizeof(packet);

// Select the appropriate antenna and channel
ranging_radio_disable();
Expand Down

0 comments on commit 7841528

Please sign in to comment.