I'm trying to make an Ethernet to CAN bridge using CB34EX. But i'm facing a very strange problem

Here are the two little programs :
Java "server" (run method of the thread) :
Code: Select all
public void run() {
while (true) {
int size = 8;//(int)(random.nextFloat()*8) + 1;
bytesSent += size;
System.out.println(bytesSent / 8);
byte[] byteBuffer = new byte[size];
random.nextBytes(byteBuffer);
DatagramPacket dgPacket = new DatagramPacket(byteBuffer, byteBuffer.length, destinationAddress, destinationPort);
try {
dgSocket.send(dgPacket);
} catch (IOException e) {
e.printStackTrace();
}
long t = System.nanoTime();
while((System.nanoTime() - t) < 3*1000000);
}
}
Code: Select all
#include "predef.h"
#include <stdio.h>
#include <ctype.h>
#include <startnet.h>
#include <autoupdate.h>
#include <canif.h>
#include <udp.h>
#define LED1_GREEN (0x80)
#define LED1_RED (0x40)
#define LED1_OFF (0xC0)
#define LED2_GREEN (0x20)
#define LED2_RED (0x10)
#define LED2_OFF (0x30)
extern "C" {
void UserMain(void * pd);
}
const char * AppName="CanEthernet";
void UserMain(void * pd) {
InitializeStack();
OSChangePrio(MAIN_PRIO);
EnableAutoUpdate();
StartHTTP();
/*
* CAN initialisation : must be done before any CAN function (except CanShutDown)
* 1Mhz, null global mask (each message is accepteds) and default IRQ level = 4
*/
int canResponse = CanInit(1000000, 0x0000);
/*
* Prepare FIFO to recieve messages from UDP
*/
OS_FIFO udpFifo;
OSFifoInit(&udpFifo);
/*
* Register UDP fifo using listen port parameter
*/
RegisterUDPFifo(15001, &udpFifo);
int freeCanChannel = FreeCanChannels();
if(freeCanChannel == 16) putleds( LED2_GREEN );
putleds( LED1_GREEN );
while (canResponse == CAN_OK) {
{//This is UDP receive scope stuff input
/*
* create UDP packet waiting until something is comming from port
*/
UDPPacket pkt(&udpFifo, 0);
if(pkt.Validate()) {
WORD nbBytesRead = pkt.GetDataSize();
PBYTE udpByteBuffer = pkt.GetDataBuffer();
//If we are here, it's because something is comming from UDP
//Send it via CAN with message ID 1
int currentPosition = 0;
int bytesToSend = 0;
while(currentPosition < nbBytesRead) {
//Send message length of maximum 8 bytes
bytesToSend = nbBytesRead - currentPosition;
if(bytesToSend > 8) bytesToSend = 8;
canResponse = SendMessage(NormToNbId(1), &udpByteBuffer[currentPosition], bytesToSend, DONT_WAIT, 0);
currentPosition += bytesToSend;
//USER_ENTER_CRITICAL();
//for(int i = 0; i<1000; i++) asm("nop");
//USER_EXIT_CRITICAL();
}
}
}
}
freeCanChannel = FreeCanChannels();
putleds( LED2_OFF );
putleds( LED1_OFF );
if(freeCanChannel < 16) putleds( LED2_RED );
if(canResponse == CAN_CHANNEL_USED) putleds( LED1_RED );
CanShutDown();
UnregisterUDPFifo(15001);
}
If I replace DONT_WAIT with any other value, than the netburner hangs, stops, (after several seconds) never returning from SendMessage function and the CAN port sends always the same values.
I've not been able to find my error.
Any help would be very appreciated.
Thanks a lot,
frank