-
Notifications
You must be signed in to change notification settings - Fork 0
/
uart_console_task.c
88 lines (75 loc) · 2.43 KB
/
uart_console_task.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
/*
* @file uart_console_task.c
* Implements a UART console on the built in UART device, allowing for
* a user to view and manipulate the state of the logger.
*/
/* XDCtools Header files */
#include <xdc/runtime/System.h>
#include <xdc/std.h>
/* BIOS Header files */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
/* TI-RTOS Header files */
#include <ti/drivers/UART.h>
#include <stdbool.h>
/* Board-specific functions */
#include "Board.h"
#include "cli.h"
// UART configuration.
#define BAUD_RATE 115200
#define UART_DEV Board_UART0
static UART_Handle uart;
static UART_Params params;
static int uart_read(char *in, int n);
static int uart_write(char *out, int n);
/*
* PreOS Task for UART console. Sets up uart instance for data transmission,
* UART device on linux will be ttyACM0.
* This code MUST be called before the BIOS is started.
*/
void uart_console_prebios(void) {
/*
* UART defaults to text mode, echo back characters, and return from read
* after newline. Default 8 bits, one stop bit, no parity.
*/
UART_Params_init(¶ms);
params.baudRate = BAUD_RATE;
params.readReturnMode = UART_RETURN_FULL;
// Do not do text manipulation on the data. CLI will handle this.
params.readDataMode = UART_DATA_BINARY;
params.writeDataMode = UART_DATA_BINARY;
params.readEcho = UART_ECHO_OFF;
uart = UART_open(UART_DEV, ¶ms);
if (uart == NULL) {
System_abort("Error opening the UART device");
}
System_printf("Setup UART Console\n");
System_flush();
}
/*
* Task entry for the UART console handler. This task is created statically,
* see the "Task creation" section of the cfg file.
* @param arg0 unused
* @param arg1 unused
*/
void uart_task_entry(UArg arg0, UArg arg1) {
CLIContext uart_context;
cli_context_init(&uart_context);
uart_context.cli_read = uart_read;
uart_context.cli_write = uart_write;
start_cli(&uart_context); // Does not return.
}
/**
* Write data to the UART device.
* @param out buffer of data to write to UART device
* @param n length of out in bytes.
* @return number of byte written to UART.
*/
static int uart_write(char *out, int n) { return UART_write(uart, out, n); }
/**
* Read data from the UART device.
* @param in buffer to read data into. Must be "n" bytes or larger.
* @param n number of bytes to read.
* @return number of bytes read.
*/
static int uart_read(char *in, int n) { return UART_read(uart, in, n); }