1 /*********************************************************************
2 * SEGGER Microcontroller GmbH *
3 * Solutions for real time microcontroller applications *
4 **********************************************************************
5 * *
6 * (c) 1995 - 2018 SEGGER Microcontroller GmbH *
7 * *
8 * www.segger.com Support: support@segger.com *
9 * *
10 **********************************************************************
11 --------- END-OF-HEADER --------------------------------------------
12 File : Main_RTT_MenuApp.c
13 Purpose : Sample application to demonstrate RTT bi-directional functionality
14 */
15
16 #define MAIN_C
17
18 #include <stdio.h>
19
20 #include "SEGGER_RTT.h"
21
22 volatile int _Cnt;
23 volatile int _Delay;
24
25 /*********************************************************************
26 *
27 * main
28 */
main(void)29 void main(void) {
30 int r;
31 int CancelOp;
32
33 do {
34 _Cnt = 0;
35
36 SEGGER_RTT_WriteString(0, "SEGGER Real-Time-Terminal Sample\r\n");
37 SEGGER_RTT_WriteString(0, "Press <1> to continue in blocking mode (Application waits if necessary, no data lost)\r\n");
38 SEGGER_RTT_WriteString(0, "Press <2> to continue in non-blocking mode (Application does not wait, data lost if fifo full)\r\n");
39 do {
40 r = SEGGER_RTT_WaitKey();
41 } while ((r != '1') && (r != '2'));
42 if (r == '1') {
43 SEGGER_RTT_WriteString(0, "\r\nSelected <1>. Configuring RTT and starting...\r\n");
44 SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL);
45 } else {
46 SEGGER_RTT_WriteString(0, "\r\nSelected <2>. Configuring RTT and starting...\r\n");
47 SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_NO_BLOCK_SKIP);
48 }
49 CancelOp = 0;
50 do {
51 //for (_Delay = 0; _Delay < 10000; _Delay++);
52 SEGGER_RTT_printf(0, "Count: %d. Press <Space> to get back to menu.\r\n", _Cnt++);
53 r = SEGGER_RTT_HasKey();
54 if (r) {
55 CancelOp = (SEGGER_RTT_GetKey() == ' ') ? 1 : 0;
56 }
57 //
58 // Check if user selected to cancel the current operation
59 //
60 if (CancelOp) {
61 SEGGER_RTT_WriteString(0, "Operation cancelled, going back to menu...\r\n");
62 break;
63 }
64 } while (1);
65 SEGGER_RTT_GetKey();
66 SEGGER_RTT_WriteString(0, "\r\n");
67 } while (1);
68 }
69
70 /*************************** End of file ****************************/
71