From: K.Ohta Date: Sat, 9 Nov 2013 15:07:42 +0000 (+0900) Subject: [UART][SHELL] Fix correct timeout, 10Sec(temp). X-Git-Url: http://git.osdn.net/view?p=openi2cradio%2FOpenI2CRadio.git;a=commitdiff_plain;h=7148d624c51f46c98c62ee98431becfa47493c89 [UART][SHELL] Fix correct timeout, 10Sec(temp). --- diff --git a/euart.c b/euart.c index 9dd0818..247a4f3 100644 --- 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; diff --git a/term_shell.c b/term_shell.c index 7bdedbc..32d992b 100644 --- a/term_shell.c +++ b/term_shell.c @@ -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; diff --git a/uart_termio.c b/uart_termio.c index ff912e4..97e3419 100644 --- a/uart_termio.c +++ b/uart_termio.c @@ -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'; } diff --git a/uart_termio.h b/uart_termio.h index 1056dc9..e09d517 100644 --- a/uart_termio.h +++ b/uart_termio.h @@ -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