コード例 #1
0
unsigned char* read(void)
{
	askAboutSending();
	unsigned char *readBuffer = NULL;
	int statusRxFifoFilling = 0;
	int howManyRead = 0;

	statusRxFifoFilling = USIC_GetRxFIFOFillingLevel(UART001_0_USIC_CH);

	if(((UART001_GetFlagStatus(&UART001_Handle0,UART001_FIFO_STD_RECV_BUF_FLAG)) == UART001_SET))
	{

		statusRxFifoFilling = USIC_GetRxFIFOFillingLevel(UART001_0_USIC_CH);

		if(statusRxFifoFilling != 0)
		{
			readBuffer = (unsigned char *)malloc((sizeof(unsigned char)*statusRxFifoFilling) + 1);

			howManyRead =  UART001_ReadDataBytes(&UART001_Handle0, readBuffer, statusRxFifoFilling);

			readBuffer[statusRxFifoFilling] = '\0';
		}

		UART001_ClearFlag(&UART001_Handle0,UART001_FIFO_STD_RECV_BUF_FLAG);

		while(!USIC_ubIsRxFIFOempty(UART001_0_USIC_CH))
		{
			USIC_FlushRxFIFO(UART001_0_USIC_CH);
		}
	}

	stopAskingAboutSending();

	return readBuffer;
}
コード例 #2
0
ファイル: Bluetooth.c プロジェクト: Mateusz1992/Bachelor
void read(void)
{
	emptyReadData();
	if(((UART001_GetFlagStatus(&UART001_Handle0,UART001_FIFO_STD_RECV_BUF_FLAG)) == UART001_SET))
	{

		IO004_TogglePin(IO004_Handle1);

		statusRxFifoFilling = USIC_GetRxFIFOFillingLevel(UART001_0_USIC_CH);
		howManyRead =  UART001_ReadDataBytes(&UART001_Handle0, readData, statusRxFifoFilling);

		if(strcmp(readData, "LSM9DS1") == 0)
		{
			chosenSensor = 1;
		}
		else if(strcmp(readData, "TEMP_SENSOR") == 0)
		{
			chosenSensor = 2;
		}

		UART001_ClearFlag(&UART001_Handle0,UART001_FIFO_STD_RECV_BUF_FLAG);

		while(!USIC_ubIsRxFIFOempty(UART001_0_USIC_CH))
		{
			USIC_FlushRxFIFO(UART001_0_USIC_CH);
		}

		copyData();
		stopAskingAboutSending();
	}
}
コード例 #3
0
void DaisyChain(void)
{
	uint8_t i=0;
	status_t status=0;
	uint32_t data=0;
	
	static enum MotorState LastmotorState = Stopped;

	if ( motorState == StartUp )
	{
		CharCNT = 0;
		USIC_FlushRxFIFO(UART001_Handle0.UartRegs);
	}

	if ( (LastmotorState == StartUp) && (motorState != Running) )//(motorState == Running)StartUp
	{
		CCU40_CC42->TCCLR |= 0x02;	//定时器清零
		//Start slicesCCU4定时器运行
		CCU40_CC42->TCSET |= 0x01UL;
		
		CharCNT++;
		if ( CharCNT >= 13 )	//能收到连续的13字节完整包
		{
			CharCNT = 0;
			LastmotorState = motorState;
			CCU40_CC42->TCCLR |= 3UL;	//定时器停止运行
			USIC_FlushRxFIFO(UART001_Handle0.UartRegs);///added
		}
		else
		{
			return;
		}
	}
	else
		LastmotorState = motorState;


	//	if (DaisyTimeOut)
	//		StopMotor();

	if(USIC_GetRxFIFOFillingLevel(UART001_Handle0.UartRegs) >= DAISY_BUFFER_SIZE)
	{
		CCU40_CC42->TCCLR |= 3UL;	//定时器停止运行

		//Read data from UART buffer
		UART001_ReadDataBytes(&UART001_Handle0,FifoRecBuffer,DAISY_BUFFER_SIZE);
		//Assumption that communication is lost --> emtpy Receive Buffer
		if (FifoRecBuffer[DAISY_BUFFER_SIZE-1] != DAISY_STOP_BYTE)
		{
			//IO004_TogglePin(IO004_Handle1);
			USIC_FlushRxFIFO(UART001_Handle0.UartRegs);
			return;
		}

		uint8_t cmd = FifoRecBuffer[0];
		uint16_t params =  (FifoRecBuffer[1] << 8 | FifoRecBuffer[2]);

		switch (cmd)
		{
			case START_MOTOR:
				StartMotor();
				break;
			case STOP_MOTOR:
				StopMotor();
				break;
			case SET_REF_CURRENT:
				SetReferenceCurrent(params);
				break;
		}

		for(i=DAISY_MESSAGE_LENGTH; i<DAISY_BUFFER_SIZE-1; i++)
			FifoTransBuffer[i-DAISY_MESSAGE_LENGTH]=FifoRecBuffer[i];

		//Status-Code
		FifoTransBuffer[i-DAISY_MESSAGE_LENGTH]=status;
		i++;
		//Data
		FifoTransBuffer[i-DAISY_MESSAGE_LENGTH]=(uint8_t)(data >> 8);
		i++;
		FifoTransBuffer[i-DAISY_MESSAGE_LENGTH]=(uint8_t)data;
		i++;
		FifoTransBuffer[i-DAISY_MESSAGE_LENGTH]=DAISY_STOP_BYTE;
		DaisyTimeOut = 0;
		DaisyCount++;

		UART001_WriteDataBytes(&UART001_Handle0, FifoTransBuffer, DAISY_BUFFER_SIZE);
	}