/* * send acc. data to uart 3 */ void sendAcclData(void) { readAccel(); int aMagnitude = abs(Ax) + abs(Ay) + abs(Az); short b; unsigned char accl[20]; accl[19] = '\0'; b = usprintf((char*) accl, "%i,%i,%i\n", Ax, Ay, Az); #ifndef wlan nrf24l01p_send(accl); #else for (int i = 0; i < b; i++) { ROM_UARTCharPut(UART3_BASE, accl[i]); } //ROM_UARTCharPut(UART3_BASE, '\n'); #endif b = usprintf((char*) accl, "%i\n", aMagnitude); #ifndef wlan nrf24l01p_send(accl); #else for (int i = 0; i < b; i++) { ROM_UARTCharPut(UART3_BASE, accl[i]); } //ROM_UARTCharPut(UART3_BASE, '\n'); #endif }
void Terminal_Write(const char *buffer, unsigned int ui32Count) { unsigned int i = 0; if(ui32Count) { for(i = 0; i < ui32Count; i++) { ROM_UARTCharPut(UART0_BASE, buffer[i]); } } else { while(buffer[i]) { ROM_UARTCharPut(UART0_BASE, buffer[i]); i++; } } }
void Terminal_Writeln(const char *buffer, unsigned int ui32Count) { if(ui32Count) { while(ui32Count--) { ROM_UARTCharPut(UART0_BASE, *buffer++); } } else { while(*buffer) { ROM_UARTCharPut(UART0_BASE, *buffer++); } } ROM_UARTCharPut(UART0_BASE, '\r'); }
void UART_printstr(char *str) { uint16_t i=0; while (str[i] != '\0') { ROM_UARTCharPut(UART0_BASE, str[i++]); } }
//***************************************************************************** // // Function that is registered with the Bluetooth system (via call to // BTPS_Init()) for debugging. This function will be called back for each // character that is to be output to the debug terminal. // //***************************************************************************** static void BTPSAPI MessageOutputCallback(char cDebugCharacter) { // // Simply output the debug character. // ROM_UARTCharPut(UART0_BASE, cDebugCharacter); }
void uart_write(uart_t uart, const uint8_t *data, size_t len) { /*The base address of the chosen UART */ unsigned long ulBase = g_ulUARTBase[uart]; for (size_t i = 0; i < len; i++) { ROM_UARTCharPut(ulBase, (char)data[i]); } }
void throttleReset() { uint8_t msg[3]; int i; msg[0] = START_BYTE; msg[1] = RESET_CMD; msg[2] = 0; for (i=0;i<3;i++) ROM_UARTCharPut(UART_THROTTLE,msg[i]); }
void throttleStop() { //truyen uart qua uint8_t msg[3]; int i; msg[0] = START_BYTE; msg[1] = STOP_CMD; msg[2] = 0; for (i=0;i<3;i++) ROM_UARTCharPut(UART_THROTTLE,msg[i]); //SetPWM_Servo_Throttle(PWM_THROTTLE,setPoint); }
//***************************************************************************** // // Send a string to the UART. // //***************************************************************************** void UARTSend(const uint8_t *pui8Buffer, uint32_t ui32Count) { // // Loop while there are more characters to send. // while(ui32Count--) { // // Write the next character to the UART. // ROM_UARTCharPut(UART0_BASE, *pui8Buffer++); //Method changed to ROM_UARTCharPut to block when buffer is full } }
/* * send calculated heading to uart3 */ void sendHeading(void) { short b; char accl[20]; accl[19] = '\0'; b = usprintf(accl, "$HEAD,%i*\n", (int) getHeading()); //$HEAD,value* #ifndef wlan nrf24l01p_send(accl); #else for (int i = 0; i < b && accl[i] != '\0'; i++) { ROM_UARTCharPut(UART3_BASE, accl[i]); } #endif }
/* * send mag. values to uart 3 */ void sendMagnetoData(void) { readMagneto(); short b; unsigned char mag[20]; mag[19] = '\0'; b = usprintf((char*) mag, "%i,%i,%i\n", Mx, My, Mz); #ifndef wlan nrf24l01p_send(mag); #else for (int i = 0; i < b; i++) { ROM_UARTCharPut(UART3_BASE, mag[i]); } #endif }
/* * UARTSend sends a string to the specified UART module. * The first argument is the module you'd like to send from * (UART0_BASE, UART1_BASE...). Here is an example function * call that sends "Enter text: " through UART2: * UARTSend(UART2_BASE, (char *)"Enter text: "); */ void UARTSendOptode(unsigned long ulBase, const char *pucBuffer) { //ulCount is the length of the passed in string unsigned long ulCount; ulCount = strlen(pucBuffer); // Loop while there are more characters to send. while(ulCount--) { // Write the next character to the UART. ROM_UARTCharPut(ulBase, *pucBuffer++); } }
void throttleSet(int32_t setPoint) { //truyen uart qua uint8_t msg[7]; int i; msg[0] = START_BYTE; msg[1] = SETPOINT_CMD; msg[2] = 4; msg[3] = setPoint; msg[4] = setPoint>>8; msg[5] = setPoint>>16; msg[6] = setPoint>>24; for (i=0;i<7;i++) ROM_UARTCharPut(UART_THROTTLE,msg[i]); //SetPWM_Servo_Throttle(PWM_THROTTLE,setPoint); }
void UART4Send(const uint8_t *pui8Buffer, uint32_t ui32Count) { // // Loop while there are more characters to send. // int i; for (i = 0; i < ui32Count; i++) { // // Write the next character to the UART. // ROM_UARTCharPut(UART4_BASE, pui8Buffer[i]); //UARTprintf("%02x ", pui8Buffer[i]); } //UARTprintf("\n>"); }
int CLI_Write(unsigned char *inBuff) { if(inBuff == NULL) return -1; #ifdef _USE_CLI_ unsigned short ret = 0; unsigned short usLength = strlen((const char *)inBuff); ret = usLength; while (usLength) { ROM_UARTCharPut(UART0_BASE, *inBuff); usLength--; inBuff++; } return (int)ret; #else return 0; #endif }
void throttleHome() { uint8_t msg[3]; int i; if (!LIMIT_SW_THROTTLE_DOWN_ON) { ROM_TimerIntDisable(WTIMER2_BASE, TIMER_CAPB_EVENT);//disable manual mode msg[0] = START_BYTE; msg[1] = HOME_CMD; msg[2] = 0; for (i=0;i<3;i++) ROM_UARTCharPut(UART_THROTTLE,msg[i]); ROM_TimerLoadSet(TIMER2_BASE, TIMER_A,ROM_SysCtlClockGet()*5); ROM_TimerEnable(TIMER2_BASE, TIMER_A); while ((!LIMIT_SW_THROTTLE_DOWN_ON) && (!flagTimeout)); ROM_TimerIntEnable(WTIMER2_BASE, TIMER_CAPB_EVENT); } }
//print a string out to the console starting from the current cursor location //only print the specified amount of characters void con_nprintf(char *str, int size) { int i; for(i = 0; i < size; i++) { ROM_UARTCharPut(UART0_BASE, str[i]); } }
//print a string out to the console starting from the current cursor location void con_printf(char *str) { int i; for(i = 0; i < strlen(str); i++) { ROM_UARTCharPut(UART0_BASE, str[i]); } }
//clear the console contents and place the cursor in the upper left corner void con_clear() { ROM_UARTCharPut(UART0_BASE, 0x0C); }
//***************************************************************************** // // The UART interrupt handler. // //***************************************************************************** void UARTIntHandler(void) { uint32_t ui32Status; // // Get the interrrupt status. // ui32Status = ROM_UARTIntStatus(UART0_BASE, true); // // Clear the asserted interrupts. // ROM_UARTIntClear(UART0_BASE, ui32Status); // // Loop while there are characters in the receive FIFO. // while(ROM_UARTCharsAvail(UART0_BASE)) { // // Delay for 1 millisecond. Each SysCtlDelay is about 3 clocks. // SysCtlDelay(g_ui32SysClock / (1000 * 3)); buffer[location] = ROM_UARTCharGetNonBlocking(UART0_BASE); //Place next character into the buffer array if (location == 0 && (buffer[0] == 27 || buffer[0] == '\r')) //Check for the <ESC> or <ENTER> character { UARTPrompt(); //Prompt the user again } else { location = location + 1; //Increase the array index ROM_UARTCharPut(UART0_BASE, buffer[location-1]); //Echo last character on screen if (buffer[location - 1] == 27 || buffer[location - 1] == '\r') //Check for the <ESC> or <ENTER> character { buffer[location - 1] = '\0'; //Replace last character with a null char UARTSend("\033[2J\033[12;30H", 12); //Clear screen and move cursor to middle-ish UARTSend(buffer, location); //Use UARTSend() to print contents of buffer location = 0; //Reset array index } } // // Blink the LED to show a character transfer is occuring. // GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, GPIO_PIN_0); // // Delay for 1 millisecond. Each SysCtlDelay is about 3 clocks. // SysCtlDelay(g_ui32SysClock / (1000 * 3)); // // Turn off the LED // GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0); } }
void UART_printchars(char *str, uint16_t count) { for (uint16_t i=0; i < count; i++) ROM_UARTCharPut(UART0_BASE, str[i]); }
static void serial_output_hexdig(uint32_t dig) { ROM_UARTCharPut(UART0_BASE, (dig >= 10 ? 'A' - 10 + dig : '0' + dig)); }
void uart_write(uart_t uart, const uint8_t *data, size_t len) { for (size_t i = 0; i < len; i++) { ROM_UARTCharPut(UART0_BASE, (char)data[i]); } }
//***************************************************************************** // // Toggle a GPIO. // //***************************************************************************** int main(void) { // 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); // // Enable the peripherals used by this example. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART2); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART3); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART4); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART5); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART6); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART7); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // Enable processor interrupts. ROM_IntMasterEnable(); //ROM_GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_5); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_6); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_7); //ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2); //ROM_GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_7); //ROM_GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_5); //* //ROM_GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_0); // RTS0 //ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_0); // RTS1 //ROM_GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_2); // RTS2 //ROM_GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_3); // RTS3 ROM_GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_4); // RTS4 //ROM_GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_5); // RTS5 //ROM_GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_6); // RTS6 //ROM_GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_7); // RTS7 //*/ // GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); GPIOPinConfigure(GPIO_PB0_U1RX); GPIOPinConfigure(GPIO_PB1_U1TX); ROM_GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1); ROM_UARTConfigSetExpClk(UART1_BASE, ROM_SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); GPIOPinConfigure(GPIO_PD6_U2RX); HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY_DD; HWREG(GPIO_PORTD_BASE + GPIO_O_CR) = 0xFF; GPIOPinConfigure(GPIO_PD7_U2TX); HWREG(GPIO_PORTD_BASE + GPIO_O_CR) = 0x7F; HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = GPIO_LOCK_M; ROM_GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_6 | GPIO_PIN_7); ROM_UARTConfigSetExpClk(UART2_BASE, ROM_SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); GPIOPinConfigure(GPIO_PC6_U3RX); GPIOPinConfigure(GPIO_PC7_U3TX); ROM_GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_6 | GPIO_PIN_7); ROM_UARTConfigSetExpClk(UART3_BASE, ROM_SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); GPIOPinConfigure(GPIO_PC4_U4RX); GPIOPinConfigure(GPIO_PC5_U4TX); ROM_GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_5); ROM_UARTConfigSetExpClk(UART4_BASE, ROM_SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); GPIOPinConfigure(GPIO_PE4_U5RX); HWREG(GPIO_PORTE_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY_DD; HWREG(GPIO_PORTE_BASE + GPIO_O_CR) = 0xFF; GPIOPinConfigure(GPIO_PE5_U5TX); HWREG(GPIO_PORTD_BASE + GPIO_O_CR) = 0xDF; HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = GPIO_LOCK_M; ROM_GPIOPinTypeUART(GPIO_PORTE_BASE, GPIO_PIN_4 | GPIO_PIN_5); ROM_UARTConfigSetExpClk(UART5_BASE, ROM_SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); GPIOPinConfigure(GPIO_PD4_U6RX); GPIOPinConfigure(GPIO_PD5_U6TX); ROM_GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_4 | GPIO_PIN_5); ROM_UARTConfigSetExpClk(UART6_BASE, ROM_SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); GPIOPinConfigure(GPIO_PE0_U7RX); GPIOPinConfigure(GPIO_PE1_U7TX); ROM_GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1); ROM_UARTConfigSetExpClk(UART7_BASE, ROM_SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); ROM_SysCtlDelay(4000000); /* ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0, GPIO_PIN_0); // RTS0 ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_PIN_0); // RTS1 ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_2, GPIO_PIN_2); // RTS2 ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_3, GPIO_PIN_3); // RTS3 ROM_GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_4, GPIO_PIN_4); // RTS4 ROM_GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_5, GPIO_PIN_5); // RTS5 ROM_GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_6, GPIO_PIN_6); // RTS6 ROM_GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_7, GPIO_PIN_7); // RTS7 //*/ while(1){ ROM_UARTCharPut(UART0_BASE, 0x55); //ROM_UARTCharPut(UART1_BASE, 0x55); ROM_UARTCharPut(UART2_BASE, 0x55); ROM_UARTCharPut(UART3_BASE, 0x55); ROM_UARTCharPut(UART4_BASE, 0x55); ROM_UARTCharPut(UART5_BASE, 0x55); ROM_UARTCharPut(UART6_BASE, 0x55); ROM_UARTCharPut(UART7_BASE, 0x55); //ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2); //ROM_GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_4, 0xFF); // RTS4 ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_6, GPIO_PIN_6); ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_7, 0); ROM_SysCtlDelay(1000000); //ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0); ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_6, 0); ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_7, GPIO_PIN_7); //ROM_GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_4, 0); // RTS4 ROM_SysCtlDelay(100000); } // Prompt for text to be entered. UARTSend(UART1_BASE, (uint8_t *)"\033[2JEnter text: ", 16); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_5); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_6); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_7); ROM_GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_5, GPIO_PIN_5); // Enable the UART interrupt. ROM_IntEnable(INT_UART1); ROM_UARTIntEnable(UART1_BASE, UART_INT_RX | UART_INT_RT); ROM_IntEnable(INT_UART5); ROM_UARTIntEnable(UART5_BASE, UART_INT_RX | UART_INT_RT); // // Loop forever. // while(1) { // Set the GPIO high. ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_6, GPIO_PIN_6); ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_7, 0); ROM_UARTCharPut(UART5_BASE, 0x55); UARTSend(UART5_BASE, (uint8_t *)"\033[2JEnter text: ", 16); // Delay for a while. ROM_SysCtlDelay(4000000); // Set the GPIO low. ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_6, 0); ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_7, GPIO_PIN_7); //ROM_UARTCharPut(UART5_BASE, 0x55); // Delay for a while. ROM_SysCtlDelay(1000000); } }
void uartBt_send(unsigned char *data, unsigned long size) { while(size--) { ROM_UARTCharPut(UARTBT_BASE, *data++); } }
void con_putchar(char c) { ROM_UARTCharPut(UART0_BASE, c); }
void UARTputc(uint8_t UART, char c) { ROM_UARTCharPut(UARTBASE[UART], c); }
//***************************************************************************** // // Handles interrupts from the UART. // //***************************************************************************** void UART0IntHandler(void) { unsigned long ulStatus; unsigned char ucChar; // // Get the interrupts that are being asserted by the UART. // ulStatus = ROM_UARTIntStatus(UART0_BASE, true); // // Clear the asserted interrupts. // ROM_UARTIntClear(UART0_BASE, ulStatus); // // Indicate that the UART link is good. // ControllerLinkGood(LINK_TYPE_UART); // // See if the receive interrupt has been asserted. // if(ulStatus & (UART_INT_RX | UART_INT_RT)) { // // Loop while there are more characters to be read from the UART. // while(ROM_UARTCharsAvail(UART0_BASE)) { // // Read the next character from the UART. // ucChar = ROM_UARTCharGet(UART0_BASE); // // See if this is a start of packet byte. // if(ucChar == 0xff) { // // Reset the length of the UART message. // g_ulUARTLength = 0; // // Set the state such that the next byte received is the size // of the message. // g_ulUARTState = UART_STATE_LENGTH; } // // See if this byte is the size of the message. // else if(g_ulUARTState == UART_STATE_LENGTH) { // // Save the size of the message. // g_ulUARTSize = ucChar; // // Subsequent bytes received are the message data. // g_ulUARTState = UART_STATE_DATA; } // // See if the previous character was an escape character. // else if(g_ulUARTState == UART_STATE_ESCAPE) { // // See if this 0xfe, the escaped version of 0xff. // if(ucChar == 0xfe) { // // Store a 0xff in the message buffer. // g_pucUARTMessage[g_ulUARTLength++] = 0xff; // // Subsequent bytes received are the message data. // g_ulUARTState = UART_STATE_DATA; } // // Otherwise, see if this is 0xfd, the escaped version of 0xfe. // else if(ucChar == 0xfd) { // // Store a 0xfe in the message buffer. // g_pucUARTMessage[g_ulUARTLength++] = 0xfe; // // Subsequent bytes received are the message data. // g_ulUARTState = UART_STATE_DATA; } // // Otherwise, this is a corrupted sequence. Set the receiver // to idle so this message is dropped, and subsequent data is // ignored until another start of packet is received. // else { g_ulUARTState = UART_STATE_IDLE; } } // // See if this is a part of the message data. // else if(g_ulUARTState == UART_STATE_DATA) { // // See if this character is an escape character. // if(ucChar == 0xfe) { // // The next byte is an escaped byte. // g_ulUARTState = UART_STATE_ESCAPE; } else { // // Store this byte in the message buffer. // g_pucUARTMessage[g_ulUARTLength++] = ucChar; } } // // See if the entire message has been received but has not been // processed (i.e. the most recent byte received was the end of the // message). // if((g_ulUARTLength == g_ulUARTSize) && (g_ulUARTState == UART_STATE_DATA)) { // // Process this message. // UARTIFCommandHandler(); // // The UART interface is idle, meaning all bytes will be // dropped until the next start of packet byte. // g_ulUARTState = UART_STATE_IDLE; } } // // Tell the controller that CAN activity was detected. // ControllerWatchdog(LINK_TYPE_UART); } // // See if the transmit interrupt has been asserted. // if(ulStatus & UART_INT_TX) { // // Loop while there are more characters to be transmitted and more // space in the UART FIFO. // while((g_ulUARTXmitRead != g_ulUARTXmitWrite) && ROM_UARTSpaceAvail(UART0_BASE)) { // // Put the next character into the UART FIFO. // ROM_UARTCharPut(UART0_BASE, g_pucUARTXmit[g_ulUARTXmitRead]); // // Increment the read pointer. // g_ulUARTXmitRead = (g_ulUARTXmitRead + 1) % UART_XMIT_SIZE; } } // // See if an enumeration response needs to be sent. // if(HWREGBITW(&g_ulUARTFlags, UART_FLAG_ENUM) != 0) { // // Send the enumeration response for this device. // UARTIFSendMessage(CAN_MSGID_API_ENUMERATE | g_sParameters.ucDeviceNumber, 0, 0); // // Clear the enumeration response flag. // HWREGBITW(&g_ulUARTFlags, UART_FLAG_ENUM) = 0; } // // See if periodic status messages need to be sent. // if(HWREGBITW(&g_ulUARTFlags, UART_FLAG_PSTATUS) != 0) { // // Send out the first periodic status message if it needs to be sent. // if(g_ulPStatFlags & 1) { UARTIFSendMessage(LM_API_PSTAT_DATA_S0 | g_sParameters.ucDeviceNumber, g_ppucPStatMessages[0], g_pucPStatMessageLen[0]); } // // Send out the second periodic status message if it needs to be sent. // if(g_ulPStatFlags & 2) { UARTIFSendMessage(LM_API_PSTAT_DATA_S1 | g_sParameters.ucDeviceNumber, g_ppucPStatMessages[1], g_pucPStatMessageLen[1]); } // // Send out the third periodic status message if it needs to be sent. // if(g_ulPStatFlags & 4) { UARTIFSendMessage(LM_API_PSTAT_DATA_S2 | g_sParameters.ucDeviceNumber, g_ppucPStatMessages[2], g_pucPStatMessageLen[2]); } // // Send out the fourth periodic status message if it needs to be sent. // if(g_ulPStatFlags & 8) { UARTIFSendMessage(LM_API_PSTAT_DATA_S3 | g_sParameters.ucDeviceNumber, g_ppucPStatMessages[3], g_pucPStatMessageLen[3]); } // // Clear the periodic status message flag. // HWREGBITW(&g_ulUARTFlags, UART_FLAG_PSTATUS) = 0; } }
//***************************************************************************** // // Sends a character to the UART. // //***************************************************************************** static void UARTIFPutChar(unsigned long ulChar) { // // See if the character being sent is 0xff. // if(ulChar == 0xff) { // // Send 0xfe 0xfe, the escaped version of 0xff. A sign extended // version of 0xfe is used to avoid the check below for 0xfe, thereby // avoiding an infinite loop. Only the lower 8 bits are actually sent, // so 0xfe is what is actually transmitted. // UARTIFPutChar(0xfffffffe); UARTIFPutChar(0xfffffffe); } // // Otherwise, see if the character being sent is 0xfe. // else if(ulChar == 0xfe) { // // Send 0xfe 0xfd, the escaped version of 0xfe. A sign extended // version of 0xfe is used to avoid the check above for 0xfe, thereby // avoiding an infinite loop. Only the lower 8 bits are actually sent, // so 0xfe is what is actually transmitted. // UARTIFPutChar(0xfffffffe); UARTIFPutChar(0xfd); } // // Otherwise, simply send this character. // else { // // Disable the UART interrupt to avoid having characters stick in the // local buffer. // ROM_UARTIntDisable(UART0_BASE, UART_INT_TX); // // See if the local buffer is empty and there is space available in the // UART FIFO. // if((g_ulUARTXmitRead == g_ulUARTXmitWrite) && ROM_UARTSpaceAvail(UART0_BASE)) { // // Simply write this character into the UART FIFO. // ROM_UARTCharPut(UART0_BASE, ulChar); } else { // // Write this character into the local buffer. // g_pucUARTXmit[g_ulUARTXmitWrite] = ulChar; // // Increment the local write buffer pointer. // g_ulUARTXmitWrite = (g_ulUARTXmitWrite + 1) % UART_XMIT_SIZE; } // // Re-enable the UART interrupt. // ROM_UARTIntEnable(UART0_BASE, UART_INT_TX); } }
//***************************************************************************** // // Main cap-touch example. // //***************************************************************************** int main(void) { uint8_t ui8CenterButtonTouched; uint32_t ui32WheelTouchCounter; uint8_t ui8ConvertedWheelPosition; uint8_t ui8GestureDetected; uint8_t ui8Loop; // // 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_FPULazyStackingEnable(); // // Set the clocking to run directly from the PLL at 80 MHz. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); // // Initialize a few GPIO outputs for the LEDs // ROM_GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_4); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_5); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_4); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_6); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_7); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_5); // // Turn on the Center LED // ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5, GPIO_PIN_5); // // Initialize the UART. // ROM_GPIOPinConfigure(GPIO_PA0_U0RX); ROM_GPIOPinConfigure(GPIO_PA1_U0TX); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTStdioConfig(0, 9600, ROM_SysCtlClockGet()); // // Configure the pins needed for capacitive touch sensing. The capsense // driver assumes that these pins are already configured, and that they // will be accessed through the AHB bus // SysCtlGPIOAHBEnable(SYSCTL_PERIPH_GPIOA); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTA_AHB_BASE, GPIO_PIN_2); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTA_AHB_BASE, GPIO_PIN_3); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTA_AHB_BASE, GPIO_PIN_4); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTA_AHB_BASE, GPIO_PIN_6); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTA_AHB_BASE, GPIO_PIN_7); // // Start up Systick to measure time. This is also required by the capsense // drivers. // ROM_SysTickPeriodSet(0x00FFFFFF); ROM_SysTickEnable(); // // Set the baseline capacitance measurements for our wheel and center // button. // TI_CAPT_Init_Baseline(&g_sSensorWheel); TI_CAPT_Update_Baseline(&g_sSensorWheel, 10); TI_CAPT_Init_Baseline(&g_sMiddleButton); TI_CAPT_Update_Baseline(&g_sMiddleButton, 10); // // Send the "sleep" code. The TIVA C-series version of this app doesn't // actually sleep, but the MSP430-based GUI it interacts with expects to // see this code on startup, so we will provide it here. // UARTprintf("\0xDE\0xAD"); // // Send the "awake" code. // UARTprintf("\0xBE\0xEF"); // // Perform an LED startup sequence. // for(ui8Loop = 0; ui8Loop < 16; ui8Loop++) { LEDOutput(ui8Loop); DelayMs(10); } LEDOutput(0); // // Assume that the center button starts off "untouched", the wheel has no // position, and no gestures are in progress. // ui8CenterButtonTouched = 0; ui8ConvertedWheelPosition = INVALID_CONVERTED_POSITION; ui8GestureDetected = 0; // // This "wheel counter" gets incremented when a button on the wheel is held // down. Every time it hits the value of WHEEL_TOUCH_DELAY, the device // sends a signal to the GUI reporting another button press. We want this // delay normally, but we'll set the counter to just below the threshold // for now, so we'll avoid any percieved lag between the initial button // press and the first position report to the GUI. // ui32WheelTouchCounter = WHEEL_TOUCH_DELAY - 1; // // Begin the main capsense loop. // while(1) { // // Start by taking a fresh measurement from the wheel. If it remains // set to ILLEGAL_SLIDER_WHEEL_POSITION, we will know it has not been // touched at all. Otherwise we will have an updated position. // g_ui32WheelPosition = ILLEGAL_SLIDER_WHEEL_POSITION; g_ui32WheelPosition = TI_CAPT_Wheel(&g_sSensorWheel); // // If we registered a touch somewhere on the wheel, we will need to // figure out how to report that touch back to the GUI on the PC. // if(g_ui32WheelPosition != ILLEGAL_SLIDER_WHEEL_POSITION) { // // First, make sure we're not reporting center button touches while // the wheel is active. // ui8CenterButtonTouched = 0; // // We need to do a quick formatting change on the wheel position. // The "zero" postion as reported by the driver is about 40 degrees // off from "up" on the physical wheel. We'll do that correction // here. // if(g_ui32WheelPosition < 8) { g_ui32WheelPosition += 64 - 8; } else { g_ui32WheelPosition -= 8; } // // We also need to reduce the effective number of positions on the // wheel. The driver reports a wheel position from zero to // sixty-three, but the GUI only recognizes positions from zero to // sixteen. Dividing our position by four accomplishes the // necessary conversion. // g_ui32WheelPosition = g_ui32WheelPosition >> 2; // // Now that we have a properly formatted wheel position, we will // use the GetGesture function to determine whether the user has // been sliding their finger around the wheel. If so, this function // will return the magnitude and direction of the slide (Check the // function description for an example of how this is formated). // Otherwise, we will get back a zero. // ui8ConvertedWheelPosition = GetGesture(g_ui32WheelPosition); // // If the magnitude of our slide was one wheel position (of // sixteen) or less, don't register it. This prevents excessive // reporting of toggles between two adjacent wheel positions. // if((ui8GestureDetected == 0) && ((ui8ConvertedWheelPosition <= 1) || (ui8ConvertedWheelPosition == 0x11) || (ui8ConvertedWheelPosition == 0x10))) { // // If we obtained a valid wheel position last time we ran this // loop, keep our wheel position set to that instead of // updating it. This prevents a mismatch between our recorded // absolute position and our recorded swipe magnitude. // if(g_ui32PreviousWheelPosition != ILLEGAL_SLIDER_WHEEL_POSITION) { g_ui32WheelPosition = g_ui32PreviousWheelPosition; } // // Set the swipe magnitude to zero. // ui8ConvertedWheelPosition = 0; } // // We've made all of the position adjustments we're going to make, // so turn on LEDs to indicate that we've detected a finger on the // wheel. // LEDOutput(g_ui32WheelPosition); // // If the (adjusted) magnitude of the swipe we detected earlier is // valid and non-zero, we should alert the GUI that a gesture is // occurring. // if((ui8ConvertedWheelPosition != 0) && (ui8ConvertedWheelPosition != 16) && (ui8ConvertedWheelPosition != INVALID_CONVERTED_POSITION)) { // // If this is a new gesture, we will need to send the gesture // start code. // if(ui8GestureDetected == 0) { // // Remember that we've started a gesture. // ui8GestureDetected = 1; // // Transmit gesture start status update & position via UART // to PC. // ROM_UARTCharPut(UART0_BASE, GESTURE_START); ROM_UARTCharPut(UART0_BASE, (g_ui32PreviousWheelPosition + GESTURE_POSITION_OFFSET)); } // // Transmit gesture & position via UART to PC // ROM_UARTCharPut(UART0_BASE, ui8ConvertedWheelPosition); ROM_UARTCharPut(UART0_BASE, (g_ui32WheelPosition + GESTURE_POSITION_OFFSET)); } else { // // If we get here, the wheel has been touched, but there hasn't // been any sliding recently. If there hasn't been any sliding // AT ALL, then this is a "press" event, and we need to start // sending press-style updates to the PC // if(ui8GestureDetected == 0) { // // Increment our wheel counter. // ui32WheelTouchCounter = ui32WheelTouchCounter + 1; // // If the user's finger is still in the same place... // if(ui32WheelTouchCounter >= WHEEL_TOUCH_DELAY) { // // Transmit wheel position (twice) via UART to PC. // ui32WheelTouchCounter = 0; ROM_UARTCharPut(UART0_BASE, (g_ui32WheelPosition + WHEEL_POSITION_OFFSET)); ROM_UARTCharPut(UART0_BASE, (g_ui32WheelPosition + WHEEL_POSITION_OFFSET)); } } else { // // We've received a slide input somewhat recently, but not // during this loop instance. This most likely means that // the user started a gesture, but is currently just // holding their finger in one spot. This isn't really a // "press" event, so there isn't anything to report. We // should, however, make sure the touch counter is primed // for future press events. // ui32WheelTouchCounter = WHEEL_TOUCH_DELAY - 1; } } // // Regardless of all pressing, sliding, reporting, and LED events // that may have occurred, we need to record our measured // (adjusted) wheel position for reference for the next pass // through the loop. // g_ui32PreviousWheelPosition = g_ui32WheelPosition; } else { // // If we get here, there were no touches recorded on the slider // wheel. We should check our middle button to see if it has been // pressed, and clean up our recorded state to prepare for future // possible wheel-touch events. // if(TI_CAPT_Button(&g_sMiddleButton))