-
Notifications
You must be signed in to change notification settings - Fork 0
/
com.c
84 lines (67 loc) · 2.85 KB
/
com.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
// com.c
// COM board support implementation file
//
// Written by Bradley Denby
// Other contributors: None
//
// See the top-level LICENSE file for the license.
// Standard library headers
#include <stdint.h> // uint8_t
// libopencm3 library
//#include <libopencm3/stm32/flash.h> // used in init_clock
//#include <libopencm3/stm32/gpio.h> // used in init_gpio
//#include <libopencm3/stm32/rcc.h> // used in init_clock, init_rtc
//#include <libopencm3/stm32/usart.h> // used in init_uart
#include <libopencm3/nrf/51/clock.h>
// Board-specific header
#include <com.h> // COM header
// TAB header
#include <tab.h> // TAB header
// Functions required by TAB
int handle_common_data(common_data_t common_data_buff_i) {
int strictly_increasing = 1;
uint8_t prev_byte = common_data_buff_i.data[0];
for(size_t i=1; i<common_data_buff_i.end_index; i++) {
if(prev_byte>=common_data_buff_i.data[i]) {
strictly_increasing = 0;
i = common_data_buff_i.end_index;
}
}
return strictly_increasing;
}
// Board initialization functions
void init_clock(void) {
clock_set_xtal_freq(CLOCK_XTAL_FREQ_16MHZ);
clock_start_lfclk (true);
clock_set_lfclk_src (CLOCK_LFCLK_SRC_RC); //CLOCK_LFCLK_SRC_RC
}
void init_uart(void) {
// TODO
}
// Feature functions
//void rx_usart1(rx_cmd_buff_t* rx_cmd_buff_o) {
/*while( // while
usart_get_flag(USART1,USART_ISR_RXNE) && // USART1 RX not empty AND
rx_cmd_buff_o->state!=RX_CMD_BUFF_STATE_COMPLETE // Command not complete
) { //
uint8_t b = usart_recv(USART1); // Receive byte from RX pin
push_rx_cmd_buff(rx_cmd_buff_o, b); // Push byte to buffer
}*/ //
//}
//void reply(rx_cmd_buff_t* rx_cmd_buff_o, tx_cmd_buff_t* tx_cmd_buff_o) {
/*if( // if
rx_cmd_buff_o->state==RX_CMD_BUFF_STATE_COMPLETE && // rx_cmd is valid AND
tx_cmd_buff_o->empty // tx_cmd is empty
) { //
write_reply(rx_cmd_buff_o, tx_cmd_buff_o); // execute cmd and reply
}*/ //
//}
//void tx_usart1(tx_cmd_buff_t* tx_cmd_buff_o) {
/*while( // while
usart_get_flag(USART1,USART_ISR_TXE) && // USART1 TX empty AND
!(tx_cmd_buff_o->empty) // TX buffer not empty
) { //
uint8_t b = pop_tx_cmd_buff(tx_cmd_buff_o); // Pop byte from TX buffer
usart_send(USART1,b); // Send byte to TX pin
}*/ //
//}