Exemplo n.º 1
0
void u4sendtest(int num)
{
	static uint8_t test[30]="0000 abcdefg1234567890\r\n";
	static uint32_t lp;
	static uint32_t ini = 0;

	if( ini == 0 )
	{
		ini = 1;
		UART4_init(115200);
	}
	while(num-- > 0)
	{
		test[0] = (num/1000)%10 + 48;
		test[1] = (num/100)%10 + 48;
		test[2] = (num/10)%10 + 48;
		test[3] = num%10 + 48;
		lp = 0;
		while( Cycbuf_WriteFrame(&U4SendBuf,test,24) < 0 )
		{
			if(lp++ > 100 )
			{
				lp = 0;
				rt_thread_delay(10);
			}
		}; 
	}	

}
Exemplo n.º 2
0
// ---------------------------------------------------------------------------------
// @brief : Common routine for initialising UART
// @param : uartNum is (USART# - 1). so USART1 -> 0
//		  : baudrate
// @retval: none
void UART_init(int16_t uartNum, int baudrate){
	switch(uartNum){
	case 0:UART1_init(baudrate); break;
	//case 1:UART2_init(baudrate); break;
	case 2:UART3_init(baudrate); break;
	case 3:UART4_init(baudrate); break;
	case 4:UART5_init(baudrate); break;
	}
}
Exemplo n.º 3
0
u8 Uart4_PutChar(u8 ch)
{
	static uint32_t ini = 0;

	if( ini == 0 )
	{
		ini = 1;
		UART4_init(115200);
	}
	USART_SendData(UART4, (u8) ch);
	while(USART_GetFlagStatus(UART4, USART_FLAG_TXE) == RESET)
	{
	}
	return ch;
}
Exemplo n.º 4
0
void FwsCOdectProcess_thread_entry(void* parameter)
{ 

	   uint32_t rxlen; 
	
	UART4_init(9600);
	/* Release 1 second cpu time solt for other module init function */
	rt_thread_delay(100);
	dogtri_init();
	rt_kprintf("[CO]UART4 band=9600 init.\n");

	while(1)
	{ 

		/* Send query command */
   		Cycbuf_WriteFrame(&U4SendBuf,QueryCmdCo,QUERY_CMD_LEN);
		/* Waitting result data */	
		
		////DOGTRI();
	 rt_thread_delay(CO_DECT_DELAY);
//		rt_thread_delay(20);
    DOGTRI();
		rxlen = Sbuf_read(&U4RevBuf,QueryCORxBuf,QUERY_RX_LEN);
	
		
		if( rxlen == 7 )
		{
			if( QueryCORxBuf[0] == 0x02 )
			/* Data analysis */
			CoPPM = (QueryCORxBuf[3]<<8)|QueryCORxBuf[4];	
			//CoPPM = 402;
			CoPPM_send_conver(CoPPM);
			
		}


		/* Query power was Start up */
		if( FwsPwrDect_isStartup() == PWR_OFF )
		{
			//TODO: Close any thing	 about CO audio warning.
			Cnt = 0;
			nowLVL = frontLVL = LV0;
			Cmd = ( CO_MARK | WARNING_NULL );
			Sbuf_write(&Ascb,&Cmd,1);
			fwsRlyWindClose(RLY_WIND_CO_FLAG);
			continue;
//			return;
		}



		/* If ppm safe */
		if( CoPPM < CO_PPM_LEVEL1 )
		{
			

			if( nowLVL > LV0  )
			{
				Cnt = 0;
				nowLVL = frontLVL = LV0;
				Cmd = ( CO_MARK | WARNING_NULL );
				Sbuf_write(&Ascb,&Cmd,1);
				fwsRlyWindClose(RLY_WIND_CO_FLAG);

			}	
		}

		/* If ppm warning */
		if( ( CoPPM >= CO_PPM_LEVEL1 ) && ( CoPPM < CO_PPM_LEVEL3 )  )
		{
		 	if( nowLVL == LV0 && frontLVL == LV0  )
			{
				nowLVL = LV1;
				Cnt = 0;
				Cmd = ( CO_MARK | CO_WARNING_SPEAK_MARK  );
				Sbuf_write(&Ascb,&Cmd,1);
				fwsRlyWindOpen(RLY_WIND_CO_FLAG,FELAY_DELAY_FOREVER);	
			}

			if( nowLVL == LV1 && frontLVL == LV0  )
			{
 				if( Cnt++ >= CO_DELAY_CNT )
				{
					Cnt = 0;
					Cmd = ( CO_MARK | WARNING_DIDI_MARK  );
					Sbuf_write(&Ascb,&Cmd,1);
					frontLVL = LV1;					 	
				}
			}

			if( nowLVL == LV2 && frontLVL == LV2 )
			{
				nowLVL = LV1; 	
				Cmd = ( CO_MARK | WARNING_DIDI_MARK  );
				Sbuf_write(&Ascb,&Cmd,1);
				frontLVL = LV1;	
			}

			if( nowLVL == LV1 && frontLVL == LV2 )
			{
				frontLVL = LV1; 		
			}
		}
		/* If ppm dangerous */
		if( CoPPM >= CO_PPM_LEVEL3 ) 
		{
			if( nowLVL < LV2  )
			{
				Cnt = 0;

				if( nowLVL == LV0 && frontLVL == LV0  )
					Cmd = ( CO_MARK | WARNING_DIDIDIDI_MARK |CO_WARNING_SPEAK_MARK  );
				else
					Cmd = ( CO_MARK | WARNING_DIDIDIDI_MARK   );
				Sbuf_write(&Ascb,&Cmd,1);
				nowLVL = frontLVL = LV2;
				fwsRlyWindOpen(RLY_WIND_CO_FLAG,FELAY_DELAY_FOREVER);	
			}
		
		}			

	}	
				
}