/** * USARTからデータを受信してデータが正しいかを検討する関数 * @param USARTx 対象のUSART * @param data 受信データを入れる配列 * @param length 受信データ幅 * @return 1なら受信バッファ < length +1 * -1なら受信データがおかしい * * この関数による受信データは、 * 0xffが先頭バイト * 以下MSBが0のデータがlength個続く * * なので実際に受信するデータlength+1byteです。先頭の0xffは配列dataに渡す情報には含めません * * @Author AOKI */ int USART_Readnbyte(USART_TypeDef* USARTx, char* data,short length){ char tempdata[USART_MAX_DATA_SIZE]; int i; char temp[1]; if(USART_GetRxBufferSize(USARTx) < (length+1)){ return 1; } USART_Read(USARTx,temp,1); if(temp[0] == 0xff){ for(i=0;i<length;i++){ USART_Read(USARTx,temp,1); if((temp[0] & 0x80) != 0x00){ return -1; } tempdata[i] = temp[0]; } for(i=0;i<length;i++){ data[i] = tempdata[i]; } return 0; } return -1; }
int platform_s_uart_recv( unsigned id, s32 timeout ) { AT91S_USART* base = id == 0 ? AT91C_BASE_US0 : AT91C_BASE_US1; if( timeout == 0 ) { // Return data only if already available if( USART_IsDataAvailable( base ) ) return USART_Read( base, 0 ); else return -1; } return USART_Read( base, 0 ); }
/** * \brief USART handler */ void USART_Handler(void) { volatile uint32_t status; status = USART_GetStatus(USART); if ((status & 0x1) == 1) printf("%c", USART_Read(USART, 0)); }
void USART2_IRQHandler(void){ // check if the USART2 receive interrupt flag was set if(USART_GetITStatus(USART2,USART_IT_RXNE) != RESET) { USART_ClearITPendingBit(USART2,USART_IT_RXNE); USART_Read(USART2); } }
void Shell_Run() { uint8 buf[8]; int len = USART_Read(DEBUG_UART_ID, buf, sizeof(buf)); if(len) { Shell_String(Null, buf, len); } }
int platform_uart_recv( unsigned id, unsigned timer_id, int timeout ) { AT91S_USART* base = id == 0 ? AT91C_BASE_US0 : AT91C_BASE_US1; timer_data_type tmr_start, tmr_crt; int res; if( timeout == 0 ) { // Return data only if already available if( USART_IsDataAvailable( base ) ) return USART_Read( base, 0 ); else return -1; } else if( timeout == PLATFORM_UART_INFINITE_TIMEOUT ) { // Wait for data return USART_Read( base, 0 ); } else { // Receive char with the specified timeout tmr_start = platform_timer_op( timer_id, PLATFORM_TIMER_OP_START,0 ); while( 1 ) { if( USART_IsDataAvailable( base ) ) { res = USART_Read( base, 0 ); break; } else res = -1; tmr_crt = platform_timer_op( timer_id, PLATFORM_TIMER_OP_READ, 0 ); if( platform_timer_get_diff_us( timer_id, tmr_crt, tmr_start ) >= timeout ) break; } return res; } }
uint8_t USART_ReadBlockingMode( void ) //阻塞方式接收串口数据 { uint8_t ret; if(USART_ReadyRead()) ret = USART_Read(); else { UCSRB &= ~(0x01 << RXCIE); while(!(UCSRA&(1<<RXC))); ret = UDR; UCSRB |= (0x01 << RXCIE); } return ret; }
int DebuggerPort_Read( COM_HANDLE ComPortNum, char* Data, size_t size ) { NATIVE_PROFILE_PAL_COM(); int ret = 0; switch(ExtractTransport(ComPortNum)) { case USART_TRANSPORT: ret = USART_Read( ConvertCOM_ComPort( ComPortNum ), Data, size ); break; case USB_TRANSPORT: ret = USB_Read( ConvertCOM_UsbStream( ComPortNum ), Data, size ); break; case SOCKET_TRANSPORT: ret = SOCKETS_Read( ConvertCOM_SockPort(ComPortNum), Data, size ); break; } return ret; }
int COM2_read( char* buffer, size_t size ) { return USART_Read( ConvertCOM_ComPort( COM2 ), buffer, size ); }
void USART1_IRQHandler(void){ // check if the USART1 receive interrupt flag was set if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET){ USART_Read(USART1); } }
//////////////////////////////////////////////////////////////////////////////// // USART0 - odbieranie danych po wystapieniu przerwania RXRDY //////////////////////////////////////////////////////////////////////////////// char UART0_Read(void) { return USART_Read(AT91C_BASE_US0, 10); // return (AT91C_BASE_US0->US_RHR & 0xFF); }
static int uart_recv() { return USART_Read( AT91C_BASE_US0, 0 ); }
void TestControllerTick(Rover * rov) { char dat[2]; char serDat[15]; char len; if (GetSpanUs(&testController.pingTimer) > FROM_uS(1000000)) { dat[0]='Z'; dat[1]=testController.inc++; if (dat[1]=='z') testController.inc='A'; CommPacket respPkt; respPkt.target = TARGET_GUI; respPkt.length = 2; respPkt.data = dat; //SendMessage(rov,&respPkt); StartTimer(&testController.pingTimer); } if (USART_RXUsed(&testController.cameraPort)!=0) { len = USART_Read(&testController.cameraPort, serDat, 15); CommPacket respPkt; respPkt.target = TARGET_GUI; respPkt.length = 2; respPkt.data = dat; SendMessage(rov,&respPkt); dat[0]='S'; dat[1]=serDat[0]; SendMessage(rov,&respPkt); } /* char data[2] = { 'X', 'a' }; CommPacket reqPacket; CommPacket confPacket; CommPacket * rcvdPacket; char confdata[6] = {'V','A','L','I','D', 0 }; reqPacket.target = 1; reqPacket.length = 2; reqPacket.data = data; confPacket.target = TARGET_GUI; confPacket.length = 6; confPacket.data = confdata; if (testController.timeoutCounter>15000) { // time to send another message CommSendPacket(&testController.inf, &reqPacket); testController.timeoutCounter = 0; } else { testController.timeoutCounter++; } if (CommRXPacketsAvailable(&testController.inf)) { // do we have a reply packet to read? rcvdPacket = CommGetPacket(&testController.inf); if (rcvdPacket->target==0) { if (CommRXPacketsAvailable(&testController.inf)==4) confdata[3] = CommRXPacketsAvailable(&testController.inf); else confdata[3] = 'I'; } confdata[3] = rcvdPacket->data[0]; SendMessage(rov, &confPacket); CommDeletePacket(rcvdPacket); free(rcvdPacket); }*/ }