drivers/win32/win32.c
changeset 591 513f5ec8b628
parent 577 0bb82be64630
child 600 7767029937aa
equal deleted inserted replaced
590:aba1bf1defc6 591:513f5ec8b628
    24 /*
    24 /*
    25  CAN driver interface.
    25  CAN driver interface.
    26 */
    26 */
    27 
    27 
    28 #include <windows.h>
    28 #include <windows.h>
    29 extern "C"
    29 
    30 {
    30 #ifdef __cplusplus
       
    31 extern "C" {
       
    32 #endif
       
    33 
    31 #include "canfestival.h"
    34 #include "canfestival.h"
    32 #include "timer.h"
    35 #include "timer.h"
    33 #include "timers_driver.h"
    36 #include "timers_driver.h"
       
    37 
       
    38 #ifdef __cplusplus
    34 };
    39 };
       
    40 #endif
       
    41 
    35 // GetProcAddress doesn't have an UNICODE version for NT
    42 // GetProcAddress doesn't have an UNICODE version for NT
    36 #ifdef UNDER_CE
    43 #ifdef UNDER_CE
    37   #define myTEXT(str) TEXT(str)
    44   #define myTEXT(str) TEXT(str)
    38 #else
    45 #else
    39   #define myTEXT(str) str
    46   #define myTEXT(str) str
   136 
   143 
   137 /***************************************************************************/
   144 /***************************************************************************/
   138 CAN_HANDLE canOpen(s_BOARD *board, CO_Data * d)
   145 CAN_HANDLE canOpen(s_BOARD *board, CO_Data * d)
   139 {
   146 {
   140 	int i;
   147 	int i;
       
   148     CAN_HANDLE fd0;
       
   149 
   141 	for(i=0; i < MAX_NB_CAN_PORTS; i++)
   150 	for(i=0; i < MAX_NB_CAN_PORTS; i++)
   142 	{
   151 	{
   143 		if(!canports[i].used)
   152 		if(!canports[i].used)
   144 		break;
   153 		break;
   145 	}
   154 	}
   150 	   	fprintf(stderr,"CanOpen : Can Driver dll not loaded\n");
   159 	   	fprintf(stderr,"CanOpen : Can Driver dll not loaded\n");
   151 	   	return NULL;
   160 	   	return NULL;
   152 	}
   161 	}
   153 	#endif
   162 	#endif
   154 
   163 
   155 	CAN_HANDLE fd0 = m_canOpen(board);
   164 	fd0 = m_canOpen(board);
   156 	if(fd0)
   165 	if(fd0)
   157 	{
   166 	{
   158 		canports[i].used = 1;
   167 		canports[i].used = 1;
   159 		canports[i].fd = fd0;
   168 		canports[i].fd = fd0;
   160 		canports[i].d = d;
   169 		canports[i].d = d;
   171 
   180 
   172 /***************************************************************************/
   181 /***************************************************************************/
   173 int canClose(CO_Data * d)
   182 int canClose(CO_Data * d)
   174 {
   183 {
   175 	UNS8 res;
   184 	UNS8 res;
   176 
   185 	CANPort* tmp;
   177 	((CANPort*)d->canHandle)->used = 0;
   186 
   178 	CANPort* tmp = (CANPort*)d->canHandle;
   187 	if((CANPort*)d->canHandle)
       
   188 	{
       
   189 	  ((CANPort*)d->canHandle)->used = 0;
       
   190 	}
       
   191 
       
   192 	tmp = (CANPort*)d->canHandle;
   179 	d->canHandle = NULL;
   193 	d->canHandle = NULL;
   180 
   194 
   181 	// close CAN port
   195 	if(tmp)
   182 	res = m_canClose(tmp->fd);
   196 	{
   183 
   197 	  // close CAN port
   184 	// kill receiver task
   198 	  res = m_canClose(tmp->fd);
   185 	WaitReceiveTaskEnd(&tmp->receiveTask);
   199 
       
   200 	  // kill receiver task
       
   201 	  WaitReceiveTaskEnd(&tmp->receiveTask);
       
   202 	}
   186 	return res;
   203 	return res;
   187 }
   204 }
   188 
   205 
   189 UNS8 canChangeBaudRate(CAN_PORT port, char* baud)
   206 UNS8 canChangeBaudRate(CAN_PORT port, char* baud)
   190 {
   207 {