OSDN Git Service

[UART][SHELL] Fix correct timeout, 10Sec(temp).
authorK.Ohta <whatisthis.sowhat@gmail.com>
Sat, 9 Nov 2013 15:07:42 +0000 (00:07 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Sat, 9 Nov 2013 15:07:42 +0000 (00:07 +0900)
euart.c
term_shell.c
uart_termio.c
uart_termio.h

diff --git a/euart.c b/euart.c
index 9dd0818..247a4f3 100644 (file)
--- a/euart.c
+++ b/euart.c
@@ -57,7 +57,7 @@ void uart_sleep(void)
     IPR1bits.TX1IP = 0;  // Low
     IPR1bits.RC1IP = 1; // High
     RCSTA = 0b10010000; //SPEN, 8bit, ASYNC, CREN = 0
-    BAUDCON = 0b00001010; // IDLE High, BRG16, ABDEN, WUE
+    BAUDCON = 0b00001010; // IDLE High, BRG16, -ABDEN, WUE
     TXSTA = 0b00100000; //8bit, ASYNC, TXEN, Break
     PIE1bits.TX1IE = 0;
     PIE1bits.RC1IE = 1;
@@ -73,7 +73,7 @@ void uart_wakeup(void)
     IPR1bits.TX1IP = 0;  // Low
     IPR1bits.RC1IP = 1; // High
     RCSTA = 0b10010000; //SPEN, 8bit, ASYNC, CREN
-    BAUDCON = 0b00001010; // IDLE High, BRG16, ABDEN, WUE
+    BAUDCON = 0b00001010; // IDLE High, BRG16, -ABDEN, WUE
     TXSTA = 0b00100000; //8bit, ASYNC, TXEN, Break
     PIE1bits.TX1IE = 0;
     PIE1bits.RC1IE = 1;
index 7bdedbc..32d992b 100644 (file)
@@ -45,7 +45,7 @@
 #include "term_shell.h"
 
 
-char cmd_shellstr[255];
+unsigned char cmd_shellstr[255];
 static char shell_strbuf[255];
 static char xarg1[128];
 static char xarg2[128];
@@ -341,7 +341,7 @@ char term_shell(unsigned int timeout)
     unsigned int ii;
     char pool[128];
 
-    cmd_shellstr[0] = '\0';
+    //cmd_shellstr[0] = '\0';
     if(timeout != 0) {
         t = timeout;
         while((uart_getstat() & UART_WAKEUP) == 0) {
@@ -356,8 +356,17 @@ char term_shell(unsigned int timeout)
     uart_term_putstr("\nOpen I2C Radio v2.0\n(C)2013- Kyuma Ohta\n");
     uart_term_putstr("\n\nWelcome to shell mode (^^).\nPress help to show usage.\n");
     do {
+        cmd_shellstr[0] = '\0';
         uart_term_putstr("\n$>");
-        uart_term_getstr(cmd_shellstr, 128, 1); // With Echo
+        uart_term_getstr(cmd_shellstr, 100, 1); // With Echo, timeout=10Sec.
+        if(cmd_shellstr[0] == TERM_CHAR_TIMEOUT){
+          uart_term_putstr("\nTimeout.\n");
+          uart_init();
+          return SHELL_CMD_NONE; // TimeOut 
+       }
+
+   
+       
         ClrWdt();
         ii = shell_gettok(pool, cmd_shellstr);
 //        if(ii >= 128) return SHELL_CMD_TOOLONG;
index ff912e4..97e3419 100644 (file)
@@ -41,7 +41,7 @@
 #include "menu.h"
 #include "uart_termio.h"
 #include "shell_strutl.h"
-
+#include "power.h"
 
 unsigned char uart_term_putstr(unsigned char *s)
 {
@@ -56,19 +56,45 @@ unsigned char uart_term_putstr(unsigned char *s)
     return 0xff;
 }
 
-void uart_term_getstr(unsigned char *s, unsigned char maxlen, unsigned char echo)
+void uart_term_getstr(unsigned char *s, unsigned int timeout, unsigned char echo)
 {
     unsigned char i = 0;
     unsigned char c = 0x00;
-    while(c != '\n'){
+    unsigned int tim;
+    unsigned char pwr;
+    unsigned char cnt;
+    tim = 0;
+    cnt = 0;
+    while(1){
         ClrWdt();
         c = uart_pullchar();
         if(c != 0x00) {
+           if(cnt > 10) {
+               if(chk_powerbutton() != 0) {
+                   shutdown(0xff);
+               }
+              cnt = 0;
+           }
+           cnt++;
             s[i] = c;
+           if((c == '\i') || (c == '\n')) break;
             if(echo != 0) uart_pushchar(c, 0); // Echoback
             i++;
-            if(i >= maxlen) break;
-        }
+            if(i >= 128) break;
+           tim = 0;
+       } else if(timeout != 0) { // ZAP n * 100mSec.
+           if(chk_powerbutton() != 0) shutdown(0xff); 
+           idle_time_ms(100 - 48); // Poll 0.1Sec
+           tim++;
+           if(tim > timeout) {
+              s[0] = TERM_CHAR_TIMEOUT;
+              i = 1;
+              break;
+           }
+       } else {
+         idle_time_ms(100 - 48); // Wait 100ms if none (and no Timeout).
+         if(chk_powerbutton() != 0) shutdown(0xff); 
+       }
     }
     s[i] = '\0';
 }
index 1056dc9..e09d517 100644 (file)
@@ -33,8 +33,9 @@
 extern "C" {
 #endif
 
+#define TERM_CHAR_TIMEOUT 0xff
 extern unsigned char uart_term_putstr(unsigned char *s);
-extern void uart_term_getstr(unsigned char *s, unsigned char maxlen, unsigned char echo);
+extern void uart_term_getstr(unsigned char *s, unsigned int maxlen, unsigned char echo);
 
 
 #ifdef __cplusplus