-
Notifications
You must be signed in to change notification settings - Fork 0
/
console.c
executable file
·67 lines (52 loc) · 1.51 KB
/
console.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
/* Scheduler include files. */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "FreeRTOS.h"
#include "task.h"
#include "serial.h"
#include "console.h"
#define consoleSTACK_SIZE ( ( unsigned portBASE_TYPE ) 256 )
#define consoleBUFFER_LEN ( ( unsigned portBASE_TYPE ) 256 )
#define consoleMAX_DELAY ( ( portTickType ) 1000 )
/* Handle to the com port used by the console. */
static xComPortHandle xPort;
/* The console task. */
static void vConsoleTask( void *pvParameters );
/* Console prompt */
const signed char *pcPrompt = "Command> ";
void vStartConsole( unsigned portBASE_TYPE uxPriority, unsigned long ulBaudRate)
{
/* Initialise the com port. */
xPort = xSerialPortInitMinimal( ulBaudRate, consoleBUFFER_LEN );
/* Spawn the console task . */
xTaskCreate( vConsoleTask, ( signed char * ) "Console", consoleSTACK_SIZE, NULL, uxPriority, ( xTaskHandle * ) NULL );
printf("Console task started ...\r\n");
}
xComPortHandle xConsolePortHandle(void)
{
return xPort;
}
static portTASK_FUNCTION( vConsoleTask, pvParameters )
{
signed char cRxChar;
/* Just to stop compiler warnings. */
( void ) pvParameters;
for( ;; )
{
/* Display prompt */
vSerialPutString(xPort, pcPrompt, strlen((const char *)pcPrompt));
cRxChar = 0;
while (cRxChar != '\r')
{
/* Read input */
xSerialGetChar(xPort, &cRxChar, portMAX_DELAY);
/* Echo input */
xSerialPutChar(xPort, cRxChar, consoleMAX_DELAY);
if (cRxChar == '\r')
{
xSerialPutChar(xPort, '\n', consoleMAX_DELAY);
}
}
}
}