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

📄 can_test.c

📁 基于三星2410嵌入式平台
💻 C
字号:
//====================================================================
// File Name : 2410test.c
// Function  : S3C2410 Test Main Menu
// Program   : Shin, On Pil (SOP)
// Date      : May 30, 2002
// Version   : 0.0
// History
//   0.0 : Programming start (February 20,2002) -> SOP
//   1.0 (20020530) : First release for customer
//   1.1 (20020801) : Strata NOR Flash Added and etc. -> SOP
//====================================================================

#include <stdlib.h>
#include <string.h>
#include "sja1000.h"
//Shin, On Pil
#include "def.h"
#include "option.h"
#include "2410addr.h"
#include "2410lib.h"
#include "2410slib.h"

#include "2410etc.h"
#include "2410IIC.h"
#include "2410iis.h"
#include "2410int.h"
#include "2410RTC.h"
#include "2410swi.h"
//#include "cpuspeed.h"
//#include "lcdpwr.h"
#include "timer.h"

//Kang, Weon Tark
#include "adc.h"
#include "dma.h"
#include "dma2.h"
#include "eint.h"
#include "extdma.h"
#include "k9s1208.h"
#include "mmu.h"
#include "nwait.h"
#include "sdi.h"
#include "stone.h"
#include "ts_auto.h"
#include "ts_sep.h"
#include "usbfifo.h"

//Shin, Jeong Seuk
#include "IrDA.h"
#include "lcd.h"
#include "lcdlib.h"
#include "glib.h"
#include "palette.h"
#include "spi.h"
#include "uart0.h"
#include "uart1.h"
#include "uart2.h"

//Kong, In Wook
#include "etc.h"
#include "flash.h"
#include "idle.h"
#include "pd6710.h"
#include "pll.h"
#include "power.h"
#include "pwr_c.h"
#include "stop.h"

void Isr_Init(void);
void HaltUndef(void);
void HaltSwi(void);
void HaltPabort(void);
void HaltDabort(void);
volatile int *ad_write=(volatile int*)(0x28500000);


unsigned int T_flag0=0;
unsigned int T_flag1=0;
unsigned long int cc=8;

//unsigned char data[11] = {'\0'};
//unsigned char Rx_Buf0[11] = {'\0'};
unsigned char Tx_Buf0[9] = {'\0'};
unsigned char Tx_Buf1[9] = {'\0'};
//unsigned char Rx_Buf1[11] = {'\0'};


/*writ to the register with tht data
	chanal--通道号,可选CAN总线1,CAN总线2
	reg-----寄存器号
	data----寄存器数据*/
void setcanport(unsigned char chanal, unsigned int reg, unsigned char data1)
{
    if(!chanal)
	   BASEADD = (volatile char*)(0x28000000);
    else
    	BASEADD =(volatile char*)(0x28400000);
	*(BASEADD+0x100)=reg;
	*(BASEADD)=data1;

}

/*read the data of the register to the return
	chanal--通道号,可选CAN总线1,CAN总线2
	reg-----寄存器号
	返回值--寄存器数据*/
unsigned char getcanport(unsigned char chanal, unsigned char reg)
{
    unsigned char temp;
    if(!chanal)
	   BASEADD = (volatile char*)(0x28000000);
    else
    	BASEADD = (volatile char*)(0x28400000);
  
	*(BASEADD+0x100)=reg;
	temp=*BASEADD;
	return (temp);
}

/*if receive mailbox have data
	chanal--通道号,可选CAN总线1,CAN总线2
	返回值--是否有数据,如果为0,表示有数据,否则没有数据*/

unsigned char ifgetdata(unsigned char chanal)
{
   unsigned char temp;
   if(((getcanport(chanal,StatusReg) & RBS_Bit) != RBS_Bit))
      temp=1;
   else
      temp=0;   
   return (temp);

}


/*Receive one message
	chanal--通道号,可选CAN总线1,CAN总线2
	返回值--数据个数*/
unsigned char getdata(unsigned char chanal, unsigned char *buf)
{	
	int num,i;
	unsigned char data[11] = {'\0'};
    unsigned char panduan;
	
	data[0] = getcanport(chanal,RxBuffer1);
	data[1] = getcanport(chanal,RxBuffer2);
	data[2] = getcanport(chanal,RxBuffer3);
	data[3] = getcanport(chanal,RxBuffer4);
	data[4] = getcanport(chanal,RxBuffer5);
	data[5] = getcanport(chanal,RxBuffer6);
	data[6] = getcanport(chanal,RxBuffer7);
	data[7] = getcanport(chanal,RxBuffer8);
	data[8] = getcanport(chanal,RxBuffer9);
	data[9] = getcanport(chanal,RxBuffer10);
	
	num = data[1]&0x0f;

	
	for(i=0;i<num;i++)
	{
	*(buf++)=data[i+2];
	}

	setcanport(chanal,CommandReg,RRB_Bit);

	*buf=0;

	return (num);

	
}

/*Transmit one message
	num-----数据个数
	data----数据
	返回值--0 忙*/
unsigned char senddata(unsigned char chanal, unsigned char *buf)
{	    
	
	unsigned char temp = 0;
	unsigned char data[11] = {'\0'};
	int i;
	

	if((getcanport(chanal,StatusReg) & TBS_Bit) == TBS_Bit)
	{
		for(i=0;i<8;i++)
		{
		data[i]=*(buf+i);
		}
		temp = getcanport(chanal, StatusReg);
		setcanport(chanal,TxBuffer1,0x00);
		setcanport(chanal,TxBuffer2,0x08);
		setcanport(chanal,TxBuffer3,data[0]);
		setcanport(chanal,TxBuffer4,data[1]);
		setcanport(chanal,TxBuffer5,data[2]);
		setcanport(chanal,TxBuffer6,data[3]);
		setcanport(chanal,TxBuffer7,data[4]);
		setcanport(chanal,TxBuffer8,data[5]);
		setcanport(chanal,TxBuffer9,data[6]);
		setcanport(chanal,TxBuffer10,data[7]);
		
		setcanport(chanal,CommandReg,0x01);
		
		do 
		  {
		     temp = getcanport(chanal, StatusReg);
		     if ((temp & TCS_Bit)==TCS_Bit)
		        break;
		  } while(1);     //If it is transmitted succeded?

		return (1);
	}
	else if(!chanal)
	{
		if(!T_flag0)
		{
			for(i=0;i<8;i++)
			{
			Tx_Buf0[i]=*(buf+i);
			}
			T_flag0=1;//传输标志,1表示一个报文等待发送
		}
		else return (0);
	}
	else
	{
		if(!T_flag1)
		{
			for(i=0;i<8;i++)
			{
			Tx_Buf1[i]=*(buf+i);
			}
			T_flag1=1;//传输标志,1表示一个报文等待发送
		}
		else return (0);
	}
	
}


/*Initial the SJA1000 It just is BasicCAN */
void FFT_init_can(unsigned char chanal,unsigned char ac,unsigned char am,unsigned char btr0,unsigned char btr1)
{
	
	unsigned char temp = 0;

//进入复位请求设置模式
	while((temp&RM_RR_Bit)!=RM_RR_Bit)
	{
	printf("\n0x01 will be set to ModeControlReg\n");
	setcanport(chanal, ModeControlReg,0x07);/*Config MOD&CR register,初始化INT*/
	temp = getcanport(chanal, ModeControlReg);
	printf("\nModeControlReg=%d\n",temp);
	}
	
//设置接收码
	setcanport(chanal, AcceptCodeReg, ac);

//设置屏蔽码
	setcanport(chanal, AcceptMaskReg, am);

//设置总线bps
	setcanport(chanal, BusTiming0Reg, btr0);

	setcanport(chanal, BusTiming1Reg, btr1);

//设置CAN输出模式	
	setcanport(chanal, OutControlReg, 0xda);

//设置时钟分频寄存器
	setcanport(chanal, ClockDivideReg, 0x48);

/*清除复位模式位*/
	do
	{
	setcanport(chanal, ModeControlReg, 0x06);/*Config MOD&CR register*/
	}while(((getcanport(chanal, ModeControlReg)) & RM_RR_Bit)!=ClrByte);
}

//===================================================================
void Main(void)
{
    int i,j,n,cc;
    unsigned char *buf;
	static unsigned int number=0;
	unsigned char d[5][9]={"asdfjkl;","12345678","90123456","78787878","abcdefgh"};
    unsigned char panduan;
	unsigned long t;

//  2. MMU的初始化
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//      MMU_Init();         //mmu.c
//   

//  3. 改变时钟配置
    ChangeClockDivider(1,1);          // 1:2:4    2410lib.c

    ChangeMPllValue(0xa1,0x3,0x1);    // FCLK=202.8MHz  2410lib.c


//  4. 所有IO口的初始化配置
    Port_Init();              //2410lib.c
    

//  5. 所有中断模式的初始化配置
    Isr_Init();

//  7. 串口的初始化配置和选择

    Uart_Init(0,115200);
    Uart_Select(0);

//  8. delay和电源管理

    Delay(0);	//calibrate Delay()
    Check_PowerOffWakeUp();  //It's needed for power-off STOP mode test.   

    //Save the wasted power consumption on GPIO.
    rIISPSR=(2<<5)|(2<<0); //IIS_LRCK=44.1Khz @384fs,PCLK=50Mhz.
    rGPHCON = rGPHCON & ~(0xf<<18)|(0x5<<18);   //CLKOUT 0,1=OUTPUT to reduce the power consumption.

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//  9. 测试LCD
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

//    while(1)
   // {
    //    i = 0;
       // Uart_Printf("\n\nFFT-S3C2410 A/D TESTED\n");
        //Test_Ad();

   // }
   	FFT_init_can(1,1,255,71,175);   //通道号,接收码,屏蔽码,波特率0,波特率1
	Uart_Printf("CanInit1 is ok\n");
	
	FFT_init_can(0,1,255,71,175);   //通道号,接收码,屏蔽码,波特率0,波特率1
    Uart_Printf("CanInit0 is ok\n");
//
	for(i=0;i<1;i++)
	{
	buf=&d[i][0];
	senddata(1,buf);
	};
	
    for(;;)
    {
       panduan=ifgetdata(0);
       if(panduan==0)
         break;
    }
	
	getdata(0,buf);
	number=number+1;
	Uart_Printf("can test ok");
}

//===================================================================
void Isr_Init(void)
{
    pISR_UNDEF  = (unsigned)HaltUndef;
    pISR_SWI    = (unsigned)HaltSwi;
    pISR_PABORT = (unsigned)HaltPabort;
    pISR_DABORT = (unsigned)HaltDabort;
    
    rINTMOD     = 0x0;                     //All=IRQ mode
//    rINTCON=0x5;                           //Non-vectored,IRQ enable,FIQ disable    
    rINTMSK     = BIT_ALLMSK;              //All interrupt is masked.
    rINTSUBMSK  = BIT_SUB_ALLMSK;          //All sub-interrupt is masked. <- April 01, 2002 SOP

//    rINTSUBMSK  = ~(BIT_SUB_RXD0);         //Enable Rx0 Default value=0x7ff
//    rINTMSK     = ~(BIT_UART0);            //Enable UART0 Default value=0xffffffff    
    
//    pISR_UART0=(unsigned)RxInt;            //pISR_FIQ,pISR_IRQ must be initialized
}

//===================================================================
void HaltUndef(void)
{
    Uart_Printf("Undefined instruction exception.\n");
    while(1);
}

//===================================================================
void HaltSwi(void)
{
    Uart_Printf("SWI exception.\n");
    while(1);
}

//===================================================================
void HaltPabort(void)
{
    Uart_Printf("Pabort exception.\n");
    while(1);
}

//===================================================================
void HaltDabort(void)
{
    Uart_Printf("Dabort exception.\n");
    while(1);
}





/*
//=========================
    while(1)
    {
       Led_Display(3);
    }
//=========================    
*/
/*
//=========================
    while(1)
    {
       Led_Display(1);
       Delay(1500);   
       Led_Display(2);
       Delay(1500);             
       Led_Display(4);
       Delay(1500);   
       Led_Display(8);
       Delay(1500);                
    }
//=========================   
*/

⌨️ 快捷键说明

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