summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2020-11-27 14:42:52 +0100
committerjaseg <git@jaseg.de>2020-11-27 14:42:52 +0100
commit6ebd1a667d6e58ca355387af24bbe2a5b00baa50 (patch)
treeb64d0c3b20739e1a5e69d13e788089d737d6af62
parent424310d957cb04bfacba9c711ee7f074fd41f962 (diff)
downloadihsm-6ebd1a667d6e58ca355387af24bbe2a5b00baa50.tar.gz
ihsm-6ebd1a667d6e58ca355387af24bbe2a5b00baa50.tar.bz2
ihsm-6ebd1a667d6e58ca355387af24bbe2a5b00baa50.zip
FW bidir comms work
-rw-r--r--prototype/fw/src/main.c28
-rw-r--r--prototype/fw/tools/ser_test.py4
2 files changed, 19 insertions, 13 deletions
diff --git a/prototype/fw/src/main.c b/prototype/fw/src/main.c
index fb3c302..16e1b78 100644
--- a/prototype/fw/src/main.c
+++ b/prototype/fw/src/main.c
@@ -53,7 +53,7 @@ int main(void) {
USART1->CR1 = USART_CR1_TE | USART_CR1_RE;
USART1->BRR = (apb2_clock + baudrate/2) / baudrate;
- USART1->CR1 |= USART_CR2_RXINV;
+ USART1->CR2 |= USART_CR2_RXINV;
USART1->CR1 |= USART_CR1_UE;
int req_seq = 0;
@@ -71,6 +71,7 @@ int main(void) {
USART1->TDR = 0; /* Kick off transmission */
while (23) {
+ /*
if (tx_st.remaining_bytes == 0) {
res_buf.req_seq = req_seq;
res_buf.res_seq = res_seq;
@@ -87,6 +88,7 @@ int main(void) {
tx_st.tx_char += 1;
tx_st.remaining_bytes -= 1;
}
+ */
if (USART1->ISR & USART_ISR_ORE)
USART1->ICR = USART_ICR_ORECF;
@@ -100,19 +102,21 @@ int main(void) {
if (USART1->ISR & USART_ISR_RXNE) {
uint8_t c = USART1->RDR;
if (!c) {
- int rc = cobs_decode(rx_buf, rx_char, (uint8_t *)&req_buf, sizeof(req_buf));
- if (rc < 0) {
- rx_cobs_error += 1;
- } else {
- if (rc == sizeof(req_buf)) {
- crc32_t check_crc = pkt_crc(&req_buf, &req_buf.trailer);
- if (check_crc != req_buf.trailer.crc32) {
- rx_crc_error += 1;
+ if (rx_char < sizeof(rx_buf)) {
+ int rc = cobs_decode(rx_buf, rx_char, (uint8_t *)&req_buf, sizeof(req_buf));
+ if (rc < 0) {
+ rx_cobs_error += 1;
+ } else {
+ if (rc == sizeof(req_buf)) {
+ crc32_t check_crc = pkt_crc(&req_buf, &req_buf.trailer);
+ if (check_crc != req_buf.trailer.crc32) {
+ rx_crc_error += 1;
+ } else {
+ req_seq = req_buf.req_seq;
+ }
} else {
- req_seq = req_buf.req_seq;
+ rx_framing_error += 1;
}
- } else {
- rx_framing_error += 1;
}
}
rx_char = 0;
diff --git a/prototype/fw/tools/ser_test.py b/prototype/fw/tools/ser_test.py
index 191124b..d9dec62 100644
--- a/prototype/fw/tools/ser_test.py
+++ b/prototype/fw/tools/ser_test.py
@@ -66,8 +66,10 @@ if __name__ == '__main__':
if time.time() - last_tx > 0.01:
+ seq = int((time.time() - start_time) * 10)
data = struct.pack('<I', seq)
- seq += 1
+ #seq += 1
+ #ser.write(bytes(list(range(255, -1, -1))))
ser.write(cobs.encode(data + struct.pack('<I', zlib.crc32(data))) + b'\0')
last_tx = time.time()
#time.sleep(0.01)