⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 can_test.c

📁 ADI blackfin processor BF527 Ezkti test driver
💻 C
📖 第 1 页 / 共 2 页
字号:
	volatile unsigned short *pCAN_Ptr;

	g_TX_Count++;
	
	mbim_status = *pCAN_MBTIF2;
	while (!(mbim_status & 0x8000))
	{
		mbim_status <<= 1;
		bit_pos++;
	}
	
	mbID = (31 - bit_pos);

	pCAN_Ptr = (unsigned short *)CAN_MB00_DATA0 + (0x10 * mbID);
	
	g_CAN_STAMP_BUF[g_rx_buf_index + g_tx_buf_index].zero = ((*pCAN_Ptr + 0x0E) >> 2);
	g_CAN_STAMP_BUF[g_rx_buf_index + g_tx_buf_index].one = *pCAN_UCCNT;
	*pCAN_MBTIF2 = (1 << (15 - bit_pos));
	ssync();
		
	if(++g_tx_buf_index == BUF_SIZE)
		g_tx_buf_index=0;
	
} // end CAN_XMT_HANDLER



//--------------------------------------------------------------------------//
// Function:	EX_INTERRUPT_HANDLER(CAN_ERR_HANDLER)												//
//																			//
// Parameters:	none														//
//																			//
// Return:		none		
//																			//
// Description:	handles CAN ERROR ISR
//				                                                            //
//--------------------------------------------------------------------------//
EX_INTERRUPT_HANDLER(CAN_ERR_HANDLER)
{
	g_CAN_ERROR_FLAG = 1;
} // end CAN_ERR_HANDLER
	


//--------------------------------------------------------------------------//
// Function:	CAN_Transmit												//
//																			//
// Parameters:	none														//
//																			//
// Return:		1 if successful 0 if timeout		
//																			//
// Description:	Sends out the information in all the TX mail boxes
//				                                                            //
//--------------------------------------------------------------------------//
int CAN_Transmit(void)
{
	int nStatus = 0;
	unsigned int delay;
	unsigned int nTimer;
	
	nTimer = SetTimeout(0x800000);
	if( ((unsigned int)-1) != nTimer )
	{
		do{
			//// Set Transmit Requests for All TX Mailboxes
			*pCAN_TRS1 = 0;
			*pCAN_TRS2 = 0xFF00;
			ssync();
	
			if(g_TX_Count >= BUF_SIZE)
			{
				nStatus = 1;
				break;
			}
		}while( !IsTimedout(nTimer) );
	}
	ClearTimeout(nTimer);
	
	return nStatus;
} // End CAN_Transmit()


//--------------------------------------------------------------------------//
// Function:	CAN_Receive												//
//																			//
// Parameters:	none														//
//																			//
// Return:		1 if successful 0 if timeout		
//																			//
// Description:	Sends out the information in all the TX mail boxes
//				                                                            //
//--------------------------------------------------------------------------//
int CAN_Receive(void)
{
	int nStatus = 0;
	unsigned int nTimer;
	
	nTimer = SetTimeout(0x800000);  // this takes about 1.25 minutes to timeout
	if( ((unsigned int)-1) != nTimer )
	{
		do{
			if(g_RX_Count >= BUF_SIZE)
			{
				nStatus = 1;
				break;
			}
		}while( !IsTimedout(nTimer) );
	}
	ClearTimeout(nTimer);
	
	return nStatus;	
} // End CAN_Receive()

//--------------------------------------------------------------------------//
// Function:	TEST_CAN_RX												//
//																			//
// Parameters:	none														//
//																			//
// Return:		1 - pass 0 - fail		
//																			//
// Description:	Send and receive data over CAN interface
//				                                                            //
//--------------------------------------------------------------------------//
int TEST_CAN_RX(void)
{
	int iStatus = 0;
	int nTimer;
	
	g_rx_buf_index = 0;
	g_tx_buf_index = 0;
	g_TX_Count = 0;
	g_RX_Count = 0;
	g_CAN_ERROR_FLAG = 0;	// flag that can error isr sets
	
	
	Init_CAN_Port();

	iStatus = CAN_Receive();	// receive the data
	if( 1 == iStatus )
	{
		nTimer = SetTimeout(0x800);
		if( ((unsigned int)-1) != nTimer )
		{
			do{
				asm("nop;");
			}while( !IsTimedout(nTimer) );
		}
		ClearTimeout(nTimer);
		
		iStatus = CAN_Transmit(); 	// transmit all the TX mailbox responses
	}
	

    // turn off interrupts so that the data is stable.
    interrupt(ik_ivg7, SIG_IGN);
    interrupt(ik_ivg8, SIG_IGN);
    interrupt(ik_ivg9, SIG_IGN);
    
	// disable SIC Level Interrupts
	*pSIC_IMASK &= (~(IRQ_ERROR2|IRQ_CAN_RX|IRQ_CAN_TX));
	
	// free the memory allocated 
	if( NULL != g_CAN_STAMP_BUF )
	{
		free(g_CAN_STAMP_BUF);
		g_CAN_STAMP_BUF = NULL;
	}
	
	if( NULL != g_CAN_RX_BUFFER )
	{
		free(g_CAN_RX_BUFFER);
		g_CAN_RX_BUFFER = NULL;
	}
	
	
	
	
	if( 1 == g_CAN_ERROR_FLAG )
	{	// an error occured in the CAN test
		iStatus = 0;
	}
    
	return iStatus;
}

//--------------------------------------------------------------------------//
// Function:	TEST_CAN												//
//																			//
// Parameters:	none														//
//																			//
// Return:		1 - pass 0 - fail		
//																			//
// Description:	Send and receive data over CAN interface
//				                                                            //
//--------------------------------------------------------------------------//
int TEST_CAN_TX(void)
{
	int iStatus = 0;
	int nTimer;
	
	g_rx_buf_index = 0;
	g_tx_buf_index = 0;
	g_TX_Count = 0;
	g_RX_Count = 0;
	g_CAN_ERROR_FLAG = 0;	// flag that can error isr sets
	
	
	Init_CAN_Port();

	iStatus = CAN_Transmit(); 	// transmit all the TX mailboxes
	if( 1 == iStatus )
	{
		nTimer = SetTimeout(0x800);
		if( ((unsigned int)-1) != nTimer )
		{
			do{
				asm("nop;");
			}while( !IsTimedout(nTimer) );
		}
		ClearTimeout(nTimer);
		
		iStatus = CAN_Receive();	// receive the responses
	}
	

    // turn off interrupts so that the data is stable.
    interrupt(ik_ivg7, SIG_IGN);
    interrupt(ik_ivg8, SIG_IGN);
    interrupt(ik_ivg9, SIG_IGN);
    
	// disable SIC Level Interrupts
	*pSIC_IMASK &= (~(IRQ_ERROR2|IRQ_CAN_RX|IRQ_CAN_TX));
	
	// free the memory allocated 
	if( NULL != g_CAN_STAMP_BUF )
	{
		free(g_CAN_STAMP_BUF);
		g_CAN_STAMP_BUF = NULL;
	}
	
	if( NULL != g_CAN_RX_BUFFER )
	{
		free(g_CAN_RX_BUFFER);
		g_CAN_RX_BUFFER = NULL;
	}
	
	
	
	
	if( 1 == g_CAN_ERROR_FLAG )
	{	// an error occured in the CAN test
		iStatus = 0;
	}
    
	return iStatus;
}



#ifdef _STANDALONE_ // use this to run standalone tests
main()
{
	int i = 0;
	
	Init_PLL();
	Init_Timers();
	Init_Timer_Interrupts();
	
#ifdef _CAN_TX_
	i = TEST_CAN_TX();
#else
	i = TEST_CAN_RX();
#endif	
	asm("nop;");
	asm("emuexcpt;");
	asm("nop;");
	
} // end main

#endif // _STANDALONE_

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -