?lang_form? ?lang_select? ?lang_submit? ?lang_endform?
{HEADER END}
{BLAME START}

library

?curdirlinks? -

Blame information for rev 6

Line No. Rev Author Line
1 6 kaklik //*****************************************************************************
2 // File Name : cmdlinetest.c
3 //
4 // Title : example usage of cmdline (command line) functions
5 // Revision : 1.0
6 // Notes :
7 // Target MCU : Atmel AVR series
8 // Editor Tabs : 4
9 //
10 // Revision History:
11 // When Who Description of change
12 // ----------- ----------- -----------------------
13 // 21-Jul-2003 pstang Created the program
14 //*****************************************************************************
15  
16  
17 //----- Include Files ---------------------------------------------------------
18 #include <avr/io.h> // include I/O definitions (port names, pin names, etc)
19 #include <avr/interrupt.h> // include interrupt support
20  
21 #include "global.h" // include our global settings
22 #include "uart.h" // include uart function library
23 #include "rprintf.h" // include printf function library
24 #include "a2d.h" // include A/D converter function library
25 #include "timer.h" // include timer function library (timing, PWM, etc)
26 #include "vt100.h" // include vt100 terminal support
27 #include "cmdline.h" // include cmdline function library
28  
29 // global variables
30 u08 Run;
31  
32 // functions
33 void goCmdline(void);
34 void exitFunction(void);
35 void helpFunction(void);
36 void dumpArgsStr(void);
37 void dumpArgsInt(void);
38 void dumpArgsHex(void);
39  
40 //----- Begin Code ------------------------------------------------------------
41 int main(void)
42 {
43 // initialize our libraries
44 // initialize the UART (serial port)
45 uartInit();
46 uartSetBaudRate(9600);
47 // make all rprintf statements use uart for output
48 rprintfInit(uartSendByte);
49 // turn on and initialize A/D converter
50 a2dInit();
51 // initialize the timer system
52 timerInit();
53 // initialize vt100 terminal
54 vt100Init();
55  
56 // configure port B for led output and pushbutton input
57 outb(DDRB, 0x0F);
58 // all LEDs on
59 outb(PORTB, 0x00);
60 // wait for hardware to power up
61 timerPause(100);
62 // all LEDs off
63 outb(PORTB, 0x0F);
64  
65 // start command line
66 goCmdline();
67  
68 return 0;
69 }
70  
71 void goCmdline(void)
72 {
73 u08 c;
74  
75 // print welcome message
76 vt100ClearScreen();
77 vt100SetCursorPos(1,0);
78 rprintfProgStrM("\r\nWelcome to the Command Line Test Suite!\r\n");
79  
80 // initialize cmdline system
81 cmdlineInit();
82  
83 // direct cmdline output to uart (serial port)
84 cmdlineSetOutputFunc(uartSendByte);
85  
86 // add commands to the command database
87 cmdlineAddCommand("exit", exitFunction);
88 cmdlineAddCommand("help", helpFunction);
89 cmdlineAddCommand("dumpargs1", dumpArgsStr);
90 cmdlineAddCommand("dumpargs2", dumpArgsInt);
91 cmdlineAddCommand("dumpargs3", dumpArgsHex);
92  
93 // send a CR to cmdline input to stimulate a prompt
94 cmdlineInputFunc('\r');
95  
96 // set state to run
97 Run = TRUE;
98  
99 // main loop
100 while(Run)
101 {
102 // pass characters received on the uart (serial port)
103 // into the cmdline processor
104 while(uartReceiveByte(&c)) cmdlineInputFunc(c);
105  
106 // run the cmdline execution functions
107 cmdlineMainLoop();
108 }
109  
110 rprintfCRLF();
111 rprintf("Exited program!\r\n");
112 }
113  
114 void exitFunction(void)
115 {
116 // to exit, we set Run to FALSE
117 Run = FALSE;
118 }
119  
120 void helpFunction(void)
121 {
122 rprintfCRLF();
123  
124 rprintf("Available commands are:\r\n");
125 rprintf("help - displays available commands\r\n");
126 rprintf("dumpargs1 - dumps command arguments as strings\r\n");
127 rprintf("dumpargs2 - dumps command arguments as decimal integers\r\n");
128 rprintf("dumpargs3 - dumps command arguments as hex integers\r\n");
129  
130 rprintfCRLF();
131 }
132  
133 void dumpArgsStr(void)
134 {
135 rprintfCRLF();
136 rprintf("Dump arguments as strings\r\n");
137  
138 rprintfProgStrM("Arg0: "); rprintfStr(cmdlineGetArgStr(0)); rprintfCRLF();
139 rprintfProgStrM("Arg1: "); rprintfStr(cmdlineGetArgStr(1)); rprintfCRLF();
140 rprintfProgStrM("Arg2: "); rprintfStr(cmdlineGetArgStr(2)); rprintfCRLF();
141 rprintfProgStrM("Arg3: "); rprintfStr(cmdlineGetArgStr(3)); rprintfCRLF();
142 rprintfCRLF();
143 }
144  
145 void dumpArgsInt(void)
146 {
147 rprintfCRLF();
148 rprintf("Dump arguments as integers\r\n");
149  
150 // printf %d will work but only if your numbers are less than 16-bit values
151 //rprintf("Arg1 as int: %d\r\n", cmdlineGetArgInt(1));
152 //rprintf("Arg2 as int: %d\r\n", cmdlineGetArgInt(2));
153 //rprintf("Arg3 as int: %d\r\n", cmdlineGetArgInt(3));
154  
155 // printfNum is good for longs too
156 rprintf("Arg1 as int: "); rprintfNum(10, 10, TRUE, ' ', cmdlineGetArgInt(1)); rprintfCRLF();
157 rprintf("Arg2 as int: "); rprintfNum(10, 10, TRUE, ' ', cmdlineGetArgInt(2)); rprintfCRLF();
158 rprintf("Arg3 as int: "); rprintfNum(10, 10, TRUE, ' ', cmdlineGetArgInt(3)); rprintfCRLF();
159 rprintfCRLF();
160 }
161  
162 void dumpArgsHex(void)
163 {
164 rprintfCRLF();
165 rprintf("Dump arguments as hex integers\r\n");
166  
167 rprintf("Arg1 as hex: "); rprintfNum(16, 8, FALSE, ' ', cmdlineGetArgHex(1)); rprintfCRLF();
168 rprintf("Arg2 as hex: "); rprintfNum(16, 8, FALSE, ' ', cmdlineGetArgHex(2)); rprintfCRLF();
169 rprintf("Arg3 as hex: "); rprintfNum(16, 8, FALSE, ' ', cmdlineGetArgHex(3)); rprintfCRLF();
170 rprintfCRLF();
171 }
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3