-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
137 lines (129 loc) · 3.82 KB
/
main.c
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/// @file main.c
/*
* Filename: main.c
* Description: This file is the entry point for program execution.
* Author: M. Malyska
*/
#include "stm32f1xx.h"
#include "spi.h"
#include "rcc.h"
#include "gpio.h"
#include "timer.h"
#include "protocol.h"
void command_handler(uint16_t rx_data);
void fill_data(void);
/**
* After the startup code finishes it will call this function, here is the entry point for user code exeution.
*/
void main(void)
{
sys_init();
rcc_init();
gpio_init();
spi1_init();
timer_init();
protocol_init();
fill_data();
comm_hal_frequency_set(0x5e);
comm_hal_datarate_set(4800U);
comm_hal_hdrmode(0x00);
while(1){
if(comm_int_handler_pending){
comm_int_handler();
comm_int_handler_pending = 0x00;
}
#ifdef COMM_RX_ENABLED
if(comm_rx_pending){
command_handler(protocol_command_get());
comm_rx_pending = 0x00;
}
#endif
if(send_flag){
protocol_frame_send();
send_flag = 0;
}
}
}
void EXTI0_IRQHandler(void){
comm_int_handler_pending = 0xff;
EXTI->PR |= EXTI_PR_PR0;
}
#ifdef COMM_RX_ENABLED
enum command_table{nop = 0x00, led_toggle = 0x03, error = 0xff};
void command_handler(uint16_t rx_data){
uint8_t value = rx_data; //drop high byte
switch((rx_data >> 8)){
case nop:{
asm("nop"); //Erst mal 'ne Runde nichts machen! (For testing purpose)
}
case led_toggle:{
if(GPIO_LED->ODR & GPIO_ODR_ODR13_Msk){
GPIO_LED->BSRR |= GPIO_BSRR_BR_LEDRED_Msk;
}
else{
GPIO_LED->BSRR |= GPIO_BSRR_BS_LEDRED_Msk;
}
break;
}
case error:{
asm("nop");//error
}
default:{
break;
}
}
}
#endif
void fill_data(void){
uint8_t status_data[40] = {
0x03, 0x1e, 0x50, 0x32, 0x37, 0x34, 0x30, 0x33,
0x38, 0x37, 0x1a, 0x00, 0x00, 0x03, 0x00, 0x00,
0x15, 0x00, 0x00, 0x5d, 0x00, 0x07, 0x32, 0x20,
0xc9, 0x66, 0xb5, 0x41, 0x00, 0x00, 0x40, 0x40,
0xff, 0xff, 0xff, 0xc6, 0xff, 0xff, 0xff, 0xc6
};
protocol_field_write(&protocol_f_status, status_data);
uint8_t meas_data[42] = {
0xcf, 0x52, 0x02, 0x2a, 0x00, 0x02, 0x9c, 0xe7,
0x02, 0x27, 0x8d, 0x08, 0xaf, 0x87, 0x07, 0x47,
0x91, 0x08, 0xcb, 0x2b, 0x02, 0x2b, 0x00, 0x02,
0x9d, 0xe7, 0x02, 0x09, 0x67, 0x05, 0xee, 0xa6,
0x04, 0xfe, 0xae, 0x06, 0x00, 0x00, 0xfb, 0xfb,
0x00, 0x00
};
protocol_field_write(&protocol_f_meas, meas_data);
uint8_t gpsinfo_data[30] = {
0xe6, 0x07, 0x18, 0xfb, 0x25, 0x12, 0x01, 0xfb,
0x11, 0xf9, 0x13, 0xf3, 0x0b, 0xfa, 0x09, 0x92,
0x16, 0xf7, 0x12, 0xf7, 0x03, 0xfa, 0x17, 0xfa,
0x1f, 0xf4, 0x0e, 0xf4, 0x0c, 0x91
};
protocol_field_write(&protocol_f_gpsinfo, gpsinfo_data);
uint8_t gpsraw_data[89] = {
0x25, 0xfc, 0x35, 0x01, 0xff, 0x3d, 0xfd, 0xd3,
0x02, 0x42, 0xbf, 0x00, 0xc6, 0x8f, 0x52, 0x0b,
0x81, 0xfe, 0xff, 0x80, 0xb5, 0xe9, 0x10, 0xd8,
0x82, 0xff, 0x37, 0xc1, 0x54, 0x0a, 0x2c, 0x31,
0x01, 0xac, 0xe5, 0x46, 0x1a, 0x51, 0x15, 0xff,
0xda, 0x73, 0x7e, 0x02, 0xd3, 0x6f, 0x00, 0x15,
0x66, 0x6e, 0x0c, 0x53, 0x39, 0x01, 0x21, 0x00,
0x00, 0x00, 0x77, 0x03, 0x00, 0x8a, 0x56, 0x41,
0x0f, 0x5e, 0x55, 0xff, 0x93, 0x7c, 0x1c, 0x12,
0x8b, 0xde, 0xff, 0x30, 0xbd, 0x00, 0x11, 0xb8,
0xfc, 0x00, 0xac, 0xa8, 0xbe, 0x1d, 0xb4, 0xe3,
0xff
};
protocol_field_write(&protocol_f_gpsraw, gpsraw_data);
uint8_t gpspos_data[21] = {
0x08, 0xea, 0xb4, 0x17, 0x96, 0xb0, 0xf1, 0x03,
0xf6, 0x5d, 0x6d, 0x1d, 0x4c, 0xfd, 0x8f, 0xf5,
0x37, 0x00, 0x0d, 0x01, 0x0c
};
protocol_field_write(&protocol_f_gpspos, gpspos_data);
uint8_t empty_data[17] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00
};
protocol_field_write(&protocol_f_empty, empty_data);
}