Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals

interfaces.c

Go to the documentation of this file.
00001 /*============================================================================*
00002  * FILE:                      interfaces.c
00003  *============================================================================*
00004  *
00005  *                      COPYRIGHT (C) 2006  BY
00006  *          CONDOR ENGINEERING, INC., SANTA BARBARA, CALIFORNIA
00007  *          ALL RIGHTS RESERVED.
00008  *
00009  *          THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND
00010  *          COPIED ONLY IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE AND WITH
00011  *          THE INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE OR ANY
00012  *          OTHER COPIES THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE
00013  *          AVAILABLE TO ANY OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF THE
00014  *          SOFTWARE IS HEREBY TRANSFERRED.
00015  *
00016  *          THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT
00017  *          NOTICE AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY CONDOR
00018  *          ENGINEERING.
00019  *
00020  *============================================================================*
00021  *
00022  * FUNCTION:    Source file to go from API -> generic interface
00023  *
00024  * Author:      Christopher McKenzie
00025  * 
00026  * MAINTENANCE NOTES:
00027  * 
00028  *============================================================================*/
00029 #include"interfaces.h"
00030 #include"..\includes\defines.h"
00031 #include"..\includes\canapi.h"
00032 #include"..\includes\irig.h"
00033 #include<string.h>
00034 #include<stdlib.h>
00035 #include<stdio.h>
00036 
00037 extern struct _if_channel       channel[CAN_MAXCHANNELS];
00038 extern int if_channel_count;
00039 extern int if_board_count;
00040 extern struct _reftsLink*refts;
00041 
00042 #ifdef CANBOARDXL
00043 #include"vector_canboard\vector_canboard.h"
00044 #endif
00045 #ifdef CARDONE
00046 #endif
00047 #ifdef CARDTWO
00048 #endif
00049 
00050 struct _s_interface interfaces[]=
00051 {
00052 #ifdef CANBOARDXL
00053         {       0,
00054                 vector_canboardprobe,
00055                 vector_canboardstartup,
00056                 vector_canboardopenchannel,
00057                 vector_canboardclosechannel,
00058                 vector_canboardshutdown,
00059                 vector_canboardread,
00060                 vector_canboardwrite,
00061                 vector_canboardupdatestatus,
00062                 vector_canboardchangestatus
00063         },
00064 #endif
00065 #ifdef CARDONE
00066         {
00067         },
00068 #endif
00069 #ifdef CARDTWO
00070         {
00071         },
00072 #endif
00073         {       0,0,0,0,0,
00074                 0,0,0,0,0
00075         }
00076 
00077 };
00078 //
00079 // This starts at the beginning if if_channel
00080 // and looks for the first datastructure where 
00081 // the "board" pointer is 0, and assumes that it
00082 // is free from then onward.
00083 //
00084 // Note, boundaries have issues.
00085 //
00086 enum
00087 {       __IFACE,
00088         __CHAN
00089 };
00090 
00091 int boardstartup(int handle,int which)
00092 {       int ret;
00093 
00094         switch(which)
00095         {       case __CHAN:
00096                         if(interfaces[channel[handle].board->boardtype].activecount==0)
00097                         {       ret=interfaces[channel[handle].board->boardtype].startupfunction(handle);
00098                                 if(ret==IF_FAILURE)
00099                                         return 0;
00100                                 interfaces[channel[handle].board->boardtype].activecount=1;
00101                         }
00102                         break;
00103                 case __IFACE:
00104                         if(interfaces[handle].activecount==0)
00105                         {       ret=interfaces[handle].startupfunction();
00106                                 if(ret==IF_FAILURE)
00107                                         return 0;
00108                                 interfaces[handle].activecount=1;
00109                         }
00110                         break;
00111                 default:
00112                         ret=0;
00113                         break;
00114         }
00115         return ret;
00116 }
00117 
00118 int boardprobe()
00119 {       int ix;
00120         long err;
00121         
00122         for(ix=0;interfaces[ix].probefunction;ix++)
00123         {       interfaces[ix].activecount=0;
00124                 boardstartup(ix,__IFACE);
00125                 err=interfaces[ix].probefunction();
00126                 if(err==IF_FAILURE)
00127                 {       printf("board failed\n");
00128                         return 0;
00129                 }
00130         }
00131         return 1;
00132 }
00133 
00134 int fakecrc(unsigned char*tocrc,int*fakedcrc)   //FIXME
00135 {       if(!tocrc)
00136                 return 0;
00137         if(!fakedcrc)
00138                 return 0;
00139 
00140         return 1;
00141 };
00142 
00143 int boardopenchannel(int which)
00144 {       int ret;
00145         boardstartup(which,__CHAN);
00146 
00147         if(channel[which].isopen==0)
00148         {       ret=interfaces[channel[which].board->boardtype].openchannelfunction(which);
00149                 if(ret==IF_SUCCESS)
00150                 {       channel[which].isopen=1;
00151                         interfaces[channel[which].board->boardtype].activecount++;
00152                 }
00153                 interfaces[channel[which].board->boardtype].updatestatusfunction(which);
00154                 return ret;
00155         }
00156         return 1;
00157 }
00158 
00159 int boardread(int which,can_frame*out)
00160 {       int ret;
00161         boardopenchannel(which);        //won't do double
00162         ret=interfaces[channel[which].board->boardtype].readfunction(which,out);
00163         //interfaces[channel[which].board->boardtype].updatestatusfunction(which);
00164         if(ret==IF_SUCCESS)
00165                 return S_SUCCESS;
00166         else
00167                 return ret;
00168 }
00169 
00170 int boardwrite(int which,can_frame*in)
00171 {       int ret;
00172         boardopenchannel(which);        //won't do double
00173         ret=interfaces[channel[which].board->boardtype].writefunction(which,in);
00174         //interfaces[channel[which].board->boardtype].updatestatusfunction(which);
00175         if(ret==IF_SUCCESS)
00176                 return S_SUCCESS;
00177         else
00178                 return ret;
00179 }
00180 
00181 int boardupdatestatus(int which)
00182 {       int ret;
00183         ret=interfaces[channel[which].board->boardtype].updatestatusfunction(which);
00184         return ret;
00185 }
00186 
00187 int boardchangestatus(int handle,int which,int status)
00188 {       int ret;
00189         ret=interfaces[channel[handle].board->boardtype].changestatusfunction(handle,which,status);
00190         interfaces[channel[handle].board->boardtype].updatestatusfunction(handle);
00191         if(ret==IF_SUCCESS)
00192                 return S_SUCCESS;
00193         else
00194                 return ret;
00195 }
00196 
00197 //close all the channels down
00198 int boardshutdown(int which)
00199 {       unsigned int ix;
00200         for(ix=0;ix<channel[which].board->channelcount;ix++)
00201         {       interfaces[channel[which].board->boardtype].closechannelfunction(
00202                         channel[which].board->channel[ix]->index);
00203         }
00204         //shutdown the driver
00205         interfaces[channel[which].board->boardtype].updatestatusfunction(which);
00206         if(interfaces[channel[which].board->boardtype].activecount==1)
00207         {       interfaces[channel[which].board->boardtype].shutdownfunction();
00208                 //bring it down
00209                 interfaces[channel[which].board->boardtype].activecount=0;
00210         }
00211         return S_SUCCESS;
00212 }
00213 /*
00214 void boarddllmain()
00215 {       static int hasdone=0;
00216         struct _reftsLink*ref;
00217         int ix;
00218         if(hasdone)
00219                 return;
00220 
00221         refts=malloc(sizeof(struct _reftsLink));
00222         ref=refts;
00223         refts->index=0;
00224         for(ix=1;ix<_MAX_IRIG;ix++)
00225         {       refts->next=malloc(sizeof(struct _reftsLink));
00226                 refts->next->prev=refts;
00227                 refts=refts->next;
00228                 refts->index=ix;
00229         }
00230         refts->next=ref;
00231         ref->prev=refts;
00232         for(ix=0;ix<_MAX_IRIG*2;ix++)
00233         {       refts=refts->next;
00234                 printf("%03d ",refts->index);
00235         }
00236                 for(ix=0;ix<_MAX_IRIG*2;ix++)
00237         {       refts=refts->prev;
00238                 printf("%03d ",refts->index);
00239         }
00240         hasdone=1;
00241         return;
00242 }
00243 */

Generated on Wed Feb 22 13:31:25 2006 for CANapi by  doxygen 1.4.4