Esempio n. 1
0
static void usart_rx_task(void *pvParameters)
{
    uint8_t i=0;
    char data_buf[BUFFER_LENGTH];
    for (;;) {
	if (pdPASS == xQueueReceive(usart_rxq, &data_buf[i], portMAX_DELAY)) {
#ifdef USART_ECHO
	    USART_SendByte(data_buf[i]);
#endif
	    if (data_buf[i]=='\r') {
		data_buf[i+1]='\0';
		if (i) {
		    USART_SendString("\r\nReceived data: ");
		    USART_SendString(data_buf);
		};
#ifndef USART_ECHO
		USART_SendByte('\r');
#endif
		USART_SendByte('\n');
		i=0;
	    } else if (i<BUFFER_LENGTH-1)
		i++;
	}
    }
    vTaskDelete(NULL);
}
Esempio n. 2
0
/* USART6 IRQ handler. */
void USART6_IRQHandler(void) {
	uint8_t i;
	uint8_t rxdata;
	BaseType_t xHigherPriTaskWoken;

	xHigherPriTaskWoken = pdFALSE;

	/* USART6 RX interrupt. */
	if(USART6->SR & USART_SR_RXNE) {
		/* Push data into RX Queue. */
		rxdata = USART_ReadByte(USART6);
#ifdef MIRROR_USART6
		USART_SendByte(USART2, rxdata);
#endif
		if(rxPipeState > 0) {
			if(PushQueue(rxQueue, &rxdata)) {
				GPIO_SetBits(LEDS_GPIO_PORT, RED);
				GPIO_ResetBits(LEDS_GPIO_PORT, BLUE);
			}
			else {
				GPIO_SetBits(LEDS_GPIO_PORT, BLUE);
				GPIO_ResetBits(LEDS_GPIO_PORT, RED);
			}
		}
	}

	/* USART6 TX interrupt. */
	if(USART6->SR & USART_SR_TXE) {
		if(usart_stream[usart_stream_idx].BufLen > 0) {
			USART_SendByte(USART6, *usart_stream[usart_stream_idx].pBuf);
			usart_stream[usart_stream_idx].pBuf++;
			usart_stream[usart_stream_idx].BufLen--;
		}
		else {
			/* Current USART streaming is finished. */
			/* Release and clear current USART stream. */
			ClearStream(usart_stream + usart_stream_idx);
			/* Try to stream next USART stream which should be stream. */
			usart_stream_idx++;
			for(i=0; i<MAX_USART_STREAM; i++) {
				usart_stream_idx = (usart_stream_idx + i) % MAX_USART_STREAM;
				if(usart_stream[usart_stream_idx].pBuf != NULL)
					break;
			}
			/* Disable USART6 TX interrupt after all streams are finished. */
			if(i >= MAX_USART_STREAM)
				USART_ITConfig(USART6, USART_IT_TXE, DISABLE);
		}
	}
}
Esempio n. 3
0
/* Send bytes array with designated length through USART. */
ssize_t USART_Send(USART_TypeDef *USARTx, void *buf, ssize_t l, uint8_t flags) {
	ssize_t i = 0;
	uint8_t idx;
	uint8_t *pBuf;

	pBuf = buf;

	/* Send with blocking mode. */
	if(flags == BLOCKING) {
		for(i=0; i<l; i++) {
			while(USART_GetFlagStatus(USARTx, USART_FLAG_TC) == RESET);
			USART_SendByte(USARTx, (uint16_t)(pBuf[i]));
		}
	}
	/* Send with non-blocking mode. */
	else if(flags == NON_BLOCKING) {
		for(i=0; i<MAX_USART_STREAM; i++) {
			idx = (i + usart_stream_idx) % MAX_USART_STREAM;
			if(usart_stream[idx].pBuf == NULL) {
				usart_stream[idx].pBuf = pBuf;
				usart_stream[idx].BufLen = l;
				/* Enable USART6 TX interrupt. */
				USART_ITConfig(USART6, USART_IT_TXE, ENABLE);
				break;
			}
		}
		if(i >= MAX_USART_STREAM)
			i = -1;
	}

	return i;
}
//////////////////////////////////////////////////////////////////////////
//	Serial Input Function:
//		This function will allow for timeout if a byte does is not
//		received in the allotted time
//////////////////////////////////////////////////////////////////////////
void fcnSendDivertData( void ) {
	// Perform only if Divert is on Divert Mode
	if ( mySys.chMode == SYSTEM_MODE_DIVERT ) {
		
		// Check if Byte separator has been satisfied
		if ( mySys.clkCount > ( uint32_t ) ( myDivert.ByteDelay + durationBYTE_DELAY ) ) {
			myDivert.IsToGo = 0xFF;
			myDivert.ByteDelay = mySys.clkCount;
		}
		
		// Send the necessary data by stages
		if ( myDivert.IsToGo ) {
			myDivert.IsToGo = 0x00;
			
			// Check correct command based on time
			fcnSelectCommandByte();
			USART_SendByte(myDivert.command);
			//eeprom_write_byte(eepromCOM_TX_RAW + myDivert.j, myDivert.command);
			
			
		}
		
		if ( !(mySys.clkCount < myDivert.SlatTravelTimes[0] * myCOM.PacketData[3]) ) {
			
			// End of action, reset everything
			mySys.clkCount = 0;
			usartCleanPacket();
			mySys.chMode = SYSTEM_MODE_DATA_WAIT;	//	Finish Transmission and go back to idling
			UCSR0C = 0b00110110;
			UCSR0B = 0b10011000;	// Tx/Rx Enabled. Rx Interrupt Enabled
		}
	}
}
Esempio n. 5
0
void USART_SendString(char * str)
{
    while(* str) {
	USART_SendByte(*str);
	str++;
    }
}
void fcnRunDebugMode(void) {
	// Run the same command for about 3 minutes
	UCSR0B = 0b10001000;	// Rx Disabled. Rx Interrupt Enabled
	
	if ( mySys.devAddress == 0 ) {
		DebugCommand = myCOM.PacketData[2];
		//DebugCommand = 0x87;
		mySys.clkCount = 0;
		myDivert.ByteDelay = mySys.clkCount;
		myDivert.IsToGo = 0xFF;
		
		while ( !(mySys.clkCount > DebugDelay) )
		{
			// Check if Byte separator has been satisfied
			if ( mySys.clkCount > ( uint32_t ) ( myDivert.ByteDelay + durationBYTE_DELAY ) ) {
				myDivert.IsToGo = 0xFF;
				myDivert.ByteDelay = mySys.clkCount;
			}
			
			if ( myDivert.irPacketLength > 2 ) {
				// Since for now, we know that no bytes should be sent, disable
				myDivert.irSendPacket = 0x00;
				
				if ( mySys.clkCount > ( uint32_t ) ( myDivert.irPacketDelay + delayIR_PACKET ) ) {
					myDivert.irSendPacket = 0xFF;
					myDivert.irPacketLength = 0;
					
					//mySys.clkCount = 0;
					myDivert.ByteDelay = mySys.clkCount;
					myDivert.IsToGo = 0xFF;
				}
			}
			
			// Send the necessary data by stages
			if ( myDivert.IsToGo && myDivert.irSendPacket ) {
				myDivert.IsToGo = 0x00;
				
				// Check correct command based on time
				USART_SendByte( DebugCommand );
				//eeprom_write_byte(eepromCOM_TX_RAW + myDivert.j, myDivert.command);
				
				myDivert.irPacketLength++;
				if ( myDivert.irPacketLength == 3 ) {
					myDivert.irPacketDelay = mySys.clkCount;
				}
			}
			
			
		}
	}
	
	mySys.clkCount = 0;
	
	usartCleanPacket();
	mySys.chMode = SYSTEM_MODE_DATA_WAIT;
	UCSR0B = 0b10011000;	// Rx Disabled. Rx Interrupt Enabled
}
Esempio n. 7
0
int main(void)
{
    GPIO_Config();
    USART_Config();

    USART_SendString("Hello");
    USART_SendByte('!');
    USART_SendString("\r\n");

    xTaskCreate(vLedTask,(signed char*) "LedTask", configMINIMAL_STACK_SIZE, (void *) NULL, tskIDLE_PRIORITY + 2, NULL);
    vTaskStartScheduler();

}
Esempio n. 8
0
int carDirectOut(CAR_INFO * carInfo)
{
	int ret =0;
	char i;
	char * usartDirectOut = carInfo->usartDirectOut;

	for(i = 0; i < 11; i ++)
	{
		USART_SendByte(USART3,usartDirectOut[i]);
	}

	return ret;
}
Esempio n. 9
0
int carSpeedOut(CAR_INFO * carInfo)
{
	int ret = 0;
	char i;
	char * usartSpeedOut = carInfo->usartSpeedOut;

	for(i = 0; i < 10; i ++)
	{
		if(usartSpeedOut[i])
		{
			USART_SendByte(USART2,usartSpeedOut[i]);
		}
	}

	return ret;
}
void fcnSendParameters( void ) {
	
	
	
		// Send Character
	USART_SendByte( myCOM.ConveyorSpeed );
		// Delay transmission	
	fcnInSeriesByteDelay();
		// Send Character
	USART_SendByte( myCOM.ConveyorSpeed );
		// Delay transmission
	fcnInSeriesByteDelay();
		// Send Character
	USART_SendByte( myCOM.RURD );
		// Delay transmission
	fcnInSeriesByteDelay();
		// Send Character
	USART_SendByte( myCOM.RURD );
		// Delay transmission
	fcnInSeriesByteDelay();
		// Send Character
	USART_SendByte( myCOM.DivertDelay );
		// Delay transmission
	fcnInSeriesByteDelay();
		// Send Character
	USART_SendByte( myCOM.DivertDelay );
		// Delay transmission
	fcnInSeriesByteDelay();
	
	// Check for end of transmission
	if ( mySys.clkCount > myDivert.ProgrammingDuration ) {
		usartCleanPacket();
		mySys.chMode = SYSTEM_MODE_PROCESS;	//	Finish Transmission and go back to idling
		UCSR0B = 0b10011000;	// Rx Enabled. Rx Interrupt Enabled
	}
}
Esempio n. 11
0
void cmdTrans(CAR_INFO * carInfo)
{
	int i = 0;

		if(cmdProcess.commandIn[i] == 1)
		{
			i ++;
			if(cmdProcess.commandIn[i] == 1)
			{
				i ++;
				carInfo->udpSpeedIn = cmdProcess.commandIn[i];
			}
			else
			{
			//其他电机指令类型待定义
			}
			i ++;
		}
		else
		{
			i ++;
			
			USART_SendByte(USART1,0x77);
		}
		if(cmdProcess.commandIn[i] == 1)
		{
			i ++;
			if(cmdProcess.commandIn[i] == 1)
			{
				i ++;
				memcpy(&(carInfo->udpDirectIn),&(cmdProcess.commandIn[i]),4);
			}
			else
			{
			//其他舵机指令类型待定义
			}
			i +=4;
		}
		else
		{
			i ++;
		}
		if(cmdProcess.commandIn[i] == 1)
		{
			i ++;
		}
		else
		{
			i ++;
		}
		if(cmdProcess.commandIn[i] == 1)
		{
			i ++;
		}
		else
		{
			i ++;
		}
	
	USART_Cmd(USART1, ENABLE);
	memset(&cmdProcess,0,sizeof(CMD_PROCESS));
}