Definition in file serial.h.
Go to the source code of this file.
Typedefs | |
typedef void * | xComPortHandle |
Enumerations | |
enum | eBaud { ser50, ser75, ser110, ser134, ser150, ser200, ser300, ser600, ser1200, ser1800, ser2400, ser4800, ser9600, ser19200, ser38400, ser57600, ser115200 } |
enum | eCOMPort { serCOM1, serCOM2, serCOM3, serCOM4, serCOM5, serCOM6, serCOM7, serCOM8 } |
enum | eDataBits { serBITS_5, serBITS_6, serBITS_7, serBITS_8 } |
enum | eParity { serNO_PARITY, serODD_PARITY, serEVEN_PARITY, serMARK_PARITY, serSPACE_PARITY } |
enum | eStopBits { serSTOP_1, serSTOP_2 } |
Functions | |
unsigned portSHORT | usUsartPutString (xComPortHandle pxPort, const signed portCHAR *const pcString, unsigned portSHORT usStringLength) |
Put a string to Usart. | |
void | vSerialClose (xComPortHandle xPort) |
Close the serial port. | |
signed portBASE_TYPE | xUsartGetChar (xComPortHandle pxPort, signed portCHAR *pcRxedChar, portTickType xBlockTime) |
Get char from Usart. | |
xComPortHandle | xUsartInit (eCOMPort UsartId, unsigned portLONG ulWantedBaud, unsigned portBASE_TYPE uxRxQueueLength, unsigned portBASE_TYPE uxTxQueueLength) |
Init the serial port. | |
signed portBASE_TYPE | xUsartPutChar (xComPortHandle pxPort, signed portCHAR cOutChar, portTickType xBlockTime) |
Put char to Usart. |
typedef void* xComPortHandle |
enum eBaud |
ser50 | |
ser75 | |
ser110 | |
ser134 | |
ser150 | |
ser200 | |
ser300 | |
ser600 | |
ser1200 | |
ser1800 | |
ser2400 | |
ser4800 | |
ser9600 | |
ser19200 | |
ser38400 | |
ser57600 | |
ser115200 |
Definition at line 84 of file serial.h.
00085 { 00086 ser50, 00087 ser75, 00088 ser110, 00089 ser134, 00090 ser150, 00091 ser200, 00092 ser300, 00093 ser600, 00094 ser1200, 00095 ser1800, 00096 ser2400, 00097 ser4800, 00098 ser9600, 00099 ser19200, 00100 ser38400, 00101 ser57600, 00102 ser115200 00103 } eBaud;
enum eCOMPort |
enum eDataBits |
enum eParity |
Definition at line 61 of file serial.h.
00062 { 00063 serNO_PARITY, 00064 serODD_PARITY, 00065 serEVEN_PARITY, 00066 serMARK_PARITY, 00067 serSPACE_PARITY 00068 } eParity;
enum eStopBits |
unsigned portSHORT usUsartPutString | ( | xComPortHandle | pxPort, | |
const signed portCHAR *const | pcString, | |||
unsigned portSHORT | usStringLength | |||
) |
Put a string to Usart.
pxPort | The Usart handle to put the string to | |
pcString | The string to transmit | |
usStringLength | The number of char to transmit. |
Definition at line 342 of file serial.c.
References serNO_BLOCK, and xUsartPutChar().
Referenced by ustracedump_Print(), vcom1shell_PrintMsg(), and vtracedump_PrintBlocking().
00343 { 00344 signed portCHAR *pxNext; 00345 00346 /* Send each character in the string, one at a time. */ 00347 pxNext = ( signed portCHAR * ) pcString; 00348 do 00349 { 00350 if(xUsartPutChar( pxPort, *pxNext, serNO_BLOCK ) != pdPASS) 00351 break; // The queue is full. 00352 pxNext++; 00353 } while( --usStringLength ); 00354 00355 return( usStringLength ); // Return the number of remaining characters. 00356 }
void vSerialClose | ( | xComPortHandle | xPort | ) |
Close the serial port.
xPort | The handle of the usart to close |
Definition at line 364 of file serial.c.
References usartPrivateData::usart.
Referenced by v_com1shell_stopResources(), and v_tracedump_stopResources().
00365 { 00366 xUsartPrivateData *pxUsart = (xUsartPrivateData *)xPort; 00367 /* Disable all USART interrupt sources */ 00368 pxUsart->usart->idr = 0xFFFFFFFF; 00369 }
signed portBASE_TYPE xUsartGetChar | ( | xComPortHandle | pxPort, | |
signed portCHAR * | pcRxedChar, | |||
portTickType | xBlockTime | |||
) |
Get char from Usart.
pxPort | The Usart handle to get the char from | |
pcRxedChar | The rxed char(output) | |
xBlockTime | The max time to wait for a rxed char |
Definition at line 297 of file serial.c.
References usartPrivateData::xRxedChars.
Referenced by com1shell_GetChar(), and prvGetChar().
00298 { 00299 xUsartPrivateData *pxUsart = (xUsartPrivateData *)pxPort; 00300 00301 /* Get the next character from the buffer. Return false if no characters 00302 are available, or arrive before xBlockTime expires. */ 00303 if( xQueueReceive( pxUsart->xRxedChars, pcRxedChar, xBlockTime ) ) 00304 { 00305 return pdTRUE; 00306 } 00307 else 00308 { 00309 return pdFALSE; 00310 } 00311 }
xComPortHandle xUsartInit | ( | eCOMPort | UsartId, | |
unsigned portLONG | ulWantedBaud, | |||
unsigned portBASE_TYPE | uxRxQueueLength, | |||
unsigned portBASE_TYPE | uxTxQueueLength | |||
) |
Init the serial port.
UsartId | The identifier of the Usart to init. | |
ulWantedBaud | The required baudrate. | |
uxRxQueueLength | The length of the Rx buffer (if 0, rx is not supported). | |
uxTxQueueLength | The length of the Tx buffer (if 0, tx is not supported). |
Configure USART.
Definition at line 206 of file serial.c.
References CP_PBA_SPEED, iprvSerialCreateQueues(), serCOM1, serINVALID_COMPORT_HANDLER, usartPrivateData::usart, vUSART0_ISR(), vUSART1_ISR(), usartPrivateData::xCharsForTx, and usartPrivateData::xRxedChars.
Referenced by itracedump_Init(), and portTASK_FUNCTION().
00209 { 00210 xComPortHandle xReturn; 00211 xUsartPrivateData *pxUsart; 00212 int UsartRxEnMask = ((uxRxQueueLength==0) ? 0 : AVR32_USART_CR_RXEN_MASK); 00213 int UsartTxEnMask = ((uxTxQueueLength==0) ? 0 : AVR32_USART_CR_TXEN_MASK); 00214 int iTempoStatus; 00215 // USART options. 00216 usart_options_t USART_OPTIONS = 00217 { 00218 .baudrate = 57600, 00219 .charlength = 8, 00220 .paritytype = USART_NO_PARITY, 00221 .stopbits = USART_1_STOPBIT, 00222 .channelmode = USART_NORMAL_CHMODE 00223 }; 00224 00225 USART_OPTIONS.baudrate = ulWantedBaud; 00226 00227 xReturn = pxUsart = (UsartId == serCOM1 ? &xUsart0 : &xUsart1); 00228 00229 /* Create the rx and tx queues. */ 00230 iTempoStatus = iprvSerialCreateQueues( uxRxQueueLength, &(pxUsart->xRxedChars), 00231 uxTxQueueLength, &(pxUsart->xCharsForTx) ); 00232 00233 /* Configure USART. */ 00234 if( ( iTempoStatus != pdFAIL ) && 00235 ( ulWantedBaud != ( unsigned portLONG ) 0 ) ) 00236 { 00237 portENTER_CRITICAL(); 00238 { 00242 /* Enable USART RXD & TXD pins. */ 00243 if(UsartId == serCOM1) 00244 { 00245 if(uxRxQueueLength) 00246 gpio_enable_module_pin(AVR32_USART0_RXD_0_0_PIN, AVR32_USART0_RXD_0_0_FUNCTION); 00247 if(uxTxQueueLength) 00248 gpio_enable_module_pin(AVR32_USART0_TXD_0_0_PIN, AVR32_USART0_TXD_0_0_FUNCTION); 00249 } 00250 else 00251 { 00252 if(uxRxQueueLength) 00253 gpio_enable_module_pin(AVR32_USART1_RXD_0_0_PIN, AVR32_USART1_RXD_0_0_FUNCTION); 00254 if(uxTxQueueLength) 00255 gpio_enable_module_pin(AVR32_USART1_TXD_0_0_PIN, AVR32_USART1_TXD_0_0_FUNCTION); 00256 } 00257 00258 // Initialize USART in RS232 mode. 00259 usart_init_rs232(pxUsart->usart, &USART_OPTIONS, CP_PBA_SPEED); 00260 00261 /* We're not fully done yet: disable receiver and transmitter. */ 00262 pxUsart->usart->cr |= AVR32_USART_CR_RXDIS_MASK | AVR32_USART_CR_TXDIS_MASK; 00263 00264 // Register the USART interrupt handler to the interrupt controller and 00265 // enable the USART interrupt. 00266 if(UsartId == serCOM1) 00267 INTC_register_interrupt((__int_handler)&vUSART0_ISR, AVR32_USART0_IRQ, AVR32_INTC_INT1); 00268 else 00269 INTC_register_interrupt((__int_handler)&vUSART1_ISR, AVR32_USART1_IRQ, AVR32_INTC_INT1); 00270 00271 /* Enable USART interrupt sources (but not Tx for now)... */ 00272 if(uxRxQueueLength) 00273 pxUsart->usart->ier = AVR32_USART_IER_RXRDY_MASK; 00274 00275 /* Enable receiver and transmitter... */ 00276 pxUsart->usart->cr |= UsartTxEnMask | UsartRxEnMask; 00277 } 00278 portEXIT_CRITICAL(); 00279 } 00280 else 00281 { 00282 xReturn = serINVALID_COMPORT_HANDLER; 00283 } 00284 00285 return xReturn; 00286 }
signed portBASE_TYPE xUsartPutChar | ( | xComPortHandle | pxPort, | |
signed portCHAR | cOutChar, | |||
portTickType | xBlockTime | |||
) |
Put char to Usart.
pxPort | The Usart handle to put the char to | |
cOutChar | The char to transmit | |
xBlockTime | The max time to wait for getting the right to transmit the char. |
Definition at line 321 of file serial.c.
References usartPrivateData::usart, and usartPrivateData::xCharsForTx.
Referenced by usUsartPutString(), vcom1shell_PutChar(), vtracedump_Putchar(), and vtracedump_Putchar_Block().
00322 { 00323 xUsartPrivateData *pxUsart = (xUsartPrivateData *)pxPort; 00324 00325 /* Place the character in the queue of characters to be transmitted. */ 00326 if( xQueueSend( pxUsart->xCharsForTx, &cOutChar, xBlockTime ) != pdPASS ) 00327 { 00328 return pdFAIL; 00329 } 00330 00331 /* Turn on the Tx interrupt so the ISR will remove the character from the 00332 queue and send it. This does not need to be in a critical section as 00333 if the interrupt has already removed the character the next interrupt 00334 will simply turn off the Tx interrupt again. */ 00335 pxUsart->usart->ier = (1 << AVR32_USART_IER_TXRDY_OFFSET); 00336 00337 return pdPASS; 00338 }