summaryrefslogtreecommitdiff
path: root/controller/fw/src
diff options
context:
space:
mode:
authorjaseg <git-bigdata-wsl-arch@jaseg.de>2020-05-05 17:50:09 +0200
committerjaseg <git-bigdata-wsl-arch@jaseg.de>2020-05-05 17:50:09 +0200
commitdb50711ba4a1f41f4082981bae58f213d48d96a1 (patch)
tree6480922fdc46a51bfb2e22e57d02cc0d3aef9d06 /controller/fw/src
parent9918eb505321183e20357221a4dcf2aa9c1e057c (diff)
downloadmaster-thesis-db50711ba4a1f41f4082981bae58f213d48d96a1.tar.gz
master-thesis-db50711ba4a1f41f4082981bae58f213d48d96a1.tar.bz2
master-thesis-db50711ba4a1f41f4082981bae58f213d48d96a1.zip
fw: Tie together all parts for an end-to-end demo
Diffstat (limited to 'controller/fw/src')
-rw-r--r--controller/fw/src/crypto.c2
-rw-r--r--controller/fw/src/crypto.h3
-rw-r--r--controller/fw/src/main.c51
-rw-r--r--controller/fw/src/protocol.c31
-rw-r--r--controller/fw/src/rscode-config.h3
-rw-r--r--controller/fw/src/rslib.c5
-rw-r--r--controller/fw/src/rslib.h5
7 files changed, 79 insertions, 21 deletions
diff --git a/controller/fw/src/crypto.c b/controller/fw/src/crypto.c
index db35745..f4f79a4 100644
--- a/controller/fw/src/crypto.c
+++ b/controller/fw/src/crypto.c
@@ -26,7 +26,7 @@ void debug_hexdump(const char *name, const uint8_t *buf, size_t len) {
DEBUG_PRINTN("\n");
}
-/* Returns 1 for correct trigger */
+/* Returns trigger sig height for correct trigger */
int verify_trigger_dom(const uint8_t inkey[PRESIG_MSG_LEN],
const char *domain_string, const uint8_t refkey[PRESIG_MSG_LEN]) {
uint8_t key[crypto_auth_hmacsha512_KEYBYTES];
diff --git a/controller/fw/src/crypto.h b/controller/fw/src/crypto.h
index 05a3c0d..18a9816 100644
--- a/controller/fw/src/crypto.h
+++ b/controller/fw/src/crypto.h
@@ -3,7 +3,8 @@
#include <stdint.h>
-#define PRESIG_MSG_LEN 16
+/* Presig message length: 15 byte = 120 bit ^= 20 * 6-bit symbols of 5-bit bipolar DSSS */
+#define PRESIG_MSG_LEN 15
#define OOB_TRIGGER_LEN PRESIG_MSG_LEN
enum trigger_domain {
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) {
diff --git a/controller/fw/src/protocol.c b/controller/fw/src/protocol.c
index 4740917..6b7d8b7 100644
--- a/controller/fw/src/protocol.c
+++ b/controller/fw/src/protocol.c
@@ -1,9 +1,14 @@
+#include <assert.h>
+
#include "sr_global.h"
#include "dsss_demod.h"
#include "con_usart.h"
+#include "rslib.h"
+#include "crypto.h"
void handle_dsss_received(uint8_t data[static TRANSMISSION_SYMBOLS]) {
+ /* Console status output */
con_printf("DSSS data received: ");
for (int i=0; i<TRANSMISSION_SYMBOLS; i++) {
int x = (data[i]>>1) * (data[i]&1 ? 1 : -1);
@@ -11,5 +16,29 @@ void handle_dsss_received(uint8_t data[static TRANSMISSION_SYMBOLS]) {
}
con_printf("\r\n");
- update_image_flash_counter();
+ /* Run reed-solomon error correction */
+ const int sym_bits = DSSS_GOLD_CODE_NBITS + 1; /* +1 for amplitude sign bit */
+ /* TODO identify erasures in DSSS demod layer */
+ (void) rslib_decode(sym_bits, TRANSMISSION_SYMBOLS, (char *)data);
+ /* TODO error detection & handling */
+
+ /* Re-bit-pack data buffer to be bit-continuous:
+ * [ . . a b c d e f ] [ . . g h i j k l ] [ . . m n o p q r ] ...
+ * ==> [ a b c d e f g h ] [ i j k l m n o p ] [ q r ... ] ...
+ */
+ static_assert((TRANSMISSION_SYMBOLS - NPAR) * (DSSS_GOLD_CODE_NBITS + 1) == OOB_TRIGGER_LEN * 8);
+ for (uint8_t i=0, j=0; i < TRANSMISSION_SYMBOLS - NPAR; i++, j += sym_bits) {
+ uint32_t sym = data[i]; /* [ ... | . . X X X X X X ] for 5-bit dsss */
+ data[i] = 0; /* clear for output */
+
+ sym <<= 8-sym_bits; /* left-align: [ ... | X X X X X X . . ] */
+ sym <<= 8; /* shift to second byte: [ ... | X X X X X X . . | . . . . . . . . ]*/
+ sym >>= (j%8); /* shift to bit write offset: [ ... | . . . . X X X X | X X . . . . . . ] for offset 4 */
+ data[j/8] |= sym >> 8; /* write upper byte */
+ data[j/8 + 1] |= sym & 0xff; /* write lower byte */
+ }
+
+ /* hand off to crypto.c */
+ oob_message_received(data);
}
+
diff --git a/controller/fw/src/rscode-config.h b/controller/fw/src/rscode-config.h
index 922aca9..ea5183b 100644
--- a/controller/fw/src/rscode-config.h
+++ b/controller/fw/src/rscode-config.h
@@ -3,7 +3,6 @@
#ifndef __RSCODE_CONFIG_H__
#define __RSCODE_CONFIG_H__
-#define NPAR 4
-#define NBITS 6
+#define NPAR 10
#endif /* __RSCODE_CONFIG_H__ */
diff --git a/controller/fw/src/rslib.c b/controller/fw/src/rslib.c
index ce54a6f..aa0db2c 100644
--- a/controller/fw/src/rslib.c
+++ b/controller/fw/src/rslib.c
@@ -6,20 +6,19 @@
#include "rslib.h"
+static struct rscode_driver driver;
+
void rslib_encode(int nbits, size_t msglen, char msg[static msglen], char out[msglen + NPAR]) {
- struct rscode_driver driver;
rscode_init(&driver, nbits);
rscode_encode(&driver, (unsigned char *)msg, msglen, (unsigned char *)out);
}
int rslib_decode(int nbits, size_t msglen, char msg_inout[static msglen]) {
- struct rscode_driver driver;
rscode_init(&driver, nbits);
return rscode_decode(&driver, (unsigned char *)msg_inout, msglen);
}
int rslib_gexp(int z, int nbits) {
- struct rscode_driver driver;
rscode_init(&driver, nbits);
return gexp(&driver, z);
}
diff --git a/controller/fw/src/rslib.h b/controller/fw/src/rslib.h
index 3ef6d19..bba8bb0 100644
--- a/controller/fw/src/rslib.h
+++ b/controller/fw/src/rslib.h
@@ -1,9 +1,12 @@
#ifndef __RSLIB_H__
#define __RSLIB_H__
+/* parity length configuration */
+#include "rscode-config.h"
+
void rslib_encode(int nbits, size_t msglen, char msg[static msglen], char out[msglen + NPAR]);
int rslib_decode(int nbits, size_t msglen, char msg_inout[static msglen]);
int rslib_gexp(int z, int nbits);
-size_t rslib_npar();
+size_t rslib_npar(void);
#endif /* __RSLIB_H__ */