summaryrefslogtreecommitdiffstats
path: root/pressure_control/firmware
diff options
context:
space:
mode:
authorMichael Buesch <mb@bu3sch.de>2009-04-04 22:08:58 +0200
committerMichael Buesch <mb@bu3sch.de>2009-04-04 22:08:58 +0200
commitde20d70112c89d0a144b5605e3bed1def78a6b87 (patch)
tree733cbf54fe15d5954fb69adc3ef5dfe10791e0a3 /pressure_control/firmware
parent734219d3cd138524b2fd0a17460409c4826eee19 (diff)
downloadcnc-de20d70112c89d0a144b5605e3bed1def78a6b87.tar.xz
cnc-de20d70112c89d0a144b5605e3bed1def78a6b87.zip
pressure_control: Add more debugging code
Signed-off-by: Michael Buesch <mb@bu3sch.de>
Diffstat (limited to 'pressure_control/firmware')
-rw-r--r--pressure_control/firmware/remote.c57
-rw-r--r--pressure_control/firmware/remote.h4
-rw-r--r--pressure_control/firmware/sensor.c3
-rw-r--r--pressure_control/firmware/util.c34
-rw-r--r--pressure_control/firmware/util.h8
5 files changed, 106 insertions, 0 deletions
diff --git a/pressure_control/firmware/remote.c b/pressure_control/firmware/remote.c
index be360e5..87a9b17 100644
--- a/pressure_control/firmware/remote.c
+++ b/pressure_control/firmware/remote.c
@@ -270,6 +270,27 @@ static void usart_rx_timeout_check()
mb();
}
+void print_sram(const char *str)
+{
+ struct remote_message msg;
+ uint8_t c, i;
+
+ do {
+ memset(&msg, 0, sizeof(msg));
+ msg.id = MSG_LOGMESSAGE;
+
+ for (i = 0; i < sizeof(msg.logmessage.str); i++) {
+ c = *str;
+ if (c == '\0')
+ break;
+ str++;
+ msg.logmessage.str[i] = c;
+ }
+
+ send_message(&msg);
+ } while (c != '\0');
+}
+
void print_pgm(const prog_char *str)
{
struct remote_message msg;
@@ -291,6 +312,42 @@ void print_pgm(const prog_char *str)
} while (c != '\0');
}
+static void __print_dec(char prefix, uint16_t number)
+{
+ uint8_t num[NUM16_NR_DIGITS + sizeof(prefix) + 1];
+
+ num[0] = prefix;
+ num16_to_ascii(num + 1, number);
+ if (prefix)
+ print_sram((char *)num);
+ else
+ print_sram((char *)(num + 1));
+}
+
+void print_dec(uint16_t number)
+{
+ __print_dec(0, number);
+}
+
+void print_dec_signed(int16_t number)
+{
+ if (number < 0)
+ __print_dec('-', -number);
+ else
+ __print_dec(0, number);
+}
+
+void print_hex(uint8_t number)
+{
+ char hex[3];
+
+ hex[0] = hexdigit_to_ascii(number >> 4);
+ hex[1] = hexdigit_to_ascii(number & 0xF);
+ hex[2] = '\0';
+
+ print_sram(hex);
+}
+
/* Maintanance work. Called with IRQs enabled. */
void remote_work(void)
{
diff --git a/pressure_control/firmware/remote.h b/pressure_control/firmware/remote.h
index 9aabfe9..7c8d77c 100644
--- a/pressure_control/firmware/remote.h
+++ b/pressure_control/firmware/remote.h
@@ -71,8 +71,12 @@ struct remote_message {
} __attribute__((packed));
+void print_sram(const char *msg);
void print_pgm(const prog_char *msg);
#define print(string_literal) print_pgm(PSTR(string_literal))
+void print_dec(uint16_t number);
+void print_dec_signed(int16_t number);
+void print_hex(uint8_t number);
void remote_pressure_change_notification(uint16_t mbar,
uint16_t hysteresis);
diff --git a/pressure_control/firmware/sensor.c b/pressure_control/firmware/sensor.c
index 2ed36f3..5633041 100644
--- a/pressure_control/firmware/sensor.c
+++ b/pressure_control/firmware/sensor.c
@@ -20,6 +20,7 @@
#include "sensor.h"
#include "util.h"
+#include "remote.h"
#include <avr/io.h>
#include <avr/interrupt.h>
@@ -47,6 +48,8 @@ ISR(ADC_vect)
val = ADC;
sensor_disable();
+print_dec(val);
+print("\n");
//TODO process value
sensor_result(val);
}
diff --git a/pressure_control/firmware/util.c b/pressure_control/firmware/util.c
index 0056cbd..0f3b8b7 100644
--- a/pressure_control/firmware/util.c
+++ b/pressure_control/firmware/util.c
@@ -93,3 +93,37 @@ uint16_t crc16_block_update(uint16_t crc, const void *_data, uint16_t size)
return crc;
}
+
+uint8_t hexdigit_to_ascii(uint8_t digit)
+{
+ /* Convert a hexadecimal digit (0-F) to an ASCII character */
+ if (digit >= 0xA)
+ digit += 0x41 - 0xA;
+ else
+ digit += 0x30;
+ return digit;
+}
+
+void num16_to_ascii(uint8_t *buf, uint16_t v)
+{
+ uint16_t orig = v;
+
+ if (orig >= 10000) {
+ *buf++ = v / 10000 + '0';
+ v %= 10000;
+ }
+ if (orig >= 1000) {
+ *buf++ = v / 1000 + '0';
+ v %= 1000;
+ }
+ if (orig >= 100) {
+ *buf++ = v / 100 + '0';
+ v %= 100;
+ }
+ if (orig >= 10) {
+ *buf++ = v / 10 + '0';
+ v %= 10;
+ }
+ *buf++ = v + '0';
+ *buf = '\0';
+}
diff --git a/pressure_control/firmware/util.h b/pressure_control/firmware/util.h
index 0c37990..9900d57 100644
--- a/pressure_control/firmware/util.h
+++ b/pressure_control/firmware/util.h
@@ -54,6 +54,14 @@ void udelay(uint16_t usecs);
typedef _Bool bool;
+/* Convert a number (0-F) to a hexadecimal ASCII digit */
+uint8_t hexdigit_to_ascii(uint8_t digit);
+
+#define NUM16_NR_DIGITS 5
+/* Convert a number to ascii.
+ * buf must be at least (NUM16_NR_DIGITS + 1) long */
+void num16_to_ascii(uint8_t *buf, uint16_t v);
+
/* IRQ handling.
* We use a macro for irq_disable_save(), because stupid gcc is not
* able to properly optimize an inline function that returns a value.
bues.ch cgit interface