int _mon_getc(int canblock) { unsigned char c; c = -1; #ifdef UseVideo MMCursor(1); while(InpQueue[InpQueueHead]==0); c=InpQueue[InpQueueHead]; InpQueue[InpQueueHead]=0; MMCursor(0); return c; #endif #ifdef UARTConsole canblock=1; if (canblock) { while (!UARTIsPressed()); return UARTGetChar(); } else { if (UARTIsPressed()) return UARTGetChar(); else return -1; } #endif }
//this is only my debug tool void Terminal(char cmd) { char h,l; unsigned char tmp; int i; struct list_entry *ptr; char *values; switch(cmd) { case 'i': USBNStart(); break; // write to usb register case 'w': //UARTWrite("write to USB reg:"); //USBNDEBUGPRINT("write to USB reg:"); h = UARTGetChar(); l = UARTGetChar(); SendHex(AsciiToHex(h,l)); tmp = AsciiToHex(h,l); UARTWrite("value:"); h = UARTGetChar(); l = UARTGetChar(); SendHex(AsciiToHex(h,l)); //USBNWrite(tmp,AsciiToHex(h,l)); UARTWrite("result:"); SendHex(USBNRead(tmp)); UARTWrite("\r\n"); break; // read from usb register case 'r': UARTWrite("read USB reg:"); h = UARTGetChar(); l = UARTGetChar(); SendHex(AsciiToHex(h,l)); UARTWrite("->"); SendHex(USBNRead(AsciiToHex(h,l))); UARTWrite("\r\n"); break; case 'h': UARTWrite("i usbn init procedure\r\n"); UARTWrite("w write USBN Register <h,l>(address) <h,l> (value) e.g 05 00\r\n"); UARTWrite("r read USBN Register <h,l> e.g. 02 ( RID)\r\n"); UARTWrite("s show all USBN Registers\r\n"); UARTWrite("b send test data from func to host\r\n"); UARTWrite("d show descriptors\r\n"); break; // show all registers case 's': for(i=0;i<=63;i++) { SendHex(i); UARTWrite("->"); SendHex(USBNRead(i)); UARTWrite("\r\n"); } break; case 'd': USBNDebug("\r\nDescriptor List\r\n"); ptr = DescriptorList; while(ptr != NULL) { values = (char*)ptr->data; SendHex(ptr->type); SendHex(ptr->len); SendHex(ptr->conf); SendHex(ptr->interf); USBNDebug(" "); for(i=0;i<ptr->len;i++) SendHex(values[i]); USBNDebug("\r\n"); ptr=ptr->next; } break; case 'b': UARTWrite("send test data from fifo1\r\n"); int j,i; char stat; USBNWrite(TXC1,FLUSH); USBNWrite(TXD1,0x01); for(j=0;j<63;j++) USBNBurstWrite((unsigned char)j); USBNWrite(TXC1,TX_LAST+TX_EN); //USBNWrite(TXC1,TX_LAST+TX_EN+TX_TOGL); break; case 'p': USBNWrite(TXC1,TX_LAST+TX_EN); break; default: UARTWrite("unknown command\r\n"); } }
static void taskUARTRXControl(void *pvParameters) { struct CarMessage pxAllocMessage; int8_t localVelocity = 0; int8_t localAccleration = 0 ; enum ButtonPressed localButton = NONE; pxAllocMessage.Velocity = localVelocity; pxAllocMessage.Acceleration = localAccleration; xTaskParameter_t *pxTaskParameter; portTickType xStartTime; /* The parameter points to an xTaskParameters_t structure. */ pxTaskParameter = (xTaskParameter_t *) pvParameters; struct UARTMessage *pxRxedMessage; struct UARTMessage Message2; pxRxedMessage = &Message2; int valid_command = 0; //char cRxedChar; UART_DATA data; //struct UARTMessage *pxRxedMessage; //struct UARTMessage Message2; //pxRxedMessage = &Message2; int j; int offset = 0; int done = 0; //Peripheral_Descriptor_t xConsole; int8_t cRxedChar, cInputIndex = 0; portBASE_TYPE xMoreDataToFollow; /* The input and output buffers are declared static to keep them off the stack. */ static int8_t pcOutputString[ MAX_OUTPUT_LENGTH ], pcInputString[ MAX_INPUT_LENGTH ]; //= "task-stats\0";//help\0"; while(1) { //take the semaphor, wait forever if it is not ready yet. xSemaphoreTake( InputByteBuffer, portMAX_DELAY ); //get data from global variable by calling UARTGetChar() cRxedChar = UARTGetChar(); //echo it on the tx buffer by queueing a message Message2.ucMessage[0] = cRxedChar; Message2.ucMessage[1] = 0; if( xQueueSendToBack( xUARTQueue, //QueueHandle_t xQueue, &Message2, //const void * pvItemToQueue, 0 //TickType_t xTicksToWait ) != pdPASS ) { //task was not able to be created after the xTicksToWait //a = 0; } //only one char is recieved at a time, therefore an "enter" press will send a \r\n, but the \n will be cut off. Going to hack it by making it just look for a \r. //if( cRxedChar == '\n' ) if( cRxedChar == '\r' ) { /* //echo a newline Message2.ucMessage[0] = '\n'; Message2.ucMessage[1] = 0; if( xQueueSendToBack( xUARTQueue, //QueueHandle_t xQueue, &Message2, //const void * pvItemToQueue, 0 //TickType_t xTicksToWait ) != pdPASS ) { //task was not able to be created after the xTicksToWait //a = 0; } */ //pcInputString[ cInputIndex ] = '\n'; //pcInputString[ cInputIndex + 1 ] = '\0'; /* A newline character was received, so the input command stirng is complete and can be processed. Transmit a line separator, just to make the output easier to read. */ //FreeRTOS_write( xConsole, "\r\n", strlen( "\r\n" ); /* The command interpreter is called repeatedly until it returns pdFALSE. See the ?Implementing a command? documentation for an exaplanation of why this is. */ do { /* Send the command string to the command interpreter. Any output generated by the command interpreter will be placed in the pcOutputString buffer. */ xMoreDataToFollow = FreeRTOS_CLIProcessCommand ( pcInputString, /* The command string.*/ pcOutputString, /* The output buffer. */ MAX_OUTPUT_LENGTH/* The size of the output buffer. */ ); /* Write the output generated by the command interpreter to the console. */ for(j = 0; j < 49 & pcOutputString[j] != 0; j++) { Message2.ucMessage[j] = pcOutputString[j]; } Message2.ucMessage[j] = STATICNULL; if( xQueueSendToBack( xUARTQueue, //QueueHandle_t xQueue, &Message2, //const void * pvItemToQueue, 0 //TickType_t xTicksToWait ) != pdPASS ) { //task was not able to be created after the xTicksToWait //a = 0; } if(j > 48) { done = 1; } while(done == 1) { offset = offset + 49; for(j = 0; j < 49 & pcOutputString[j+offset] != 0; j++) { Message2.ucMessage[j] = pcOutputString[j+offset]; } if(j < 48) { done = 0; for(; j < 49; j++) { Message2.ucMessage[j] = STATICNULL; } } //Message2.ucMessage[j] = STATICNULL; if( xQueueSendToBack( xUARTQueue, //QueueHandle_t xQueue, &Message2, //const void * pvItemToQueue, 0 //TickType_t xTicksToWait ) != pdPASS ) { //task was not able to be created after the xTicksToWait //a = 0; } } offset = 0; //FreeRTOS_write( xConsole, pcOutputString, strlen( pcOutputString ) ); } while( xMoreDataToFollow != pdFALSE ); /* All the strings generated by the input command have been sent. Processing of the command is complete. Clear the input string ready to receive the next command. */ cInputIndex = 0; memset( pcInputString, 0x00, MAX_INPUT_LENGTH ); } else { if( cRxedChar == 'q' ) // Keyboard ?q? ? Emergency Clear inside car { pxAllocMessage.button = Q; if( xQueueSendToBack( xCarMessageQueue, //QueueHandle_t xQueue, &pxAllocMessage, //const void * pvItemToQueue, 0 //TickType_t xTicksToWait ) != pdPASS ) { //task was not able to be created after the xTicksToWait //a = 0; } } else if( cRxedChar == 'w' ) //Keyboard ?w? ? P1Call DN outside car { pxAllocMessage.button = W; if( xQueueSendToBack( xCarMessageQueue, //QueueHandle_t xQueue, &pxAllocMessage, //const void * pvItemToQueue, 0 //TickType_t xTicksToWait ) != pdPASS ) { //task was not able to be created after the xTicksToWait //a = 0; } } else if( cRxedChar == 'e' ) //Keyboard ?e? ? P1Call UP outside car { pxAllocMessage.button = E; if( xQueueSendToBack( xCarMessageQueue, //QueueHandle_t xQueue, &pxAllocMessage, //const void * pvItemToQueue, 0 //TickType_t xTicksToWait ) != pdPASS ) { //task was not able to be created after the xTicksToWait //a = 0; } } else if( cRxedChar == 'r' ) //Keyboard ?r? ? P2 Call outside car { pxAllocMessage.button = R; if( xQueueSendToBack( xCarMessageQueue, //QueueHandle_t xQueue, &pxAllocMessage, //const void * pvItemToQueue, 0 //TickType_t xTicksToWait ) != pdPASS ) { //task was not able to be created after the xTicksToWait //a = 0; } } else if( cRxedChar == 't' ) //Keyboard ?t? ? GD Call button inside car { pxAllocMessage.button = T; if( xQueueSendToBack( xCarMessageQueue, //QueueHandle_t xQueue, &pxAllocMessage, //const void * pvItemToQueue, 0 //TickType_t xTicksToWait ) != pdPASS ) { //task was not able to be created after the xTicksToWait //a = 0; } } else if( cRxedChar == 'y' ) //Keyboard ?y? ? Emergency Stop inside car { pxAllocMessage.button = Y; if( xQueueSendToBack( xCarMessageQueue, //QueueHandle_t xQueue, &pxAllocMessage, //const void * pvItemToQueue, 0 //TickType_t xTicksToWait ) != pdPASS ) { //task was not able to be created after the xTicksToWait //a = 0; } } else if( cRxedChar == 'u' ) //Keyboard ?u? ? Emergency Clear inside car { pxAllocMessage.button = U; if( xQueueSendToBack( xCarMessageQueue, //QueueHandle_t xQueue, &pxAllocMessage, //const void * pvItemToQueue, 0 //TickType_t xTicksToWait ) != pdPASS ) { //task was not able to be created after the xTicksToWait //a = 0; } } else if( cRxedChar == 'i' ) //Keyboard ?i? ? Door Interference { pxAllocMessage.button = I; if( xQueueSendToBack( xCarMessageQueue, //QueueHandle_t xQueue, &pxAllocMessage, //const void * pvItemToQueue, 0 //TickType_t xTicksToWait ) != pdPASS ) { //task was not able to be created after the xTicksToWait //a = 0; } } else if( cRxedChar == '\r' ) { /* Ignore carriage returns. */ } else if( cRxedChar == '\b' ) { /* Backspace was pressed. Erase the last character in the input buffer - if there are any. */ if( cInputIndex > 0 ) { cInputIndex--; pcInputString[ cInputIndex ] = '\0'; } } else { /* A character was entered. It was not a new line, backspace or carriage return, so it is accepted as part of the input and placed into the input buffer. When a \n is entered the complete string will be passed to the command interpreter. */ if( cInputIndex < MAX_INPUT_LENGTH ) { pcInputString[ cInputIndex ] = cRxedChar; cInputIndex++; } } } } }
/***************************************************************************** ** Function name: GPSRetreiveData ** ** Descriptions: Reads and parses the next set of GPS data. ** ** parameters: None ** Returned value: The parsed information ** *****************************************************************************/ const gpsData* GPSRetreiveData(void) { uint8_t * pattern = (uint8_t*)"GPGGA"; while (1) { uint8_t buf[100]; uint8_t ch = 0; uint8_t *ptr = 0; int index = 0; // Retrieve the first byte if (!UARTGetChar(&ch)) continue; // look for "$GPGGA," header if (ch != '$') { continue; } // Retrieve the next six bytes for (index=0; index<6; index++) { buf[index] = UARTGetCharBlock(); } //Check if its Global Positioning System fixed Data if(hasPattern((uint8_t*)&buf, pattern) == 0) { continue; } //Retrieve the data from the GPS module for (index=0; index<100; index++) { buf[index] = UARTGetCharBlock(); if (buf[index] == '\r') { buf[index] = END_OF_MESSAGE; break; } } ptr = &buf[0]; //parse UTC time parseUTC(&ptr); //parse Latitude parseLatitude(&ptr); // parse N/S field parseNSIndicator(&ptr); // parse Longitude parseLongitude(&ptr); // parse E/W field parseEWIndicator(&ptr); // parse fix position parseFixIndicator(&ptr); // parse satellites parseSatellites(&ptr); // parse horizontal-dilution-of-precision field parseHDOP(&ptr); // parse altitude parseAltitudes(&ptr); break; } return &data; }