Ejemplo n.º 1
0
unsigned char J1939_ReceiveOneMessage(struct J1939_message *msg, unsigned char buff_id)
{
	unsigned long id;
	unsigned char data[8];
	unsigned char len;
	unsigned char ret=0;

	ret = can_Receive(buff_id,&id,data,&len);
	if (ret)
	{
		for (ret=0; ret<len; ret++)
			msg->data[ret] = data[ret];
		msg->dataLen = len;

		clear_CPU_operation_detection();

		msg->sourceAddr   =  id&0x000000FF;
		msg->PDUspecific  = (id&0x0000FF00)>>8;
		msg->PDUformat    = (id&0x00FF0000)>>16;
		msg->dp           = (id&0x01000000)>>24;
		msg->r            = (id&0x02000000)>>25;
		msg->priority     = (id&0x1C000000)>>26;

		return 1;
	}

	return 0;
}
Ejemplo n.º 2
0
void i2c_Write(unsigned char byte)
{
	unsigned char i;
	unsigned int t=40;
	
	for (i=0; i<8; i++)
	{
		SCL = L; PSCL = 0;
		if (byte & 0x80)
			SDA = H;
		else
		{	SDA = L;PSDA = 0;}
		i2c_pause();
		
		byte<<=1;
	
		SCL = H;
		i2c_pause();
		//i2c_pause();	
	}

	SCL = L; PSCL = 0;
	SDA = H;
	i2c_pause();
	
	timeout = TIMEOUT;
	
	SCL = H;
	i2c_pause();
	while (PSDA && timeout)
	{
			timeout--;
			clear_CPU_operation_detection();
	}
	
	SCL = L; PSCL = 0;
	SDA = H;	
	i2c_pause();
	
	i2c_bigPause();
}
Ejemplo n.º 3
0
unsigned int mem_Read(unsigned int addr,unsigned char *data, unsigned int data_len)
{
	unsigned int i=0;
	unsigned char b;
	
	i2c_Start();
	i2c_Write(MEM_ADDRESS);
	if (i2c_Timeout()) goto Timeout;
	b = addr>>8;
	i2c_Write(b);
	if (i2c_Timeout()) goto Timeout;
	b = addr&0xFF;
	i2c_Write(b);
	if (i2c_Timeout()) goto Timeout;

	//i2c_Stop();
	
	i2c_Start();	
	i2c_Write(MEM_ADDRESS | 1);
	if (i2c_Timeout()) goto Timeout;
	
	for (i=0; i<data_len; i++)
	{
		data[i] = i2c_Read();
		clear_CPU_operation_detection();
		if (i<data_len-1)
			i2c_Ack();
		else
			i2c_Nack();
	}	
	
	i2c_Stop();
	
	return i;
	
	
	Timeout:
		return i;	
}
Ejemplo n.º 4
0
void main(void)
{
  unsigned char t = 0;
  unsigned int i = 0;
//  unsigned int i;
  
//  unsigned char wdtc = *((__far unsigned char*)0x188);
//  name[2] = wdtc;
  
//  WDTC_WTE = 0;
  
  clear_CPU_operation_detection();
  
  clear_CPU_operation_detection();
  DDR8 = 0x00;
  PDR8 = 0x00;
  DDR8_D87 = 1;
  PDR8_P87 = 1;
  
  DDR0 = 0x00;
  DDR1 = 0x00;
  DDR3 = 0x00;
  DDR4 = 0x00;
  DDR5 = 0x00;
  DDR6 = 0x00;
  DDR7 = 0x00;
  DDR9 = 0x00;
  
  PDR0 = 0x00;
  PDR1 = 0x00;
  PDR3 = 0x00;
  PDR4 = 0x00;
  PDR5 = 0x00;
  PDR6 = 0x00;
  PDR7 = 0x00;
  PDR9 = 0x00;
 
  EIRR = 0;  
  
  ADER = 0;
  
  PWC0_OE1 = 0;
  PWC0_OE2 = 0;   
  PWC1_OE1 = 0;
  PWC1_OE2 = 0;  
  PWC2_OE1 = 0;
  PWC2_OE2 = 0;  
  PWC3_OE1 = 0;
  PWC3_OE2 = 0;  
  
  
  InitTimer1();
  driver_Init();
  
  InitIrqLevels();
  __set_il(7);                /* allow all levels */
  __EI();                     /* globaly enable interrupts */
  
/*
  for (i=0; i<30000; i++)
		clear_CPU_operation_detection();
  for (i=0; i<30000; i++)
		clear_CPU_operation_detection();
  for (i=0; i<30000; i++)
		clear_CPU_operation_detection();
  for (i=0; i<30000; i++)
		clear_CPU_operation_detection();
  for (i=0; i<30000; i++)
		clear_CPU_operation_detection();
//*/		

  
  while(1)
  {
    driver_Update();
    clear_CPU_operation_detection();
    
//    if (t)
//	   	PDR8_P87 = 1;
//	else
//		PDR8_P87 = 0;
//	t=~t;
//	PDR8_P87 = ~PDR8_P87;
  }

}
Ejemplo n.º 5
0
void J1939_init(const unsigned char startAddress,const unsigned char *name)
{
	unsigned char i=0;

	TXstart=TXend=RXstart=RXend=0;
	TXsize=RXsize=0;

	ComandedAddress = startAddress;
	J1939_Address = startAddress;
	for (i;i<8;i++)	Name[i] = name[i];

	can_Init();		// 250 Kbit/s

   	for (i=0; i<BUFFER_TX_COUNT;i++)
	{
		can_SetBuffer(START_BUFFER_TX+i,0,0xFFFFFE);
		clear_CPU_operation_detection();
	}
	for (i=0; i<BUFFER_COUNT; i++)
	{
		can_SetBuffer(START_BUFFER+i,1,((unsigned long int)startAddress)<<8);
		can_EnableIRQ(START_BUFFER+i);
		clear_CPU_operation_detection();
	}
	for (i=0; i<BUFFER_GLOBAL_COUNT; i++)
	{
		can_SetBuffer(START_BUFFER_GLOBAL+i,1,0x0000F000);
		can_EnableIRQ(START_BUFFER_GLOBAL+i);
		clear_CPU_operation_detection();
	}

	can_SetMask0(0xFF00FF);
	can_SetMask1(0xFF0FFF);
	//can_Mode(0);

	J1939_Flags.CannotClaimAddress = 0;
	J1939_Flags.WaitingForAddressClaimContention = 0;
	J1939_Flags.ReceivedMessagesDropped = 0;

	J1939_Flags.AddressRequest = 0;

	J1939_Flags.Connected = 0;
	J1939_Flags.BAM = 0;
	J1939_Flags.WaitingForConnection = 0;
	J1939_Flags.ConnectFalied = 0;
	J1939_Flags.TransmisionError = 0;
	J1939_Flags.TransmisionComplete = 0;
	J1939_Flags.RemoteAddress = J1939_NULL_ADDRESS;

	J1939_timer = timer_Start();
	can_DisableAllIRQ();
    J1939_ClaimAddress(J1939_CLAIM_ADDRESS_TX);

	while (J1939_Flags.WaitingForAddressClaimContention)
	{
		clear_CPU_operation_detection();
		J1939_poll(5);
//		clear_CPU_operation_detection();
	}
	can_EnableAllIRQ();
	
	return;
}