Ignore:
Timestamp:
12/21/01 11:38:35 (23 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Cosy/candrv/vmodican.cc

    r1109 r1137  
     1/* ======================================================================== *\
     2!
     3! *
     4! * This file is part of Stesy, the MAGIC Steering System
     5! * Software. It is distributed to you in the hope that it can be a useful
     6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
     7! * It is distributed WITHOUT ANY WARRANTY.
     8! *
     9! * Permission to use, copy, modify and distribute this software and its
     10! * documentation for any purpose is hereby granted without fee,
     11! * provided that the above copyright notice appear in all copies and
     12! * that both that copyright notice and this permission notice appear
     13! * in supporting documentation. It is provided "as is" without express
     14! * or implied warranty.
     15! *
     16!
     17!
     18!   Author(s): Thomas Bretz, 2001 <mailto:tbretz@uni-sw.gwdg.de>
     19!
     20!   Copyright: MAGIC Software Development, 2000-2001
     21!
     22!
     23\* ======================================================================== */
     24
     25///////////////////////////////////////////////////////////////////////
     26//
     27// VmodIcan
     28//
     29// Class describing the interface to the Janz card in RawCan mode.
     30//
     31///////////////////////////////////////////////////////////////////////
    132#include "vmodican.h"
    233
     
    1344ClassImp(VmodIcan);
    1445
     46// --------------------------------------------------------------------------
     47//
     48// Prints a CAN Message.
     49//
    1550void VmodIcan::PrintMsg(Message *m)
    1651{
     
    2459}
    2560
     61// --------------------------------------------------------------------------
     62//
     63// Embedded ioctl-function from C-lib
     64//
    2665int VmodIcan::Ioctl(int msg, void *arg)
    2766{
     
    2968}
    3069
     70// --------------------------------------------------------------------------
     71//
     72// Enables/Disables the termination.
     73//
    3174void VmodIcan::SetTermination(int state)  /* 0 = off, 1 = on */
    3275{
     
    5497}
    5598
     99// --------------------------------------------------------------------------
     100//
     101// Receiver Thread. Listener. Listens for incomming messages and processes
     102// these messages through the standard interface:
     103//  - therefor overload HandleCanMessge
     104//
    56105void *VmodIcan::Thread()
    57106{
     
    63112        struct timeval tv;
    64113
    65         //cout << "waiting..." << endl;
    66 
    67         const int n = read(fd, &c, 1); // sleep until message arrive
    68 
     114        //
     115        // Sleeps until a message arrives
     116        //
     117        const int n = read(fd, &c, 1);
     118
     119        //
     120        // read the time for the message as soon as possible
     121        //
    69122        gettimeofday(&tv, NULL);
    70123
    71         //cout << "read n=" << n << " c=" << (int)c << endl;
    72 
     124        //
     125        // if n==0 something strange happened. Stop receiver(?)
     126        //
    73127        if (n == 0)
    74128        {
     
    77131        }
    78132
    79         switch(c)
     133        //
     134        // Check for what we received
     135        //
     136        switch (c)
    80137        {
     138        //
     139        // Fast message (not used/working)
     140        //
    81141        case FAST_QUEUE:
    82142            cout << "--> Fast Queue:  " << flush;
     
    96156            break;
    97157
     158        //
     159        // Plain Can Message to be processed
     160        //
    98161        case PLAIN_QUEUE:
    99162
    100163            Message msg;
    101164
     165            //
     166            // Read the message from the card and process it
     167            //
    102168            if (Receive(&msg) < 0)
    103169                return (void *)1;
    104170
    105             //cal->PrintMsg(&msg);
    106171            HandleMessage(&msg, &tv);
    107172
     
    112177}
    113178
     179// --------------------------------------------------------------------------
     180//
     181// Does a basic message processing and hadles the so called command (cmd)
     182// stamp of the message. This is some kind of message type which is send
     183// by the can interface
     184//
    114185void VmodIcan::HandleMessage(Message *msg, struct timeval *tv)
    115186{
     187    //
     188    // Decode message
     189    //
    116190    const WORD_t desc  = msg->data[2]<<8 | msg->data[3];
    117191    const BYTE_t rtr   = (desc>>4)&1;
     
    158232        return;
    159233    case M_BCAN_RX_ind:
     234        //
     235        // Message is a message from the Can bus
     236        //
    160237        HandleCanMessage(cobid, &msg->data[4], tv);
    161238        return;
    162239    }
    163240
     241    //
     242    // Nothing of the above happened
     243    //
    164244    cout << hex;
    165245    cout << "Cmd=0x"    << (int)msg->cmd << ":  ";
     
    174254}
    175255
     256// --------------------------------------------------------------------------
     257//
     258//  This is can_recv from the Janz software.
     259//
     260//  /* can_recv - receive a message from standard interface
     261//   *
     262//   * This function reads a whole message from the standard host interface of
     263//   * a VMOD-ICAN.
     264//   * The module is selected by the module number <fd>.
     265//   *
     266//   * The structure <pm> is filled with the received message.
     267//   *
     268//   * RETURNS:
     269//   * The function returns the number of message received, or -1 when the
     270//   * system call failed.
     271//   * The return value therefore 0 determines, that no message was available to
     272//   * be read: can_recv() does not block in such a case and therefore
     273//   * can be used to poll a module for incoming messages.
     274//   */
     275//
    176276int VmodIcan::Receive(Message *pm) /* receive buffer */
    177277{
    178     /* can_recv - receive a message from standard interface
    179      *
    180      * This function reads a whole message from the standard host interface of
    181      * a VMOD-ICAN.
    182      * The module is selected by the module number <fd>.
    183      *
    184      * The structure <pm> is filled with the received message.
    185      *
    186      * RETURNS:
    187      * The function returns the number of message received, or -1 when the
    188      * system call failed.
    189      * The return value therefore 0 determines, that no message was available to
    190      * be read: can_recv() does not block in such a case and therefore
    191      * can be used to poll a module for incoming messages.
    192      */
    193278
    194279    struct dpm_rw_can_desc arg;
     
    202287}
    203288
     289// --------------------------------------------------------------------------
     290//
     291// This is can_recv_fast from the Janz software
     292//
     293//  /* can_recv_fast - receive a message from layer2 interface
     294//   *
     295//   * This function reads a FastMessage from the layer2 fast message
     296//   * interface of a VMOD-ICAN.
     297//   * The module is selected by the file descriptor <fd>.
     298//   *
     299//   * The structure <pm> is filled with the received message.
     300//   *
     301//   * RETURNS:
     302//   * The function returns -1 when the * system call failed.
     303//   * The return value therefore 0 determines, that no message was available to
     304//   * be read: can_recv_fast() does not block in such a case and therefore
     305//   * can be used to poll a module for incoming messages.
     306//   */
     307//
    204308int VmodIcan::ReceiveFast(FastMessage *pm)
    205309{
    206 
    207     /* can_recv_fast - receive a message from layer2 interface
    208      *
    209      * This function reads a FastMessage from the layer2 fast message
    210      * interface of a VMOD-ICAN.
    211      * The module is selected by the file descriptor <fd>.
    212      *
    213      * The structure <pm> is filled with the received message.
    214      *
    215      * RETURNS:
    216      * The function returns -1 when the * system call failed.
    217      * The return value therefore 0 determines, that no message was available to
    218      * be read: can_recv_fast() does not block in such a case and therefore
    219      * can be used to poll a module for incoming messages.
    220      */
    221 
    222310    struct dpm_write_fast_can_desc arg;
    223311
     
    230318}
    231319
    232 
     320// --------------------------------------------------------------------------
     321//
     322// This is IcWriteBtrBCAN from the Janz software
     323//
     324//  /* IcWriteBtrBCAN - Set bit timing parameters
     325//   *
     326//   * Set bit timing parameters in CAN controller. May only be used if
     327//   * CAN controller is in bus-off state. <btr> stores the bus-timing
     328//   * parameters as required by the 82C200 controller. See the description
     329//   * of the CBTRreq-service for possible values.
     330//   *
     331//   * BTR1 is stored in the upper byte of <btr> and BTR0 in the lower. Examples
     332//   * are:
     333//   * .CS
     334//   *     Baudrate   btr       Macro
     335//   *       1Mbit    0x2300    BTR_1MB
     336//   *     500kBit    0x1c00    BTR_500KB
     337//   *     250kBit    0x1c01    BTR_250KB
     338//   *     125kBit    0x1c03    BTR_125KB
     339//   *     100kBit    0x34c7    BTR_100KB
     340//   *      50kBit    0x34cf    BTR_50KB
     341//   *      20kBit    0x7fcf    BTR_20KB
     342//   * .CE
     343//   *
     344//   * SERVICE: CBTRreq
     345//   *
     346//   * NOTE:
     347//   * Raw ICANOS version of the firmware only.
     348//   */
     349//
    233350void VmodIcan::SetBaudRate(int rate)
    234351{
    235     /* IcWriteBtrBCAN - Set bit timing parameters
    236      *
    237      * Set bit timing parameters in CAN controller. May only be used if
    238      * CAN controller is in bus-off state. <btr> stores the bus-timing
    239      * parameters as required by the 82C200 controller. See the description
    240      * of the CBTRreq-service for possible values.
    241      *
    242      * BTR1 is stored in the upper byte of <btr> and BTR0 in the lower. Examples
    243      * are:
    244      * .CS
    245      *     Baudrate   btr       Macro
    246      *       1Mbit    0x2300    BTR_1MB
    247      *     500kBit    0x1c00    BTR_500KB
    248      *     250kBit    0x1c01    BTR_250KB
    249      *     125kBit    0x1c03    BTR_125KB
    250      *     100kBit    0x34c7    BTR_100KB
    251      *      50kBit    0x34cf    BTR_50KB
    252      *      20kBit    0x7fcf    BTR_20KB
    253      * .CE
    254      *
    255      * SERVICE: CBTRreq
    256      *
    257      * NOTE:
    258      * Raw ICANOS version of the firmware only.
    259      */
    260 
    261     /* create message for vmod-ican */
    262352    Message msg;  /* buffer for module messages */
    263353
     
    305395}
    306396
    307 
     397// --------------------------------------------------------------------------
     398//
     399// This is IcBusOnBCAN from the Janz software
     400//
     401//  /* IcBusOnBCAN - switch CANbus controller to bus-on state
     402//   *
     403//   * Switch CAN controller bus-on. You will need to use this
     404//   * function explicitly after you have connected yourself
     405//   * to the module with can_open() (or ican_open() under DOS/WINDOWS).
     406//   * This is because the module comes up in the bus-off state.
     407//   *
     408//   * SERVICE: CONreq
     409//   *
     410//   * NOTE:
     411//   * Raw ICANOS version of the firmware only.
     412//   */
     413//
    308414void VmodIcan::EnableCanBusConnection()
    309415{
    310     /* IcBusOnBCAN - switch CANbus controller to bus-on state
    311      *
    312      * Switch CAN controller bus-on. You will need to use this
    313      * function explicitly after you have connected yourself
    314      * to the module with can_open() (or ican_open() under DOS/WINDOWS).
    315      * This is because the module comes up in the bus-off state.
    316      *
    317      * SERVICE: CONreq
    318      *
    319      * NOTE:
    320      * Raw ICANOS version of the firmware only.
    321      */
    322416    Message msg;                  /* buffer for module messages */
    323417
     
    330424}
    331425
     426// --------------------------------------------------------------------------
     427//
     428// This is ican2_init_fast_canfrom the Janz software
     429//
     430//  /* ican2_init_fast_can - initialize fast can access for VMOD-ICAN
     431//   *
     432//   * By this function, the user may initialize and enable the fast
     433//   * host interface (layer2 access) for a VMOD-ICAN module.
     434//   *
     435//   * The calling application can request <rbuffers> buffer elements in the queue
     436//   * that sends data to the host and <wbuffers> buffer elements for the queue
     437//   * that transports data to the module.
     438//   *
     439//   * NOTE:
     440//   * Notice that the message filtering on the VMOD-ICAN has to be
     441//   * set correctly, so that messages can be received through the fast
     442//   * interface.
     443//   *
     444//   * CAVE AT:
     445//   * The <rbuffers> and wbuffers> have no special limit, but the general
     446//   * resources of the DPM must not be exceeded.
     447//   * For the calculation you need to assume, that 16 buffers in one of the fast
     448//   * interface queues take the same DPM space as 1 buffer in the standard
     449//   * host interface.
     450//   *
     451//   * The user must use only one of the functions, either
     452//   * ican2_init_fast_can or ican2_init_fast_can_prio
     453//   *
     454//   * RETURNS:
     455//   * Zero if the operation performed successfully, or less than zero on error.
     456//   */
     457//
    332458int VmodIcan::EnableFastCan(int rbuffers, int wbuffers)
    333459{
    334     /* ican2_init_fast_can - initialize fast can access for VMOD-ICAN
    335      *
    336      * By this function, the user may initialize and enable the fast
    337      * host interface (layer2 access) for a VMOD-ICAN module.
    338      *
    339      * The calling application can request <rbuffers> buffer elements in the queue
    340      * that sends data to the host and <wbuffers> buffer elements for the queue
    341      * that transports data to the module.
    342      *
    343      * NOTE:
    344      * Notice that the message filtering on the VMOD-ICAN has to be
    345      * set correctly, so that messages can be received through the fast
    346      * interface.
    347      *
    348      * CAVE AT:
    349      * The <rbuffers> and wbuffers> have no special limit, but the general
    350      * resources of the DPM must not be exceeded.
    351      * For the calculation you need to assume, that 16 buffers in one of the fast
    352      * interface queues take the same DPM space as 1 buffer in the standard
    353      * host interface.
    354      *
    355      * The user must use only one of the functions, either
    356      * ican2_init_fast_can or ican2_init_fast_can_prio
    357      *
    358      * RETURNS:
    359      * Zero if the operation performed successfully, or less than zero on error.
    360      */
    361460    struct dpm_fast_can_desc hdp;
    362461
     
    372471}
    373472
     473// --------------------------------------------------------------------------
     474//
     475// This is IcWriteEwlBCAN from the Janz software
     476//
     477//  /* IcWriteEwlBCAN - Set error warning limit
     478//   *
     479//   * Set error warning limit in CAN controller. If this limit is passed, the
     480//   * user will get a CEVTind message stating an error interrupt. This type
     481//   * of message will also occur if the both error counter again fall below
     482//   * this limit.
     483//   *
     484//   * RESTRICTIONS:
     485//   * Will only take effect if CAN controller is in bus-off state. Requires
     486//   * an SJA1000 CANbus controller, and will be no-op for 82C200.
     487//   *
     488//   * SERVICE: CBCONFreq
     489//   *
     490//   * NOTE:
     491//   * Raw ICANOS version of the firmware only.
     492//   */
     493//
    374494void VmodIcan::DisableCanBusConnection()
    375495{
    376     /* IcWriteEwlBCAN - Set error warning limit
    377      *
    378      * Set error warning limit in CAN controller. If this limit is passed, the
    379      * user will get a CEVTind message stating an error interrupt. This type
    380      * of message will also occur if the both error counter again fall below
    381      * this limit.
    382      *
    383      * RESTRICTIONS:
    384      * Will only take effect if CAN controller is in bus-off state. Requires
    385      * an SJA1000 CANbus controller, and will be no-op for 82C200.
    386      *
    387      * SERVICE: CBCONFreq
    388      *
    389      * NOTE:
    390      * Raw ICANOS version of the firmware only.
    391      */
    392496    lout << "- Disconnect from Bus!" << endl;
    393497
     
    400504}
    401505
     506// --------------------------------------------------------------------------
     507//
     508// This is can_close from the Janz software
     509//
     510//  /* can_close - close connection to a VMOD-ICAN module
     511//   *
     512//   * The function can be used to close a connection to a VMOD-ICAN
     513//   * that has been established by a can_open() call.
     514//   * The module has to be selected by the file descriptor <fd> which was
     515//   * obtained when you did the can_open() call.
     516//   *
     517//   * When you call can_close, all the resources that were used by the driver
     518//   * for communication are freed.
     519//   *
     520//   * The VMOD-ICAN module under question will be reseted, to make sure that
     521//   * the communication with the host will stop. That means especially that
     522//   * no further interrupt will occur and that the module will not longer be
     523//   * active on the CANbus.
     524//   *
     525//   * RETURNS: N/A
     526//   */
     527//
    402528void VmodIcan::Close()
    403529{
    404     /* can_close - close connection to a VMOD-ICAN module
    405      *
    406      * The function can be used to close a connection to a VMOD-ICAN
    407      * that has been established by a can_open() call.
    408      * The module has to be selected by the file descriptor <fd> which was
    409      * obtained when you did the can_open() call.
    410      *
    411      * When you call can_close, all the resources that were used by the driver
    412      * for communication are freed.
    413      *
    414      * The VMOD-ICAN module under question will be reseted, to make sure that
    415      * the communication with the host will stop. That means especially that
    416      * no further interrupt will occur and that the module will not longer be
    417      * active on the CANbus.
    418      *
    419      * RETURNS: N/A
    420      */
    421530    lout << "- Close Device!" << endl;
    422531
     
    431540}
    432541
     542// --------------------------------------------------------------------------
     543//
     544// Enable the fifo of the Janz card
     545// Allow VMOD to send messages through the fifo
     546//
    433547int VmodIcan::EnableFifo()
    434548{
    435     //
    436     // Allow VMOD to send messages through the fifo
    437     //
    438549    Message msg; /* connect message */
    439550
     
    448559}
    449560
     561// --------------------------------------------------------------------------
     562//
     563// Reset the module
     564//
    450565int VmodIcan::Reset()
    451566{
     
    457572}
    458573
     574// --------------------------------------------------------------------------
     575//
     576// This is can_open from the Janz software
     577//
     578//  /* can_open - open VMOD-ICAN device
     579//   *
     580//   * With this function call you open a VMOD-ICAN plugged
     581//   * into a MODULbus carrier board for use. The module is
     582//   * reseted and then initialized for communication to the host.
     583//   *
     584//   * A specific module is selected by it's device name (e.g. "/dev/dpm_01").
     585//   */
     586//
    459587int VmodIcan::Open(const char *devname)          /* pathname of device */
    460588{
    461     /* can_open - open VMOD-ICAN device
    462      *
    463      * With this function call you open a VMOD-ICAN plugged
    464      * into a MODULbus carrier board for use. The module is
    465      * reseted and then initialized for communication to the host.
    466      *
    467      * A specific module is selected by it's device name (e.g. "/dev/dpm_01").
    468      */
    469 
    470     fd = open (devname, O_RDONLY, 0);
     589    fd = open(devname, O_RDONLY, 0);
    471590
    472591    if (fd < 0)
     
    481600}
    482601
     602// --------------------------------------------------------------------------
     603//
     604// This is ican2_select_hostif from the Janz software
     605//
     606//  /* ican2_select_hostif - switch standard host interface to new style mode
     607//   *
     608//   * The routine ican2_select_hostif() can be used to switch a module from
     609//   * the standard host interface to the new style mode. The module is selected
     610//   * by the module number <fd>.
     611//   *
     612//   * The calling application can request <rbuffers> buffer for the communication
     613//   * queue that sends data to the host and <wbuffers> buffer for the reverse
     614//   * communication direction (normal priority queue). By this function the hi- and
     615//   * low-prioritized message-queues which sends data to the module are initialized
     616//   * to a length of 1.
     617//   *
     618//   * NOTE:
     619//   * To notify the module of the new situation, the driver sends
     620//   * a M_NEWHOSTIF message to the module. This is the last message to be
     621//   * transfered through the old style host interface. Immediately after
     622//   * sending this message, the library is switched to the new style mode.
     623//   * Any messages that are sent by the module in this time gap, may be lost.
     624//   * It is therefore not recommended to use this function when you wait
     625//   * for messages from the module.
     626//   *
     627//   * The selection of the new host interface is not reversible. It will stay
     628//   * until the next reset for the module occurs. This will probably occur
     629//   * when you use can_close().
     630//   *
     631//   * HINTS:
     632//   * When the new style mode is active, no more internal message buffering
     633//   * on the module exists. That is whenever the module tries to send something
     634//   * and cannot because the queue is full, this message will be dropped.
     635//   * Thereby, when enabling the new style host interface you should create
     636//   * enough buffers for the queue that sends to the host, to prevent the
     637//   * loss of messages. If you loose messages, however you will be indicated
     638//   * of that event by a MSGLOST messages (which will not be lost!).
     639//   *
     640//   * CAVE AT:
     641//   * The parameters <rbuffers>, <wbuffers>, <wbuffers_hi> and <wbuffers_low>
     642//   * must be greater than 0, less than 128, and the total sum must not
     643//   * exceed 236. These parameters aren't checked by the driver!
     644//   */
     645//
    483646int VmodIcan::StdHost2NewStyle(int rbuffers, int wbuffers,
    484647                               int wbuffers_hi, int wbuffers_low)
    485 /* buffers in to, from, from_hi, from_low host queue */
    486 /* ican2_select_hostif - switch standard host interface to new style mode
    487  *
    488  * The routine ican2_select_hostif() can be used to switch a module from
    489  * the standard host interface to the new style mode. The module is selected
    490  * by the module number <fd>.
    491  *
    492  * The calling application can request <rbuffers> buffer for the communication
    493  * queue that sends data to the host and <wbuffers> buffer for the reverse
    494  * communication direction (normal priority queue). By this function the hi- and
    495  * low-prioritized message-queues which sends data to the module are initialized
    496  * to a length of 1.
    497  *
    498  * NOTE:
    499  * To notify the module of the new situation, the driver sends
    500  * a M_NEWHOSTIF message to the module. This is the last message to be
    501  * transfered through the old style host interface. Immediately after
    502  * sending this message, the library is switched to the new style mode.
    503  * Any messages that are sent by the module in this time gap, may be lost.
    504  * It is therefore not recommended to use this function when you wait
    505  * for messages from the module.
    506  *
    507  * The selection of the new host interface is not reversible. It will stay
    508  * until the next reset for the module occurs. This will probably occur
    509  * when you use can_close().
    510  *
    511  * HINTS:
    512  * When the new style mode is active, no more internal message buffering
    513  * on the module exists. That is whenever the module tries to send something
    514  * and cannot because the queue is full, this message will be dropped.
    515  * Thereby, when enabling the new style host interface you should create
    516  * enough buffers for the queue that sends to the host, to prevent the
    517  * loss of messages. If you loose messages, however you will be indicated
    518  * of that event by a MSGLOST messages (which will not be lost!).
    519  *
    520  * CAVE AT:
    521  * The parameters <rbuffers>, <wbuffers>, <wbuffers_hi> and <wbuffers_low>
    522  * must be greater than 0, less than 128, and the total sum must not
    523  * exceed 236. These parameters aren't checked by the driver!
    524  */
    525648{
    526649    struct dpm_new_hostif_desc_prio hdp;
     
    538661}
    539662
     663// --------------------------------------------------------------------------
     664//
     665// This is can_send_hi from the Janz software
     666//
     667//  /* can_send_hi - send message to standard host interface (high priority)
     668//   *
     669//   * This function performs the same action as can_send(), except it will
     670//   * append message <pm> to the highest priority queue of the standard
     671//   * host interface.
     672//   *
     673//   * NOTE:
     674//   * Notice that the prioritized issue of the message take effect on the new style
     675//   * mode of the standard host interface only.
     676//   *
     677//   * RETURNS:
     678//   * The function returns the number of message send, or -1 when the system
     679//   * call failed.
     680//   * The return value 0 determines that no message could be send,
     681//   * probably because there was no space in the targeted queue. can_send_hi()
     682//   * does not block or retry in such a case, so you need to loop explicitly
     683//   * until the message is send.
     684//   */
     685//
    540686int VmodIcan::SendHi(Message *pm)
    541687{
    542     /* can_send_hi - send message to standard host interface (high priority)
    543      *
    544      * This function performs the same action as can_send(), except it will
    545      * append message <pm> to the highest priority queue of the standard
    546      * host interface.
    547      *
    548      * NOTE:
    549      * Notice that the prioritized issue of the message take effect on the new style
    550      * mode of the standard host interface only.
    551      *
    552      * RETURNS:
    553      * The function returns the number of message send, or -1 when the system
    554      * call failed.
    555      * The return value 0 determines that no message could be send,
    556      * probably because there was no space in the targeted queue. can_send_hi()
    557      * does not block or retry in such a case, so you need to loop explicitly
    558      * until the message is send.
    559      */
    560688    struct dpm_rw_can_desc arg;
    561689
     
    568696}
    569697
     698// --------------------------------------------------------------------------
     699//
     700// This is can_send_low from the Janz software
     701//
     702//  /* can_send_low - send message to standard host interface (low priority)
     703//   *
     704//   * This function performs the same action as can_send(), except it will
     705//   * append message <pm> to the lowest priority queue of the standard
     706//   * host interface.
     707//   *
     708//   * NOTE:
     709//   * Notice that the prioritized issue of the message take effect on the new
     710//   * style mode of the standard host interface only.
     711//   *
     712//   * RETURNS:
     713//   * The function returns the number of message send, or -1 when the system
     714//   * call failed.
     715//   * The return value 0 determines that no message could be send,
     716//   * probably because there was no space in the targeted queue. can_send_low()
     717//   * does not block or retry in such a case, so you need to loop explicitly
     718//   * until the message is send.
     719//   *
     720//   */
    570721int VmodIcan::SendLo(Message *pm)
    571722{
    572     /* can_send_low - send message to standard host interface (low priority)
    573      *
    574      * This function performs the same action as can_send(), except it will
    575      * append message <pm> to the lowest priority queue of the standard
    576      * host interface.
    577      *
    578      * NOTE:
    579      * Notice that the prioritized issue of the message take effect on the new
    580      * style mode of the standard host interface only.
    581      *
    582      * RETURNS:
    583      * The function returns the number of message send, or -1 when the system
    584      * call failed.
    585      * The return value 0 determines that no message could be send,
    586      * probably because there was no space in the targeted queue. can_send_low()
    587      * does not block or retry in such a case, so you need to loop explicitly
    588      * until the message is send.
    589      *
    590      */
    591723    struct dpm_rw_can_desc arg;
    592724
     
    599731}
    600732
     733// --------------------------------------------------------------------------
     734//
     735// This is can_send from the Janz software
     736//
     737//  /* can_send - send message to standard host interface (mid priority)
     738//   *
     739//   * This function sends a complete message to the standard host interface of
     740//   * a VMOD-ICAN.
     741//   *
     742//   * The message <pm> will be queued to the middle prioritized of the three
     743//   * queues.
     744//   *
     745//   * RETURNS:
     746//   * The function returns the number of message send, or -1 when the system
     747//   * call failed.
     748//   * The return value 0 determines that no message could be send,
     749//   * probably because there was no space in the targeted queue. can_send()
     750//   * does not block or retry in such a case, so you need to loop explicitly
     751//   * until the message is send.
     752//   */
     753//
    601754int VmodIcan::Send(Message *pm) /* file descriptor, message to send */
    602755{
    603     /* can_send - send message to standard host interface (mid priority)
    604      *
    605      * This function sends a complete message to the standard host interface of
    606      * a VMOD-ICAN.
    607      *
    608      * The message <pm> will be queued to the middle prioritized of the three
    609      * queues.
    610      *
    611      * RETURNS:
    612      * The function returns the number of message send, or -1 when the system
    613      * call failed.
    614      * The return value 0 determines that no message could be send,
    615      * probably because there was no space in the targeted queue. can_send()
    616      * does not block or retry in such a case, so you need to loop explicitly
    617      * until the message is send.
    618      */
    619756    struct dpm_rw_can_desc arg;
    620757
     
    627764}
    628765
     766// --------------------------------------------------------------------------
     767//
     768// This is can_fast_send from the Janz software
     769//
     770//  /* can_fast_send - send message to fast interface
     771//   *
     772//   * This function sends a message to the fast host interface (layer-2
     773//   * interface) of a VMOD-ICAN. The module is selected by the module number
     774//   * <fd>.
     775//   * The message to be send will be given in the structure <pm>.
     776//   *
     777//   * The fast host interface needs to be established before can_fast_send()
     778//   * can be used successfully.
     779//   *
     780//   * RETURNS:
     781//   * The function returns 1 if can_fast_send() completed successful.
     782//   * Otherwise the return value 0 determines that the message could not be send,
     783//   * probably because there was no space in the DPM. The function
     784//   * does not block or retry in such a case, so you need to loop explicitly
     785//   * until the message is send.
     786//   * The function returns -1 when the system-call itself failed.
     787//   */
     788//
    629789int VmodIcan::Send(FastMessage *pm) /* file descriptor, message to send */
    630790{
    631     /* can_fast_send - send message to fast interface
    632      *
    633      * This function sends a message to the fast host interface (layer-2
    634      * interface) of a VMOD-ICAN. The module is selected by the module number
    635      * <fd>.
    636      * The message to be send will be given in the structure <pm>.
    637      *
    638      * The fast host interface needs to be established before can_fast_send()
    639      * can be used successfully.
    640      *
    641      * RETURNS:
    642      * The function returns 1 if can_fast_send() completed successful.
    643      * Otherwise the return value 0 determines that the message could not be send,
    644      * probably because there was no space in the DPM. The function
    645      * does not block or retry in such a case, so you need to loop explicitly
    646      * until the message is send.
    647      * The function returns -1 when the system-call itself failed.
    648      */
    649791    struct dpm_write_fast_can_desc arg;
    650792
     
    659801}
    660802
     803// --------------------------------------------------------------------------
     804//
     805// This is IcSetAfil from the Janz software
     806//
     807//  /*
     808//   * IcSetAfil - Set software acceptance filter mask
     809//   *
     810//   * Set software acceptance filtering.
     811//   *
     812//   * SERVICE: SetAfilMask
     813//   */
     814//
    661815void VmodIcan::DisableAllCobIds()
    662816{
    663     /* -*-Func-*-
    664      *
    665      * IcSetAfil - Set software acceptance filter mask
    666      *
    667      * Set software acceptance filtering.
    668      *
    669      * SERVICE: SetAfilMask
    670      */
    671817    Message msg;
    672818
     
    685831}
    686832
    687 
     833// --------------------------------------------------------------------------
     834//
     835// This is IcSetAfil from the Janz software
     836//
     837//  /*
     838//   * IcSetAfil - Set software acceptance filter mask
     839//   *
     840//   * Set software acceptance filtering.
     841//   *
     842//   * SERVICE: SetAfilMask
     843//   */
     844//
    688845void VmodIcan::EnableCobId(WORD_t cobid, int flag)
    689846{
    690     /* -*-Func-*-
    691      *
    692      * IcSetAfil - Set software acceptance filter mask
    693      *
    694      * Set software acceptance filtering.
    695      *
    696      * SERVICE: SetAfilMask
    697      *
    698      * NOTE: This service is available in both version of the firmware: Raw-CAN
    699      * and CAL.
    700      */
    701847    Message msg;
    702848
     
    713859}
    714860
     861// --------------------------------------------------------------------------
     862//
     863// This is IcSendReqBCAN from the Janz software
     864//
     865//  /*
     866//   * IcSendReqBCAN - Send a CANbus message
     867//   *
     868//   * Issue request to send a CAN message. <Spec> controls whether to send with
     869//   * or without spec/confirmation.
     870//   * .CS
     871//   *    spec     action
     872//   *      0      send only
     873//   *      1      send with confirmation to the host.
     874//   *      2      send and echo message to the host.
     875//   *      3      send and generate both echo and confirmation.
     876//   * .CE
     877//   *
     878//   * SERVICE: CTXreq, CTXCreq, CTXEreq, CTXCEreq
     879//   *
     880//   * NOTE:
     881//   * Raw ICANOS version of the firmware only.
     882//   */
     883//
    715884void VmodIcan::SendCanFrame(WORD_t cobid, BYTE_t m[8])
    716885{
    717        /* -*-Func-*-
    718          *
    719          * IcSendReqBCAN - Send a CANbus message
    720          *
    721          * Issue request to send a CAN message. <Spec> controls whether to send with
    722          * or without spec/confirmation.
    723          * .CS
    724          *    spec     action
    725          *      0      send only
    726          *      1      send with confirmation to the host.
    727          *      2      send and echo message to the host.
    728          *      3      send and generate both echo and confirmation.
    729          * .CE
    730          *
    731          * SERVICE: CTXreq, CTXCreq, CTXEreq, CTXCEreq
    732          *
    733          * NOTE:
    734          * Raw ICANOS version of the firmware only.
    735          */
    736         const WORD_t desc = MsgDescr(cobid, 8);
    737 
    738         Message msg;
    739 
    740         msg.cmd = M_BCAN_TX_req;
    741 
    742         msg.len = 12;
    743         msg.data[0]  = 0;
    744         msg.data[1]  = 0;
    745         msg.data[2]  = word_to_msb(desc);
    746         msg.data[3]  = word_to_lsb(desc);
    747 
    748         memcpy(&msg.data[4], m, 8);
    749 
    750         while (!Send(&msg));
    751 
    752         /*
    753         cout << "0x" << hex << (int)cobid << ": ";
    754         for(int i=0; i<10; i++)
    755             cout << hex << (int)msg.data[i+2] << " " << flush;
    756         cout << endl;
    757         cout << "- Message sent." << endl;
    758         */
    759 
    760 }
    761 
     886    const WORD_t desc = MsgDescr(cobid, 8);
     887
     888    Message msg;
     889
     890    msg.cmd = M_BCAN_TX_req;
     891
     892    msg.len = 12;
     893    msg.data[0]  = 0;
     894    msg.data[1]  = 0;
     895    msg.data[2]  = word_to_msb(desc);
     896    msg.data[3]  = word_to_lsb(desc);
     897
     898    memcpy(&msg.data[4], m, 8);
     899
     900    while (!Send(&msg));
     901}
     902
     903// --------------------------------------------------------------------------
     904//
     905// Constructor. Sets logging.
     906//  Set the receiving thread to priority -10 and detached.
     907//
     908//  Open the device.
     909//  reset the device
     910//  Enable the fifo buffers
     911//  Set the baud rate to the given rate
     912//  Disable passthrough of all cobids (all canbus messages)
     913//  and switch the can bus communication on
     914//
    762915VmodIcan::VmodIcan(const char *dev, const int baud, MLog &out) : Log(out), MThread(false)//: CanDriver(dev, baud)
    763916{
     
    781934}
    782935
     936// --------------------------------------------------------------------------
     937//
     938// Destructor. Stopt the receiver, disables the bus connection and
     939// close the device
     940//
    783941VmodIcan::~VmodIcan()
    784942{
     
    788946}
    789947
     948// --------------------------------------------------------------------------
     949//
     950// Sends a can frame with the given cobid and the given eight bytes
     951// through the can network
     952//
    790953void VmodIcan::SendCanFrame(WORD_t cobid,
    791954                            BYTE_t m0, BYTE_t m1, BYTE_t m2, BYTE_t m3,
Note: See TracChangeset for help on using the changeset viewer.