summaryrefslogtreecommitdiffstats
path: root/radiator-plc/stm32/app/main.c
diff options
context:
space:
mode:
authorfishsoupisgood <github@madingley.org>2020-09-09 11:53:37 +0100
committerfishsoupisgood <github@madingley.org>2020-09-09 11:53:37 +0100
commit9d87c925a9eaa4fc256be3173c14a20d1469472d (patch)
tree50d63f87a47a0eac3f5b8058850184bcd4e6ee95 /radiator-plc/stm32/app/main.c
parentdafd8cf2fdcdd637cc06f760d318cf8391b1a294 (diff)
downloadheating-9d87c925a9eaa4fc256be3173c14a20d1469472d.tar.gz
heating-9d87c925a9eaa4fc256be3173c14a20d1469472d.tar.bz2
heating-9d87c925a9eaa4fc256be3173c14a20d1469472d.zip
everything, mostly, working
Diffstat (limited to 'radiator-plc/stm32/app/main.c')
-rw-r--r--radiator-plc/stm32/app/main.c150
1 files changed, 150 insertions, 0 deletions
diff --git a/radiator-plc/stm32/app/main.c b/radiator-plc/stm32/app/main.c
new file mode 100644
index 0000000..57b6752
--- /dev/null
+++ b/radiator-plc/stm32/app/main.c
@@ -0,0 +1,150 @@
+#include "project.h"
+
+
+volatile int request_search;
+
+static void mqtt_cmd (char *type)
+{
+ char *m;
+ char *who, *what;
+
+ m = rindex (type, ' ');
+
+ if (!m) return;
+
+ *m = 0;
+ m++;
+
+ while (index (type, ' ') == type)
+ type++;
+
+ who = index (type, ' ');
+ if (who) *who = 0;
+
+
+ who = index (type, '/');
+
+ if (!who) {
+ who = "";
+ what = "";
+ } else {
+ *who = 0;
+ who++;
+
+ what = index (who, '/');
+
+ if (!what)
+ what = "";
+
+ else {
+ *what = 0;
+ what++;
+ }
+ }
+
+
+ mqtt_dispatch (type, who, what, m);
+}
+
+static void cmd_dispatch (char *cmd)
+{
+
+ if (!strcmp (cmd, "SEARCH")) {
+ request_search = 1;
+ return;
+ }
+
+ if (!strncmp (cmd, "MQTT ", 5)) {
+ mqtt_cmd (cmd + 5);
+ return;
+ }
+
+
+ printf ("Unknown command %s\n", cmd);
+}
+
+
+
+
+static void
+kbd_dispatch (void)
+{
+ static char cmd_buf[80];
+ static unsigned cmd_ptr;
+
+ uint8_t c;
+
+ while (!ring_read_byte (&rx1_ring, &c)) {
+
+ switch (c) {
+ case ' ':
+ case '\t':
+ if (!cmd_ptr)
+ break;
+
+ /*fall through */
+ default:
+ cmd_buf[cmd_ptr++] = c;
+ cmd_buf[cmd_ptr] = 0;
+
+
+ if (cmd_ptr < (sizeof (cmd_buf) - 1))
+ break;
+
+ /*fall through*/
+ case '\r':
+ case '\n':
+ if (!cmd_ptr)
+ break;
+
+ cmd_dispatch (cmd_buf);
+ cmd_ptr = 0;
+ break;
+ }
+ }
+}
+
+
+int
+main (void)
+{
+ /*set up pll */
+ rcc_clock_setup_in_hse_8mhz_out_72mhz();
+
+ /*turn on clocks which aren't done elsewhere */
+ rcc_periph_clock_enable (RCC_GPIOA);
+ rcc_periph_clock_enable (RCC_GPIOB);
+ rcc_periph_clock_enable (RCC_GPIOC);
+ rcc_periph_clock_enable (RCC_GPIOD);
+ rcc_periph_clock_enable (RCC_GPIOE);
+ rcc_periph_clock_enable (RCC_AFIO);
+
+ //watchdog_init ();
+
+ /*Adjust interrupt priorities so that uarts trump timer */
+ nvic_set_priority (NVIC_USART1_IRQ, 0x40);
+ nvic_set_priority (NVIC_USART2_IRQ, 0x40);
+ nvic_set_priority (NVIC_USART3_IRQ, 0x40);
+ nvic_set_priority (NVIC_SYSTICK_IRQ, 0xff);
+
+ ticker_init();
+ usart_init();
+ led_init();
+ onewire_init();
+ inputs_init();
+ outputs_init();
+
+ printf ("D: RESET\n");
+
+ //onewire_search();
+
+ for (;;) {
+ if (!ring_empty (&rx1_ring))
+ kbd_dispatch();
+
+ logic_dispatch();
+
+ }
+
+ return 0;
+}