can_drv_linux.c
Go to the documentation of this file.
00001 /*******************************************************************************/
00002 /*                          Interface zur Tiny-CAN API                         */
00003 /* --------------------------------------------------------------------------- */
00004 /*  Beschreibung    : Laden einer Treiber DLL                                  */
00005 /*                                                                             */
00006 /*  Version         : 1.20                                                     */
00007 /*  Datei Name      : can_drv_win.c                                            */
00008 /* --------------------------------------------------------------------------- */
00009 /*  Datum           : 22.01.13                                                 */
00010 /*  Copyright       : (C) 2011 - 2013 by MHS-Elektronik GmbH & Co. KG, Germany */
00011 /*                      www.mhs-elektronik.de                                  */
00012 /*  Autor           : Demlehner Klaus, info@mhs-elektronik.de                  */ 
00013 /*******************************************************************************/
00014 #include <stdio.h>
00015 #include <stdlib.h>
00016 #include <unistd.h>
00017 #include <dlfcn.h>
00018 #include "can_drv.h"
00019 
00020 int32_t DefCanInitDriver(char *options);
00021 void DefCanDownDriver(void);
00022 int32_t DefCanSetOptions(char *options);
00023 int32_t DefCanDeviceOpen(uint32_t  index, char *parameter);
00024 int32_t DefCanDeviceClose(uint32_t  index);
00025 
00026 int32_t DefCanSetMode(uint32_t  index, unsigned char can_op_mode, uint16_t  can_command);
00027 int32_t DefCanSet(uint32_t  index, uint16_t  obj_index, uint16_t  obj_sub_index, void *data, int32_t size);
00028 int32_t DefCanGet(uint32_t  index, uint16_t  obj_index, uint16_t  obj_sub_index, void *data, int32_t size);
00029 
00030 int32_t DefCanTransmit(uint32_t  index, struct TCanMsg *msg, int32_t count);
00031 void DefCanTransmitClear(uint32_t  index);
00032 uint32_t  DefCanTransmitGetCount(uint32_t  index);
00033 int32_t DefCanTransmitSet(uint32_t  index, uint16_t  cmd,
00034   uint32_t  time);
00035 int32_t DefCanReceive(uint32_t  index, struct TCanMsg *msg, int32_t count);
00036 void DefCanReceiveClear(uint32_t  index);
00037 uint32_t  DefCanReceiveGetCount(uint32_t  index);
00038 
00039 int32_t DefCanSetSpeed(uint32_t  index, uint16_t  speed);
00040 int32_t DefCanSetSpeedUser(uint32_t  index, uint32_t  value1);
00041 char *DefCanDrvInfo(void);
00042 char *DefCanDrvHwInfo(uint32_t  index);
00043 int32_t DefCanSetFilter(uint32_t  index, struct TMsgFilter *msg_filter);
00044 int32_t DefCanGetDeviceStatus(uint32_t  index, struct TDeviceStatus *status);
00045 void DefCanSetPnPEventCallback(void (*event)(uint32_t  index, int32_t status));
00046 void DefCanSetStatusEventCallback(void (*event)
00047   (uint32_t  index, struct TDeviceStatus *device_status));
00048 void DefCanSetRxEventCallback(void (*event)(uint32_t  index,
00049   struct TCanMsg *msg, int32_t count));
00050 
00051 void DefCanSetEvents(uint16_t  events);
00052 uint32_t  DefCanEventStatus(void);
00053 
00054 
00055 TCanInitDriver CanInitDriver = DefCanInitDriver;
00056 TCanDownDriver CanDownDriver = DefCanDownDriver;
00057 TCanSetOptions CanSetOptions = DefCanSetOptions;
00058 TCanDeviceOpen CanDeviceOpen = DefCanDeviceOpen;
00059 TCanDeviceClose CanDeviceClose = DefCanDeviceClose;
00060 TCanSetMode CanSetMode = DefCanSetMode;
00061 TCanTransmit CanTransmit = DefCanTransmit;
00062 TCanTransmitClear CanTransmitClear = DefCanTransmitClear;
00063 TCanTransmitGetCount CanTransmitGetCount = DefCanTransmitGetCount;
00064 TCanTransmitSet CanTransmitSet = DefCanTransmitSet;
00065 TCanReceive CanReceive = DefCanReceive;
00066 TCanReceiveClear CanReceiveClear = DefCanReceiveClear;
00067 TCanReceiveGetCount CanReceiveGetCount = DefCanReceiveGetCount;
00068 TCanSetSpeed CanSetSpeed = DefCanSetSpeed;
00069 TCanSetSpeedUser CanSetSpeedUser = DefCanSetSpeedUser;
00070 TCanDrvInfo CanDrvInfo = DefCanDrvInfo;
00071 TCanDrvHwInfo CanDrvHwInfo = DefCanDrvHwInfo;
00072 TCanSetFilter CanSetFilter = DefCanSetFilter;
00073 TCanGetDeviceStatus CanGetDeviceStatus = DefCanGetDeviceStatus;
00074 TCanSetPnPEventCallback CanSetPnPEventCallback = DefCanSetPnPEventCallback;
00075 TCanSetStatusEventCallback CanSetStatusEventCallback = DefCanSetStatusEventCallback;
00076 TCanSetRxEventCallback CanSetRxEventCallback = DefCanSetRxEventCallback;
00077 TCanSetEvents CanSetEvents = DefCanSetEvents;
00078 TCanEventStatus CanEventStatus = DefCanEventStatus;
00079 
00080 void *DriverHandle = NULL;
00081 
00082 
00083 /***************************************************************/
00084 /*  Treiber DLL laden                                          */
00085 /***************************************************************/
00086 int32_t LoadDriver(const char *file_name)
00087 {
00088 int32_t error;
00089 
00090 error = 0;
00091 UnloadDriver();
00092 DriverHandle = dlopen(file_name, RTLD_LAZY);  //  | RTLD_DEEPBIND
00093 if (DriverHandle)
00094   {
00095   CanInitDriver = (TCanInitDriver)dlsym(DriverHandle, "CanInitDriver");
00096   CanDownDriver = (TCanDownDriver)dlsym(DriverHandle, "CanDownDriver");
00097   CanSetOptions = (TCanSetOptions)dlsym(DriverHandle, "CanSetOptions");
00098   CanDeviceOpen = (TCanDeviceOpen)dlsym(DriverHandle, "CanDeviceOpen");
00099   CanDeviceClose = (TCanDeviceClose)dlsym(DriverHandle, "CanDeviceClose");
00100   CanSetMode = (TCanSetMode)dlsym(DriverHandle, "CanSetMode");
00101   CanTransmit = (TCanTransmit)dlsym(DriverHandle, "CanTransmit");
00102   CanTransmitClear = (TCanTransmitClear)dlsym(DriverHandle, "CanTransmitClear");
00103   CanTransmitGetCount = (TCanTransmitGetCount)dlsym(DriverHandle, "CanTransmitGetCount");
00104   CanTransmitSet = (TCanTransmitSet)dlsym(DriverHandle, "CanTransmitSet");
00105   CanReceive = (TCanReceive)dlsym(DriverHandle, "CanReceive");
00106   CanReceiveClear = (TCanReceiveClear)dlsym(DriverHandle, "CanReceiveClear");
00107   CanReceiveGetCount = (TCanReceiveGetCount)dlsym(DriverHandle, "CanReceiveGetCount");
00108   CanSetSpeed = (TCanSetSpeed)dlsym(DriverHandle, "CanSetSpeed");
00109   CanSetSpeedUser = (TCanSetSpeedUser)dlsym(DriverHandle, "CanSetSpeedUser");
00110   CanDrvInfo = (TCanDrvInfo)dlsym(DriverHandle, "CanDrvInfo");
00111   CanDrvHwInfo = (TCanDrvHwInfo)dlsym(DriverHandle, "CanDrvHwInfo");
00112   CanSetFilter = (TCanSetFilter)dlsym(DriverHandle, "CanSetFilter");
00113   CanGetDeviceStatus = (TCanGetDeviceStatus)dlsym(DriverHandle, "CanGetDeviceStatus");
00114   CanSetPnPEventCallback = (TCanSetPnPEventCallback)dlsym(DriverHandle, "CanSetPnPEventCallback");
00115   CanSetStatusEventCallback = (TCanSetStatusEventCallback)dlsym(DriverHandle, "CanSetStatusEventCallback");
00116   CanSetRxEventCallback = (TCanSetRxEventCallback)dlsym(DriverHandle, "CanSetRxEventCallback");
00117   CanSetEvents = (TCanSetEvents)dlsym(DriverHandle, "CanSetEvents");
00118   CanEventStatus = (TCanEventStatus)dlsym(DriverHandle, "CanEventStatus");
00119 
00120   if (!CanInitDriver)
00121     error = -1;
00122   else if (!CanDownDriver)
00123     error = -2;
00124   else if (!CanSetOptions)
00125     error = -3;
00126   else if (!CanDeviceOpen)
00127     error = -4;
00128   else if (!CanDeviceClose)
00129     error = -5;
00130   else if (!CanSetMode)
00131     error = -7;
00132   else if (!CanTransmit)
00133     error = -10;
00134   else if (!CanTransmitClear)
00135     error = -11;
00136   else if (!CanTransmitGetCount)
00137     error = -12;
00138   else if (!CanTransmitSet)
00139     error = -13;
00140   else if (!CanReceive)
00141     error = -14;
00142   else if (!CanReceiveClear)
00143     error = -15;
00144   else if (!CanReceiveGetCount)
00145     error = -16;
00146   else if (!CanSetSpeed)
00147     error = -17;
00148   else if (!CanSetSpeedUser)
00149     error = -18;
00150   else if (!CanDrvInfo)
00151     error = -19;
00152   else if (!CanDrvHwInfo)
00153     error = -20;
00154   else if (!CanSetFilter)
00155     error = -21;
00156   else if (!CanGetDeviceStatus)
00157     error = -22;
00158   else if (!CanSetPnPEventCallback)
00159     error = -23;
00160   else if (!CanSetStatusEventCallback)
00161     error = -24;
00162   else if (!CanSetRxEventCallback)
00163     error = -25;
00164   else if (!CanSetEvents)
00165     error = -26;
00166   else if (!CanEventStatus)
00167     error = -27;
00168   }
00169 else    
00170   error = -100;  
00171 if (error)
00172   UnloadDriver();
00173 return(error);
00174 }
00175 
00176 
00177 /***************************************************************/
00178 /*  Treiber DLL entladen                                       */
00179 /***************************************************************/
00180 void UnloadDriver(void)
00181 {
00182 if ((DriverHandle) && (CanDownDriver))
00183   CanDownDriver();
00184 
00185 CanInitDriver = DefCanInitDriver;
00186 CanDownDriver = DefCanDownDriver;
00187 CanSetOptions = DefCanSetOptions;
00188 CanDeviceOpen = DefCanDeviceOpen;
00189 CanDeviceClose = DefCanDeviceClose;
00190 CanSetMode = DefCanSetMode;
00191 CanTransmit = DefCanTransmit;
00192 CanTransmitClear = DefCanTransmitClear;
00193 CanTransmitGetCount = DefCanTransmitGetCount;
00194 CanTransmitSet = DefCanTransmitSet;
00195 CanReceive = DefCanReceive;
00196 CanReceiveClear = DefCanReceiveClear;
00197 CanReceiveGetCount = DefCanReceiveGetCount;
00198 CanSetSpeed = DefCanSetSpeed;
00199 CanSetSpeedUser = DefCanSetSpeedUser;
00200 CanDrvInfo = DefCanDrvInfo;
00201 CanDrvHwInfo = DefCanDrvHwInfo;
00202 CanSetFilter = DefCanSetFilter;
00203 CanGetDeviceStatus = DefCanGetDeviceStatus;
00204 CanSetPnPEventCallback = DefCanSetPnPEventCallback;
00205 CanSetStatusEventCallback = DefCanSetStatusEventCallback;
00206 CanSetRxEventCallback = DefCanSetRxEventCallback;
00207 CanSetEvents = DefCanSetEvents;
00208 CanEventStatus = DefCanEventStatus;
00209 
00210 if (DriverHandle)
00211   {
00212   dlclose(DriverHandle);
00213   DriverHandle = NULL;
00214   }
00215 }
00216 
00217 
00218 /***************************************************************/
00219 /*  Default Call                                               */
00220 /***************************************************************/
00221 void DefDriverProcedure(int32_t func)
00222 {
00223 
00224 }
00225 
00226 
00227 /***************************************************************/
00228 /*  Default Funktionen                                         */
00229 /***************************************************************/
00230 int32_t DefCanInitDriver(char *options)
00231 {
00232 DefDriverProcedure(1);
00233 return(0);
00234 }
00235 
00236 
00237 void DefCanDownDriver(void)
00238 {
00239 // DefDriverProcedure(1);
00240 }
00241 
00242 
00243 int32_t DefCanSetOptions(char *options)
00244 {
00245 DefDriverProcedure(1);
00246 return(0);
00247 }
00248 
00249 
00250 int32_t DefCanDeviceOpen(uint32_t  index, char *parameter)
00251 {
00252 DefDriverProcedure(1);
00253 return(0);
00254 }
00255 
00256 
00257 int32_t DefCanDeviceClose(uint32_t  index)
00258 {
00259 return(0);
00260 }
00261 
00262 
00263 int32_t DefCanSetMode(uint32_t  index, unsigned char can_op_mode, uint16_t  can_command)
00264 {
00265 DefDriverProcedure(1);
00266 return(0);
00267 }
00268 
00269 
00270 int32_t DefCanSet(uint32_t  index, uint16_t  obj_index, uint16_t  obj_sub_index, void *data, int32_t size)
00271 {
00272 DefDriverProcedure(1);
00273 return(0);
00274 }
00275 
00276 
00277 int32_t DefCanGet(uint32_t  index, uint16_t  obj_index, uint16_t  obj_sub_index, void *data, int32_t size)
00278 {
00279 DefDriverProcedure(1);
00280 return(0);
00281 }
00282 
00283 
00284 int32_t DefCanTransmit(uint32_t  index, struct TCanMsg *msg, int32_t count)
00285 {
00286 DefDriverProcedure(1);
00287 return(0);
00288 }
00289 
00290 
00291 void DefCanTransmitClear(uint32_t  index)
00292 {
00293 DefDriverProcedure(1);
00294 }
00295 
00296 
00297 uint32_t  DefCanTransmitGetCount(uint32_t  index)
00298 {
00299 DefDriverProcedure(1);
00300 return(0);
00301 }
00302 
00303 
00304 int32_t DefCanTransmitSet(uint32_t  index, uint16_t  cmd,
00305   uint32_t  time)
00306 {
00307 DefDriverProcedure(1);
00308 return(0);
00309 }
00310 
00311 
00312 int32_t DefCanReceive(uint32_t  index, struct TCanMsg *msg, int32_t count)
00313 {
00314 DefDriverProcedure(1);
00315 return(0);
00316 }
00317 
00318 
00319 void DefCanReceiveClear(uint32_t  index)
00320 {
00321 DefDriverProcedure(1);
00322 }
00323 
00324 
00325 uint32_t  DefCanReceiveGetCount(uint32_t  index)
00326 {
00327 DefDriverProcedure(1);
00328 return(0);
00329 }
00330 
00331 
00332 int32_t DefCanSetSpeed(uint32_t  index, uint16_t  speed)
00333 {
00334 DefDriverProcedure(1);
00335 return(0);
00336 }
00337 
00338 
00339 int32_t DefCanSetSpeedUser(uint32_t  index, uint32_t  value)
00340 {
00341 DefDriverProcedure(1);
00342 return(0);
00343 }
00344 
00345 
00346 char *DefCanDrvInfo(void)
00347 {
00348 DefDriverProcedure(1);
00349 return(NULL);
00350 }
00351 
00352 
00353 char *DefCanDrvHwInfo(uint32_t  index)
00354 {
00355 DefDriverProcedure(1);
00356 return(NULL);
00357 }
00358 
00359 
00360 int32_t DefCanSetFilter(uint32_t  index, struct TMsgFilter *msg_filter)
00361 {
00362 DefDriverProcedure(1);
00363 return(0);
00364 }
00365 
00366 
00367 int32_t DefCanGetDeviceStatus(uint32_t  index, struct TDeviceStatus *status)
00368 {
00369 status->CanStatus = CAN_STATUS_UNBEKANNT;
00370 status->FifoStatus = FIFO_STATUS_UNBEKANNT;
00371 status->DrvStatus = DRV_NOT_LOAD;
00372 return(0);
00373 }
00374 
00375 
00376 void DefCanSetPnPEventCallback(void (*event)(uint32_t  index, int32_t status))
00377 {
00378 DefDriverProcedure(1);
00379 }
00380 
00381 
00382 void DefCanSetStatusEventCallback(void (*event)
00383   (uint32_t  index, struct TDeviceStatus *device_status))
00384 {
00385 DefDriverProcedure(1);
00386 }
00387 
00388 
00389 void DefCanSetRxEventCallback(void (*event)(uint32_t  index,
00390   struct TCanMsg *msg, int32_t count))
00391 {
00392 DefDriverProcedure(1);
00393 }
00394 
00395 
00396 void DefCanSetEvents(uint16_t  events)
00397 {
00398 DefDriverProcedure(1);
00399 }
00400 
00401 
00402 uint32_t  DefCanEventStatus(void)
00403 {
00404 DefDriverProcedure(1);
00405 return(1);
00406 }
00407 


tinycan
Author(s): M.Fischer
autogenerated on Thu Jun 6 2019 20:39:28