# HG changeset patch # User etisserant # Date 1176270634 -7200 # Node ID ebf4bd44f2822a6b7dfe7f4e074dc4514db8f2f5 # Parent d2fc5d5f8a3624040004bdbb745e63c41c72ed92 Updated doc. Cleaned some code. diff -r d2fc5d5f8a36 -r ebf4bd44f282 doc/canfestival_OS.png Binary file doc/canfestival_OS.png has changed diff -r d2fc5d5f8a36 -r ebf4bd44f282 doc/canfestival_OS.svg --- a/doc/canfestival_OS.svg Sat Apr 07 09:49:05 2007 +0200 +++ b/doc/canfestival_OS.svg Wed Apr 11 07:50:34 2007 +0200 @@ -20,7 +20,7 @@ inkscape:export-xdpi="87.57" inkscape:export-ydpi="87.57" inkscape:output_extension="org.inkscape.output.svg.inkscape" - sodipodi:modified="TRUE"> + sodipodi:modified="true"> s_BOARD SlaveBoard = {"0", "500K"}; s_BOARD MyBoard = {"0", "500K"};scheduled function call. satck calls withstack calls with -#include -#include -#include -#include /* for NULL */ -#include -#include -#include -#include -#include - -/* driver pcan pci for Peak board */ -//#include "libpcan.h" -//#include "pcan.h" - -#include "libpcan.h" // for CAN_HANDLE - -#include -#include "timer.h" -#include "can_driver.h" -#include "timers_driver.h" - -#define MAX_NB_CAN_PORTS 16 - -typedef struct { - char used; - HANDLE fd; - TASK_HANDLE receiveTask; - CO_Data* d; -} CANPort; - -CANPort canports[MAX_NB_CAN_PORTS] = {{0,},}; - -// Define for rtr CAN message -#define CAN_INIT_TYPE_ST_RTR MSGTYPE_STANDARD | MSGTYPE_RTR - -/*********functions which permit to communicate with the board****************/ -UNS8 canReceive(CAN_HANDLE fd0, Message *m) -{ - UNS8 data; - TPCANMsg peakMsg; - if ((errno = CAN_Read(((CANPort*)fd0)->fd, & peakMsg))) { // Blocks until no new message or error. - if(errno != -EIDRM && errno != -EPERM) // error is not "Can Port closed while reading" - { - perror("!!! Peak board : error of reading. (from f_can_receive function) \n"); - } - return 1; - } - m->cob_id.w = peakMsg.ID; - if (peakMsg.MSGTYPE == CAN_INIT_TYPE_ST) /* bits of MSGTYPE_*/ - m->rtr = 0; - else - m->rtr = 1; - m->len = peakMsg.LEN; /* count of data bytes (0..8) */ - for(data = 0 ; data < peakMsg.LEN ; data++) - m->data[data] = peakMsg.DATA[data]; /* data bytes, up to 8 */ - - return 0; -} - -void canReceiveLoop(CAN_HANDLE fd0) -{ - CO_Data* d = ((CANPort*)fd0)->d; - Message m; - while (1) { - if(!canReceive(fd0, &m)) - { - EnterMutex(); - canDispatch(d, &m); - LeaveMutex(); - }else{ -// printf("canReceive returned error\n"); - break; - } - } -} - -/***************************************************************************/ -UNS8 canSend(CAN_HANDLE fd0, Message *m) -{ - UNS8 data; - TPCANMsg peakMsg; - peakMsg.ID=m -> cob_id.w; /* 11/29 bit code */ - if(m->rtr == 0) - peakMsg.MSGTYPE = CAN_INIT_TYPE_ST; /* bits of MSGTYPE_*/ - else { - peakMsg.MSGTYPE = CAN_INIT_TYPE_ST_RTR; /* bits of MSGTYPE_*/ - } - peakMsg.LEN = m->len; - /* count of data bytes (0..8) */ - for(data = 0 ; data < m->len; data ++) - peakMsg.DATA[data] = m->data[data]; /* data bytes, up to 8 */ - - if((errno = CAN_Write(((CANPort*)fd0)->fd, & peakMsg))) { - perror("!!! Peak board : error of writing. (from canSend function) \n"); - return 1; - } - return 0; - -} - -/***************************************************************************/ -CAN_HANDLE canOpen(s_BOARD *board) -{ - HANDLE fd0 = NULL; - char busname[64]; - char* pEnd; - int i; - - for(i=0; i < MAX_NB_CAN_PORTS; i++) - { - if(!canports[i].used) - break; - } - - if(strtol(board->busname, &pEnd,0) >= 0) - { - sprintf(busname,"/dev/pcan%s",board->busname); - fd0 = LINUX_CAN_Open(busname, O_RDWR); - } - - if (i==MAX_NB_CAN_PORTS || fd0 == NULL) - { - fprintf (stderr, "Open failed.\n"); - return (CAN_HANDLE)NULL; - } - - CAN_Init(fd0, board->baudrate, CAN_INIT_TYPE_ST); - - canports[i].used = 1; - canports[i].fd = fd0; - - canports[i].d = board->d; - CreateReceiveTask((CANPort*) &canports[i], &canports[i].receiveTask); - - return (CANPort*) &canports[i]; -} - -/***************************************************************************/ -int canClose(CAN_HANDLE fd0) -{ - CAN_Close(((CANPort*)fd0)->fd); - WaitReceiveTaskEnd(&((CANPort*)fd0)->receiveTask); - ((CANPort*)fd0)->used = 0; - return 0; -} diff -r d2fc5d5f8a36 -r ebf4bd44f282 drivers/unix/unix.c --- a/drivers/unix/unix.c Sat Apr 07 09:49:05 2007 +0200 +++ b/drivers/unix/unix.c Wed Apr 11 07:50:34 2007 +0200 @@ -27,16 +27,6 @@ #define DLL_CALL(funcname) (* funcname##_driver) #define FCT_PTR_INIT =NULL -#ifdef WIN32 -#define DLSYM(name)\ - *(void **) (&_##name) = GetProcAddress(handle, TEXT(#name"_driver"));\ - if (name##_driver == NULL) {\ - fprintf (stderr, "Error loading symbol %s\n",#name"_driver");\ - UnLoadCanDriver(handle);\ - return NULL;\ - } - -#else #define DLSYM(name)\ *(void **) (&name##_driver) = dlsym(handle, #name"_driver");\ if ((error = dlerror()) != NULL) {\ @@ -44,7 +34,6 @@ UnLoadCanDriver(handle);\ return NULL;\ } -#endif #else /*NOT_USE_DYNAMIC_LOADING*/ @@ -83,11 +72,8 @@ { if(handle!=NULL) { -#ifdef WIN32 - FreeLibrary(handle); -#else dlclose(handle); -#endif + handle=NULL; return 0; } @@ -100,21 +86,9 @@ LIB_HANDLE handle = NULL; char *error; -#ifdef WIN32 if(handle==NULL) { - handle = LoadLibrary(driver_name); - } - - if (handle == NULL) { - fprintf(stderr,"Error loading Can Driver dll \n"); - return -1; - } - -#else - if(handle==NULL) - { handle = dlopen(driver_name, RTLD_LAZY); } @@ -122,7 +96,6 @@ fprintf (stderr, "%s\n", dlerror()); return NULL; } -#endif /*Get function ptr*/ DLSYM(canReceive)