-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
112 lines (98 loc) · 2.53 KB
/
main.c
File metadata and controls
112 lines (98 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "program.h"
#include "setup.h"
#include "crc32.h"
#include "functions.h"
#include "project.h"
#define GetNodeValue 0x16
#define GetProgramChecksum 0x17
#define SetForcingEnabled 0x18
#define SetNodeForceEnable 0x19
#define SetNodeForceDisable 0x20
#define GetNodeForceStatus 0x21
#define GetNodeForceStatus 0x21
#define WriteDataToExternalFlash 0x22
#define ReadDataFromExternalFlash 0x23
#define EraseBlockFromExternalFlash 0x24
const char project_data[] = PROJECT_DATA;
static void tx_u8(uint8_t data)
{
//How do we send bytes
while(!uart_tx_byte(data))
{
;
}
}
void on_rx_uart_circle_buffer_data(uint8_t data)
{
//Feed hdlc when there is data in circle buffer
hdlc_on_rx_u8(data);
}
void hdlc_on_rx_frame(const u8_t * data, size_t nr_of_bytes)
{
DeviceDataFrame *request = (DeviceDataFrame*)data;
DeviceDataFrame reply;
u8_t forced = 0;
u32_t addr = 0;
uint8_t byte = 0;
reply.command = request->command;
reply.id = request->id;
reply.param = request->param;
reply.data = request->data;
switch(request->command){
case GetProgramChecksum:
reply.data = CHECKSUM;
break;
case GetNodeValue: //Get data value
if(request->param >= MAX_DATA)
break;
reply.data = _data[request->param];
break;
case SetForcingEnabled: //Set force enabled
force_enabled = request->param;
zero_data_forced();
break;
case SetNodeForceEnable:
set_data_forced(request->param, 1);
if(request->param < MAX_DATA && request->param >=0 )
_data[request->param] = request->data;
break;
case SetNodeForceDisable: //Unforce data id
set_data_forced(request->param, 0);
break;
case GetNodeForceStatus: //Get force data id
forced = is_data_forced(request->param);
reply.param = forced;
reply.data = _data[request->param];
break;
case WriteDataToExternalFlash:
//addr = (request->data >> 8);
//byte = (request->data & 0xFF);
//reply.data = (addr << 8) | byte;
//w25_write_byte(addr, byte);
break;
case ReadDataFromExternalFlash:
addr = request->data;
byte = project_data[addr]; //w25_read_byte(addr);
reply.data = (addr << 8) | byte;
break;
case EraseBlockFromExternalFlash:
w25_block_erase(request->data);
break;
}
hdlc_tx_frame((u8_t*)&reply, sizeof(DeviceDataFrame));
}
int main(void)
{
setup();
//DO1(0,0);
hdlc_init(&tx_u8, &hdlc_on_rx_frame);
while (1)
{
//hdlc_tx_frame(test_string, 5);
//tx_u8_array(test_string, 27);
//w25_write_byte(0x00, 0xAA);
//w25_read_byte(0x00);
loop();
read_from_uart_rx_circle_buffer();
}
}