void ProcessTerminal()
{
     BYTE i,j;
     BYTE Out;
     
     //Make sure to prime the UART Pump if there is data in the queue 
     //but TX IRQ is disabled
    if(BytesInQueue(&TERMINAL_OUT_QUEUE)>0 && (UART2_S1 & UART_S1_TDRE_MASK))
    {
    	UART2_C2 |= UART_C2_TIE_MASK; //Enable Reciever Interrupts
    }
    
    if(BytesInQueue(&TERMINAL_IN_QUEUE)>0)
    {
        ByteDequeue(&TERMINAL_IN_QUEUE,&NextCharIn);
        
        switch(NextCharIn)
        {
            case '\r':
             
             TerminalLineBuf[TerminalPos++] = 0x0;
             ByteEnqueue(&TERMINAL_OUT_QUEUE,NextCharIn);
            
             if(TerminalPos > 1)
             {
                 //find the command
                 i=0;
                 while(TerminalLineBuf[i]>0x20 &&  TerminalLineBuf[i]<0x7f)
                 {
                      TerminalCmdBuf[i] = TerminalLineBuf[i];
                      i++;
    
                    if(i==MAX_TERMINAL_CMD_CHARS)
                        {
                         break;
                        }
                 }
                    
                TerminalCmdBuf[i] = 0;
                TerminalCmdBuf[i+1] = 0;
            
                strcpy(TerminalArgs,&TerminalLineBuf[i]);

                CmdFound = FALSE;
                for(j=0;j<NUM_TERMINAL_CMDS;j++)
                {           
                    if(strcmp(TerminalCmdBuf,TerminalCommands[j]) == 0)
                    {
                    	printf_Q(&TERMINAL_OUT_QUEUE,"\r\n");
                    	if(TerminalCallbacks[j] != NULL)
                            TerminalCallbacks[j](TerminalArgs);
                    
                        CmdFound = TRUE;
                        break;
                    }             
                }        
                if(CmdFound == FALSE)
                {
                   printf_Q(&TERMINAL_OUT_QUEUE,"\r\n%s command not recognized.\r\n", TerminalCmdBuf);
                }
              }    
             ByteEnqueue(&TERMINAL_OUT_QUEUE,'\r\n');
             ByteEnqueue(&TERMINAL_OUT_QUEUE,'>');
             TerminalPos = 0;
            
            break;
            
            case '\b':
                if(TerminalPos > 0)
                {
                    TerminalPos--;    
                    ByteEnqueue(&TERMINAL_OUT_QUEUE,NextCharIn);
                }
            break;
            
            default:
                
                if(TerminalPos == 0 && NextCharIn == 0x020)
                {
                     //Do nothing if space bar is pressed at beginning of line    
                }
                   else if(NextCharIn >= 0x20 && NextCharIn<0x7F)
                {
                    
                    if(TerminalPos < MAX_TERMINAL_LINE_CHARS-1)
                    {
                         TerminalLineBuf[TerminalPos++] = NextCharIn;
                           ByteEnqueue(&TERMINAL_OUT_QUEUE,NextCharIn);
                    }
                }
            
            break;
        
        }
    }
 
}
Exemple #2
0
bool UART1_TxDequeue(byte *data)
{

    return (ByteDequeue(&UART1TxQueue, data));
}