void UARTIsr() { //static unsigned int length = sizeof(txArray); //static unsigned int count = 0; char rxData = 0; unsigned int int_id = 0; static char *inBufferPtr = inBuffer; static char traceBuf[2] = {'\0', '\0'}; do { /* This determines the cause of UART2 interrupt.*/ int_id = UARTIntStatus(SOC_UART_2_REGS); #ifdef _TMS320C6X // Clear UART2 system interrupt in DSPINTC IntEventClear(SYS_INT_UART2_INT); #else /* Clears the system interupt status of UART2 in AINTC. */ IntSystemStatusClear(SYS_INT_UARTINT2); #endif #if 0 /* Checked if the cause is transmitter empty condition.*/ if(UART_INTID_TX_EMPTY == int_id) { if(0 < length) { /* Write a byte into the THR if THR is free. */ UARTCharPutNonBlocking(SOC_UART_2_REGS, txArray[count]); length--; count++; } if(0 == length) { /* Disable the Transmitter interrupt in UART.*/ UARTIntDisable(SOC_UART_2_REGS, UART_INT_TX_EMPTY); } } #endif /* Check if the cause is receiver data condition.*/ if(UART_INTID_RX_DATA == int_id) { rxData = UARTCharGetNonBlocking(SOC_UART_2_REGS); if (uartNewString == 0) { if (rxData == '\r') { *inBufferPtr = '\0'; uartNewString = 1; inBufferPtr = inBuffer; /* Disable the Receiver interrupt in UART.*/ //UARTIntDisable(SOC_UART_2_REGS, UART_INT_RXDATA_CTI); } else { *inBufferPtr = rxData; inBufferPtr++; if (inBufferPtr >= (inBuffer + inBufferSize)) inBufferPtr--; else { *traceBuf = rxData; trace(traceBuf); } } } //UARTCharPutNonBlocking(SOC_UART_2_REGS, rxData); } /* Check if the cause is receiver line error condition.*/ if(UART_INTID_RX_LINE_STAT == int_id) { while(UARTRxErrorGet(SOC_UART_2_REGS)) { /* Read a byte from the RBR if RBR has data.*/ UARTCharGetNonBlocking(SOC_UART_2_REGS); } } } while (int_id); return; }
static void vSerialTxCoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex ) { portTickType xDelayPeriod; static unsigned long *pulRandomBytes = mainFIRST_PROGRAM_BYTES; /* Co-routine MUST start with a call to crSTART. */ crSTART( xHandle ); for(;;) { /* Was the previously transmitted string received correctly? */ if( uxErrorStatus != pdPASS ) { /* An error was encountered so set the error LED. */ vSetErrorLED(); } /* The next character to Tx is the first in the string. */ cNextChar = mainFIRST_TX_CHAR; UARTIntDisable( UART0_BASE, UART_INT_TX ); { /* Send the first character. */ if( !( HWREG( UART0_BASE + UART_O_FR ) & UART_FR_TXFF ) ) { HWREG( UART0_BASE + UART_O_DR ) = cNextChar; } /* Move the variable to the char to Tx on so the ISR transmits the next character in the string once this one has completed. */ cNextChar++; } UARTIntEnable(UART0_BASE, UART_INT_TX); /* Toggle the LED to show a new string is being transmitted. */ vParTestToggleLED( mainCOMMS_TX_LED ); /* Delay before we start the string off again. A pseudo-random delay is used as this will provide a better test. */ xDelayPeriod = xTaskGetTickCount() + ( *pulRandomBytes ); pulRandomBytes++; if( pulRandomBytes > mainTOTAL_PROGRAM_MEMORY ) { pulRandomBytes = mainFIRST_PROGRAM_BYTES; } /* Make sure we don't wait too long... */ xDelayPeriod &= mainMAX_TX_DELAY; /* ...but we do want to wait. */ if( xDelayPeriod < mainMIN_TX_DELAY ) { xDelayPeriod = mainMIN_TX_DELAY; } /* Block for the random(ish) time. */ crDELAY( xHandle, xDelayPeriod ); } /* Co-routine MUST end with a call to crEND. */ crEND(); }
/********************************************************************************************** * Main *********************************************************************************************/ void main(void) { //After tomorrow's test flight. FOR THE LOVE OF GOD MOVE THESE INITALIZATIONS TO FUNCTIONS /********************************************************************************************** * Local Variables *********************************************************************************************/ unsigned long ultrasonic = 0; // 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. FPULazyStackingEnable(); //Set the clock speed to 80MHz aka max speed SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); /*unsigned long test[2]; test[0] = 180; test[1] = 10; short bob[1]; bob[0] = ((char)test[0]<<8)|(char)test[1]; float jimmy = (short)(((char)test[0]<<8)|(char)test[1]); jimmy /= 26;*/ /********************************************************************************************** * Peripheral Initialization Awake *********************************************************************************************/ SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); //Turn on GPIO communication on F pins for switches SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); //Turn on GPIO for ADC SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); //Turn on GPIO for the PWM comms SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); //Turn on GPIO for LED test SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); //Turn on GPIO for UART SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); //Turn on Timer for PWM SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); //Turn on Timer for PWM SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2); //Turn on Timer for PWM SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER3); //Turn on Timer for PWM SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C1); //Turn on I2C communication I2C slot 0 SysCtlPeripheralEnable(SYSCTL_PERIPH_UART2); //Turn on the UART com SysCtlPeripheralEnable(SYSCTL_PERIPH_WDOG); //Turn on the watchdog timer. This is a risky idea but I think it's for the best. /********************************************************************************************** * Peripheral Initialization Sleep *********************************************************************************************/ /*SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOF); //This sets what peripherals are still enabled in sleep mode while UART would be nice, it would require the clock operate at full speed which is :P SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_GPIOB); SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_GPIOA); SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_TIMER0); SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_TIMER1); SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_TIMER2); SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_TIMER3); SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_SSI0); SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_I2C1); SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_ADC); SysCtlPeripheralClockGating(true); //I'm not sure about this one maybe remove it */ /********************************************************************************************** * PWM Initialization *********************************************************************************************/ SysCtlDelay((SysCtlClockGet() / (1000 * 3))*100); //This shouldn't be needed will test to remove //PWM pin Setup //PWM 0 on GPIO PB6, PWM 1 on pin 4... etc GPIOPinConfigure(GPIO_PB6_T0CCP0); //Pitch - yaw + GPIOPinConfigure(GPIO_PB4_T1CCP0); //Pitch + yaw + GPIOPinConfigure(GPIO_PB0_T2CCP0); //Roll - yaw - GPIOPinConfigure(GPIO_PB2_T3CCP0); //Roll + yaw - GPIOPinTypeTimer(GPIO_PORTB_BASE, (GPIO_PIN_6|GPIO_PIN_4|GPIO_PIN_0|GPIO_PIN_2)); //Prescale the timers so they are slow enough to work with the ESC TimerPrescaleSet(TIMER0_BASE,TIMER_A,2); TimerPrescaleSet(TIMER1_BASE,TIMER_A,2); TimerPrescaleSet(TIMER2_BASE,TIMER_A,2); TimerPrescaleSet(TIMER3_BASE,TIMER_A,2); //Basic LED Out Test Not sure why this is here look into This just turns on an LED that I don't have plugged in. should remove later GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_3); GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_3,0xFF); //GPIOPinTypeGPIOOutputOD(GPIO_PORTB_BASE,GPIO_PIN_0); //Timers Setup for PWM and the load for the countdown TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM); TimerLoadSet(TIMER0_BASE, TIMER_A, ulPeriod -1); TimerConfigure(TIMER1_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM); TimerLoadSet(TIMER1_BASE, TIMER_A, ulPeriod -1); TimerConfigure(TIMER2_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM); TimerLoadSet(TIMER2_BASE, TIMER_A, (ulPeriod -1)); TimerConfigure(TIMER3_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM); TimerLoadSet(TIMER3_BASE, TIMER_A, ulPeriod -1); //TimerPrescaleSet(TIMER2_BASE, TIMER_A, extender1); //TimerLoadSet(TIMER2_BASE, TIMER_A, period1); //Set the match which is when the thing will pull high TimerMatchSet(TIMER0_BASE, TIMER_A, 254); //Duty cycle = (1-%desired)*1000 note this means this number is percent low not percent high TimerMatchSet(TIMER1_BASE, TIMER_A, 254); TimerMatchSet(TIMER2_BASE, TIMER_A, 254); TimerMatchSet(TIMER3_BASE, TIMER_A, 254); //TimerPrescaleMatchSet(TIMER2_BASE, TIMER_A, extender2); //TimerMatchSet(TIMER2_BASE, TIMER_A, period2); //Enable the timers TimerEnable(TIMER0_BASE, TIMER_A); TimerEnable(TIMER1_BASE, TIMER_A); TimerEnable(TIMER2_BASE, TIMER_A); TimerEnable(TIMER3_BASE, TIMER_A); //SysCtlDelay((SysCtlClockGet() / (1000 * 3))*1000000); PWMSet(TIMER0_BASE,998); PWMSet(TIMER1_BASE,998); PWMSet(TIMER2_BASE,998); PWMSet(TIMER3_BASE,998); /********************************************************************************************** * onboard Chip interrupt Initialization *********************************************************************************************/ //These two buttons are used to reset the bluetooth module in case of disconnection GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3); //RGB LED's GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x00); HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY_DD; //Sw1 (PF4) is unaviable unless you make it only a GPIOF input via these commands HWREG(GPIO_PORTF_BASE + GPIO_O_CR) = 0x1; GPIOPinTypeGPIOInput(GPIO_PORTF_BASE,GPIO_PIN_0|GPIO_PIN_4); //Onboard buttons (PF0=Sw2,PF4=Sw1 GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0|GPIO_PIN_4, GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU); //This will make the buttons falling edge (a press pulls them low) //void (*functionPtr)(void) = &onBoardInteruptHandle; GPIOPortIntRegister(GPIO_PORTF_BASE, onBoardInteruptHandle); //set function to handle interupt GPIOIntTypeSet(GPIO_PORTF_BASE,GPIO_PIN_0|GPIO_PIN_4,GPIO_FALLING_EDGE); //Set the interrupt as falling edge GPIOPinIntEnable(GPIO_PORTF_BASE,GPIO_PIN_0|GPIO_PIN_4); //Enable the interrupt //IntMasterEnable(); IntEnable(INT_GPIOF); /********************************************************************************************** * UART Initialization *********************************************************************************************/ //Unlock PD7 HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY_DD; HWREG(GPIO_PORTD_BASE + GPIO_O_CR) = 0x80; GPIOPinConfigure(GPIO_PD7_U2TX); //Set PD7 as TX GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_7); GPIOPinConfigure(GPIO_PD6_U2RX); //Set PD6 as RX GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_6); UARTConfigSetExpClk(UART2_BASE,SysCtlClockGet(),115200,UART_CONFIG_WLEN_8|UART_CONFIG_STOP_ONE|UART_CONFIG_PAR_NONE); //I believe the Xbee defaults to no parity I do know it's 9600 baud though, changed to 115200 for bluetooth reasons UARTFIFOLevelSet(UART2_BASE,UART_FIFO_TX1_8,UART_FIFO_RX1_8); //Set's how big the fifo needs to be in order to call the interrupt handler, 2byte UARTIntRegister(UART2_BASE,Uart2IntHandler); //Regiester the interrupt handler UARTIntClear(UART2_BASE, UART_INT_TX | UART_INT_RX); //Clear the interrupt UARTIntEnable(UART2_BASE, UART_INT_RX); //Enable the interrupt to trigger on both TX and RX event's. Could possibly remove TX UARTIntDisable(UART2_BASE,UART_INT_TX); UARTEnable(UART2_BASE); //Enable UART IntEnable(INT_UART2); //Second way to enable handler not sure if needed using anyway /********************************************************************************************** * I2C Initialization *********************************************************************************************/ //Serious credit to the man who made the Arduino version of this. he gave me addresses and equations. Sadly Arduino obfuscates what really is happening //Link posted on blog page //gyro address = 0x68 not 0x69 GPIOPinConfigure(GPIO_PA7_I2C1SDA); GPIOPinTypeI2C(GPIO_PORTA_BASE, GPIO_PIN_7); //Set GPA7 as SDA GPIOPinConfigure(GPIO_PA6_I2C1SCL); GPIOPinTypeI2CSCL(GPIO_PORTA_BASE, GPIO_PIN_6); //Set GPA6 as SCL I2CMasterInitExpClk(I2C1_MASTER_BASE,SysCtlClockGet(),false); //I think it operates at 100kbps I2CMasterEnable(I2C1_MASTER_BASE); //Initalize the accelerometer Address = 0x53 GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x02); //UARTSend(0xAB); I2CTransmit(0x53,0x2D,0x00); I2CTransmit(0x53,0x2D,0x10); I2CTransmit(0x53,0x2D,0x08); //Initalize the gyroscope Address = 0x68 I2CTransmit(0x68,0x3E,0x00); I2CTransmit(0x68,0x15,0x07); I2CTransmit(0x68,0x16,0x1E); I2CTransmit(0x68,0x17,0x00); //UARTSend(0xAC); /********************************************************************************************** * SysTick Initialization *********************************************************************************************/ SysTickIntRegister(SysTickIntHandler); SysTickIntEnable(); SysTickPeriodSet((SysCtlClockGet() / (1000 * 3))*timeBetweenCalculations); //This sets the period for the delay. the last num is the num of milliseconds SysTickEnable(); /********************************************************************************************** * Watchdog Initialization *********************************************************************************************/ WatchdogReloadSet(WATCHDOG_BASE, 0xFEEFEEFF); //Set the timer for a reset WatchdogIntRegister(WATCHDOG_BASE,WatchdogIntHandler); //Enable interrupt WatchdogIntClear(WATCHDOG_BASE); WatchdogIntEnable(WATCHDOG_BASE); WatchdogEnable(WATCHDOG_BASE); //Enable the actual timer IntEnable(INT_WATCHDOG); /********************************************************************************************** * Preflight motor inialization maybe not necessary not going to test *********************************************************************************************/ PWMSet(TIMER0_BASE,998); PWMSet(TIMER1_BASE,998); PWMSet(TIMER2_BASE,998); PWMSet(TIMER3_BASE,998); recievedCommands[0]=253; SysCtlDelay((SysCtlClockGet() / (1000 * 3))*100); //Very important to ensure motor see's a start high (998 makes 0 sense but it works so shhhh don't tell anyone) GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x06); while(1){ WatchdogReloadSet(WATCHDOG_BASE, 0xFEEFEEFF); //Feed the dog a new time //UARTSend(recievedCommands[0]); //SysCtlDelay(50000); //Set 4 PWM Outputs //Get Acc data I2CRead(0x53,0x32,6,quadAcc); //Address blah blah 2 for each axis rawAccToG(quadAcc,RwAcc); /*GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x04); //Blue //Get Gyro data /************************************** Gyro ITG-3200 I2C registers: temp MSB = 1B, temp LSB = 1C x axis MSB = 1D, x axis LSB = 1E y axis MSB = 1F, y axis LSB = 20 z axis MSB = 21, z axis LSB = 22 *************************************/ I2CRead(0x68,0x1B,8,quadGyro); //Address blah blah 2 for each axis + 2 for temperature. why. because why not rawGyroToDegsec(quadGyro,Gyro_ds); //GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x02); //Red //Get the actual angles in XYZ. Store them in RwEst getInclination(RwAcc, RwEst, RwGyro, Gyro_ds, Awz); //After this function is called RwEst will hold the roll pitch and yaw //RwEst will be returned in PITCH, ROLL, YAW 0, 1, 2 remember this order very important. Little obvious but yaw is worthless /*if(RwEst[1]>0.5){ GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x06); //Red Blue, Correct data read in }else{ GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x0A); //Red Green, The correct data is not there }*/ /*GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x06); //Red Blue, Correct data read in float test=RwAcc[0]*100; //These two commands work char temp = (char)test; //UARTSend((char)(RwAcc[0])*100); //This one does not UARTSend(temp); //UARTSend((char)(RwAcc[1])*100); UARTSend(0xAA); SysCtlDelay((SysCtlClockGet() / (1000 * 3))*1); */ } }
//***************************************************************************** // // Writes a message to the log. The message is preceeded by a time stamp, and // the message can not exceed 28 characters in length (unless g_pcBuffer is // increased in size). // //***************************************************************************** void LogWrite(char *pcPtr) { tTime sTime; // // Convert the current time from seconds since Jan 1, 1970 to the month, // day, year, hour, minute, and second equivalent. // ulocaltime(g_ulTime, &sTime); // // Construct the log message with the time stamp preceeding it. // usprintf(g_pcBuffer, "%s %s %2d %02d:%02d:%02d.%02d UT %d => %s\r\n", g_ppcDays[sTime.ucWday], g_ppcMonths[sTime.ucMon], sTime.ucMday, sTime.ucHour, sTime.ucMin, sTime.ucSec, g_ulTimeCount / 10, sTime.usYear, pcPtr); // // Get a pointer to the start of the log message. // pcPtr = g_pcBuffer; // // Disable the UART interrupt to prevent the UART interrupt handler from // executing, which would cause corruption of the logging state (possibly // losing characters in the process). // UARTIntDisable(UART1_BASE, UART_INT_TX); // // See if the software FIFO is empty. // if(g_ulReadPtr == g_ulWritePtr) { // // The software FIFO is empty, so copy as many characters from the log // message into the hardware FIFO as will fit. // while(*pcPtr && (UARTCharPutNonBlocking(UART1_BASE, *pcPtr) == true)) { pcPtr++; } } // // Copy as many characters from the log message into the software FIFO as // will fit. // while(*pcPtr && (((g_ulWritePtr + 1) & (SOFT_FIFO_SIZE - 1)) != g_ulReadPtr)) { g_pcTransmitBuffer[g_ulWritePtr] = *pcPtr++; g_ulWritePtr = (g_ulWritePtr + 1) & (SOFT_FIFO_SIZE - 1); } // // Re-enable the UART interrupt. // UARTIntEnable(UART1_BASE, UART_INT_TX); }
/* ** Interrupt Service Routine for UART. */ static void UARTIsr(void) { unsigned int rxErrorType = 0; unsigned char rxByte = 0; unsigned int intId = 0; unsigned int idx = 0; unsigned int i=0; unsigned short rx_array[22]; //unsigned int rx_integer=0,rx_integer1=0; /* Checking ths syource of UART interrupt. */ intId = UARTIntIdentityGet(SOC_UART_0_REGS); //printf("intId=0x%x\n\r",intId); switch(intId) { case UART_INTID_TX_THRES_REACH: printf("UART_INTID_TX_THRES_REACH\n\r"); /* ** Checking if the entire transmisssion is complete. If this ** condition fails, then the entire transmission has been completed. */ if(currNumTxBytes < (sizeof(txArray) - 1)) { txEmptyFlag = TRUE; } /* ** Disable the THR interrupt. This has to be done even if the ** transmission is not complete so as to prevent the Transmit ** empty interrupt to be continuously generated. */ UARTIntDisable(SOC_UART_0_REGS, UART_INT_THR); break; case UART_INTID_RX_THRES_REACH: /*Берём один байт из UART */ //printf("UART_INTID_RX_THRES_REACH"); rx_array[0]=UARTCharGetTimeout(SOC_UART_0_REGS, 100); rx_array[1]=UARTCharGetTimeout(SOC_UART_0_REGS, 100); rx_array[2]=UARTCharGetTimeout(SOC_UART_0_REGS, 100); rx_array[3]=UARTCharGetTimeout(SOC_UART_0_REGS, 100); rx_array[4]=UARTCharGetTimeout(SOC_UART_0_REGS, 100); rx_array[5]=UARTCharGetTimeout(SOC_UART_0_REGS, 100); rx_array[6]=UARTCharGetTimeout(SOC_UART_0_REGS, 100); rx_array[7]=UARTCharGetTimeout(SOC_UART_0_REGS, 100); rx_array[8]=UARTCharGetTimeout(SOC_UART_0_REGS, 100); rx_array[9]=UARTCharGetTimeout(SOC_UART_0_REGS, 100); rx_array[10]=UARTCharGetTimeout(SOC_UART_0_REGS, 100); rx_array[11]=UARTCharGetTimeout(SOC_UART_0_REGS, 100); rx_array[12]=UARTCharGetTimeout(SOC_UART_0_REGS, 100); rx_array[13]=UARTCharGetTimeout(SOC_UART_0_REGS, 100); rx_array[14]=UARTCharGetTimeout(SOC_UART_0_REGS, 100); rx_array[15]=UARTCharGetTimeout(SOC_UART_0_REGS, 100); rx_array[16]=UARTCharGetTimeout(SOC_UART_0_REGS, 100); rx_array[17]=UARTCharGetTimeout(SOC_UART_0_REGS, 100); rx_array[18]=UARTCharGetTimeout(SOC_UART_0_REGS, 100); rx_array[19]=UARTCharGetTimeout(SOC_UART_0_REGS, 100); rx_array[20]=UARTCharGetTimeout(SOC_UART_0_REGS, 100); rx_array[21]=UARTCharGetTimeout(SOC_UART_0_REGS, 100); for(i=0;i<22;i++) { printf("rx_byte=%X\n\r",rx_array[i]); } //rxByte = UARTCharGetNonBlocking(SOC_UART_0_REGS); //printf("rx_byte=%c\n\r",rxByte); // printf("rx_byte=%x,rx_byte1=%x\n\r",rx_integer,rx_integer1); //UARTCharPutNonBlocking(SOC_UART_0_REGS, rxByte); break; case UART_INTID_RX_LINE_STAT_ERROR: printf("UART_INTID_RX_LINE_STAT_ERROR\n\r"); rxErrorType = UARTRxErrorGet(SOC_UART_0_REGS); /* Check if Overrun Error has occured. */ if(rxErrorType & UART_LSR_RX_OE) { ConsoleUtilsPrintf("\r\nUART Overrun Error occured." " Reading and Echoing all data in RX FIFO.\r\n"); /* Read the entire RX FIFO and the data in RX Shift register. */ for(idx = 0; idx < (RX_FIFO_SIZE + 1); idx++) { rxByte = UARTFIFOCharGet(SOC_UART_0_REGS); UARTFIFOCharPut(SOC_UART_0_REGS, rxByte); } break; } /* Check if Break Condition has occured. */ else if(rxErrorType & UART_LSR_RX_BI) { ConsoleUtilsPrintf("\r\nUART Break Condition occured."); } /* Check if Framing Error has occured. */ else if(rxErrorType & UART_LSR_RX_FE) { ConsoleUtilsPrintf("\r\nUART Framing Error occured."); } /* Check if Parity Error has occured. */ else if(rxErrorType & UART_LSR_RX_PE) { ConsoleUtilsPrintf("\r\nUART Parity Error occured."); } ConsoleUtilsPrintf(" Data at the top of RX FIFO is: "); rxByte = UARTFIFOCharGet(SOC_UART_0_REGS); UARTFIFOCharPut(SOC_UART_0_REGS, rxByte); break; case UART_INTID_CHAR_TIMEOUT: printf("UART_INTID_CHAR_TIMEOUT\n\r"); ConsoleUtilsPrintf("\r\nUART Character Timeout Interrupt occured." " Reading and Echoing all data in RX FIFO.\r\n"); /* Read all the data in RX FIFO. */ while(TRUE == UARTCharsAvail(SOC_UART_0_REGS)) { rxByte = UARTFIFOCharGet(SOC_UART_0_REGS); UARTFIFOCharPut(SOC_UART_0_REGS, rxByte); } break; default: printf("default\n\r"); break; } }
void GPS::InterruptDisable(){ IntDisable(INT_UART1); UARTIntDisable(UART1_BASE, UART_INT_RX | UART_INT_RT); // receiver RX and receiver timeout interrupts RT(timeout = 32 bits) }
//***************************************************************************** // // Configure the UART and perform reads and writes using polled I/O. // //***************************************************************************** int main(void) { char cThisChar; // // Set the clocking to run directly from the external crystal/oscillator. // (no ext 32k osc, no internal osc) // SysCtrlClockSet(false, false, SYS_CTRL_SYSDIV_32MHZ); // // Set IO clock to the same as system clock // SysCtrlIOClockSet(SYS_CTRL_SYSDIV_32MHZ); // // Enable UART peripheral module // SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_UART0); // // Disable UART function // UARTDisable(UART0_BASE); // // Disable all UART module interrupts // UARTIntDisable(UART0_BASE, 0x1FFF); // // Set IO clock as UART clock source // UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC); // // Map UART signals to the correct GPIO pins and configure them as // hardware controlled. // IOCPinConfigPeriphOutput(EXAMPLE_GPIO_BASE, EXAMPLE_PIN_UART_TXD, IOC_MUX_OUT_SEL_UART0_TXD); GPIOPinTypeUARTOutput(EXAMPLE_GPIO_BASE, EXAMPLE_PIN_UART_TXD); IOCPinConfigPeriphInput(EXAMPLE_GPIO_BASE, EXAMPLE_PIN_UART_RXD, IOC_UARTRXD_UART0); GPIOPinTypeUARTInput(EXAMPLE_GPIO_BASE, EXAMPLE_PIN_UART_RXD); // // Configure the UART for 115,200, 8-N-1 operation. // This function uses SysCtrlClockGet() to get the system clock // frequency. This could be also be a variable or hard coded value // instead of a function call. // UARTConfigSetExpClk(UART0_BASE, SysCtrlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); UARTEnable(UART0_BASE); // // Put a character to show start of example. This will display on the // terminal. // UARTCharPut(UART0_BASE, '!'); // // Enter a loop to read characters from the UART, and write them back // (echo). When a line end is received, the loop terminates. // do { // // Read a character using the blocking read function. This function // will not return until a character is available. // cThisChar = UARTCharGet(UART0_BASE); // // Write the same character using the blocking write function. This // function will not return until there was space in the FIFO and // the character is written. // UARTCharPut(UART0_BASE, cThisChar); // // Stay in the loop until either a CR or LF is received. // } while((cThisChar != '\n') && (cThisChar != '\r')); // // Put a character to show the end of the example. This will display on // the terminal. // UARTCharPut(UART0_BASE, '@'); // // Enter an infinite loop. // while(1) { } }
void UART_0_ISR(void) { unsigned int rxErrorType = 0; unsigned char rxByte = 0; unsigned int intId = 0; unsigned int idx = 0; /* Checking ths source of UART interrupt. */ intId = UARTIntIdentityGet(SOC_UART_0_REGS); switch(intId) { case UART_INTID_RX_THRES_REACH: rxByte = UARTCharGetNonBlocking(SOC_UART_0_REGS); UART_AddToRXBuffer(rxByte); break; case UART_INTID_RX_LINE_STAT_ERROR: rxErrorType = UARTRxErrorGet(SOC_UART_0_REGS); /* Check if Overrun Error has occured. */ if(rxErrorType & UART_LSR_RX_OE) { /* Read the entire RX FIFO and the data in RX Shift register. */ for(idx = 0; idx < (RX_FIFO_SIZE + 1); idx++) { rxByte = UARTFIFOCharGet(SOC_UART_0_REGS); UART_AddToRXBuffer(rxByte); } break; } rxByte = UARTFIFOCharGet(SOC_UART_0_REGS); break; case UART_INTID_CHAR_TIMEOUT: /* Read all the data in RX FIFO. */ while(TRUE == UARTCharsAvail(SOC_UART_0_REGS)) { rxByte = UARTFIFOCharGet(SOC_UART_0_REGS); UART_AddToRXBuffer(rxByte); } break; case (UART_INTID_TX_THRES_REACH): /* UART transfer register and FIFO is empty */ if(UART_TX_remove != UART_TX_add) { while(UARTTxFIFOFullStatusGet(SOC_UART_0_REGS) == UART_TX_FIFO_NOT_FULL) { if(UART_TX_remove == UART_TX_add) { break; } UARTFIFOCharPut(SOC_UART_0_REGS, UART_TX_buffer[UART_TX_remove]); UART_TX_remove = (UART_TX_remove + 1UL) % UART_TX_SIZE; } } else { /* Disabling required TX Interrupts. */ UARTIntDisable(SOC_UART_0_REGS, UART_INT_THR); } break; default: break; } }
void UART1Send(unsigned char *pucBuffer, unsigned ulCount) { tBoolean bRc; static int FCount = 0; static int SCount = 0; // // Loop while there are more characters to send. // if(m_nTxBuffIn1 + ulCount >= TXBUFFSIZE1) { // No place to put new data // To be sure we purge all tx data //IntDisable(INT_UART1); /* Start the Tx of the message on the UART. */ UARTIntDisable( UART1_BASE, UART_INT_TX ); #if 0 // Sent all data buffer until empty and put new data in to the buffer for sent // Fill hardware FIFO while(m_nTxBuffIn1 > 0) { bRc = UARTCharPutNonBlocking(UART1_BASE,m_tTxBuff1[m_nTxNextNdx1]); if(bRc == true) { m_nTxNextNdx1++; m_nTxBuffIn1--; } } memcpy(m_tTxBuff1 ,pucBuffer,ulCount); m_nTxNextNdx1 = 0; m_nTxBuffIn1 = ulCount; #else // Throw all data buffer and put new data in to buffer for sent //memcpy(m_tTxBuff1 ,pucBuffer,ulCount); //m_nTxNextNdx1 = 0; //m_nTxBuffIn1 = ulCount; // Fill hardware FIFO bRc = true; while(m_nTxBuffIn1 > 0 && bRc == true) { bRc = UARTCharPutNonBlocking(UART1_BASE,m_tTxBuff1[m_nTxNextNdx1]); if(bRc == true) { m_nTxNextNdx1++; m_nTxBuffIn1--; } } #endif //IntEnable(INT_UART1); UARTIntEnable(UART1_BASE, UART_INT_TX); } else if(ulCount > 0) { //IntDisable(INT_UART1); /* Start the Tx of the message on the UART. */ UARTIntDisable( UART1_BASE, UART_INT_TX ); if(m_nTxBuffIn1 > 0) { // Move TX data to start if(m_nTxNextNdx1 > 0) { memmove(m_tTxBuff1,&m_tTxBuff1[m_nTxNextNdx1],m_nTxBuffIn1); } m_nTxNextNdx1 = 0; // Add data to TXBuff memcpy(&m_tTxBuff1[m_nTxBuffIn1],pucBuffer,ulCount); m_nTxBuffIn1 += ulCount; } else { memcpy(m_tTxBuff1 ,pucBuffer,ulCount); m_nTxNextNdx1 = 0; m_nTxBuffIn1 = ulCount; } // Fill hardware FIFO bRc = true; while(m_nTxBuffIn1 > 0 && bRc == true) { bRc = UARTCharPutNonBlocking(UART1_BASE,m_tTxBuff1[m_nTxNextNdx1]); if(bRc == true) { m_nTxNextNdx1++; m_nTxBuffIn1--; } } //IntEnable(INT_UART1); UARTIntEnable(UART1_BASE, UART_INT_TX); } }
void UART0Send(unsigned char *pucBuffer, unsigned ulCount) { tBoolean bRc; static int FCount = 0; static int SCount = 0; // // Loop while there are more characters to send. // if(m_nTxBuffIn + ulCount >= TXBUFFSIZE) { // No place to put new data // To be sure we purge all tx data //IntDisable(INT_UART0); /* Start the Tx of the message on the UART. */ UARTIntDisable( UART0_BASE, UART_INT_TX ); #if 0 // TX int // Push next char to transmitter while(m_nTxBuffIn > 0) { bRc = UARTCharPutNonBlocking(UART0_BASE,m_tTxBuff[m_nTxNextNdx]); if(bRc == true) { m_nTxNextNdx++; m_nTxBuffIn--; } } memcpy(m_tTxBuff ,pucBuffer,ulCount); m_nTxNextNdx = 0; m_nTxBuffIn = ulCount; #else //memcpy(m_tTxBuff ,pucBuffer,ulCount); //m_nTxNextNdx = 0; //m_nTxBuffIn = ulCount; // Fill hardware FIFO bRc = true; while(m_nTxBuffIn > 0 && bRc == true) { bRc = UARTCharPutNonBlocking(UART0_BASE,m_tTxBuff[m_nTxNextNdx]); if(bRc == true) { m_nTxNextNdx++; m_nTxBuffIn--; } } #endif UARTIntEnable(UART0_BASE, UART_INT_TX); //IntEnable(INT_UART0); } else if(ulCount > 0) { //IntDisable(INT_UART0); /* Start the Tx of the message on the UART. */ UARTIntDisable( UART0_BASE, UART_INT_TX ); if(m_nTxBuffIn > 0) { // Move TX data to start if(m_nTxNextNdx > 0) { memmove(m_tTxBuff,&m_tTxBuff[m_nTxNextNdx],m_nTxBuffIn); } m_nTxNextNdx = 0; // Add data to TXBuff memcpy(&m_tTxBuff[m_nTxBuffIn],pucBuffer,ulCount); m_nTxBuffIn += ulCount; } else { memcpy(m_tTxBuff ,pucBuffer,ulCount); m_nTxNextNdx = 0; m_nTxBuffIn = ulCount; } // Fill hardware FIFO bRc = true; while(m_nTxBuffIn > 0 && bRc == true) { bRc = UARTCharPutNonBlocking(UART0_BASE,m_tTxBuff[m_nTxNextNdx]); if(bRc == true) { m_nTxNextNdx++; m_nTxBuffIn--; } } UARTIntEnable(UART0_BASE, UART_INT_TX); //IntEnable(INT_UART0); } }
void uart_disableInterrupts(){ UARTIntDisable(UART0_BASE, UART_INT_RX | UART_INT_TX | UART_INT_RT); }
//***************************************************************************** // // UART interrupt handler. // // This is the interrupt handler for the UART interrupts from the UART // peripheral that has been associated with the remote network processor. // // \return None. //***************************************************************************** void RemoTIUARTIntHandler(void) { uint8_t ui8TxByte; // // Process all available interrupts while we are in this routine. // do { // // Check if a receive interrupt is pending. // if(UARTIntStatus(g_ui32UARTBase, 1) & UART_INT_RX) { // // A char was receieved, process it // Do this first so it does not get overwritten by future bytes. // RemoTIUARTRxHandler(); UARTIntClear(g_ui32UARTBase, UART_INT_RX); } // // Check if a transmit interrupt is pending. // if(UARTIntStatus(g_ui32UARTBase, 1) & UART_INT_TX) { // // A byte transmission completed so load another byte or turn off // tx interrupts. // if(RingBufUsed(&g_rbRemoTITxRingBuf)) { // // We still have more stuff to transfer so read the next byte // from the buffer and load it into the UART. Finally clear // the pending interrupt status. // ui8TxByte = RingBufReadOne(&g_rbRemoTITxRingBuf); UARTCharPutNonBlocking(g_ui32UARTBase, ui8TxByte); UARTIntClear(g_ui32UARTBase, UART_INT_TX); } else { // // Transmission is complete the internal buffer is empty. // Therefore, disable TX interrupts until next transmit is // started by the user. // UARTIntDisable(g_ui32UARTBase, UART_INT_TX); UARTIntClear(g_ui32UARTBase, UART_INT_TX); // // Clear the transmitter busy flag. // g_bTxBusy = false; // // callback to the TX Complete callback function // if(g_pfnTxCallback) { g_pfnTxCallback(0); } } } // // Continue to process the interrupts until there are no more pending. // }while(UARTIntStatus(g_ui32UARTBase, 1) & (UART_INT_RX | UART_INT_TX)); // // Finished. // }
static void UARTIsr(void) { unsigned int rxErrorType = 0; unsigned char rxByte = 0; unsigned int intId = 0; unsigned int idx = 0; /* Checking ths source of UART interrupt. */ intId = UARTIntIdentityGet(SOC_UART_0_REGS); switch(intId) { case UART_INTID_TX_THRES_REACH: /* ** Checking if the entire transmisssion is complete. If this ** condition fails, then the entire transmission has been completed. */ if(currNumTxBytes < (sizeof(txArray) - 1)) { txEmptyFlag = TRUE; } /* ** Disable the THR interrupt. This has to be done even if the ** transmission is not complete so as to prevent the Transmit ** empty interrupt to be continuously generated. */ UARTIntDisable(SOC_UART_0_REGS, UART_INT_THR); break; case UART_INTID_RX_THRES_REACH: rxByte = UARTCharGetNonBlocking(SOC_UART_0_REGS); UARTCharPutNonBlocking(SOC_UART_0_REGS, rxByte); break; case UART_INTID_RX_LINE_STAT_ERROR: rxErrorType = UARTRxErrorGet(SOC_UART_0_REGS); /* Check if Overrun Error has occured. */ if(rxErrorType & UART_LSR_RX_OE) { ConsoleUtilsPrintf("\r\nUART Overrun Error occured." " Reading and Echoing all data in RX FIFO.\r\n"); /* Read the entire RX FIFO and the data in RX Shift register. */ for(idx = 0; idx < (RX_FIFO_SIZE + 1); idx++) { rxByte = UARTFIFOCharGet(SOC_UART_0_REGS); UARTFIFOCharPut(SOC_UART_0_REGS, rxByte); } break; } /* Check if Break Condition has occured. */ else if(rxErrorType & UART_LSR_RX_BI) { ConsoleUtilsPrintf("\r\nUART Break Condition occured."); } /* Check if Framing Error has occured. */ else if(rxErrorType & UART_LSR_RX_FE) { ConsoleUtilsPrintf("\r\nUART Framing Error occured."); } /* Check if Parity Error has occured. */ else if(rxErrorType & UART_LSR_RX_PE) { ConsoleUtilsPrintf("\r\nUART Parity Error occured."); } ConsoleUtilsPrintf(" Data at the top of RX FIFO is: "); rxByte = UARTFIFOCharGet(SOC_UART_0_REGS); UARTFIFOCharPut(SOC_UART_0_REGS, rxByte); break; case UART_INTID_CHAR_TIMEOUT: ConsoleUtilsPrintf("\r\nUART Character Timeout Interrupt occured." " Reading and Echoing all data in RX FIFO.\r\n"); /* Read all the data in RX FIFO. */ while(TRUE == UARTCharsAvail(SOC_UART_0_REGS)) { rxByte = UARTFIFOCharGet(SOC_UART_0_REGS); UARTFIFOCharPut(SOC_UART_0_REGS, rxByte); } break; default: break; } }