//debug code int main(void){ char ch; char string[20]; // global to assist in debugging uint32_t n; PLL_Init(Bus50MHz); // 50 MHz UART_Init(); // initialize UART OutCRLF(); for(ch='A'; ch<='Z'; ch=ch+1){// print the uppercase alphabet UART_OutChar(ch); } OutCRLF(); UART_OutChar(' '); for(ch='a'; ch<='z'; ch=ch+1){// print the lowercase alphabet UART_OutChar(ch); } OutCRLF(); UART_OutChar('-'); UART_OutChar('-'); UART_OutChar('>'); while(1){ UART_OutString("InString: "); UART_InString(string,19); UART_OutString(" OutString="); UART_OutString(string); OutCRLF(); UART_OutString("InUDec: "); n=UART_InUDec(); UART_OutString(" OutUDec="); UART_OutUDec(n); OutCRLF(); UART_OutString("InUHex: "); n=UART_InUHex(); UART_OutString(" OutUHex="); UART_OutUHex(n); OutCRLF(); } }
void Interpreter(void){char inchar; char inString1[MAXSTRLEN]; for(;;){ UART_InString(inString1, MAXSTRLEN); process_cmd(inString1); if(StreamToFile){ UART_OutChar('\n'); UART_OutChar('\r'); inchar = UART_InChar(); UART_OutChar(inchar); while(inchar != 0x1B){ //while user doesn't press escape eFile_Write(inchar); inchar = UART_InChar(); UART_OutChar(inchar); } eFile_EndRedirectToFile(); } UART_OutChar(CR); UART_OutChar(LF); } }
static int _SH_Write(void) { int i; if(!_SH_cmd.args[0][0]) { fprintf(stderr, "Usage: %s <file_name>\n", _SH_cmd.command); return 1; } memset(_SH_Buffer, 0, 512); if(eFile_WOpen(_SH_cmd.args[0])) { fprintf(stderr, "Unable to open file for writing!\n"); return 1; } UART_InString(_SH_Buffer, 512); printf("\nWriting to file %s...\n", _SH_cmd.args[0]); for(i = 0; i < 512 && _SH_Buffer[i]; i++) { if(eFile_Write(_SH_Buffer[i])) { fprintf(stderr, "Error writing to file!\n"); eFile_WClose(); return 1; } } eFile_Write('\n'); eFile_WClose(); return 0; }
void Interpreter(void) // just a prototype, link to your interpreter { uint32_t stringSize; uint32_t adcVoltage; uint8_t deviceChosen; uint8_t taskAddedBefore = 0; uint8_t commandChosen = -1; char message[MESSAGELENGTH] = ""; OutCRLF(); UART_OutString("Input Command: "); while(1){ OutCRLF(); //UART_OutString("Commands: 0 - ADC, 1 - LCD, 2 - Time"); OutCRLF(); commandChosen = UART_InChar(); switch(commandChosen) { case '0': OutCRLF(); UART_OutString("ADC Voltage = "); //ADC_Open(4); adcVoltage = (ADC_In() *3300) / 4095; //convert to mV UART_OutUDec(adcVoltage); OutCRLF(); break; case '1': OutCRLF(); UART_OutString("Enter LCD device 0 or 1: "); deviceChosen = UART_InUDec(); OutCRLF(); UART_OutString("Enter message: "); UART_InString(message, MESSAGELENGTH); OutCRLF(); stringSize = strlen(message); if(stringSize > 20) { OutCRLF(); UART_OutString("String too long..."); OutCRLF(); } LCD_test(deviceChosen, message); //prints to lcd OutCRLF(); break; case '2': if(!taskAddedBefore){ OS_AddPeriodicThread(dummy, 5, 1); taskAddedBefore = 1; } OutCRLF(); UART_OutUDec(OS_ReadPeriodicTime()); OutCRLF(); break; case '3': UART_OutString("NumSamples: "); UART_OutUDec(NumSamples); OutCRLF(); break; case '4': UART_OutString("Jitter: "); UART_OutUDec(MaxJitter); OutCRLF(); break; case '5': UART_OutString("DataLost: "); UART_OutUDec(DataLost); OutCRLF(); break; case '6': UART_OutString("FilterWork: "); UART_OutUDec(FilterWork); OutCRLF(); break; case '7': UART_OutString("NumCreated: "); UART_OutUDec(NumCreated); OutCRLF(); break; case '8': for(int i = 0; i<64; i++) { UART_OutUDec(x[i]); OutCRLF(); } break; default: UART_OutString("Incorrect command!"); break; } //adcSample = ADC_In(); //ST7735_SetCursor(0,0); //ST7735_OutUDec(adcSample); } }
//------------UART_InStringNL------------ // Runs UART_InString() and adds a new line. // Input: pointer to empty buffer, size of buffer // Output: Null terminated string void UART_InStringNL(char *bufPt, uint16_t max){ UART_InString(bufPt, max); UART_OutCRLF(); }