int main( void ) { char cmd_buf[10]; unsigned short data = 0; prvSetupHardware(); for( ;; ) { blinky(2); INFO(welcome); UARTgets(UART0_BASE,cmd_buf, 10); SELECT(); // wait_ready(); data=recv_command(MSR); INFO("reg MSR: %X", data); data=recv_command(LSR); INFO("reg LSR: %X", data); data = xmit_spi( LCR); // write to LCR INFO("reg LCR: %X", data); data = xmit_spi( 0x83); // write to LCR INFO("data: %X", data); // for(size_t i = 0; i < 10; ++i) { // spi_uart_send(UART4_SSI_BASE,"ABDC",4); // } DESELECT(); } return 0; }
//***************************************************************************** // Start Main //***************************************************************************** int main(void) { char data_in[128]; //*************************************************************************** // Setting the system Clock // // 400 MHz PLL driven by 16 MHz external crystal // builtin /2 from PLL, then /4 --> 50Hz Clock speed SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // //*************************************************************************** InitUART3(); MotorInit(); //Initialize Motors LineInit(); //Initialize Line Sensors ultrasonicInit(); //Initialize UltraSonic IRdsitinit(); //Initialize IR Distance Sensor colorinit(); //Initialize Color Sensor FollowINIT(); //Initialize timer interrupts for following ShaftEncoder_Init(); IntMasterEnable(); //Enable Interrupts UARTprintf("An & Paolina's Robot says Hello\n\r"); while (1) { UARTgets(data_in,128); MB_Get((unsigned char *)data_in); Interpret(data_in); } }
void cmd_periodic_cont(void) { long cmd_status; if(UARTPeek('\r') == -1) { return; } // Get the buffer UARTgets(input_buffer, sizeof(input_buffer)); cmd_status = CmdLineProcess(input_buffer); switch(cmd_status) { case CMDLINE_BAD_CMD: UARTprintf("Bad command!\n"); break; case CMDLINE_TOO_MANY_ARGS: UARTprintf("Bad arguments!\n"); break; default: break; } UARTprintf("> "); }
//***************************************************************************** // // Checks to see if a new command has been received via the serial port and, // if so, processes it. // //***************************************************************************** void LogProcessCommands(void) { int nStatus; // // Check to see if there is a new serial command to process. // if(UARTPeek('\r') >= 0) { // // A new command has been entered so read it. // UARTgets(g_cCmdBuf, sizeof(g_cCmdBuf)); // // Pass the line from the user to the command processor. // It will be parsed and valid commands executed. // nStatus = CmdLineProcess(g_cCmdBuf); // // Handle the case of bad command. // if(nStatus == CMDLINE_BAD_CMD) { UARTprintf("Bad command!\n"); } // // Handle the case of too many arguments. // else if(nStatus == CMDLINE_TOO_MANY_ARGS) { UARTprintf("Too many arguments for command processor!\n"); } // // Otherwise the command was executed. Print the error // code if one was returned. // else if(nStatus != 0) { UARTprintf("Command returned error code %d\n", nStatus); } // // Print a prompt on the console. // UARTprintf("\n> "); } }
void uartDemo(void) { UARTprintf("tell me something!\n-> "); { char charArray[100]; UARTgets(charArray, 100); UARTprintf("you said, \"%s\"\n", charArray); UARTprintf("thanks for the input!\n"); } { char newline = 13; char ch = getc(); while(ch != newline) { ch = getc(); putc(ch); } } }
// // Main - It performs initialization, then runs a command processing loop to // read commands from the console. // int main(void) { int nStatus; FRESULT fresult; // // Set the clocking to run from the PLL at 50MHz // SysCtlClockSet(SYSCTL_OSCSRC_OSC2 | SYSCTL_PLL_ENABLE | SYSCTL_IMULT(10) | SYSCTL_SYSDIV(2)); SysCtlAuxClockSet(SYSCTL_OSCSRC_OSC2 | SYSCTL_PLL_ENABLE | SYSCTL_IMULT(12) | SYSCTL_SYSDIV(2)); //60 MHz #ifdef _FLASH // // Copy time critical code and Flash setup code to RAM // This includes the following functions: InitFlash_Bank0(); // The RamfuncsLoadStart, RamfuncsLoadSize, and RamfuncsRunStart // symbols are created by the linker. Refer to the device .cmd file. // memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize); // // Call Flash Initialization to setup flash waitstates // This function must reside in RAM // InitFlash_Bank0(); #endif // // Initialize interrupt controller and vector table // InitPieCtrl(); InitPieVectTable(); // // Set the system tick to fire 100 times per second. // SysTickInit(); SysTickPeriodSet(SysCtlClockGet(SYSTEM_CLOCK_SPEED) / 100); SysTickIntRegister(SysTickHandler); SysTickIntEnable(); SysTickEnable(); // // Enable Interrupts // IntMasterEnable(); // // Configure UART0 for debug output. // ConfigureUART(); // // Print hello message to user. // UARTprintf("\n\nSD Card Example Program\n"); UARTprintf("Type \'help\' for help.\n"); // // Mount the file system, using logical disk 0. // fresult = f_mount(0, &g_sFatFs); if(fresult != FR_OK) { UARTprintf("f_mount error: %s\n", StringFromFresult(fresult)); return(1); } // // Enter an (almost) infinite loop for reading and processing commands from // the user. // while(1) { // // Print a prompt to the console. Show the CWD. // UARTprintf("\n%s> ", g_cCwdBuf); // // Get a line of text from the user. // UARTgets(g_cCmdBuf, sizeof(g_cCmdBuf)); // // Pass the line from the user to the command processor. // It will be parsed and valid commands executed. // nStatus = CmdLineProcess(g_cCmdBuf); // // Handle the case of bad command. // if(nStatus == CMDLINE_BAD_CMD) { UARTprintf("Bad command!\n"); } // // Handle the case of too many arguments. // else if(nStatus == CMDLINE_TOO_MANY_ARGS) { UARTprintf("Too many arguments for command processor!\n"); } // // Otherwise the command was executed. Print the error // code if one was returned. // else if(nStatus != 0) { UARTprintf("Command returned error code %s\n", StringFromFresult((FRESULT)nStatus)); } } }
int main2(void) { UINT8 IsDHCP = 0; int32_t i32CommandStatus; _NetCfgIpV4Args_t ipV4; unsigned char len = sizeof(_NetCfgIpV4Args_t); int Status = 0; /* Stop WDT */ stopWDT(); /* Initialize the system clock of MCU */ initClk(); Board_Init(); // initialize LaunchPad I/O and PD1 LED ConfigureUART(); // Initialize the UART. UARTprintf("Section 11.4 IoT example, Volume 2 Real-time interfacing\n"); UARTprintf("This application is configured to measure analog signals from Ain7=PD0\n"); UARTprintf(" and send UDP packets to IP: %d.%d.%d.%d Port: %d\n\n", SL_IPV4_BYTE(IP_ADDR,3), SL_IPV4_BYTE(IP_ADDR,2), SL_IPV4_BYTE(IP_ADDR,1), SL_IPV4_BYTE(IP_ADDR,0),PORT_NUM); /* Initializing the CC3100 device */ sl_Start(0, 0, 0); /* Connecting to WLAN AP - Set with static parameters defined at the top After this call we will be connected and have IP address */ WlanConnect(); /* Read the IP parameter */ sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&IsDHCP,&len, (unsigned char *)&ipV4); //Print the IP UARTprintf("This node is at IP: %d.%d.%d.%d\n", SL_IPV4_BYTE(ipV4.ipV4,3), SL_IPV4_BYTE(ipV4.ipV4,2), SL_IPV4_BYTE(ipV4.ipV4,1), SL_IPV4_BYTE(ipV4.ipV4,0)); // // Loop forever waiting for commands from PC... // while(1) { // // Print prompt for user. // UARTprintf("\n>"); // // Peek to see if a full command is ready for processing. // while(UARTPeek('\r') == -1) { // // Approximately 1 millisecond delay. // ROM_SysCtlDelay(ROM_SysCtlClockGet() / 3000); } // // A '\r' was detected so get the line of text from the receive buffer. // UARTgets(g_cInput,sizeof(g_cInput)); // // Pass the line from the user to the command processor. // It will be parsed and valid commands executed. // i32CommandStatus = CmdLineProcess(g_cInput); // // Handle the case of bad command. // if(i32CommandStatus == CMDLINE_BAD_CMD) { UARTprintf(" Bad command. Try again.\n"); } // // Handle the case of too many arguments. // else if(i32CommandStatus == CMDLINE_TOO_MANY_ARGS) { UARTprintf(" Too many arguments for command. Try again.\n"); } // // Handle the case of too few arguments. // else if(i32CommandStatus == CMDLINE_TOO_FEW_ARGS) { UARTprintf(" Too few arguments for command. Try again.\n"); } // // Handle the case of too few arguments. // else if(i32CommandStatus == CMDLINE_INVALID_ARG) { UARTprintf(" Invalid command argument(s). Try again.\n"); } } }
//***************************************************************************** // // main loop - sets up UART1, UART 0, and the command loop to process commands // //***************************************************************************** int main(void) { int nStatus; int x; // // Enable lazy stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // ROM_FPUEnable(); ROM_FPULazyStackingEnable(); // // Set the clocking to run directly from the crystal. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); //Setup UART1 on PB0 / PB1 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); GPIOPinConfigure(GPIO_PB0_U1RX); GPIOPinConfigure(GPIO_PB1_U1TX); GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTStdioConfig(1, 9600, SysCtlClockGet()); ConfigureUART(); //UART0 // // Enable the UART1 interrupt. // ROM_IntEnable(INT_UART1); ROM_UARTIntEnable(UART1_BASE, UART_INT_RX | UART_INT_RT); //Initialize LED's SYSCTL_RCGC2_R = SYSCTL_RCGC2_GPIOF; x = SYSCTL_RCGC2_R; //dummy cycle GPIO_PORTF_DIR_R |= 0x08; GPIO_PORTF_DEN_R |= 0x08; GPIO_PORTF_DIR_R |= 0x04; GPIO_PORTF_DEN_R |= 0x04; GPIO_PORTF_DIR_R |= 0x02; GPIO_PORTF_DEN_R |= 0x02; // // Enable processor interrupts. // ROM_IntMasterEnable(); // // Enter an infinite loop for reading and processing commands from the // user. // Cmd_help(0,0); while(1) { // // Print a prompt to the console. Show the CWD. // UARTprintf("\n> "); // // Get a line of text from the user. // UARTgets(g_pcCmdBuf, sizeof(g_pcCmdBuf)); // // Pass the line from the user to the command processor. It will be // parsed and valid commands executed. // nStatus = CmdLineProcess(g_pcCmdBuf); // // Handle the case of bad command. // if(nStatus == CMDLINE_BAD_CMD) { UARTprintf("Bad command!\n"); } // // Handle the case of too many arguments. // else if(nStatus == CMDLINE_TOO_MANY_ARGS) { UARTprintf("Too many arguments for command processor!\n"); } // // Otherwise the command was executed. Print the error code if one was // returned. // else if(nStatus != 0) { UARTprintf("Command returned error code\n"); } } }
// going to print to the console generally instead of transmitting // in order to help with debugging static void DriverEEPROM(void) { unsigned char *driver_ptr = (unsigned char*)0x20000800; unsigned char *verify_ptr = (unsigned char*)0x20002000; unsigned short driver_size = 0x800; // can we determine this at run time?? unsigned short eeprom_addr = 0x0800; int i, errors = 0; tBoolean success = true; char uartGetBuff[2]; Transceiver_TX_Queue = xQueueCreate ( 4, sizeof( Message ) ); // Initialize UART stdio UART_Init(); // Initialize GPIO driver GPIO_InitTasks(); // Initialize EEPROM EEPROM_Init(); EEPROM_Open( CS_PORT, CS_PIN ); UARTprintf( "\n\nWriting to EEPROM...\n" ); // Copy the driver from internal RAM to the external EEPROM EEPROM_WriteBurst( eeprom_addr, driver_ptr, driver_size ); UARTprintf( "Verifying write...\n" ); // Read the driver from external EEPROM EEPROM_ReadBurst(eeprom_addr, verify_ptr, driver_size); EEPROM_Close( CS_PORT, CS_PIN ); // Verify the contents of both drivers are the same for(i = 0; i < driver_size; i++) { if(driver_ptr[i] != verify_ptr[i]) { success = false; errors++; } } if(success) { UARTprintf( "Successfully wrote driver 2 to eeprom: %d bytes\n", driver_size ); } else { UARTprintf( "Verify failed, %d errors :(\n", errors ); } // XXX Why does this not work??? GPIO_Init( GPIO_PORT_B, GPIO_PIN_1, GPIO_STRENGTH_2MA, GPIO_DIR_MODE_IN, GPIO_PIN_TYPE_STD_WPD ); GPIO_SetInterruptTask( GPIO_PORT_B, GPIO_PIN_1, GPIO_RISING_EDGE, 2, intTask ); // Run simple command-line interface to test the sensor driver UARTprintf( "\n" ); while(1) { // Simple command line interface to test sensor: // - 'i' calls sensor_init() // - 'c' calls sensor_config() // - 't' calls sensor_task() UARTgets(uartGetBuff, 2); // get letter switch(uartGetBuff[0]) { case 'i': DriverJumpTable[0](&SensorPort1); break; case 'c': DriverJumpTable[1](&SensorPort1); break; case 't': DriverJumpTable[2](&SensorPort1); break; case 'h': UARTprintf( "Usage:\n" ); UARTprintf( "i - calls sensor_init()\n" ); UARTprintf( "c - calls sensor_config()\n" ); UARTprintf( "t - calls sensor_task()\n" ); break; default: UARTprintf( "\n" ); } } }
/******** Debug_NetworkTransceiver ***************************************** // setup necessary debug instrument, run the tests // Input: none // Output: none // ------------------------------------------------------------------------*/ void Debug_NetworkTransceiver ( void ) { unsigned char status, request_loop, completed_loop; UARTprintf ( "\n\n--- Network Transceiver Test Suite ---\n" "0) ALL\n" "1) EmptyQueue\n" "2) FullQueue\n" "3) Invalid Packet\n" "4) Lock\n" "5) Positive\n" "6) Max Retries\n" "7) Quit\n" "> "); UARTgets ( &testID, 2 ); switch ( testID ) { case '0': UARTprintf ( "Test suite begin in 5 seconds. Turn on another device now...5>" ); Delay_S(1); UARTprintf ( "4>" ); Delay_S(1); UARTprintf ( "3>" ); Delay_S(1); UARTprintf ( "2>" ); Delay_S(1); UARTprintf ( "1>" ); Delay_S(1); UARTprintf ( "0\n" ); Delay_S(1); xTaskCreate( Debug_NetworkTransceiver_InvalidPakcet, ( signed portCHAR * ) "Debug_NetworkTransceiver_InvalidPakcet", DEFAULT_STACK_SIZE, NULL, DEFAULT_PRIORITY, NULL ); break; case '1': xTaskCreate( Debug_NetworkTransceiver_EmptyQueue, ( signed portCHAR * ) "Debug_NetworkTransceiver_EmptyQueue", DEFAULT_STACK_SIZE, NULL, DEFAULT_PRIORITY, NULL ); break; case '2': xTaskCreate( Debug_NetworkTransceiver_FullQueue, ( signed portCHAR * ) "Debug_NetworkTransceiver_FullQueue", DEFAULT_STACK_SIZE, NULL, DEFAULT_PRIORITY, NULL ); break; case '3': xTaskCreate( Debug_NetworkTransceiver_InvalidPakcet, ( signed portCHAR * ) "Debug_NetworkTransceiver_InvalidPakcet", DEFAULT_STACK_SIZE, NULL, DEFAULT_PRIORITY, NULL ); break; case '4': xTaskCreate( Transceiver_Locker, ( signed portCHAR * ) "Transceiver_Locker", DEFAULT_STACK_SIZE, NULL, DEFAULT_PRIORITY, NULL ); xTaskCreate( Debug_NetworkTransceiver_Lock, ( signed portCHAR * ) "Debug_NetworkTransceiver_Lock", DEFAULT_STACK_SIZE, NULL, DEFAULT_PRIORITY, NULL ); break; case '5': xTaskCreate( Debug_NetworkTransceiver_Positive, ( signed portCHAR * ) "Debug_NetworkTransceiver_Positive", DEFAULT_STACK_SIZE, NULL, DEFAULT_PRIORITY, NULL ); break; case '6': xTaskCreate( Debug_NetworkTransceiver_MaxRetries, ( signed portCHAR * ) "Debug_NetworkTransceiver_MaxRetries", DEFAULT_STACK_SIZE, NULL, DEFAULT_PRIORITY, NULL ); break; case '7': UARTprintf ( "Goodbye!\n\n" ); break; default: UARTprintf ( "Invalid choice\n\n" ); xTaskCreate( Debug_NetworkTransceiver, ( signed portCHAR * ) "Debug_NetworkTransceiver", DEFAULT_STACK_SIZE, NULL, DEFAULT_PRIORITY, NULL ); break; } vTaskDelete ( NULL ); }
int main (void) { char read_buffer[32]; char kurve_buf[64]; char d1_buf[64]; char* str; char* id; char* value; char *pch; int i_value; int pos_value; int kurve=12; int d1 = 1; // Set the clocking to run directly from the crystal. SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); UARTStdioInit(0); // Initialize the OLED display. RIT128x96x4Init(1000000); //Display the constants RIT128x96x4StringDraw("Maschinensimulation!", 0, 0, 15); RIT128x96x4StringDraw("by Anzinger und Hahn", 0, 80, 15); UARTprintf("Hi UART\n;"); while(1){//wait until output is necassary UARTgets(&read_buffer, 32); id = &read_buffer; str = id+3; id=str; if(read_buffer[0] == '!' && read_buffer[1] == 'g'){ RIT128x96x4StringDraw("Wert get", 0, 50, 15); if(strcmp(id, "kurve") == 0) UARTprintf("%d", kurve); if(strcmp(id, "d1") == 0) UARTprintf("%d", d1); } if(read_buffer[0] == '!' && read_buffer[1] == 's'){ RIT128x96x4StringDraw("Wert set", 0, 50, 15); pos_value = findChar(str, '='); value = str + pos_value + 1; id[pos_value] = 0; i_value = atoi(value); if(strcmp(id, "kurve") == 0) kurve = i_value; if(strcmp(id, "d1") == 0) d1 = i_value; UARTprintf("%s=%d\n", id, i_value); } sprintf(&kurve_buf, "Wert Kurve: %d", kurve); sprintf(&d1_buf, "Wert d1: %d", d1); RIT128x96x4StringDraw(kurve_buf, 0, 60, 15); RIT128x96x4StringDraw(d1_buf, 0, 70, 15); } }
//***************************************************************************** // // Read a command line from the user and process it. // //***************************************************************************** void CommandReadAndProcess(void) { int iCount; // // Check to see if there is a string available in the UART receive // buffer. // iCount = UARTPeek('\r'); // // A negative return code indicates that there is no '\r' character in // the receive buffer and, hence, no complete string entered by the user // so just return. // if(iCount < 0) { return; } // // Here, we know that a string is available so read it. // iCount = UARTgets(g_pcCmdLine, COMMAND_BUFFER_LEN); // // If something sensible was entered, go ahead and process the command // line. // if(iCount) { // // Process the command entered by the user // iCount = CmdLineProcess(g_pcCmdLine); switch(iCount) { // // The command was not recognized // case CMDLINE_BAD_CMD: { UARTprintf("ERROR: Unrecognized command\n"); break; } // // The command contained too many arguments for the command // line processor to handle. // case CMDLINE_TOO_MANY_ARGS: { UARTprintf("ERROR: Too many arguments\n"); break; } } // // Display a prompt // UARTprintf(">"); } }
//***************************************************************************** // // Main 'C' Language entry point. // //***************************************************************************** int main(void) { const uint8_t bufLength=10; char inputBuf[1]; // // Configure the system frequency. // g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // Configure the device pins for this board. // PinoutSet(false, false); // // Initialize the UART. // ConfigureUART(); // // Print the welcome message to the terminal. // UARTprintf("\033[2J\033[H"); UARTprintf("SHT21 Example\n"); // // The I2C7 peripheral must be enabled before use. // // Note: For BoosterPack 2 interface use I2C8. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C8); //ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // // Configure the pin muxing for I2C7 functions on port D0 and D1. // This step is not necessary if your part does not support pin muxing. // // Note: For BoosterPack 2 interface use PA2 and PA3. // ROM_GPIOPinConfigure(GPIO_PA2_I2C8SCL); ROM_GPIOPinConfigure(GPIO_PA3_I2C8SDA); // // Select the I2C function for these pins. This function will also // configure the GPIO pins pins for I2C operation, setting them to // open-drain operation with weak pull-ups. Consult the data sheet // to see which functions are allocated per pin. // // Note: For BoosterPack 2 interface use PA2 and PA3. // ROM_GPIOPinTypeI2CSCL(GPIO_PORTA_BASE, GPIO_PIN_2); ROM_GPIOPinTypeI2C(GPIO_PORTA_BASE, GPIO_PIN_3); // // Keep only some parts of the systems running while in sleep mode. // GPIOE is for the ISL29023 interrupt pin. // UART0 is the virtual serial port. // I2C7 is the I2C interface to the ISL29023. // // Note: For BoosterPack 2 change this to I2C8. // ROM_SysCtlPeripheralClockGating(true); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOE); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART0); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_I2C8); // // Enable interrupts to the processor. // ROM_IntMasterEnable(); // // Initialize I2C7 peripheral. // // Note: For BoosterPack 2 use I2C8. // I2CMInit(&g_sI2CInst, I2C8_BASE, INT_I2C8, 0xff, 0xff, g_ui32SysClock); // // Turn on D2 to show we are starting an I2C transaction with the sensor. // This is turned off in the application callback. // LEDWrite(CLP_D1 | CLP_D2 , CLP_D2); // // Initialize the SHT21. // SHT21Init(&g_sSHT21Inst, &g_sI2CInst, SHT21_I2C_ADDRESS, SHT21AppCallback, &g_sSHT21Inst); // // Initialize the TMP006 // TMP006Init(&g_sTMP006Inst, &g_sI2CInst, TMP006_I2C_ADDRESS, TMP006AppCallback, &g_sTMP006Inst); // // Wait for the I2C transactions to complete before moving forward. // SHT21AppI2CWait(__FILE__, __LINE__); // // Delay for 20 milliseconds for SHT21 reset to complete itself. // Datasheet says reset can take as long 15 milliseconds. // ROM_SysCtlDelay(g_ui32SysClock / (50 * 3)); UARTprintf("Menu:\n"); UARTprintf("h for Humidity \n"); UARTprintf("t for Temperature \n"); // // Loop Forever. // while(1) { if(UARTgets(inputBuf,bufLength)){ if(inputBuf[0]=='h'){ UARTprintf("Sensing Humidity Data:\n"); printHumidityData(); } else if(inputBuf[0]=='t'){ UARTprintf("Sensing Temperature Data:\n"); printTemperatureData(); } } } }
int main(void) { UINT8 IsDHCP = 0; int32_t i32CommandStatus; _NetCfgIpV4Args_t ipV4; SlSockAddrIn_t Addr; UINT16 AddrSize = 0; INT16 SockID = 0; UINT32 data; long x = 0; //counter unsigned char len = sizeof(_NetCfgIpV4Args_t); int Status = 0; /* Stop WDT */ stopWDT(); /* Initialize the system clock of MCU */ initClk(); Board_Init(); // initialize LaunchPad I/O and PD1 LED ConfigureUART(); // Initialize the UART. UARTprintf("Section 11.4 IoT example, Volume 2 Real-time interfacing\n"); UARTprintf("This application is configured to generate text\n"); UARTprintf(" and send UDP packets to IP: %d.%d.%d.%d Port: %d\n\n", SL_IPV4_BYTE(IP_ADDR,3), SL_IPV4_BYTE(IP_ADDR,2), SL_IPV4_BYTE(IP_ADDR,1), SL_IPV4_BYTE(IP_ADDR,0),PORT_NUM); //added code from the powerpoint slide /* Initializing the CC3100 device */ sl_Start(0, 0, 0); /* Connecting to WLAN AP - Set with static parameters defined at the top After this call we will be connected and have IP address */ WlanConnect(); /* Read the IP parameter */ sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&IsDHCP,&len,(unsigned char *)&ipV4); UARTprintf("This node is at IP: %d.%d.%d.%d\n", SL_IPV4_BYTE(ipV4.ipV4,3), SL_IPV4_BYTE(ipV4.ipV4,2), SL_IPV4_BYTE(ipV4.ipV4,1), SL_IPV4_BYTE(ipV4.ipV4,0)); Addr.sin_family = SL_AF_INET; Addr.sin_port = sl_Htons((UINT16)PORT_NUM); Addr.sin_addr.s_addr = sl_Htonl((UINT32)IP_ADDR); AddrSize = sizeof(SlSockAddrIn_t); SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0); // Loop forever waiting for commands from PC... // while(1) { // Print prompt for user. UARTprintf("\n>"); // Peek to see if a full command is ready for processing. while(UARTPeek('\r') == -1) LED_On(); // Approximately 1 millisecond delay. ROM_SysCtlDelay(ROM_SysCtlClockGet() / 3000); } // A '\r' was detected so get the line of text from the receive buffer. while(Status >= 0){ UARTprintf("\nSending a UDP packet ...\n"); UARTgets(g_cInput,sizeof(g_cInput)); //this function receives the input from the Putty and places it in a string //DO NOT CHANGE ANYTHING ABOVE THIS COMMENT //WHAT WE NEED TO DO: //work with the g_cInput to get the array of letters typed into the Putty //then send that Array using UARTprintf uBuf[0] = ATYPE; // defines this as an analog data type uBuf[1] = '='; data = 1000; Int2Str(data,(char*)&uBuf[2]); // [2] to [7] is 6 digit number UARTprintf(" %s ",uBuf); //this line sends a string to the receiver //the above 5 lines print out a = 1000; //everything below this is just error cases if( SockID < 0 ){ UARTprintf("SockIDerror "); Status = -1; // error }else{ LED_Toggle(); Status = sl_SendTo(SockID, uBuf, BUF_SIZE, 0, (SlSockAddr_t *)&Addr, AddrSize); if( Status <= 0 ){ sl_Close(SockID); UARTprintf("SockIDerror %d ",Status); }else{ UARTprintf("ok"); } } ROM_SysCtlDelay(ROM_SysCtlClockGet() / 100); // 10ms LED_Off(); } }
int Gets(char *pcBuf, unsigned long ulLen) { return UARTgets(pcBuf, ulLen); }
//***************************************************************************** // // This example demonstrates how to send a string of data to the UART. // //***************************************************************************** int main(void) { int32_t i32CommandStatus; int i; initUart(); UARTprintf("Welcome to the Tiva C Series TM4C123G LaunchPad!\n"); UARTprintf("Type 'help' for a list of commands to control Moto\n"); UARTprintf("> "); InitDelay(); cSPIN_Peripherals_Init(); cSPIN_Reset_And_Standby(); /* Structure initialization by default values, in order to avoid blank records */ cSPIN_Regs_Struct_Reset(&cSPIN_RegsStruct); //cSPIN_PWM_Enable(2000); //cSPIN_Delay(0x00FFFFFF); //cSPIN_PWM_DISABLE(); #if 0 /* Acceleration rate settings to cSPIN_CONF_PARAM_ACC in steps/s2, range 14.55 to 59590 steps/s2 */ cSPIN_RegsStruct.ACC = AccDec_Steps_to_Par(cSPIN_CONF_PARAM_ACC); /* Deceleration rate settings to cSPIN_CONF_PARAM_DEC in steps/s2, range 14.55 to 59590 steps/s2 */ cSPIN_RegsStruct.DEC = AccDec_Steps_to_Par(cSPIN_CONF_PARAM_DEC); /* Maximum speed settings to cSPIN_CONF_PARAM_MAX_SPEED in steps/s, range 15.25 to 15610 steps/s */ cSPIN_RegsStruct.MAX_SPEED = MaxSpd_Steps_to_Par(cSPIN_CONF_PARAM_MAX_SPEED); /* Full step speed settings cSPIN_CONF_PARAM_FS_SPD in steps/s, range 7.63 to 15625 steps/s */ cSPIN_RegsStruct.FS_SPD = FSSpd_Steps_to_Par(cSPIN_CONF_PARAM_FS_SPD); /* Minimum speed settings to cSPIN_CONF_PARAM_MIN_SPEED in steps/s, range 0 to 976.3 steps/s */ cSPIN_RegsStruct.MIN_SPEED = cSPIN_CONF_PARAM_LSPD_BIT|MinSpd_Steps_to_Par(cSPIN_CONF_PARAM_MIN_SPEED); /* Acceleration duty cycle (torque) settings to cSPIN_CONF_PARAM_KVAL_ACC in %, range 0 to 99.6% */ cSPIN_RegsStruct.KVAL_ACC = Kval_Perc_to_Par(cSPIN_CONF_PARAM_KVAL_ACC); /* Deceleration duty cycle (torque) settings to cSPIN_CONF_PARAM_KVAL_DEC in %, range 0 to 99.6% */ cSPIN_RegsStruct.KVAL_DEC = Kval_Perc_to_Par(cSPIN_CONF_PARAM_KVAL_DEC); /* Run duty cycle (torque) settings to cSPIN_CONF_PARAM_KVAL_RUN in %, range 0 to 99.6% */ cSPIN_RegsStruct.KVAL_RUN = Kval_Perc_to_Par(cSPIN_CONF_PARAM_KVAL_RUN); /* Hold duty cycle (torque) settings to cSPIN_CONF_PARAM_KVAL_HOLD in %, range 0 to 99.6% */ cSPIN_RegsStruct.KVAL_HOLD = Kval_Perc_to_Par(cSPIN_CONF_PARAM_KVAL_HOLD); /* Thermal compensation param settings to cSPIN_CONF_PARAM_K_THERM, range 1 to 1.46875 */ cSPIN_RegsStruct.K_THERM = KTherm_to_Par(cSPIN_CONF_PARAM_K_THERM); /* Intersect speed settings for BEMF compensation to cSPIN_CONF_PARAM_INT_SPD in steps/s, range 0 to 3906 steps/s */ cSPIN_RegsStruct.INT_SPD = IntSpd_Steps_to_Par(cSPIN_CONF_PARAM_INT_SPD); /* BEMF start slope settings for BEMF compensation to cSPIN_CONF_PARAM_ST_SLP in % step/s, range 0 to 0.4% s/step */ cSPIN_RegsStruct.ST_SLP = BEMF_Slope_Perc_to_Par(cSPIN_CONF_PARAM_ST_SLP); /* BEMF final acc slope settings for BEMF compensation to cSPIN_CONF_PARAM_FN_SLP_ACC in% step/s, range 0 to 0.4% s/step */ cSPIN_RegsStruct.FN_SLP_ACC = BEMF_Slope_Perc_to_Par(cSPIN_CONF_PARAM_FN_SLP_ACC); /* BEMF final dec slope settings for BEMF compensation to cSPIN_CONF_PARAM_FN_SLP_DEC in% step/s, range 0 to 0.4% s/step */ cSPIN_RegsStruct.FN_SLP_DEC = BEMF_Slope_Perc_to_Par(cSPIN_CONF_PARAM_FN_SLP_DEC); /* Stall threshold settings to cSPIN_CONF_PARAM_STALL_TH in mV, range 31.25 to 1000mV */ cSPIN_RegsStruct.STALL_TH = StallTh_to_Par(cSPIN_CONF_PARAM_STALL_TH); /* Set Config register according to config parameters */ /* clock setting, switch hard stop interrupt mode, */ /* supply voltage compensation, overcurrent shutdown */ /* UVLO threshold, VCC reg output voltage , PWM frequency */ cSPIN_RegsStruct.CONFIG = (uint16_t)cSPIN_CONF_PARAM_CLOCK_SETTING | \ (uint16_t)cSPIN_CONF_PARAM_SW_MODE | \ (uint16_t)cSPIN_CONF_PARAM_VS_COMP | \ (uint16_t)cSPIN_CONF_PARAM_OC_SD | \ (uint16_t)cSPIN_CONF_PARAM_UVLOVAL | \ (uint16_t)cSPIN_CONF_PARAM_VCCVAL | \ (uint16_t)cSPIN_CONF_PARAM_PWM_DIV | \ (uint16_t)cSPIN_CONF_PARAM_PWM_MUL; /* Overcurrent threshold settings to cSPIN_CONF_PARAM_OCD_TH, range 31.25 to 1000mV */ cSPIN_RegsStruct.OCD_TH = cSPIN_CONF_PARAM_OCD_TH; /* Alarm settings to cSPIN_CONF_PARAM_ALARM_EN */ cSPIN_RegsStruct.ALARM_EN = cSPIN_CONF_PARAM_ALARM_EN; /* Step mode and sycn mode settings via cSPIN_CONF_PARAM_SYNC_MODE and cSPIN_CONF_PARAM_STEP_MODE */ cSPIN_RegsStruct.STEP_MODE = (uint8_t)cSPIN_CONF_PARAM_SYNC_MODE | \ (uint8_t)cSPIN_CONF_PARAM_STEP_MODE; /* Sink/source current, duration of constant current phases, duration of overboost phase settings */ cSPIN_RegsStruct.GATECFG1 = (uint16_t)cSPIN_CONF_PARAM_IGATE | \ (uint16_t)cSPIN_CONF_PARAM_TCC | \ (uint16_t)cSPIN_CONF_PARAM_TBOOST; /* Blank time, Dead time stiings */ cSPIN_RegsStruct.GATECFG2 = (uint16_t)cSPIN_CONF_PARAM_TBLANK | \ (uint16_t)cSPIN_CONF_PARAM_TDT; /* Program all cSPIN registers */ cSPIN_Registers_Set(&cSPIN_RegsStruct); #if defined(DEBUG) /* check the values of all cSPIN registers */ cSPIN_rx_data = cSPIN_Registers_Check(&cSPIN_RegsStruct); /* get the values of all cSPIN registers and print them to the terminal I/O */ cSPIN_Registers_Get(&cSPIN_RegsStruct); #endif /* defined(DEBUG) */ #else /**********************************************************************/ /* Start example of DAISY CHAINING */ /**********************************************************************/ /* Structure initialization by default values, in order to avoid blank records */ for (i=0;i<number_of_slaves;i++) { cSPIN_Regs_Struct_Reset(&cSPIN_RegsStructArray[i]); } /* Setting of parameters for ALL DEVICES */ for (i=0;i<number_of_slaves;i++) { cSPIN_RegsStructArray[i].ACC = AccDec_Steps_to_Par(ACC[i]); cSPIN_RegsStructArray[i].DEC = AccDec_Steps_to_Par(DEC[i]); cSPIN_RegsStructArray[i].MAX_SPEED = MaxSpd_Steps_to_Par(MAX_SPEED[i]); cSPIN_RegsStructArray[i].FS_SPD = FSSpd_Steps_to_Par(FS_SPD[i]); cSPIN_RegsStructArray[i].MIN_SPEED = LSPD_BIT[i]|MinSpd_Steps_to_Par(MIN_SPEED[i]); cSPIN_RegsStructArray[i].KVAL_ACC = Kval_Perc_to_Par(KVAL_ACC[i]); cSPIN_RegsStructArray[i].KVAL_DEC = Kval_Perc_to_Par(KVAL_DEC[i]); cSPIN_RegsStructArray[i].KVAL_RUN = Kval_Perc_to_Par(KVAL_RUN[i]); cSPIN_RegsStructArray[i].KVAL_HOLD = Kval_Perc_to_Par(KVAL_HOLD[i]); cSPIN_RegsStructArray[i].K_THERM = KTherm_to_Par(K_THERM[i]); cSPIN_RegsStructArray[i].INT_SPD = IntSpd_Steps_to_Par(INT_SPD[i]); cSPIN_RegsStructArray[i].ST_SLP = BEMF_Slope_Perc_to_Par(ST_SLP[i]); cSPIN_RegsStructArray[i].FN_SLP_ACC = BEMF_Slope_Perc_to_Par(FN_SLP_ACC[i]); cSPIN_RegsStructArray[i].FN_SLP_DEC = BEMF_Slope_Perc_to_Par(FN_SLP_DEC[i]); cSPIN_RegsStructArray[i].STALL_TH = StallTh_to_Par(STALL_TH[i]); cSPIN_RegsStructArray[i].CONFIG = (uint16_t)CONFIG_CLOCK_SETTING[i] | (uint16_t)CONFIG_SW_MODE[i] | \ (uint16_t)CONFIG_VS_COMP[i] | \ (uint16_t)CONFIG_OC_SD[i] | \ (uint16_t)CONFIG_UVLOVAL[i] | \ (uint16_t)CONFIG_VCCVAL[i] | \ (uint16_t)CONFIG_PWM_DIV[i] | \ (uint16_t)CONFIG_PWM_MUL[i]; cSPIN_RegsStructArray[i].OCD_TH = OCD_TH[i]; cSPIN_RegsStructArray[i].ALARM_EN = ALARM_EN[i]; cSPIN_RegsStructArray[i].STEP_MODE = (uint8_t)SYNC_MODE[i] | (uint8_t)STEP_MODE[i]; cSPIN_RegsStructArray[i].GATECFG1 = (uint16_t)GATECFG1_WD_EN[i] | \ (uint16_t)GATECFG1_TBOOST[i] | \ (uint16_t)GATECFG1_IGATE[i] | \ (uint16_t)GATECFG1_TCC[i]; cSPIN_RegsStructArray[i].GATECFG2 = (uint16_t)GATECFG2_TBLANK[i] | \ (uint16_t)GATECFG2_TDT[i]; } /* Program all cSPIN registers of All Devices */ cSPIN_All_Slaves_Registers_Set(number_of_slaves, &cSPIN_RegsStructArray[0]); /* Get status of all devices, clear FLAG pin */ cSPIN_All_Slaves_Get_Status(number_of_slaves, responseArray); #endif // // Loop forever echoing data through the UART. // while(1) { UARTprintf("\n>"); // // Peek to see if a full command is ready for processing // while(UARTPeek('\r') == -1) { // // millisecond delay. A SysCtlSleep() here would also be OK. // SysCtlDelay(SysCtlClockGet() / (1000 / 3)); // // Check for change of mode and enter hibernate if requested. // all other mode changes handled in interrupt context. // //if(g_sAppState.ui32Mode == APP_MODE_HIB) //{ // AppHibernateEnter(); //} } // // a '\r' was detected get the line of text from the user. // UARTgets(g_cInput,sizeof(g_cInput)); // // Pass the line from the user to the command processor. // It will be parsed and valid commands executed. // i32CommandStatus = CmdLineProcess(g_cInput); // // Handle the case of bad command. // if(i32CommandStatus == CMDLINE_BAD_CMD) { UARTprintf("Bad command!\n"); } // // Handle the case of too many arguments. // else if(i32CommandStatus == CMDLINE_TOO_MANY_ARGS) { UARTprintf("Too many arguments for command processor!\n"); } } }
//***************************************************************************** // // The program main function. It performs initialization, then handles wav // file playback. // //***************************************************************************** int main(void) { int nStatus; // // Set the system clock to run at 80MHz from the PLL. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Give bget some memory to work with. // bpool(g_pulHeap, sizeof(g_pulHeap)); // // Set the device pin out appropriately for this board. // PinoutSet(); // // Configure the relevant pins such that UART0 owns them. // ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // Open the UART for I/O // UARTStdioInit(0); UARTprintf("i2s_speex_enc\n"); // // Configure and enable uDMA // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); SysCtlDelay(10); ROM_uDMAControlBaseSet(&sDMAControlTable[0]); ROM_uDMAEnable(); // // Enable Interrupts // ROM_IntMasterEnable(); // // Configure the I2S peripheral. // SoundInit(1); // // Set the format of the play back in the sound driver. // SoundSetFormat(AUDIO_RATE, AUDIO_BITS, AUDIO_CHANNELS); // // Print out some header information to the serial console. // UARTprintf("\ni2s_speex_enc Stellaris Example\n"); UARTprintf("Streaming at %d %d bit ",SoundSampleRateGet(), AUDIO_BITS); if(AUDIO_CHANNELS == 2) { UARTprintf("Stereo\n"); } else { UARTprintf("Mono\n"); } // // Set the initial volume. // SoundVolumeSet(INITIAL_VOLUME_PERCENT); // // Initialize the Speex decoder. // SpeexDecodeInit(); // // Set the default quality to 2. // g_iQuality = 2; // // Initialize the Speex encoder to Complexity of 1 and Quality 2. // SpeexEncodeInit(AUDIO_RATE, 1, g_iQuality); // // Initialize the audio buffers. // InitBuffers(); // // Initialize the applications global state flags. // g_ulFlags = 0; // // Kick off a request for a buffer play back and advance the encoder // pointer. // SoundBufferRead(g_pucRecBuffer, RECORD_BUFFER_INC, RecordBufferCallback); g_pucEncode += RECORD_BUFFER_INC; // // Kick off a second request for a buffer play back and advance the encode // pointer. // SoundBufferRead(&g_pucRecBuffer[RECORD_BUFFER_INC], RECORD_BUFFER_INC, RecordBufferCallback); g_pucEncode += RECORD_BUFFER_INC; // // The rest of the handling occurs at interrupt time so the main loop will // simply stall here. // while(1) { // // Print a prompt to the console. Show the CWD. // UARTprintf("\n> "); // // Get a line of text from the user. // UARTgets(g_cCmdBuf, sizeof(g_cCmdBuf)); // // Pass the line from the user to the command processor. // It will be parsed and valid commands executed. // nStatus = CmdLineProcess(g_cCmdBuf); // // Handle the case of bad command. // if(nStatus == CMDLINE_BAD_CMD) { UARTprintf("Bad command!\n"); } // // Handle the case of too many arguments. // else if(nStatus == CMDLINE_TOO_MANY_ARGS) { UARTprintf("Too many arguments for command processor!\n"); } // // Otherwise the command was executed. Print the error // code if one was returned. // else if(nStatus != 0) { UARTprintf("Command returned error code \n"); } } }
//***************************************************************************** // // Main function performs init and manages system. // // Called automatically after the system and compiler pre-init sequences. // Performs system init calls, restores state from hibernate if needed and // then manages the application context duties of the system. // //***************************************************************************** int main(void) { uint32_t ui32Status; uint32_t ui32ResetCause; int32_t i32CommandStatus; // // Enable stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // ROM_FPUEnable(); ROM_FPUStackingEnable(); // // Set the system clock to run at 40Mhz off PLL with external crystal as // reference. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); // // Enable the hibernate module // SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE); // // Enable and Initialize the UART. // ConfigureUART(); UARTprintf("Welcome to the Tiva C Series TM4C123G LaunchPad!\n"); UARTprintf("Type 'help' for a list of commands\n"); UARTprintf("> "); // // Determine why system reset occurred and respond accordingly. // ui32ResetCause = SysCtlResetCauseGet(); SysCtlResetCauseClear(ui32ResetCause); if(ui32ResetCause == SYSCTL_CAUSE_POR) { if(HibernateIsActive()) { // // Read the status bits to see what caused the wake. // ui32Status = HibernateIntStatus(0); HibernateIntClear(ui32Status); // // Wake was due to the push button. // if(ui32Status & HIBERNATE_INT_PIN_WAKE) { UARTprintf("Hibernate Wake Pin Wake Event\n"); UARTprintf("> "); // // Recover the application state variables from battery backed // hibernate memory. Set ui32Mode to normal. // HibernateDataGet((uint32_t*) &g_sAppState, sizeof(tAppState) / 4 + 1); g_sAppState.ui32Mode = APP_MODE_NORMAL; } // // Wake was due to RTC match // else if(ui32Status & HIBERNATE_INT_RTC_MATCH_0) { UARTprintf("Hibernate RTC Wake Event\n"); UARTprintf("> "); // // Recover the application state variables from battery backed // hibernate memory. Set ui32Mode to briefly flash the RGB. // HibernateDataGet((uint32_t*) &g_sAppState, sizeof(tAppState) / 4 + 1); g_sAppState.ui32Mode = APP_MODE_HIB_FLASH; } } else { // // Reset was do to a cold first time power up. // UARTprintf("Power on reset. Hibernate not active.\n"); UARTprintf("> "); g_sAppState.ui32Mode = APP_MODE_NORMAL; g_sAppState.fColorWheelPos = 0; g_sAppState.fIntensity = APP_INTENSITY_DEFAULT; g_sAppState.ui32Buttons = 0; } } else { // // External Pin reset or other reset event occured. // UARTprintf("External or other reset\n"); UARTprintf("> "); // // Treat this as a cold power up reset without restore from hibernate. // g_sAppState.ui32Mode = APP_MODE_NORMAL; g_sAppState.fColorWheelPos = APP_PI; g_sAppState.fIntensity = APP_INTENSITY_DEFAULT; g_sAppState.ui32Buttons = 0; // // colors get a default initialization later when we call AppRainbow. // } // // Initialize clocking for the Hibernate module // HibernateEnableExpClk(SysCtlClockGet()); // // Initialize the RGB LED. AppRainbow typically only called from interrupt // context. Safe to call here to force initial color update because // interrupts are not yet enabled. // RGBInit(0); RGBIntensitySet(g_sAppState.fIntensity); AppRainbow(1); RGBEnable(); // // Initialize the buttons // ButtonsInit(); // // Initialize the SysTick interrupt to process colors and buttons. // SysTickPeriodSet(SysCtlClockGet() / APP_SYSTICKS_PER_SEC); SysTickEnable(); SysTickIntEnable(); IntMasterEnable(); // // spin forever and wait for carriage returns or state changes. // while(1) { UARTprintf("\n>"); // // Peek to see if a full command is ready for processing // while(UARTPeek('\r') == -1) { // // millisecond delay. A SysCtlSleep() here would also be OK. // SysCtlDelay(SysCtlClockGet() / (1000 / 3)); // // Check for change of mode and enter hibernate if requested. // all other mode changes handled in interrupt context. // if(g_sAppState.ui32Mode == APP_MODE_HIB) { AppHibernateEnter(); } } // // a '\r' was detected get the line of text from the user. // UARTgets(g_cInput,sizeof(g_cInput)); // // Pass the line from the user to the command processor. // It will be parsed and valid commands executed. // i32CommandStatus = CmdLineProcess(g_cInput); // // Handle the case of bad command. // if(i32CommandStatus == CMDLINE_BAD_CMD) { UARTprintf("Bad command!\n"); } // // Handle the case of too many arguments. // else if(i32CommandStatus == CMDLINE_TOO_MANY_ARGS) { UARTprintf("Too many arguments for command processor!\n"); } } }
void handleCommMessage(void){ char buffer[COMM_BUFFER_SIZE]; unsigned char function_code = 0; long i; buffer[64]=0; buffer[79]=0; UARTgets((uint8*)buffer, COMM_BUFFER_SIZE); //UARTgetMessage(buffer); //UARTprintf("MESSAGE GET!!%s\r\n", buffer); if(isValidMessage(buffer)) { for(i = 0; i < CODE_LENGTH; i++) //generate hash of function code { function_code ^= buffer[CODE_START + i]; } switch(function_code) { case SPLM: //JoystickXOut(SATURATE(atoi(&buffer[DATA_START]),0,255)); //UARTprintf("GOOD MESSAGE- SVXA: %s\r\n", buffer); SetLeftMotor(SATURATE(atoi(&buffer[DATA_START]),-128,127)); VelCtrlRunning = 0; ResetWatchdog(); //we got a valid message, so they are still talking to us break; case SPRM: //JoystickYOut(SATURATE(atoi(&buffer[DATA_START]),0,255)); //UARTprintf("GOOD MESSAGE- SVYA: %s\r\n", buffer); SetRightMotor(SATURATE(atoi(&buffer[DATA_START]),-128,127)); VelCtrlRunning = 0; ResetWatchdog(); //we got a valid message, so they are still talking to us break; case SAHS: SetHokuyoServo(SATURATE(atoi(&buffer[DATA_START]),-128,127)); break; case SVLX: UpdateLinearX(atoi(&buffer[DATA_START])); ResetWatchdog(); VelCtrlRunning = 1; break; case SVAZ: UpdateAngularZ(atoi(&buffer[DATA_START])); VelCtrlRunning = 1; ResetWatchdog(); break; case ETFM: EnableSensorFeedbackMessages = 1; break; case DTFM: EnableSensorFeedbackMessages = 0; break; case RSTE: ResetEncoders(); break; case STMR: if(1000 % atoi(&buffer[DATA_START]) == 0) SetMessageRate(atoi(&buffer[DATA_START])); else UARTprintf("INVALID MESSAGE RATE (1000%rate must = 0): %s", buffer); break; case SETT: SetTime(atoi(&buffer[DATA_START])); break; case EHST: EnableHokuyoTilting(); break; case DHST: DisableHokuyoTilting(); break; case SHTR: if(1000 % atoi(&buffer[DATA_START]) == 0) SetHokuyoTiltRate(atoi(&buffer[DATA_START])); else UARTprintf("INVALID RATE (1000%rate must = 0): %s", buffer); break; case SACD: SetAccelDivisor(atoi(&buffer[DATA_START])); break; /*case FLPC: Servo_0_WriteCompare1(atoi(&buffer[DATA_START])); break; case FRPC: Servo_0_WriteCompare2(atoi(&buffer[DATA_START])); break;*/ default: UARTprintf("UNRECOGNIZED MESSAGE: %s\r\n", buffer); break; } } else { UARTprintf("INVALID START CHARACTER: %s\r\n", buffer); } }
//***************************************************************************** // // Main application entry function. // //***************************************************************************** int main(void) { int nStatus; // // Set the system clock to run at 50MHz from the PLL // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Set the default pinout (and query any daughter board that may be // there already. This has the side-effect of initializing the I2C // controller for us too. // PinoutSet(); // // Enable UART0. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // Initialize the UART standard I/O. // UARTStdioInit(0); UARTprintf("\n\nDaughter Board ID EEPROM Read/Write\n"); UARTprintf( "-----------------------------------\n\n"); UARTprintf("Use this tool to read or repair the information stored\n"); UARTprintf("in the 128 byte ID EEPROM on optional development kit\n"); UARTprintf("daughter boards.\n"); // // Output our help screen. // Cmd_help(0, 0); // // Tell the user which daughter board we have detected. // UARTprintf("\nCurrent daughter board: "); switch(g_eDaughterType) { case DAUGHTER_NONE: { UARTprintf("None or SDRAM\n"); break; } case DAUGHTER_SRAM_FLASH: case DAUGHTER_FPGA: case DAUGHTER_EM2: { UARTprintf(g_pcIDNames[g_eDaughterType - 1]); break; } default: { UARTprintf("Unrecognized\n"); break; } } // // // Fall into the command line processing loop. // while (1) { // // Print a prompt to the console // UARTprintf("\n> "); // // Get a line of text from the user. // UARTgets(g_cCmdBuf, sizeof(g_cCmdBuf)); // // Pass the line from the user to the command processor. // It will be parsed and valid commands executed. // nStatus = CmdLineProcess(g_cCmdBuf); // // Handle the case of bad command. // if(nStatus == CMDLINE_BAD_CMD) { UARTprintf("Bad command!\n"); } // // Handle the case of too many arguments. // else if(nStatus == CMDLINE_TOO_MANY_ARGS) { UARTprintf("Too many arguments for command processor!\n"); } } }