--- /dev/null
+/**\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
--- /dev/null
+/**\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