4 static uint8_t (*ucconfig_fp_flashRead)(uint16_t address);
7 static void (*ucconfig_fp_flashWrite)(uint8_t byte,uint16_t address);
10 static void (*ucconfig_fp_serialWrite)(uint8_t byte);
13 static void (*ucconfig_fp_onExit)(void);
16 static void (*ucconfig_fp_onEnter)(void);
19 static void (*ucconfig_fp_onFirstWrite)(void);
22 static uint16_t ucconfig_written;
25 static uint16_t ucconfig_activeMode;
28 static uint16_t ucconfig_memPointer;
29 static uint16_t ucconfig_memPointerOffset;
32 static FIFO8 ucconfig_fifo;
35 static void ucconfig_checkKey(uint8_t byte);
39 static void ucconfig_active(
void);
42 static void ucconfig_call_if_first(
void);
45 static void ucconfig_parseCommand();
48 static void ucconfig_write_data();
50 static void ucconfig_read_data();
52 static void ucconfig_set_address();
54 static void ucconfig_get_address();
56 static void ucconfig_terminate();
58 static void ucconfig_sendNack();
60 static void ucconfig_sendAck();
62 static void ucconfig_sendNack();
65 static void ucconfig_send_u8(
void);
66 static void ucconfig_send_8(
void);
67 static void ucconfig_send_u16(
void);
68 static void ucconfig_send_16(
void);
69 static void ucconfig_send_u32(
void);
70 static void ucconfig_send_32(
void);
71 static void ucconfig_send_float(
void);
72 static void ucconfig_send_char(
void);
75 static void ucconfig_write_u8(
char *data);
76 static void ucconfig_write_8(
char *data);
77 static void ucconfig_write_u16(
char *data);
78 static void ucconfig_write_16(
char *data);
79 static void ucconfig_write_u32(
char *data);
80 static void ucconfig_write_32(
char *data);
81 static void ucconfig_write_float(
char *data);
82 static void ucconfig_write_char(
char *data);
86 while(ucconfig_activeMode){
88 for(
volatile uint16_t i = 0; i < 0xFFF;i++);
89 ucconfig_activeMode--;
99 ucconfig_fp_onEnter = on_enter;
103 ucconfig_fp_onExit = on_exit;
107 ucconfig_fp_onFirstWrite = on_first;
112 ucconfig_memPointer =
flash_get(data,address);
118 ucconfig_memPointer =
flash_get(data,address);
124 ucconfig_memPointer =
flash_get(data,address);
131 ucconfig_memPointer =
flash_get(data,address);
137 ucconfig_memPointer =
flash_get(data,address);
143 ucconfig_memPointer =
flash_get(data,address);
149 ucconfig_memPointer =
flash_get(data,address);
155 ucconfig_memPointer =
flash_get(data,address);
161 ucconfig_memPointerOffset = address;
165 void ucconfig_active(
void){
182 ucconfig_fp_serialWrite = current_fp;
183 ucconfig_fp_flashWrite = current_fw_fp;
184 ucconfig_fp_flashRead = current_fr_fp;
186 ucconfig_written = 0;
190 if(ucconfig_fp_onEnter != NULL){
192 ucconfig_fp_onEnter();
201 void ucconfig_write_data(){
212 dataLength =
FIFO8_pop(&ucconfig_fifo) - 64 ;
215 if((dataLength < 1) | (dataLength > 24)){
232 for(i = 0; i < dataLength; i++){
237 if((data[i] > 47) && (data[i] < 58)){
291 ucconfig_call_if_first();
292 ucconfig_write_u8(data);
295 ucconfig_call_if_first();
296 ucconfig_write_8(data);
299 ucconfig_call_if_first();
300 ucconfig_write_u16(data);
303 ucconfig_call_if_first();
304 ucconfig_write_16(data);
307 ucconfig_call_if_first();
308 ucconfig_write_u32(data);
311 ucconfig_call_if_first();
312 ucconfig_write_32(data);
315 ucconfig_call_if_first();
316 ucconfig_write_float(data);
319 ucconfig_call_if_first();
320 ucconfig_write_char(data);
334 static void ucconfig_call_if_first(
void){
336 if(ucconfig_written == 0){
337 ucconfig_fp_onFirstWrite();
347 static void ucconfig_write_u8(
char *data){
351 ucconfig_memPointer =
flash_put(toWrite,ucconfig_memPointer);
354 static void ucconfig_write_8(
char *data){
358 ucconfig_memPointer =
flash_put(toWrite,ucconfig_memPointer);
361 static void ucconfig_write_u16(
char *data){
365 ucconfig_memPointer =
flash_put(toWrite,ucconfig_memPointer);
368 static void ucconfig_write_16(
char *data){
372 ucconfig_memPointer =
flash_put(toWrite,ucconfig_memPointer);
375 static void ucconfig_write_u32(
char *data){
379 ucconfig_memPointer =
flash_put(toWrite,ucconfig_memPointer);
382 static void ucconfig_write_32(
char *data){
386 ucconfig_memPointer =
flash_put(toWrite,ucconfig_memPointer);
389 static void ucconfig_write_float(
char *data){
393 ucconfig_memPointer =
flash_put(toWrite,ucconfig_memPointer);
396 static void ucconfig_write_char(
char *data){
398 ucconfig_memPointer =
flash_put((
char)data[0],ucconfig_memPointer);
404 void ucconfig_read_data(){
406 uint8_t dataType =
FIFO8_pop(&ucconfig_fifo);
453 ucconfig_send_float();
456 ucconfig_send_char();
468 void ucconfig_send_u8(
void){
472 ucconfig_memPointer =
flash_get(&data,ucconfig_memPointer);
479 print((
char)UCCONFIG_NOT_USED);
481 print((
char)UCCONFIG_NULL);
487 void ucconfig_send_8(
void){
491 ucconfig_memPointer =
flash_get(&data,ucconfig_memPointer);
498 print((
char)UCCONFIG_NOT_USED);
500 print((
char)UCCONFIG_NULL);
506 void ucconfig_send_u16(
void){
510 ucconfig_memPointer =
flash_get(&data,ucconfig_memPointer);
517 print((
char)UCCONFIG_NOT_USED);
519 print((
char)UCCONFIG_NULL);
525 void ucconfig_send_16(
void){
529 ucconfig_memPointer =
flash_get(&data,ucconfig_memPointer);
536 print((
char)UCCONFIG_NOT_USED);
538 print((
char)UCCONFIG_NULL);
544 void ucconfig_send_u32(
void){
548 ucconfig_memPointer =
flash_get(&data,ucconfig_memPointer);
555 print((
char)UCCONFIG_NOT_USED);
557 print((
char)UCCONFIG_NULL);
563 void ucconfig_send_32(
void){
567 ucconfig_memPointer =
flash_get(&data,ucconfig_memPointer);
574 print((
char)UCCONFIG_NOT_USED);
576 print((
char)UCCONFIG_NULL);
582 void ucconfig_send_float(
void){
586 ucconfig_memPointer =
flash_get(&data,ucconfig_memPointer);
593 print((
char)UCCONFIG_NOT_USED);
595 print((
char)UCCONFIG_NULL);
601 void ucconfig_send_char(
void){
605 ucconfig_memPointer =
flash_get(&data,ucconfig_memPointer);
612 print((
char)UCCONFIG_NOT_USED);
614 print((
char)UCCONFIG_NULL);
622 void ucconfig_set_address(){
624 uint8_t addressLength;
635 addressLength =
FIFO8_pop(&ucconfig_fifo) - 64 ;
638 if((addressLength < 1) | (addressLength > 5)){
657 for(i = 0; i < addressLength; i++){
661 if((address[i] < 48) | (address[i] > 57)){
669 if(i != addressLength){
685 ucconfig_memPointer = (uint16_t)
str2int(address) + ucconfig_memPointerOffset;
693 void ucconfig_get_address(){
731 print((
char)UCCONFIG_NOT_USED);
732 print(ucconfig_memPointer);
733 print((
char)UCCONFIG_NULL);
739 void ucconfig_terminate(){
789 ucconfig_fp_serialWrite = current_fp;
790 ucconfig_fp_flashWrite = current_fw_fp;
791 ucconfig_fp_flashRead = current_fr_fp;
793 if(ucconfig_fp_onExit != NULL){
795 ucconfig_fp_onExit();
799 ucconfig_activeMode = 0;
803 void ucconfig_sendNack(){
812 void ucconfig_sendAck(){
822 void ucconfig_parseCommand(){
838 ucconfig_set_address();
853 ucconfig_write_data();
868 ucconfig_read_data();
883 ucconfig_get_address();
897 ucconfig_terminate();
909 void UCCONFIG_setup(uint8_t (*flash_read)(uint16_t address),
void (*flash_write)(uint8_t byte, uint16_t address),
void (*serial_write)(uint8_t byte)){
912 ucconfig_fp_flashRead = flash_read;
913 ucconfig_fp_flashWrite = flash_write;
916 ucconfig_fp_serialWrite = serial_write;
925 ucconfig_activeMode = 0;
931 void ucconfig_checkKey(uint8_t received){
1010 if(ucconfig_activeMode){
1019 ucconfig_parseCommand();
void ucconfig_get_u32(uint32_t *data, uint16_t address)
Get a uint32 from the given memory address.
float str2float(char *buffer)
Convert a null terminated string to a float.
void UCCONFIG_setAddressOffset(uint16_t address)
Set the memory address offset of the flash memory pointer (optional)
#define UCCONFIG_KEY_3
Key character 3.
#define UCCONFIG_KEY_4
Key character 4.
#define UCCONFIG_TYPE_CHAR
ASCII character used for char types.
void UCCONFIG_loop(void)
Runs config mode if the key has been received.
void ucconfig_get_u16(uint16_t *data, uint16_t address)
Get a uint16 from the given memory address.
void UCCONFIG_setOnExit(void(*on_exit)(void))
Sets the function which is called when config mode is exited (optional)
void ucconfig_get_u8(uint8_t *data, uint16_t address)
Get a uint8 from the given memory address.
void FLASHWRITE_setInput(uint8_t(*in_fun)(uint16_t))
Set the target input stream for flash_get functions.
void ucconfig_get_16(int16_t *data, uint16_t address)
Get a int16 from the given memory address.
void UCCONFIG_setOnEnter(void(*on_enter)(void))
Sets the function which is called when config mode is entered (optional)
#define UCCONFIG_NACK
Command used to not acknowledge a command.
#define print(X)
Print a given datatype to the output stream.
void STRING11_setOutput(void(*out_fun)(uint8_t))
Set the target output stream for print functions.
v_fp_u8_u16 FLASHWRITE_getOutput(void)
Get the current target output stream.
v_fp_u8 STRING11_getOutput(void)
Get the current target output stream.
#define UCCONFIG_TERMINATE
Command used to exit from commmand mode.
#define UCCONFIG_ACTIVE_MODE_TIMEOUT
Number of loop iterratios before automattically exits from active mode.
#define UCCONFIG_KEY_LENGTH
The length of the key which the PC needs to send to enter Config mode.
void UCCONFIG_setOnFirstWrite(void(*on_first)(void))
Sets the function which is called when the first byte is written to the UC from PC.
#define UCCONFIG_TYPE_INT16_T
ASCII character used for int16_t types.
#define UCCONFIG_TYPE_FLOAT
ASCII character used for float types.
#define UCCONFIG_TYPE_UINT8_T
ASCII character used for uint8_t types.
#define UCCONFIG_SET_MEMORY_ADDRESS
Command used to initiate setting the memory address pointer.
uint16_t FIFO8_size(FIFO8 *target)
Return the size in bytes of the FIFO8 buffer.
#define flash_put(DATA, ADDRESS)
Flash a given datatype to the output stream.
void FLASHWRITE_setOutput(void(*out_fun)(uint8_t, uint16_t))
Set the target output stream for flash_put functions.
#define UCCONFIG_LENGTH_ZERO
ASCII character used for zero length data frames.
fifo8_error_t FIFO8_put(FIFO8 *target, uint8_t byte)
Adds a character to the buffer.
int32_t str2int(char *buffer)
Convert a null terminated string to an integer.
#define UCCONFIG_READ_FRAME
Command used to initial reading data.
#define UCCONFIG_SET_WRITE_FRAME
Command used to initial writing data.
uint8_t FIFO8_pop(FIFO8 *target)
Reset the fifo buffer and set its size to 0.
fifo8_error_t FIFO8_init(FIFO8 *target, fifo8_mode_t mode, uint8_t *buffer, uint16_t size, void(*output)(uint8_t byte))
Initializes the FIFO8 buffer.
u8_fp_u16 FLASHWRITE_getInput(void)
Get the current target input stream.
fifo8_error_t FIFO8_flush(FIFO8 *target)
Flush all contents of the FIFO8 to the output function.
void ucconfig_get_8(int8_t *data, uint16_t address)
Get a int8 from the given memory address.
#define UCCONFIG_TYPE_UINT16_T
ASCII character used for uint16_t types.
#define UCCONFIG_TYPE_NONE
ASCII character used for none types.
void ucconfig_get_c(char *data, uint16_t address)
Get a character from the given memory address.
#define flash_get(DATA, ADDRESS)
Read a given datatype from the input stream.
void ucconfig_get_32(int32_t *data, uint16_t address)
Get a int32 from the given memory address.
Header file for UCConfig module.
#define UCCONFIG_TYPE_UINT32_T
ASCII character used for uint32_t types.
#define UCCONFIG_NULL
ASCII character used for NULL.
#define UCCONFIG_KEY_2
Key character 2.
#define UCCONFIG_KEY_1
Key character 1.
#define UCCONFIG_FIFO_SIZE
The size of the FIFO used by the module, don't change this.
void ucconfig_get_float(float *data, uint16_t address)
Get a float from the given memory address.
#define UCCONFIG_NEWLINE
ASCII character used for new line, UC needs to send this so python module can easly pick end of comma...
#define UCCONFIG_FRAME_END
The frame and character.
uint32_t str2uint(char *buffer)
Convert a null terminated string to an unsigned integer.
#define UCCONFIG_TYPE_INT32_T
ASCII character used for int32_t types.
Fifo content flushed to output function on call FIFO_flush()
#define UCCONFIG_TYPE_INT8_T
ASCII character used for int8_t types.
Data structure for FIFO8 perihperal interface.
void UCCONFIG_listen(uint8_t received)
Listens to serial communication and sets module in config mode if correct key is sent.
#define UCCONFIG_AT_ADDRESS
Command used get the current memory addresss pointer.
#define UCCONFIG_NOT_USED
ASCII character used for Not used.
#define UCCONFIG_ACK
Command used to acknowledge a command.
void UCCONFIG_setup(uint8_t(*flash_read)(uint16_t address), void(*flash_write)(uint8_t byte, uint16_t adrress), void(*serial_write)(uint8_t byte))
Set up the module, this should be called before any other module function will work.