summaryrefslogtreecommitdiffstats
path: root/pressure_control/firmware
diff options
context:
space:
mode:
authorMichael Buesch <mb@bu3sch.de>2009-11-22 15:01:38 +0100
committerMichael Buesch <mb@bu3sch.de>2009-11-22 15:01:38 +0100
commit9af43462bd0989a2930afb9e1fdb7bb58fbdf5c4 (patch)
tree9c0c0c1f60f85378a82092ec4b9bd32dbe1d52ac /pressure_control/firmware
parentf6e560e764e4315c8d50ce26b4894da680efb43a (diff)
downloadcnc-9af43462bd0989a2930afb9e1fdb7bb58fbdf5c4.tar.xz
cnc-9af43462bd0989a2930afb9e1fdb7bb58fbdf5c4.zip
pressure_control: Use 8bit CRC
Signed-off-by: Michael Buesch <mb@bu3sch.de>
Diffstat (limited to 'pressure_control/firmware')
-rw-r--r--pressure_control/firmware/remote.c18
-rw-r--r--pressure_control/firmware/remote.h2
-rw-r--r--pressure_control/firmware/util.c9
-rw-r--r--pressure_control/firmware/util.h2
4 files changed, 14 insertions, 17 deletions
diff --git a/pressure_control/firmware/remote.c b/pressure_control/firmware/remote.c
index 7863b55..a80683b 100644
--- a/pressure_control/firmware/remote.c
+++ b/pressure_control/firmware/remote.c
@@ -2,7 +2,7 @@
* Pneumatic pressure controller.
* Remote control.
*
- * Copyright (C) 2008 Michael Buesch <mb@bu3sch.de>
+ * Copyright (C) 2008-2009 Michael Buesch <mb@bu3sch.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -87,9 +87,9 @@ static inline int8_t usart_rx(uint8_t *data)
static void send_message(struct remote_message *msg)
{
/* Calculate the CRC. */
- msg->crc = crc16_block_update(0xFFFF, msg,
- sizeof(*msg) - sizeof(msg->crc));
- msg->crc ^= 0xFFFF;
+ msg->crc = crc8_block_update(0xFF, msg,
+ sizeof(*msg) - sizeof(msg->crc));
+ msg->crc ^= 0xFF;
/* And transmit the bits. */
usart_tx_buf(msg, sizeof(*msg));
}
@@ -97,12 +97,12 @@ static void send_message(struct remote_message *msg)
static void handle_received_message(void)
{
struct remote_message reply;
- uint16_t calc_crc;
+ uint8_t calc_crc;
uint8_t err = MSG_ERR_NONE;
- calc_crc = crc16_block_update(0xFFFF, &rx_msg,
- sizeof(rx_msg) - sizeof(rx_msg.crc));
- calc_crc ^= 0xFFFF;
+ calc_crc = crc8_block_update(0xFF, &rx_msg,
+ sizeof(rx_msg) - sizeof(rx_msg.crc));
+ calc_crc ^= 0xFF;
if (calc_crc != rx_msg.crc) {
/* CRC mismatch. */
err = MSG_ERR_CHKSUM;
@@ -460,7 +460,7 @@ static void usart_init(void)
void remote_init(void)
{
/* The remote tool depends on the exact size (and layout). */
- BUILD_BUG_ON(sizeof(struct remote_message) != 7);
+ BUILD_BUG_ON(sizeof(struct remote_message) != 6);
usart_init();
}
diff --git a/pressure_control/firmware/remote.h b/pressure_control/firmware/remote.h
index 944dc43..36caf40 100644
--- a/pressure_control/firmware/remote.h
+++ b/pressure_control/firmware/remote.h
@@ -78,7 +78,7 @@ struct remote_message {
uint8_t __padding[4];
} __attribute__((packed));
- uint16_t crc;
+ uint8_t crc;
} __attribute__((packed));
diff --git a/pressure_control/firmware/util.c b/pressure_control/firmware/util.c
index 0b0bbab..7497740 100644
--- a/pressure_control/firmware/util.c
+++ b/pressure_control/firmware/util.c
@@ -87,15 +87,12 @@ void infinite_sleep(void)
sleep_mode();
}
-uint16_t crc16_block_update(uint16_t crc, const void *_data, uint16_t size)
+uint8_t crc8_block_update(uint8_t crc, const void *_data, uint8_t size)
{
const uint8_t *data = _data;
- while (size) {
- crc = _crc16_update(crc, *data);
- data++;
- size--;
- }
+ while (size--)
+ crc = _crc_ibutton_update(crc, *data++);
return crc;
}
diff --git a/pressure_control/firmware/util.h b/pressure_control/firmware/util.h
index 28e98f8..992df0e 100644
--- a/pressure_control/firmware/util.h
+++ b/pressure_control/firmware/util.h
@@ -81,7 +81,7 @@ static inline void irq_restore(uint8_t sreg_flags)
#define irqs_disabled() (!(SREG & (1 << SREG_I)))
-uint16_t crc16_block_update(uint16_t crc, const void *data, uint16_t size);
+uint8_t crc8_block_update(uint8_t crc, const void *data, uint8_t size);
/* Convenient casting macros. */
#define U8(value) ((uint8_t)(value))
bues.ch cgit interface