-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcomm_uart2.c
More file actions
99 lines (72 loc) · 2.25 KB
/
comm_uart2.c
File metadata and controls
99 lines (72 loc) · 2.25 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
/*
Copyright 2015 Benjamin Vedder benjamin@vedder.se
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* comm_uart.c
*
* Created on: 17 aug 2015
* Author: benjamin
*/
#include "comm_uart.h"
// #include "ch.h"
// #include "hal.h"
#include "bldc_interface_uart.h"
#include <string.h>
// Private functions
static void send_packet(unsigned char *data, unsigned int len);
// Variables
static uint8_t serial_rx_buffer[1024];
static int serial_rx_read_pos = 0;
static int serial_rx_write_pos = 0;
;
/**
* Callback that the packet handler uses to send an assembled packet.
*
* @param data
* Data array pointer
* @param len
* Data array length
*/
static void send_packet(unsigned char *data, unsigned int len) {
// if (len > (PACKET_MAX_PL_LEN + 5)) {
// return;
// }
// // write(fd, (void *)d, len);
// // Wait for the previous transmission to finish.
// while (UART_DEV.txstate == UART_TX_ACTIVE) {
// chThdSleep(1);
// }
// // Copy this data to a new buffer in case the provided one is re-used
// // after this function returns.
// static uint8_t buffer[PACKET_MAX_PL_LEN + 5];
// memcpy(buffer, data, len);
// // Send the data over UART
// uartStartSend(&UART_DEV, len, buffer);
}
/**
* This thread is only for calling the timer function once
* per millisecond. Can also be implementer using interrupts
* if no RTOS is available.
*/
static THD_FUNCTION(timer_thread, arg) {
(void)arg;
chRegSetThreadName("packet timer");
for(;;) {
bldc_interface_uart_run_timer();
chThdSleepMilliseconds(1);
}
}
void comm_uart_init(void) {
// Initialize the bldc interface and provide a send function
bldc_interface_uart_init(send_packet);
}