diff options
| author | J08nY | 2020-02-26 14:28:52 +0100 |
|---|---|---|
| committer | J08nY | 2020-02-26 14:28:52 +0100 |
| commit | f78ff987ac2df62dbd8326ce33ae61c97673710e (patch) | |
| tree | 9b63026e223254bc3c4e6af164bd3ae3bdcc0404 /pyecsca/codegen/simpleserial | |
| parent | 3892d994470b181f950703fabf719a9c963d1c20 (diff) | |
| download | pyecsca-codegen-f78ff987ac2df62dbd8326ce33ae61c97673710e.tar.gz pyecsca-codegen-f78ff987ac2df62dbd8326ce33ae61c97673710e.tar.zst pyecsca-codegen-f78ff987ac2df62dbd8326ce33ae61c97673710e.zip | |
Get stuff to work on STM32F0.
Diffstat (limited to 'pyecsca/codegen/simpleserial')
| -rw-r--r-- | pyecsca/codegen/simpleserial/Makefile.simpleserial | 23 | ||||
| -rw-r--r-- | pyecsca/codegen/simpleserial/simpleserial.c | 31 | ||||
| -rw-r--r-- | pyecsca/codegen/simpleserial/simpleserial.h | 4 |
3 files changed, 22 insertions, 36 deletions
diff --git a/pyecsca/codegen/simpleserial/Makefile.simpleserial b/pyecsca/codegen/simpleserial/Makefile.simpleserial index 47a0d1e..1cb855b 100644 --- a/pyecsca/codegen/simpleserial/Makefile.simpleserial +++ b/pyecsca/codegen/simpleserial/Makefile.simpleserial @@ -1,26 +1,3 @@ SRC += simpleserial.c VPATH += :$(FIRMWAREPATH)/simpleserial/ EXTRAINCDIRS += $(FIRMWAREPATH)/simpleserial/ - -SS_VERS_ALLOWED = SS_VER_1_0 SS_VER_1_1 - -define SS_VERS_LIST - - +---------+--------------+ - | Version | SS_VER value | - +---------+--------------+ - | V1.0 | SS_VER_1_0 | - | V1.1 | SS_VER_1_1 | - +---------+--------------+ - -endef - -# SimpleSerial version -# To change this, define SS_VER before including this file -ifeq ($(SS_VER),) - SS_VER = SS_VER_1_1 -else ifeq ($(filter $(SS_VER),$(SS_VERS_ALLOWED)),) - $(error Invalid SimpleSerial version: $(SS_VER); allowed verions: $(SS_VERS_LIST)) -endif - -CDEFS += -DSS_VER=$(SS_VER)
\ No newline at end of file diff --git a/pyecsca/codegen/simpleserial/simpleserial.c b/pyecsca/codegen/simpleserial/simpleserial.c index 8ca20c4..9a8be4c 100644 --- a/pyecsca/codegen/simpleserial/simpleserial.c +++ b/pyecsca/codegen/simpleserial/simpleserial.c @@ -7,23 +7,20 @@ typedef struct ss_cmd { char c; - unsigned int len; + uint32_t len; uint8_t (*fp)(uint8_t*, uint16_t); } ss_cmd; static ss_cmd commands[MAX_SS_CMDS]; static int num_commands = 0; -#define SS_VER_1_0 0 -#define SS_VER_1_1 1 - static char hex_lookup[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; -int hex_decode(int len, char* ascii_buf, uint8_t* data_buf) +int hex_decode(uint32_t len, char* ascii_buf, uint8_t* data_buf) { if (len % 2 != 0) return 1; @@ -69,7 +66,7 @@ void simpleserial_init() simpleserial_addcmd('v', 0, check_version); } -int simpleserial_addcmd(char c, unsigned int len, uint8_t (*fp)(uint8_t*, uint16_t)) +int simpleserial_addcmd(char c, uint32_t len, uint8_t (*fp)(uint8_t*, uint16_t)) { if(num_commands >= MAX_SS_CMDS) return 1; @@ -109,7 +106,7 @@ int simpleserial_get(void) return 1; // Receive characters until we fill the ASCII buffer - int i = 0; + uint32_t i = 0; for(; i < 2*commands[cmd].len; i++) { c = getch(); @@ -120,6 +117,21 @@ int simpleserial_get(void) ascii_buf[i] = c; } +// uint8_t ik[4]; +// ik[3] = (uint8_t) i & 0xff; +// ik[2] = (uint8_t) (i>>8) & 0xff; +// ik[1] = (uint8_t) (i>>16) & 0xff; +// ik[0] = (uint8_t) (i>>24) & 0xff; +// uint8_t ic[4]; +// ic[3] = (uint8_t) c & 0xff; +// ic[2] = (uint8_t) (c>>8) & 0xff; +// ic[1] = (uint8_t) (c>>16) & 0xff; +// ic[0] = (uint8_t) (c>>24) & 0xff; +// if (commands[cmd].c == 'd') { +// simpleserial_put('o', 4, ik); +// simpleserial_put('c', 4, ic); +// } + // ASCII buffer is full: convert to bytes // Check for illegal characters here @@ -130,14 +142,11 @@ int simpleserial_get(void) uint8_t ret[1]; ret[0] = commands[cmd].fp(data_buf, i/2); - // Acknowledge (if version is 1.1) -#if SS_VER == SS_VER_1_1 simpleserial_put('z', 1, ret); -#endif return 1; } -void simpleserial_put(char c, int size, uint8_t* output) +void simpleserial_put(char c, uint32_t size, uint8_t* output) { // Write first character putch(c); diff --git a/pyecsca/codegen/simpleserial/simpleserial.h b/pyecsca/codegen/simpleserial/simpleserial.h index a5dff81..224cc3b 100644 --- a/pyecsca/codegen/simpleserial/simpleserial.h +++ b/pyecsca/codegen/simpleserial/simpleserial.h @@ -27,7 +27,7 @@ void simpleserial_init(void); // - Returns 1 if either of these fail; otherwise 0 // - The callback function returns a number in [0x00, 0xFF] as a status code; // in protocol v1.1, this status code is returned through a "z" message -int simpleserial_addcmd(char c, unsigned int len, uint8_t (*fp)(uint8_t*, uint16_t)); +int simpleserial_addcmd(char c, uint32_t len, uint8_t (*fp)(uint8_t*, uint16_t)); // Attempt to process a command // If a full string is found, the relevant callback function is called @@ -40,6 +40,6 @@ int simpleserial_get(void); // Write some data to the serial port // Prepends the character c to the start of the line // Example: simpleserial_put('r', 16, ciphertext) -void simpleserial_put(char c, int size, uint8_t* output); +void simpleserial_put(char c, uint32_t size, uint8_t* output); #endif // SIMPLESERIAL_H |
