summaryrefslogtreecommitdiffstats
path: root/pressure_control/firmware/main.c
diff options
context:
space:
mode:
authorMichael Buesch <mb@bu3sch.de>2008-10-12 16:46:48 +0200
committerMichael Buesch <mb@bu3sch.de>2008-10-12 16:46:48 +0200
commit4a914e8c559cd48173bed088e2122d1d35c8de9b (patch)
treebd31fdcbe3fb8c645663760ef84ad24875b15dc9 /pressure_control/firmware/main.c
parent660677d70eeacb01304a547df5dacac1bda8d036 (diff)
downloadcnc-4a914e8c559cd48173bed088e2122d1d35c8de9b.tar.xz
cnc-4a914e8c559cd48173bed088e2122d1d35c8de9b.zip
Add code to the pressure control.
Signed-off-by: Michael Buesch <mb@bu3sch.de>
Diffstat (limited to 'pressure_control/firmware/main.c')
-rw-r--r--pressure_control/firmware/main.c73
1 files changed, 72 insertions, 1 deletions
diff --git a/pressure_control/firmware/main.c b/pressure_control/firmware/main.c
index 949e5cb..02272ef 100644
--- a/pressure_control/firmware/main.c
+++ b/pressure_control/firmware/main.c
@@ -18,15 +18,86 @@
*/
#include "util.h"
+#include "calibration.h"
+#include "sensor.h"
+#include "valves.h"
+static inline void usart_tx(uint8_t data)
+{
+ while (!(UCSRA & (1 << UDRE)))
+ ;
+ UDR = data;
+}
+
+static void __print(const prog_char *msg)
+{
+ uint8_t c;
+
+ for ( ; ; msg++) {
+ c = pgm_read_byte(msg);
+ if (c == '\0')
+ break;
+ usart_tx(c);
+ }
+}
+#define print(msg) __print(PSTR(msg))
+
+#define ERXFE 1 /* USART RX frame error */
+#define ERXPE 2 /* USART RX parity error */
+#define ERXOV 3 /* USART RX hardware buffer overflow */
+#define ENODATA 4 /* No data available */
+
+static inline int8_t usart_rx(uint8_t *data)
+{
+ uint8_t status;
+
+ status = UCSRA;
+ if (!(status & (1 << RXC)))
+ return -ENODATA;
+ if (unlikely(status & ((1 << FE) | (1 << PE) | (1 << DOR)))) {
+ if (status & (1 << FE))
+ return -ERXFE;
+ if (status & (1 << PE))
+ return -ERXPE;
+ if (status & (1 << DOR))
+ return -ERXOV;
+ }
+ *data = UDR;
+
+ return 0;
+}
+
+#define BAUDRATE 9600
+
+static void usart_init(void)
+{
+ uint8_t dummy;
+
+ /* Set baud rate */
+ UBRRL = lo8((CPU_HZ / 16 / BAUDRATE) * 2);
+ UBRRH = hi8((CPU_HZ / 16 / BAUDRATE) * 2) & ~(1 << URSEL);
+ UCSRA = (1 << U2X);
+ /* 8 Data bits, 2 Stop bits, Even parity */
+ UCSRC = (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1) | (1 << UPM1) | (1 << USBS);
+ /* Enable transceiver and RX IRQs */
+ UCSRB = (1 << RXEN) | (1 << TXEN);// | (1 << RXCIE);
+ /* Drain the RX buffer */
+ while (usart_rx(&dummy) != -ENODATA)
+ mb();
+}
+
int main(void)
{
cli();
- //TODO
+
+ valves_init();
+ usart_init();
+
sei();
while (1) {
+ print("Hallo!\n");
//TODO
}
}
bues.ch cgit interface