This is sample program for Nucleo L152RE (and F401RE & F411RE) mbed-rtos. You need to modify mbed-src and mbed-rtos before compile it.
Dependencies: mbed-rtos mbed-src SetRTC
Fork of GR-PEACH_test_on_rtos_works_well by
Please refer below link.
/users/kenjiArai/notebook/necleo-l152re-rtos-sample-also-for-f401re--f411re-/
Diff: mon.cpp
- Revision:
- 10:1c0f58b9c048
- Parent:
- 9:de986e74bd93
--- a/mon.cpp Thu Feb 12 07:53:25 2015 +0000 +++ b/mon.cpp Sat May 16 00:43:39 2015 +0000 @@ -7,7 +7,7 @@ * Created: May 15th, 2010 * Spareted: June 25th, 2014 mon() & mon_hw() * Ported: July 12th, 2014 from L152RE - * Revised: Feburary 8th, 2015 + * Revised: May 16th, 2015 * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE @@ -21,7 +21,7 @@ #include "rtos.h" // Object ---------------------------------------------------------------------------------------- -Serial pc(USBTX, USBRX); +extern Serial pc; // Definition ------------------------------------------------------------------------------------ #define BAUD(x) pc.baud(x) @@ -31,10 +31,11 @@ #define READABLE(x) pc.readable(x) // RAM ------------------------------------------------------------------------------------------- -static char linebuf[64]; +char linebuf[64]; extern float fa[3]; // Acc 0:X, 1:Y, 2:Z extern float fg[3]; // Gyro 0:X, 1:Y, 2:Z +extern float analog[2]; extern uint8_t show_flag0; extern uint8_t show_flag1; @@ -42,12 +43,148 @@ static char *const mon_msg = "Monitor for mbed system, created on "__DATE__""; // Function prototypes --------------------------------------------------------------------------- +extern void mon_hw(void); + extern void debug_interface(void); -extern int read_sw(uint8_t n); +extern int read_sw(void); + +static void put_r ( void ); +static void get_line (char *buff, int len); +static int xatoi (char **str, int32_t *res); +static void put_rn ( void ); +static void msg_hlp (void); +static void chk_and_set_time(char *ptr); //------------------------------------------------------------------------------------------------- // Control Program //------------------------------------------------------------------------------------------------- +// Help Massage +static void msg_hlp (void){ + PRINTF(mon_msg); put_rn(); + PRINTF("a - Show analog data"); put_rn(); + PRINTF("d - Show control data"); put_rn(); + PRINTF("m - Show mail data"); put_rn(); + PRINTF("s - Show USER Button"); put_rn(); + PRINTF("t - Check and set RTC"); put_rn(); + PRINTF("x - Goto HW monitor"); put_rn(); + PRINTF("q - Return to main"); put_rn(); +} + +// ---------- Program starts here! --------------------------------------------------------------- +int mon(void) { +char *ptr; + + BAUD(9600); + put_rn(); + put_rn(); + PRINTF("%s [Help:'?' key]", mon_msg); + put_rn(); + for (;;) { + put_r(); + PUTC('>'); + ptr = linebuf; + get_line(ptr, sizeof(linebuf)); + switch (*ptr++) { + //--------------------------------------------------------------------------------------------- + // Check control data + //--------------------------------------------------------------------------------------------- + case 'a' : + while(true) { + put_r(); + PRINTF("A:%+6.1f,%+6.1f", analog[0], analog[1]); + put_rn(); + if ( READABLE() ) { + break; + } + Thread::wait(500); // Wait 200mS + } + break; + //--------------------------------------------------------------------------------------------- + // Check control data + //--------------------------------------------------------------------------------------------- + case 'd' : + while(true) { + put_r(); + PRINTF("G:%+6.1f,%+6.1f,%+6.1f, ", fg[0], fg[1], fg[2]); + Thread::yield(); // change thread + PRINTF("A:%+6.1f,%+6.1f,%+6.1f ", fa[0], fa[1], fa[2]); + put_rn(); + if ( READABLE() ) { + break; + } + Thread::wait(200); // Wait 200mS + } + break; + //--------------------------------------------------------------------------------------------- + // Show Mail data + //--------------------------------------------------------------------------------------------- + case 'm' : + put_rn(); + while(true) { + show_flag0 = 1; + if ( READABLE() ) { + break; + } + Thread::wait(100); // Wait 100mS + } + show_flag0 = 0; + break; + //--------------------------------------------------------------------------------------------- + // Show switch status + //--------------------------------------------------------------------------------------------- + case 's' : + put_r(); + PRINTF("Show USER_Button status"); + put_rn(); + PRINTF("every 500mS - hit any key for stop"); + put_rn(); + while (true){ + PRINTF("SW0 = "); + if (read_sw() == 1) { + PRINTF("ON "); + } else { + PRINTF("OFF"); + } + put_rn(); + if (READABLE()){ GETC(); break;} + wait(0.5); + } + break; + //--------------------------------------------------------------------------------------------- + // check and set RTC + //--------------------------------------------------------------------------------------------- + case 't' : + put_r(); + chk_and_set_time(ptr); + break; + //--------------------------------------------------------------------------------------------- + // Hardware monitor + //--------------------------------------------------------------------------------------------- + case 'x' : + put_r(); + mon_hw(); + break; + //--------------------------------------------------------------------------------------------- + // help + //--------------------------------------------------------------------------------------------- + case '?' : + put_r(); + msg_hlp(); + break; + //--------------------------------------------------------------------------------------------- + // Go back to main() + //--------------------------------------------------------------------------------------------- + case 'q' : // Quit + PRINTF("\rReturn to main\r\n"); + PRINTF("cannot control anymore from here\r\n"); + return 0; + } + } +} + +//------------------------------------------------------------------------------------------------- +// Monitor related subroutines +//------------------------------------------------------------------------------------------------- // Put \r\n static void put_rn ( void ){ Thread::yield(); // change thread @@ -63,7 +200,6 @@ } // Change string -> integer -//int xatoi (char **str, unsigned long *res){ static int xatoi (char **str, int32_t *res){ unsigned long val; unsigned char c, radix, s = 0; @@ -109,21 +245,6 @@ return 1; } -//------------------------------------------------------------------------------------------------- -// Monitor -//------------------------------------------------------------------------------------------------- -// Help Massage -static void msg_hlp (void){ - PRINTF(mon_msg); put_rn(); - PRINTF("d - Show control data"); put_rn(); - PRINTF("m - Show mail data"); put_rn(); - PRINTF("s - Show USER Button"); put_rn(); - PRINTF("t - Check and set RTC"); put_rn(); - PRINTF("r - Show RTC date & time"); put_rn(); - PRINTF("x - Goto HW monitor"); put_rn(); - PRINTF("q - Return to main"); put_rn(); -} - // Get key input data static void get_line (char *buff, int len){ char c; @@ -186,110 +307,3 @@ strftime(buf, 40, "%B %d,'%y, %H:%M:%S", localtime(&seconds)); PRINTF("Date: %s\r\n", buf); } - -// ---------- Program starts here! --------------------------------------------------------------- -int mon(void) { -char *ptr; - - BAUD(9600); - put_rn(); - put_rn(); - PRINTF("%s [Help:'?' key]", mon_msg); - put_rn(); - for (;;) { - put_r(); - PUTC('>'); - ptr = linebuf; - get_line(ptr, sizeof(linebuf)); - switch (*ptr++) { - //--------------------------------------------------------------------------------------------- - // Check control data - //--------------------------------------------------------------------------------------------- - case 'd' : - while(true) { - put_r(); - PRINTF("G:%+6.1f,%+6.1f,%+6.1f, ", fg[0], fg[1], fg[2]); - Thread::yield(); // change thread - PRINTF("A:%+6.1f,%+6.1f,%+6.1f ", fa[0], fa[1], fa[2]); - put_rn(); - if ( READABLE() ) { - break; - } - Thread::wait(200); // Wait 200mS - } - break; - //--------------------------------------------------------------------------------------------- - // Show Mail data - //--------------------------------------------------------------------------------------------- - case 'm' : - put_rn(); - while(true) { - show_flag0 = 1; - if ( READABLE() ) { - break; - } - Thread::wait(100); // Wait 100mS - } - show_flag0 = 0; - break; - //--------------------------------------------------------------------------------------------- - // Show switch status - //--------------------------------------------------------------------------------------------- - case 's' : - put_r(); - PRINTF("Show USER_Button status"); - put_rn(); - PRINTF("every 500mS - hit any key for stop"); - put_rn(); - while (true){ - PRINTF("SW0 = "); - if (read_sw(0) == 1) { PRINTF("ON "); - } else { PRINTF("OFF"); - } - PRINTF(", SW1 = "); - if (read_sw(1) == 1) { PRINTF("ON"); - } else { PRINTF("OFF"); - } - put_rn(); - if (READABLE()){ GETC(); break;} - wait(0.5); - } - break; - //--------------------------------------------------------------------------------------------- - // check and set RTC - //--------------------------------------------------------------------------------------------- - case 't' : - put_r(); - chk_and_set_time(ptr); - break; - //--------------------------------------------------------------------------------------------- - // check and set RTC - //--------------------------------------------------------------------------------------------- - case 'r' : - put_r(); - while(true) { - show_flag1 = 1; - if ( READABLE() ) { - break; - } - Thread::wait(50); // Wait 100mS - } - show_flag1 = 0; - break; - //--------------------------------------------------------------------------------------------- - // help - //--------------------------------------------------------------------------------------------- - case '?' : - put_r(); - msg_hlp(); - break; - //--------------------------------------------------------------------------------------------- - // Go back to main() - //--------------------------------------------------------------------------------------------- - case 'q' : // Quit - PRINTF("\rReturn to main\r\n"); - PRINTF("cannot control anymore from here\r\n"); - return 0; - } - } -}