CANfestival - an open source CANopen framework

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers pdo.h Source File

pdo.h

00001 /*
00002 This file is part of CanFestival, a library implementing CanOpen Stack. 
00003 
00004 Copyright (C): Edouard TISSERANT and Francis DUPIN
00005 
00006 See COPYING file for copyrights details.
00007 
00008 This library is free software; you can redistribute it and/or
00009 modify it under the terms of the GNU Lesser General Public
00010 License as published by the Free Software Foundation; either
00011 version 2.1 of the License, or (at your option) any later version.
00012 
00013 This library is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 Lesser General Public License for more details.
00017 
00018 You should have received a copy of the GNU Lesser General Public
00019 License along with this library; if not, write to the Free Software
00020 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 */
00022 
00023 /** @defgroup pdo Process Data Object (PDO)
00024  *  PDO is a communication object defined by the DPO communication parameter and PDA mapping parameter objects.
00025  *  It is an uncomfirmed communication service without protocol overhead.
00026  *  @ingroup comobj
00027  */
00028  
00029 #ifndef __pdo_h__
00030 #define __pdo_h__
00031 
00032 #include <applicfg.h>
00033 #include <def.h>
00034 
00035 #include "canopen_can.h"
00036 
00037 typedef struct struct_s_PDO_status s_PDO_status;
00038 
00039 #include "data.h"
00040 
00041 #ifdef __cplusplus
00042 extern "C"{
00043 #endif
00044 
00045 /* Status of the TPDO : */
00046 #define PDO_INHIBITED 0x01
00047 #define PDO_RTR_SYNC_READY 0x01
00048 
00049 /** The PDO structure */
00050 struct struct_s_PDO_status {
00051   UNS8 transmit_type_parameter;
00052   TIMER_HANDLE event_timer;
00053   TIMER_HANDLE inhibit_timer;
00054   Message last_message;
00055 };
00056 
00057 #define s_PDO_status_Initializer {0, TIMER_NONE, TIMER_NONE, Message_Initializer}
00058 
00059 /** definitions of the different types of PDOs' transmission
00060  * 
00061  * SYNCHRO(n) means that the PDO will be transmited every n SYNC signal.
00062  */
00063 #define TRANS_EVERY_N_SYNC(n) (n) /*n = 1 to 240 */
00064 #define TRANS_SYNC_ACYCLIC    0    /* Trans after reception of n SYNC. n = 1 to 240 */
00065 #define TRANS_SYNC_MIN        1    /* Trans after reception of n SYNC. n = 1 to 240 */
00066 #define TRANS_SYNC_MAX        240  /* Trans after reception of n SYNC. n = 1 to 240 */
00067 #define TRANS_RTR_SYNC        252  /* Transmission on request */
00068 #define TRANS_RTR             253  /* Transmission on request */
00069 #define TRANS_EVENT_SPECIFIC  254  /* Transmission on event */
00070 #define TRANS_EVENT_PROFILE   255  /* Transmission on event */
00071 
00072 /** 
00073  * @brief Copy all the data to transmit in process_var
00074  * Prepare the PDO defined at index to be sent
00075  * *pwCobId : returns the value of the cobid. (subindex 1)
00076  * @param *d Pointer on a CAN object data structure
00077  * @param numPdo The PDO number
00078  * @param *pdo Pointer on a CAN message structure
00079  * @return 0 or 0xFF if error.
00080  */
00081 UNS8 buildPDO(CO_Data* d, UNS8 numPdo, Message *pdo);
00082 
00083 /** 
00084  * @ingroup pdo
00085  * @brief Transmit a PDO request frame on the network to the slave.
00086  * @param *d Pointer on a CAN object data structure
00087  * @param RPDOIndex Index of the receive PDO
00088  * @return
00089  *       - CanFestival file descriptor is returned upon success.
00090  *       - 0xFF is returned if RPDO Index is not found.
00091  
00092  * @return 0xFF if error, other in success.
00093  */
00094 UNS8 sendPDOrequest( CO_Data* d, UNS16 RPDOIndex );
00095 
00096 /**
00097  * @brief Compute a PDO frame reception
00098  * bus_id is hardware dependant
00099  * @param *d Pointer on a CAN object data structure
00100  * @param *m Pointer on a CAN message structure
00101  * @return 0xFF if error, else return 0
00102  */
00103 UNS8 proceedPDO (CO_Data* d, Message *m);
00104 
00105 /** 
00106  * @brief Used by the application to signal changes in process data
00107  * that could be mapped to some TPDO.
00108  * This do not necessarily imply PDO emission.
00109  * Function iterates on all TPDO and look TPDO transmit 
00110  * type and content change before sending it.    
00111  * @param *d Pointer on a CAN object data structure
00112  */
00113 UNS8 sendPDOevent (CO_Data* d);
00114 UNS8 sendOnePDOevent (CO_Data* d, UNS8 pdoNum);
00115 
00116 /** 
00117  * @ingroup pdo
00118  * @brief Function iterates on all TPDO and look TPDO transmit 
00119  * type and content change before sending it.
00120  * @param *d Pointer on a CAN object data structure
00121  * @param isSyncEvent
00122  */
00123 UNS8 _sendPDOevent(CO_Data* d, UNS8 isSyncEvent);
00124 
00125 /** 
00126  * @brief Initialize PDO feature 
00127  * @param *d Pointer on a CAN object data structure
00128  */
00129 void PDOInit(CO_Data* d);
00130 
00131 /** 
00132  * @brief Stop PDO feature 
00133  * @param *d Pointer on a CAN object data structure
00134  */
00135 void PDOStop(CO_Data* d);
00136 
00137 /** 
00138  * @ingroup pdo
00139  * @brief Set timer for PDO event
00140  * @param *d Pointer on a CAN object data structure
00141  * @param pdoNum The PDO number
00142  */
00143 void PDOEventTimerAlarm(CO_Data* d, UNS32 pdoNum);
00144 
00145 /** 
00146  * @ingroup pdo
00147  * @brief Inhibit timer for PDO event
00148  * @param *d Pointer on a CAN object data structure
00149  * @param pdoNum The PDO number
00150  */
00151 void PDOInhibitTimerAlarm(CO_Data* d, UNS32 pdoNum);
00152 
00153 /* copy bit per bit in little endian */
00154 void CopyBits (UNS8 NbBits, UNS8* SrcByteIndex, UNS8 SrcBitIndex, UNS8 SrcBigEndian, UNS8* DestByteIndex, UNS8 DestBitIndex, UNS8 DestBigEndian);
00155 
00156 #ifdef __cplusplus
00157 }
00158 #endif
00159 #endif