OSDN Git Service

[UART][v2.0] Enable to shell.Work temporally.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Sat, 9 Nov 2013 11:57:09 +0000 (20:57 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Sat, 9 Nov 2013 11:57:09 +0000 (20:57 +0900)
euart.c
iodef.h
main.c
nbproject/Makefile-genesis.properties
shell_strutl.c
term_shell.c
uart_termio.c

diff --git a/euart.c b/euart.c
index 55b4406..9dd0818 100644 (file)
--- a/euart.c
+++ b/euart.c
@@ -56,12 +56,14 @@ void uart_sleep(void)
     PIR1bits.RC1IF = 0;
     IPR1bits.TX1IP = 0;  // Low
     IPR1bits.RC1IP = 1; // High
-    RCSTA = 0b00010000; //SPEN, 8bit, ASYNC, CREN
-    BAUDCON = 0b00001011; // IDLE High, BRG16, ABDEN, WUE
+    RCSTA = 0b10010000; //SPEN, 8bit, ASYNC, CREN = 0
+    BAUDCON = 0b00001010; // IDLE High, BRG16, ABDEN, WUE
     TXSTA = 0b00100000; //8bit, ASYNC, TXEN, Break
     PIE1bits.TX1IE = 0;
-    PIE1bits.RC1IE = 0;
+    PIE1bits.RC1IE = 1;
     uart_rx_wakeup = 0;
+    SPBRGH = 51 / 256;
+    SPBRG = 51 % 256;
 }
 
 void uart_wakeup(void)
@@ -71,10 +73,13 @@ void uart_wakeup(void)
     IPR1bits.TX1IP = 0;  // Low
     IPR1bits.RC1IP = 1; // High
     RCSTA = 0b10010000; //SPEN, 8bit, ASYNC, CREN
-    BAUDCON = 0b00001011; // IDLE High, BRG16, ABDEN, WUE
+    BAUDCON = 0b00001010; // IDLE High, BRG16, ABDEN, WUE
     TXSTA = 0b00100000; //8bit, ASYNC, TXEN, Break
     PIE1bits.TX1IE = 0;
     PIE1bits.RC1IE = 1;
+//   uart_rx_wakeup = 0xff;
+   SPBRGH = 51 / 256;
+   SPBRG = 51 % 256;
 }
 
 void uart_init(void)
@@ -85,14 +90,14 @@ void uart_init(void)
     uart_rx_wakeup = 0;
     uart_rx_xon = 0xff;
     uart_tx_xon = 0xff;
-    uart_wakeup();
+    uart_sleep();
 }
 
 
 void uart_inthdr_rx(void)
 {
     unsigned char c;
-
+#if 1
     if(uart_rx_wakeup == 0){
         if(BAUDCONbits.WUE != 1){ // Okay, Wakeup interrupt
             uart_rx_wakeup = 0xff;
@@ -102,7 +107,7 @@ void uart_inthdr_rx(void)
     if(BAUDCONbits.ABDEN == 1) { // Still configure baudrate
         goto _l0; // Exit
     }
-
+#endif
     if(RCSTAbits.OERR == 0) {
         if(RCSTAbits.FERR == 0) {
             uart_rx_sts = 0; // Clear error
@@ -111,11 +116,12 @@ void uart_inthdr_rx(void)
                 uart_tx_xon = 0;  // XOFF Sequence for TX
              } else if(c == UART_CH_XON) { // XON Sequence for TX
                  uart_tx_xon = 0xff;
-             }  else if(uart_rx_bytes < UART_BUF_SIZE) { //
+             }  else { //if(uart_rx_bytes < UART_BUF_SIZE) { //
                         uart_rfifo[uart_rx_wptr++] = c;
                         if(uart_rx_wptr >= UART_BUF_SIZE) uart_rx_wptr = 0;
                         uart_rx_bytes++;
                         if(uart_rx_bytes >= UART_BUF_SIZE) uart_rx_bytes = UART_BUF_SIZE;
+//             uart_pushchar(c, 0x0000);
              }
         } else { // Frame Error
          uart_rx_sts != UART_FRAMEERROR;
@@ -126,6 +132,7 @@ void uart_inthdr_rx(void)
 
 _l0:  // Exit
  PIR1bits.RC1IF = 0;
+ RCSTAbits.CREN = 1;
  return;
 }
 
diff --git a/iodef.h b/iodef.h
index 2aecfa1..99137d0 100644 (file)
--- a/iodef.h
+++ b/iodef.h
@@ -109,8 +109,8 @@ extern "C" {
 #define TRIS_B_VAL   0b11111111 /* PORTB as INPUT.*/
 #define AN_B_VAL     0b00000000
 
-#define TRIS_C_VAL_O 0b00011000 /* FOR I2C-WRITE */
-#define TRIS_C_VAL_I  0b00011000 /* FOR I2C-WRITE */
+#define TRIS_C_VAL_O 0b10011000 /* FOR I2C-WRITE, RC7=INPUT */
+#define TRIS_C_VAL_I  0b10011000 /* FOR I2C-WRITE, RC7=INPUT */
 #define AN_C_VAL     0b00000000
 
 #define TRIS_D_VAL   0b00000000 /* FOR OUTPUT, LCD(Optional) */
diff --git a/main.c b/main.c
index f1c2ab6..56168d4 100644 (file)
--- a/main.c
+++ b/main.c
@@ -354,6 +354,7 @@ int main(void)
         /* Main routine*/
 
         term_shell(0); // Steel Shell
+//       uart_term_putstr("\nOpen I2C Radio v2.0\n(C)2013- Kyuma Ohta\n");
        for(i = 0; i < 4; i++) {
            c = pollkey_single_timeout(ui_idlekey, 1); // 23*41 = 943ms
            p = 0;
index 92ae58d..4e8b12c 100644 (file)
@@ -1,5 +1,5 @@
 #
-#Thu Nov 07 19:46:53 JST 2013
+#Sat Nov 09 20:07:51 JST 2013
 default.languagetoolchain.dir=/opt/microchip/xc8/v1.21/bin
 com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=0b040d5e5949b59f004c7912367437ce
 default.languagetoolchain.version=1.21
index eec3409..7a47839 100644 (file)
@@ -311,6 +311,7 @@ unsigned char shell_gettok(char *dst, char *src)
     while(src[i] != '\0') {
         if(src[i] == ' ') break;
         if(src[i] == '\t') break;
+        if(src[i] == '\n') break;
         dst[i] = src[i];
         i++;
         if(i > 128) break;
index 93511f4..7708797 100644 (file)
@@ -358,17 +358,17 @@ char term_shell(unsigned int timeout)
     do {
         uart_term_putstr("\n$>");
         uart_term_getstr(cmd_shellstr, 128, 1); // With Echo
-
-        ii = shell_gettok(pool, cmd_shellstr);
+        ClrWdt();
+//        ii = shell_gettok(pool, cmd_shellstr);
 //        if(ii >= 128) return SHELL_CMD_TOOLONG;
-        if(ii >= 128) continue; // Discard
+//        if(ii >= 128) continue; // Discard
 
         for(t = 0; t < SHELL_TOPCMDS; t++){
-            i = shell_strcmp((char *)cmdstr[t], pool);
+            i = shell_strcmp((char *)cmdstr[t], cmd_shellstr);
             if(i > 0) break;
         }
         //if(i <= 0) return SHELL_CMD_NOTFOUND;
-        ii = shell_gettok(pool, &cmd_shellstr[ii]);
+        //ii = shell_gettok(pool, &cmd_shellstr[ii]);
         switch(t){
             case 0:
                 cmd_help(pool);
@@ -390,12 +390,14 @@ char term_shell(unsigned int timeout)
                 break;
             case 15: // Exit
                 uart_term_putstr("\nBye... (^^)/~~\n");
+               uart_init();
                 return SHELL_CMD_OK;
                 break;
             default:
                 uart_term_putstr("\n?? CMD Error\n");
                 break;
         }
+
     } while(1);
     return SHELL_CMD_OK;
 }
index 6fb1ea1..ff912e4 100644 (file)
@@ -49,7 +49,7 @@ unsigned char uart_term_putstr(unsigned char *s)
     if((uart_getstat() & UART_WAKEUP) == 0) return 0; // Error
     while(s[p] != 0x00)
     {
-        uart_pushchar(s[p], 0x0000);
+        uart_pushchar(s[p], 100); // Timeout = 10ms
         p++;
         if(p >= 255) return 0; // Overlen
     }
@@ -58,9 +58,10 @@ unsigned char uart_term_putstr(unsigned char *s)
 
 void uart_term_getstr(unsigned char *s, unsigned char maxlen, unsigned char echo)
 {
-    unsigned int i = 0;
+    unsigned char i = 0;
     unsigned char c = 0x00;
     while(c != '\n'){
+        ClrWdt();
         c = uart_pullchar();
         if(c != 0x00) {
             s[i] = c;