]> jspc29.x-matter.uni-frankfurt.de Git - mvd_firmware.git/commitdiff
ReadBackAll toggles back
authorMichael Wiebusch <stratomaster@gmx.net>
Fri, 20 Dec 2013 17:38:29 +0000 (18:38 +0100)
committerMichael Wiebusch <stratomaster@gmx.net>
Fri, 20 Dec 2013 17:38:29 +0000 (18:38 +0100)
firmware/src/CB_functions.c
firmware/src/misc_utils.c [new file with mode: 0644]
firmware/src/misc_utils.h [new file with mode: 0644]

index 3f5cfd0c5070ead1fe2d425622a4ac34ad23a458..55958bd5be3b82eda5317cdefe57d1c080d9dc79 100644 (file)
@@ -46,6 +46,7 @@ void decode_register(uint8_t addr) {
   switch (addr){
     case 0x0:
       if (thisRegister & 0xFF00) {
+        uC_regs[0] &= 0x00FF;
         report_all_registers();
       } else {
         report_register( (uint8_t) (thisRegister & 0x00FF) );
diff --git a/firmware/src/misc_utils.c b/firmware/src/misc_utils.c
new file mode 100644 (file)
index 0000000..71c5d6b
--- /dev/null
@@ -0,0 +1,57 @@
+/**\r
+ ********************************************************\r
+ * \r
+ *  Misc Utils\r
+ * \r
+ ********************************************************\r
+ */\r
+\r
+\r
+#include "misc_utils.h"\r
+#include "stm32f10x_conf.h"\r
+\r
+\r
+uint16_t counter;\r
+\r
+\r
+\r
+void delay_ms(uint16_t time_ms) {\r
+  counter = time_ms;\r
+  SysTick_Config(72000); // 1000 hz\r
+  while(counter != 0);\r
+  \r
+}\r
+\r
+\r
+void SysTick_Handler(void)\r
+{\r
+  counter--;\r
+}\r
+\r
+\r
+\r
+\r
+// implementation of a ring buffer\r
+struct Buffer {\r
+  uint8_t data[BUFFER_SIZE];\r
+  uint8_t read;\r
+  uint8_t write;\r
+} buffer = { { }, 0, 0 };\r
+\r
+uint8_t BufferIn(uint8_t byte) {\r
+  uint8_t next = ((buffer.write + 1) & BUFFER_MASK);\r
+  if (buffer.read == next)\r
+    return FAIL;\r
+  buffer.data[buffer.write] = byte;\r
+  // buffer.data[buffer.write & BUFFER_MASK] = byte; // more secure\r
+  buffer.write = next;\r
+  return SUCCESS;\r
+}\r
+\r
+uint8_t BufferOut(uint8_t *pByte) {\r
+  if (buffer.read == buffer.write)\r
+    return FAIL;\r
+  *pByte = buffer.data[buffer.read];\r
+  buffer.read = (buffer.read + 1) & BUFFER_MASK;\r
+  return SUCCESS;\r
+}
\ No newline at end of file
diff --git a/firmware/src/misc_utils.h b/firmware/src/misc_utils.h
new file mode 100644 (file)
index 0000000..c3ffeab
--- /dev/null
@@ -0,0 +1,31 @@
+/**\r
+ ********************************************************\r
+ * \r
+ *  Misc Utils (headers)\r
+ * \r
+ ********************************************************\r
+ */\r
+  \r
+\r
+/* Includes ------------------------------------------------------------------*/\r
+#include "stm32f10x.h"\r
+\r
+// ############################# buffer stuff ##############################\r
+// basic buffer read and write functions\r
+\r
+#define SUCCESS 1\r
+#define FAIL 0\r
+\r
+#define BUFFER_SIZE 32 // size has to be 2^n (8, 16, 32, 64 ...)\r
+#define BUFFER_MASK (BUFFER_SIZE-1)\r
+\r
+\r
+\r
+\r
+\r
+void SysTick_Handler(void);\r
+//void delay_us(uint32_t time_us);\r
+void delay_ms(uint16_t time_ms);\r
+\r
+uint8_t BufferIn(uint8_t byte);\r
+uint8_t BufferOut(uint8_t *pByte);
\ No newline at end of file