From: Michael Wiebusch Date: Fri, 20 Dec 2013 17:38:29 +0000 (+0100) Subject: ReadBackAll toggles back X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=7657d53f652b261b97deef4ce4ae44e9b2bcc90a;p=mvd_firmware.git ReadBackAll toggles back --- diff --git a/firmware/src/CB_functions.c b/firmware/src/CB_functions.c index 3f5cfd0..55958bd 100644 --- a/firmware/src/CB_functions.c +++ b/firmware/src/CB_functions.c @@ -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 index 0000000..71c5d6b --- /dev/null +++ b/firmware/src/misc_utils.c @@ -0,0 +1,57 @@ +/** + ******************************************************** + * + * Misc Utils + * + ******************************************************** + */ + + +#include "misc_utils.h" +#include "stm32f10x_conf.h" + + +uint16_t counter; + + + +void delay_ms(uint16_t time_ms) { + counter = time_ms; + SysTick_Config(72000); // 1000 hz + while(counter != 0); + +} + + +void SysTick_Handler(void) +{ + counter--; +} + + + + +// implementation of a ring buffer +struct Buffer { + uint8_t data[BUFFER_SIZE]; + uint8_t read; + uint8_t write; +} buffer = { { }, 0, 0 }; + +uint8_t BufferIn(uint8_t byte) { + uint8_t next = ((buffer.write + 1) & BUFFER_MASK); + if (buffer.read == next) + return FAIL; + buffer.data[buffer.write] = byte; + // buffer.data[buffer.write & BUFFER_MASK] = byte; // more secure + buffer.write = next; + return SUCCESS; +} + +uint8_t BufferOut(uint8_t *pByte) { + if (buffer.read == buffer.write) + return FAIL; + *pByte = buffer.data[buffer.read]; + buffer.read = (buffer.read + 1) & BUFFER_MASK; + return SUCCESS; +} \ No newline at end of file diff --git a/firmware/src/misc_utils.h b/firmware/src/misc_utils.h new file mode 100644 index 0000000..c3ffeab --- /dev/null +++ b/firmware/src/misc_utils.h @@ -0,0 +1,31 @@ +/** + ******************************************************** + * + * Misc Utils (headers) + * + ******************************************************** + */ + + +/* Includes ------------------------------------------------------------------*/ +#include "stm32f10x.h" + +// ############################# buffer stuff ############################## +// basic buffer read and write functions + +#define SUCCESS 1 +#define FAIL 0 + +#define BUFFER_SIZE 32 // size has to be 2^n (8, 16, 32, 64 ...) +#define BUFFER_MASK (BUFFER_SIZE-1) + + + + + +void SysTick_Handler(void); +//void delay_us(uint32_t time_us); +void delay_ms(uint16_t time_ms); + +uint8_t BufferIn(uint8_t byte); +uint8_t BufferOut(uint8_t *pByte); \ No newline at end of file