Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: vt100 mbed afLib_1_3
main.cpp
00001 #include "mbed.h" 00002 #include "vt100.h" 00003 00004 #include "af_mgr.h" 00005 #include "af_attributes.h" 00006 #include "edge_mgr.h" 00007 #include "edge_pin.h" 00008 #include "edge_time.h" 00009 #include "edge_reset_mgr.h" 00010 00011 vt100 *tty = 0 ; 00012 uint32_t wait_tolerance = 500 ; /* 5sec */ 00013 uint32_t connect_tolerance = 60 ; /* after 60 trials, reboot */ 00014 uint32_t wait_count = 0 ; 00015 uint32_t connect_trial_count = 0 ; 00016 00017 DigitalOut *led_r = 0 ; 00018 DigitalOut *led_g = 0 ; 00019 DigitalOut *led_b = 0 ; 00020 // DigitalOut myled(LED1); 00021 00022 void doLEDs(int num) 00023 { 00024 if (num & 0x01) { *led_b = 0 ; } else { *led_b = 1 ; } 00025 if (num & 0x02) { *led_g = 0 ; } else { *led_g = 1 ; } 00026 if (num & 0x04) { *led_r = 0 ; } else { *led_r = 1 ; } 00027 } 00028 00029 /** 00030 * wait_connection 00031 * When gConnected == false, which is connection is lost. 00032 * Each 5sec check attribute ATTR_WIFI_STDY_STATE to see 00033 * if the connection has recovered. 00034 * Meantime even if connection is established communicated 00035 * data is invalid, so AF_SYSTEM_ASR_STATE is also 00036 * checked for gLinked ; 00037 * And in case connect_tolerance trials failed 00038 * try to reboot the system if it can improve the situation. 00039 */ 00040 void wait_connection(void) 00041 { 00042 int result ; 00043 wait_count++ ; 00044 if (wait_count > wait_tolerance) { 00045 if (gConnected == false) { 00046 result = afero->getAttribute(ATTR_WIFI_STDY_STATE) ; 00047 if (result != afSUCCESS) { 00048 print_af_error(result) ; 00049 } 00050 } 00051 if (gLinked == false) { 00052 result = afero->getAttribute(AF_SYSTEM_ASR_STATE) ; 00053 if (result != afSUCCESS) { 00054 print_af_error(result) ; 00055 } 00056 } 00057 connect_trial_count++ ; 00058 if (connect_trial_count > connect_tolerance) { 00059 reboot_edge() ; 00060 } 00061 wait_count = 0 ; 00062 } 00063 } 00064 00065 void init_hardware(void) 00066 { 00067 tty = new vt100(PTA2, PTA1, 115200) ; 00068 // tty->cls() ; 00069 led_r = new DigitalOut(PIN_LED_R, 1) ; 00070 led_g = new DigitalOut(PIN_LED_G, 1) ; 00071 led_b = new DigitalOut(PIN_LED_B, 1) ; 00072 } 00073 00074 #if 1 00075 int main() 00076 { 00077 int led_state = 0 ; 00078 init_hardware() ; 00079 tty->printf("afLib1.3 UART test program (%s)\n", __DATE__) ; 00080 tty->printf("Reset Reason: ") ; 00081 print_reset_reason() ; 00082 init_aflib() ; 00083 tty->printf("afLib 1.3 initialized\n") ; 00084 doLEDs(0x04) ; 00085 init_timer() ; 00086 tty->printf("timer init done\n") ; 00087 while(1) { 00088 afero->loop() ; 00089 if (afero->isIdle()) { 00090 led_state = 0x04 ; /* red */ 00091 if (gLinked && gConnected) { 00092 led_state = 0x02 ; /* green */ 00093 } else if (gConnected) { 00094 led_state = 0x01 ; /* blue */ 00095 } else { 00096 wait_connection() ; 00097 } 00098 doLEDs(led_state) ; 00099 wait_ms(100); 00100 } 00101 } 00102 } 00103 #else 00104 int main() 00105 { 00106 init_hardware() ; 00107 tty->printf("afLib1.3 test program (%s)\n", __DATE__) ; 00108 init_aflib() ; 00109 tty->printf("afLib 1.3 initialized\n") ; 00110 init_timer() ; 00111 tty->printf("timer init done\n") ; 00112 while(1) { 00113 afero->loop() ; 00114 if (afero->isIdle()) { 00115 *led_r = ! (*led_r) ; 00116 wait_ms(100); 00117 } 00118 } 00119 } 00120 #endif
Generated on Wed Jul 20 2022 21:24:28 by
1.7.2