# HG changeset patch # User Edouard Tisserant # Date 1327170778 -3600 # Node ID 1c2cb6088050092328dd15c2df00e3fee76420e5 # Parent d6fcd388f2dbf04e4324eec683edd75d5554f654# Parent 11e95dd60ffc1e05e01e3e83f349d7dd097d954d Merge further Ica changes diff -r 11e95dd60ffc -r 1c2cb6088050 drivers/can_ixxat_win32/ixxat.cpp --- a/drivers/can_ixxat_win32/ixxat.cpp Sat Jan 21 18:49:54 2012 +0100 +++ b/drivers/can_ixxat_win32/ixxat.cpp Sat Jan 21 19:32:58 2012 +0100 @@ -70,8 +70,8 @@ bool send(const Message *m); bool receive(Message *m); private: - bool open(const char* board_name, int board_number, const char* baud_rate); - bool close(); + bool open(int board_number, const char* baud_rate); + bool close(); void receive_queuedata(UINT16 que_hdl, UINT16 count, VCI_CAN_OBJ* p_obj); // VCI2 handler static void VCI_CALLBACKATTR message_handler(char *msg_str); @@ -108,19 +108,20 @@ m_RxQueHdl(0xFFFF) { - char busname[100]; - ::strcpy(busname,board->busname); - char board_name[100]; - long board_number = 0; - char *ptr = ::strrchr(busname,':'); - if (ptr != 0) - { - *ptr = 0; - ::strcpy(board_name,busname); - if (++ptr - busname < (int)::strlen(board->busname)) - board_number = ::atoi(ptr); - } - if (!open(board_name,board_number,board->baudrate)) + if (!board) + { + close(); + throw error(); + } + + long board_number = 0; + + if (board->busname) + { + board_number = atol(board->busname); + } + + if (!open(board_number, board->baudrate)) { close(); throw error(); @@ -165,7 +166,7 @@ return false; } -bool IXXAT::open(const char* board_name, int board_number, const char* baud_rate) +bool IXXAT::open(int board_number, const char* baud_rate) { // check, if baudrate is supported struct IXXAT_baud_rate_param @@ -196,21 +197,26 @@ if (::strcmp(br_lut[index].baud_rate,baud_rate)==0) break; } - if (index == br_lut_size) + if (index == br_lut_size) + { + MSG_ERR_DRV("IXXAT::open: The given baudrate %S is invalid.", baud_rate); return false; + } // close existing board close(); // init IXXAT board - unsigned long board_type = VCI_GetBrdTypeByName(const_cast(board_name)); - long res = VCI2_PrepareBoard( board_type, // board type - board_number, // unique board index + long res = VCI2_PrepareBoard( 0, // board type, unused in VCI2 + board_number, // unique board index, see XAT_EnumHwEntry() and XAT_GetConfig() NULL, // pointer to buffer for additional info 0, // length of additional info buffer message_handler, // pointer to msg-callbackhandler receive_queuedata_handler, // pointer to receive-callbackhandler exception_handler); // pointer to exception-callbackhandler if (res < 0) + { + MSG_ERR_DRV("IXXAT::open: VCI2_PrepareBoard failed with code '%d'.", res); return false; + } m_BoardHdl = (UINT16)res; VCI_ResetBoard(m_BoardHdl); @@ -230,7 +236,7 @@ res = VCI_ConfigQueue(m_BoardHdl, CAN_NUM, VCI_RX_QUE, 500, 1, 0, 100, &m_RxQueHdl); // assign the all IDs to the Receive Queue - res = VCI_AssignRxQueObj(m_BoardHdl, m_RxQueHdl ,VCI_ACCEPT, 0, 0) ; + res = VCI_AssignRxQueObj(m_BoardHdl, m_RxQueHdl ,VCI_ACCEPT, 0, 0); // And now start the CAN res = VCI_StartCan(m_BoardHdl, CAN_NUM); @@ -267,9 +273,7 @@ void VCI_CALLBACKATTR IXXAT::message_handler(char *msg_str) { - char buf[200]; - ::sprintf(buf,"IXXAT Message: [%s]\n", msg_str); - ::OutputDebugString(buf); + MSG_ERR_DRV("IXXAT Message: [%S]", msg_str); } void VCI_CALLBACKATTR IXXAT::exception_handler(VCI_FUNC_NUM func_num, INT32 err_code, UINT16 ext_err, char* err_str) @@ -305,9 +309,8 @@ "VCI_UpdateBufObj", "VCI_CciReqData" }; - char buf[200]; - ::sprintf(buf, "IXXAT Exception: %s (%i / %u) [%s]\n", Num2Function[func_num], err_code, ext_err, err_str); - ::OutputDebugString(buf); + + MSG_ERR_DRV("IXXAT Exception: %S (%i / %u) [%S]", Num2Function[func_num], err_code, ext_err, err_str); } void IXXAT::watchdog() @@ -317,9 +320,7 @@ if (res < 0) { - char buf[200]; - ::sprintf(buf, "\nIXXAT canBusWatchdog: ERROR: Reading the can state failed!\n"); - ::OutputDebugString(buf); + MSG_ERR_DRV("IXXAT canBusWatchdog: ERROR: Reading the can state failed!"); } else { @@ -327,34 +328,34 @@ { if (sts.sts & STS_CAN_BUS_OFF) { - ::OutputDebugString("\nIXXAT canBusWatchdog: CAN bus off detected!\n"); + MSG_ERR_DRV("IXXAT canBusWatchdog: CAN bus off detected!"); } if (sts.sts & STS_CAN_DATA_OVERRUN) { - ::OutputDebugString("\nIXXAT canBusWatchdog: CAN data overrun detected!\n"); + MSG_ERR_DRV("IXXAT canBusWatchdog: CAN data overrun detected!"); } if (sts.sts & STS_REMOTE_QUEUE_OVERRUN) { - ::OutputDebugString("\nIXXAT canBusWatchdog: Remote queue overrun detected!\n"); + MSG_ERR_DRV("IXXAT canBusWatchdog: Remote queue overrun detected!"); } - if (VCI_ResetCan(m_BoardHdl, CAN_NUM) < 0) - { - ::OutputDebugString("\nIXXAT canBusWatchdog: ERROR: Resetting the can module failed!\n"); + res = VCI_ResetCan(m_BoardHdl, CAN_NUM); + if (res <= 0) + { + MSG_ERR_DRV("IXXAT canBusWatchdog: ERROR: Resetting the can module failed with code '%d'!", res); } - if (VCI_StartCan(m_BoardHdl, CAN_NUM) < 0) - { - ::OutputDebugString("\nIXXAT canBusWatchdog: ERROR: Restaring the can module failed!\n"); + res = VCI_StartCan(m_BoardHdl, CAN_NUM); + if (res <= 0) + { + MSG_ERR_DRV("IXXAT canBusWatchdog: ERROR: Restaring the can module failed with code '%d'!", res); } } } if (SetTimer(NULL, m_watchdogTimerId, IXXAT::CAN_BUS_WATCHDOG_INTERVAL_MSEC, IXXAT::canBusWatchdog) == 0) { - char buf[200]; - ::sprintf(buf, "\nIXXAT canBusWatchdog: ERROR: Creation of the watchdog timer failed!\n"); - ::OutputDebugString(buf); + MSG_ERR_DRV("IXXAT canBusWatchdog: ERROR: Creation of the watchdog timer failed!"); } } diff -r 11e95dd60ffc -r 1c2cb6088050 drivers/timers_win32/timers_win32.c --- a/drivers/timers_win32/timers_win32.c Sat Jan 21 18:49:54 2012 +0100 +++ b/drivers/timers_win32/timers_win32.c Sat Jan 21 19:32:58 2012 +0100 @@ -38,7 +38,7 @@ }; #endif -struct _timeb timebuffer; +DWORD timebuffer; /* Synchronization Object Implementation */ CRITICAL_SECTION CanFestival_mutex; @@ -90,8 +90,8 @@ WaitForSingleObject(timer, INFINITE); if(stop_timer) break; - _ftime(&timebuffer); EnterMutex(); + timebuffer = GetTickCount(); TimeDispatch(); LeaveMutex(); } @@ -112,7 +112,7 @@ } // Take first absolute time ref in milliseconds. - _ftime(&timebuffer); + timebuffer = GetTickCount(); } void TimerCleanup(void) @@ -158,7 +158,7 @@ LARGE_INTEGER liDueTime; /* arg 2 of SetWaitableTimer take 100 ns interval */ - liDueTime.QuadPart = (-1 * value); + liDueTime.QuadPart = ((long long) (-1) * value * 10000); //printf("SetTimer(%llu)\n", value); if (!SetWaitableTimer(timer, &liDueTime, 0, NULL, NULL, FALSE)) @@ -171,8 +171,7 @@ /* Get the elapsed time since the last occured alarm */ TIMEVAL getElapsedTime(void) { - struct _timeb timetmp; - _ftime(&timetmp); - return (timetmp.time - timebuffer.time) * 10000000 + (timetmp.millitm - timebuffer.millitm) * 10000; + DWORD timetmp = GetTickCount(); + return (timetmp - timebuffer); } diff -r 11e95dd60ffc -r 1c2cb6088050 drivers/win32/win32.c --- a/drivers/win32/win32.c Sat Jan 21 18:49:54 2012 +0100 +++ b/drivers/win32/win32.c Sat Jan 21 19:32:58 2012 +0100 @@ -189,7 +189,7 @@ } else { - MSG(("CanOpen : Cannot open board {busname='%s',baudrate='%s'}\n",board->busname, board->baudrate)); + MSG("CanOpen : Cannot open board {busname='%S',baudrate='%S'}\n",board->busname, board->baudrate); return NULL; } } diff -r 11e95dd60ffc -r 1c2cb6088050 include/win32/applicfg.h --- a/include/win32/applicfg.h Sat Jan 21 18:49:54 2012 +0100 +++ b/include/win32/applicfg.h Sat Jan 21 19:32:58 2012 +0100 @@ -102,16 +102,13 @@ #ifdef UNICODE #define MSG(...) \ do{wchar_t msg[300];\ - swprintf(msg,L##__VA_ARGS__);\ + swprintf(msg,sizeof(msg)/sizeof(msg[0]), L##__VA_ARGS__); \ OutputDebugString(msg);}while(0) #else #define MSG(...) \ - do{printf(__VA_ARGS__);fflush(stdout);}while(0) - -/*do{char msg[300];\ +do{char msg[300];\ sprintf(msg,##__VA_ARGS__);\ OutputDebugString(msg);}while(0) -*/ #endif #else //(_MSC_VER < 1400) //For Visual Studio 2003 and below, without VA_ARGS @@ -132,6 +129,9 @@ MSG(("%s(%d) : 0x%X %s 0x%lX\n",__FILE__, __LINE__,num, str, value)); \ } +#define CANFESTIVAL_DEBUG_DRV_MSG(...)\ + MSG(__VA_ARGS__); + /// Definition of MSG_WAR // --------------------- #ifdef DEBUG_WAR_CONSOLE_ON @@ -148,6 +148,11 @@ # define MSG_ERR(num, str, val) #endif +#ifdef DEBUG_ERR_DRIVER_CONSOLE_ON +# define MSG_ERR_DRV(...) CANFESTIVAL_DEBUG_DRV_MSG(__VA_ARGS__) +#else +# define MSG_ERR_DRV(...) +#endif typedef void* CAN_HANDLE; diff -r 11e95dd60ffc -r 1c2cb6088050 include/win32/canfestival.h --- a/include/win32/canfestival.h Sat Jan 21 18:49:54 2012 +0100 +++ b/include/win32/canfestival.h Sat Jan 21 19:32:58 2012 +0100 @@ -32,7 +32,7 @@ typedef HINSTANCE LIB_HANDLE; UNS8 UnLoadCanDriver(LIB_HANDLE handle); -LIB_HANDLE LoadCanDriver(const char* driver_name); +LIB_HANDLE LoadCanDriver(LPCTSTR driver_name); UNS8 canSend(CAN_PORT port, Message *m); CAN_PORT canOpen(s_BOARD *board, CO_Data * d); int canClose(CO_Data * d); diff -r 11e95dd60ffc -r 1c2cb6088050 include/win32/timerscfg.h --- a/include/win32/timerscfg.h Sat Jan 21 18:49:54 2012 +0100 +++ b/include/win32/timerscfg.h Sat Jan 21 19:32:58 2012 +0100 @@ -26,12 +26,12 @@ #include -// Time unit : 100 ns -#define TIMEVAL unsigned long long +// Time unit : 1msec +#define TIMEVAL DWORD #define TIMEVAL_MAX ~(TIMEVAL)0 -#define MS_TO_TIMEVAL(ms) ms*10000 -#define US_TO_TIMEVAL(us) us*10 +#define MS_TO_TIMEVAL(ms) ms +#define US_TO_TIMEVAL(us) (us / 1000) #define TASK_HANDLE HANDLE diff -r 11e95dd60ffc -r 1c2cb6088050 src/pdo.c --- a/src/pdo.c Sat Jan 21 18:49:54 2012 +0100 +++ b/src/pdo.c Sat Jan 21 19:32:58 2012 +0100 @@ -410,7 +410,7 @@ Message pdo; if (buildPDO (d, numPdo, &pdo)) { - MSG_ERR (0x1948, " Couldn't build TPDO n�", numPdo); + MSG_ERR (0x1948, " Couldn't build TPDO number : ", numPdo); return 0xFF; } canSend (d->canHandle, &pdo); @@ -743,7 +743,7 @@ break; default: - MSG_ERR (0x1972, "Unknown state has been reached : %d", status); + MSG_ERR (0x1972, "Unknown state has been reached :", status); return 0xFF; } /* end switch case */ diff -r 11e95dd60ffc -r 1c2cb6088050 src/sdo.c --- a/src/sdo.c Sat Jan 21 18:49:54 2012 +0100 +++ b/src/sdo.c Sat Jan 21 19:32:58 2012 +0100 @@ -1017,7 +1017,7 @@ else {/* So, if it is not an expedited transfert */ if (getSDOs(m->data[0])) { nbBytes = (m->data[4]) + ((UNS32)(m->data[5])<<8) + ((UNS32)(m->data[6])<<16) + ((UNS32)(m->data[7])<<24); - err = setSDOlineRestBytes(d, CliServNbr, nbBytes); + err = setSDOlineRestBytes(d, line, nbBytes); if (err) { failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_GENERAL_ERROR); return 0xFF; diff -r 11e95dd60ffc -r 1c2cb6088050 src/win32/CanFestival-3.def --- a/src/win32/CanFestival-3.def Sat Jan 21 18:49:54 2012 +0100 +++ b/src/win32/CanFestival-3.def Sat Jan 21 19:32:58 2012 +0100 @@ -60,6 +60,7 @@ proceedPDO sendPDOevent _sendPDOevent + sendOnePDOevent PDOInit PDOStop PDOEventTimerAlarm