void CC3100_InterruptDisable() { GPIOIntDisable(CC3100_IRQBASE,CC3100_IRQPIN); #ifdef SL_IF_TYPE_UART ROM_UARTIntDisable(CC3100_UARTBASE, UART_INT_RX); #endif }
void HardwareSerial::setModule(unsigned long module) { ROM_UARTIntDisable(UART_BASE, UART_INT_RX | UART_INT_RT); ROM_IntDisable(g_ulUARTInt[uartModule]); uartModule = module; begin(baudRate); }
/* * closeOptode turns off the Optode (removes power * and disables UART3). */ void closeOptode(void) { //disable UART3 and its interrupt ROM_UARTIntDisable(UART3_BASE, UART_INT_RX); ROM_UARTDisable(UART3_BASE); //turn off power OPTODE_OFF; }
void HardwareSerial::UARTIntHandler(void){ unsigned long ulInts; long lChar; // Get and clear the current interrupt source(s) // ulInts = ROM_UARTIntStatus(UART_BASE, true); ROM_UARTIntClear(UART_BASE, ulInts); // Are we being interrupted because the TX FIFO has space available? // if(ulInts & UART_INT_TX) { // // Move as many bytes as we can into the transmit FIFO. // primeTransmit(UART_BASE); // // If the output buffer is empty, turn off the transmit interrupt. // if(TX_BUFFER_EMPTY) { ROM_UARTIntDisable(UART_BASE, UART_INT_TX); } } if(ulInts & (UART_INT_RX | UART_INT_RT)) { while(ROM_UARTCharsAvail(UART_BASE)) { // // Read a character // lChar = ROM_UARTCharGetNonBlocking(UART_BASE); // // If there is space in the receive buffer, put the character // there, otherwise throw it away. // uint8_t volatile full = RX_BUFFER_FULL; if(full) break; rxBuffer[rxWriteIndex] = (unsigned char)(lChar & 0xFF); rxWriteIndex = ((rxWriteIndex) + 1) % rxBufferSize; // // If we wrote anything to the transmit buffer, make sure it actually // gets transmitted. // } primeTransmit(UART_BASE); ROM_UARTIntEnable(UART_BASE, UART_INT_TX); } }
int uart_Read(Fd_t fd, unsigned char *pBuff, int len) { int i = 0; ROM_UARTIntDisable(UART1_BASE, UART_INT_RX); for(i=0; i< len; i++) { pBuff[i] = (unsigned char)UARTCharGet(UART1_BASE); } ROM_UARTIntEnable(UART1_BASE, UART_INT_RX); return len; }
//***************************************************************************** // // Interrupt handler for the UART which we are redirecting via USB. // //***************************************************************************** void USBUARTIntHandler(void) { uint32_t ui32Ints; int32_t i32Errors; // // Get and clear the current interrupt source(s) // ui32Ints = ROM_UARTIntStatus(USB_UART_BASE, true); ROM_UARTIntClear(USB_UART_BASE, ui32Ints); // // Are we being interrupted because the TX FIFO has space available? // if(ui32Ints & UART_INT_TX) { // // Move as many bytes as we can into the transmit FIFO. // USBUARTPrimeTransmit(USB_UART_BASE); // // If the output buffer is empty, turn off the transmit interrupt. // if(!USBBufferDataAvailable(&g_sRxBuffer)) { ROM_UARTIntDisable(USB_UART_BASE, UART_INT_TX); } } // // Handle receive interrupts. // // gjs if(ui32Ints & (UART_INT_RX)) if(ui32Ints & (UART_INT_RX | UART_INT_RT)) { // // Read the UART's characters into the buffer. // i32Errors = ReadUARTData(); // // Check to see if we need to notify the host of any errors we just // detected. // CheckForSerialStateChange(&g_sCDCDevice, i32Errors); } }
//***************************************************************************** // // Interrupt handler for the UART which is being redirected via USB. // //***************************************************************************** void USBUARTIntHandler(void) { unsigned long ulInts; long lErrors; // // Get and clear the current interrupt source(s) // ulInts = ROM_UARTIntStatus(UART0_BASE, true); ROM_UARTIntClear(UART0_BASE, ulInts); // // Handle transmit interrupts. // if(ulInts & UART_INT_TX) { // // Move as many bytes as possible into the transmit FIFO. // USBUARTPrimeTransmit(); // // If the output buffer is empty, turn off the transmit interrupt. // if(!USBBufferDataAvailable(&g_sRxBuffer)) { ROM_UARTIntDisable(UART0_BASE, UART_INT_TX); } } // // Handle receive interrupts. // if(ulInts & (UART_INT_RX | UART_INT_RT)) { // // Read the UART's characters into the buffer. // lErrors = ReadUARTData(); // // Check to see if the host needs to be notified of any errors just // detected. // CheckForSerialStateChange(&g_sCDCDevice, lErrors); } }
char UARTgetc(uint8_t UART) { if (!rxQSize(UART)) { // Disable interrupt to avoid possible race condition ROM_UARTIntDisable(UARTBASE[UART], UART_INT_RX); // Wait for data if the buffer is empty while (!rxQSize(UART)) flushReadFIFO(UART); // Return to the previous state ROM_UARTIntEnable(UARTBASE[UART], UART_INT_RX); } return (char)rxDequeue(UART); }
char UARTpeekBlocking(uint8_t UART) { // If there is data in the buffer return that if (rxQSize(UART)) return rxBuff[UART][rxBufferTail[UART]]; // Disable interrupt to avoid possible race condition ROM_UARTIntDisable(UARTBASE[UART], UART_INT_RX); // Wait for data if the buffer is empty while (!rxQSize(UART)) flushReadFIFO(UART); // Return to the previous state ROM_UARTIntEnable(UARTBASE[UART], UART_INT_RX); // Return what was read without popping it from the queue return rxBuff[UART][rxBufferTail[UART]]; }
void HardwareSerial::begin(unsigned long baud) { // // Initialize the UART. // ROM_SysCtlPeripheralEnable(g_ulUARTInt[uartModule]); //TODO:Add functionality for PinConfigure with variable uartModule ROM_GPIOPinConfigure(GPIO_PA0_U0RX); ROM_GPIOPinConfigure(GPIO_PA1_U0TX); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // Only allow a single instance to be opened. // ASSERT(g_ulUARTBase[uartModule] == 0); // // Check to make sure the UART peripheral is present. // if(!ROM_SysCtlPeripheralPresent(g_ulUARTPeriph[uartModule])) { return; } ROM_SysCtlPeripheralEnable(g_ulUARTPeriph[uartModule]); ROM_UARTConfigSetExpClk(g_ulUARTBase[uartModule], ROM_SysCtlClockGet(), baud, (UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_ONE | UART_CONFIG_WLEN_8)); // // Set the UART to interrupt whenever the TX FIFO is almost empty or // when any character is received. // ROM_UARTFIFOLevelSet(g_ulUARTBase[uartModule], UART_FIFO_TX1_8, UART_FIFO_RX1_8); flushAll(); ROM_UARTIntDisable(g_ulUARTBase[uartModule], 0xFFFFFFFF); ROM_UARTIntEnable(g_ulUARTBase[uartModule], UART_INT_RX | UART_INT_RT); ROM_IntMasterEnable(); ROM_IntEnable(g_ulUARTInt[uartModule]); // // Enable the UART operation. // ROM_UARTEnable(g_ulUARTBase[uartModule]); }
int UARTpeek(uint8_t UART) { // If there is data in the buffer return that if (rxQSize(UART)) return rxBuff[UART][rxBufferTail[UART]]; // Disable interrupt to avoid possible race condition ROM_UARTIntDisable(UARTBASE[UART], UART_INT_RX); // Try flushing the hardware FIFO and see if we can get data from there flushReadFIFO(UART); if (rxQSize(UART)) return rxBuff[UART][rxBufferTail[UART]]; // Return to the previous state ROM_UARTIntEnable(UARTBASE[UART], UART_INT_RX); // No data was found return -255; }
void HardwareSerial::end() { unsigned long ulInt = ROM_IntMasterDisable(); flushAll(); // // If interrupts were enabled when we turned them off, turn them // back on again. // if(!ulInt) { ROM_IntMasterEnable(); } ROM_IntDisable(g_ulUARTInt[uartModule]); ROM_UARTIntDisable(UART_BASE, UART_INT_RX | UART_INT_RT); }
void HardwareSerial::begin(unsigned long baud) { baudRate = baud; // // Initialize the UART. // ROM_SysCtlPeripheralEnable(g_ulUARTPeriph[uartModule]); //TODO:Add functionality for PinConfigure with variable uartModule ROM_GPIOPinConfigure(g_ulUARTConfig[uartModule][0]); ROM_GPIOPinConfigure(g_ulUARTConfig[uartModule][1]); ROM_GPIOPinTypeUART(g_ulUARTPort[uartModule], g_ulUARTPins[uartModule]); ROM_UARTConfigSetExpClk(UART_BASE, F_CPU, baudRate, (UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_ONE | UART_CONFIG_WLEN_8)); // // Set the UART to interrupt whenever the TX FIFO is almost empty or // when any character is received. // ROM_UARTFIFOLevelSet(UART_BASE, UART_FIFO_TX1_8, UART_FIFO_RX1_8); flushAll(); ROM_UARTIntDisable(UART_BASE, 0xFFFFFFFF); ROM_UARTIntEnable(UART_BASE, UART_INT_RX | UART_INT_RT); ROM_IntEnable(g_ulUARTInt[uartModule]); // // Enable the UART operation. // ROM_UARTEnable(UART_BASE); // Allocate TX & RX buffers if (txBuffer != (unsigned char *)0xFFFFFFFF) // Catch attempts to re-init this Serial instance by freeing old buffer first free(txBuffer); if (rxBuffer != (unsigned char *)0xFFFFFFFF) // Catch attempts to re-init this Serial instance by freeing old buffer first free(rxBuffer); txBuffer = (unsigned char *) malloc(txBufferSize); rxBuffer = (unsigned char *) malloc(rxBufferSize); SysCtlDelay(100); }
//***************************************************************************** // // The UART interrupt handler. // //***************************************************************************** void UARTIntHandler(void) { uint32_t ui32Status; char data; // // Get the interrrupt status. // ui32Status = ROM_UARTIntStatus(UART0_BASE, true); UARTIntClear(UART0_BASE, ui32Status); if ((ui32Status&UART_INT_RX) == UART_INT_RX) { // // Loop while there are characters in the receive FIFO. // while(ROM_UARTCharsAvail(UART0_BASE)) { // // Read the next character from the UART and write it back to the UART. // data = (char)ROM_UARTCharGetNonBlocking(UART0_BASE); OSQueuePost(qUART, data); } } if ((ui32Status&UART_INT_TX) == UART_INT_TX) { ROM_UARTIntDisable(UART0_BASE, UART_INT_TX); // Call the keyboard analysis task OSSemPost(sUART); } // ************************ // Interrupt Exit // ************************ OS_INT_EXIT_EXT(); // ************************ }
//***************************************************************************** // // 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); } }
Fd_t uart_Open(char *ifName, unsigned long flags) { /* Configure CS (PE0) and nHIB (PE4) lines */ SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_4); ROM_GPIOPinWrite(GPIO_PORTE_BASE,GPIO_PIN_4, PIN_LOW); /* configuring UART interface */ SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); GPIOPinConfigure(GPIO_PB0_U1RX); GPIOPinConfigure(GPIO_PB1_U1TX); ROM_GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1); GPIOPinConfigure(GPIO_PC4_U1RTS); GPIOPinConfigure(GPIO_PC5_U1CTS); ROM_GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_5); GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_0, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); /* configure with baud rate 115200 */ ROM_UARTConfigSetExpClk(UART1_BASE, ROM_SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); UARTFlowControlSet(UART1_BASE, UART_FLOWCONTROL_TX | UART_FLOWCONTROL_RX); UARTFIFOLevelSet(UART1_BASE, UART_FIFO_TX1_8, UART_FIFO_RX1_8); ROM_UARTEnable(UART1_BASE); ROM_UARTFIFOEnable(UART1_BASE); ROM_IntEnable(INT_UART1); ROM_UARTIntEnable(UART1_BASE, UART_INT_RX); ROM_UARTIntDisable(UART1_BASE, UART_INT_TX | UART_INT_RT); /* configure host IRQ line */ GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_2); GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPD); GPIOIntTypeSet(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_RISING_EDGE); GPIOIntClear(GPIO_PORTB_BASE,GPIO_PIN_2); GPIOIntDisable(GPIO_PORTB_BASE,GPIO_PIN_2); ROM_IntEnable(INT_GPIOB); ROM_IntMasterEnable(); IntIsMasked = FALSE; /* Enable WLAN interrupt */ CC3100_InterruptEnable(); /* 50 ms delay */ ROM_SysCtlDelay((ROM_SysCtlClockGet()/(3*1000))*50 ); return NONOS_RET_OK; }