diff options
Diffstat (limited to 'controller/fw/src/main.c')
-rw-r--r-- | controller/fw/src/main.c | 51 |
1 files changed, 39 insertions, 12 deletions
diff --git a/controller/fw/src/main.c b/controller/fw/src/main.c index 6547c38..e2f7353 100644 --- a/controller/fw/src/main.c +++ b/controller/fw/src/main.c @@ -15,6 +15,7 @@ #include "dsss_demod.h" #include "con_usart.h" #include "mspdebug_wrapper.h" +#include "crypto.h" static struct spi_flash_if spif; @@ -28,6 +29,7 @@ unsigned int apb2_timer_speed = 0; struct leds leds; ssize_t jt_spi_flash_read_block(void *usr, int addr, size_t len, uint8_t *out); +static void update_image_flash_counter(void); void __libc_init_array(void) { /* we don't need this. */ } void __assert_func (unused_a const char *file, unused_a int line, unused_a const char *function, unused_a const char *expr) { @@ -208,7 +210,7 @@ ssize_t jt_spi_flash_read_block(void *usr, int addr, size_t len, uint8_t *out) { return len; } -void update_image_flash_counter(void) { +void update_image_flash_counter() { static int flash_counter = 0; flash_counter ++; fw_dump[row2_offx + 0] = flash_counter/10000 + '0'; @@ -222,6 +224,24 @@ void update_image_flash_counter(void) { fw_dump[row2_offx + 4] = flash_counter + '0'; } +/* Callback from crypto.c:oob_message_received */ +void oob_trigger_activated(enum trigger_domain domain, int serial) { + con_printf("oob_trigger_activated(%d, %d)\r\n", domain, serial); + con_printf("Attempting to flash meter...\r\n"); + update_image_flash_counter(); + + int flash_tries = 0; + while (flash_tries++ < 25) { + mspd_jtag_init(); + if (!mspd_jtag_flash_and_reset(jtag_img.devmem_img_start, jtag_img.img_len, jt_spi_flash_read_block, &jtag_img)) + break; + for (int j=0; j<168*1000*5; j++) + asm volatile ("nop"); + } + if (flash_tries == 25) + con_printf("Giving up.\r\n"); +} + static unsigned int measurement_errors = 0; static struct dsss_demod_state demod_state; static uint32_t freq_sample_ts = 0; @@ -264,17 +284,24 @@ int main(void) dsss_demod_init(&demod_state); con_printf("Booted.\r\n"); - con_printf("Attempting to flash meter...\r\n"); - int flash_tries = 0; - while (flash_tries++ < 25) { - mspd_jtag_init(); - if (!mspd_jtag_flash_and_reset(jtag_img.devmem_img_start, jtag_img.img_len, jt_spi_flash_read_block, &jtag_img)) - break; - for (int j=0; j<168*1000*5; j++) - asm volatile ("nop"); - } - if (flash_tries == 25) - con_printf("Giving up.\r\n"); + + + /* FIXME DEBUG */ +#if 0 + uint8_t test_data[TRANSMISSION_SYMBOLS] = { + 0 + }; + con_printf("Test 0\r\n"); + handle_dsss_received(test_data); + + uint8_t test_data2[TRANSMISSION_SYMBOLS] = { + 0x24, 0x0f, 0x3b, 0x10, 0x27, 0x0e, 0x22, 0x30, 0x01, 0x2c, 0x1c, 0x0b, 0x35, 0x0a, 0x12, 0x27, 0x11, 0x20, + 0x0c, 0x10, 0xc0, 0x08, 0xa4, 0x72, 0xa9, 0x9b, 0x7b, 0x27, 0xee, 0xcd + }; + con_printf("Test 1\r\n"); + handle_dsss_received(test_data2); +#endif + /* END DEBUG */ while (23) { if (adc_fft_buf_ready_idx != -1) { |