Sam Grove
/
canopen_slavenode
CANfestival - an open source CANopen framework
framework/include/pdo.h@0:6219434a0cb5, 2011-05-30 (annotated)
- Committer:
- sam_grove
- Date:
- Mon May 30 07:14:41 2011 +0000
- Revision:
- 0:6219434a0cb5
Initial public release of slave node framework port
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sam_grove |
0:6219434a0cb5 | 1 | /* |
sam_grove |
0:6219434a0cb5 | 2 | This file is part of CanFestival, a library implementing CanOpen Stack. |
sam_grove |
0:6219434a0cb5 | 3 | |
sam_grove |
0:6219434a0cb5 | 4 | Copyright (C): Edouard TISSERANT and Francis DUPIN |
sam_grove |
0:6219434a0cb5 | 5 | |
sam_grove |
0:6219434a0cb5 | 6 | See COPYING file for copyrights details. |
sam_grove |
0:6219434a0cb5 | 7 | |
sam_grove |
0:6219434a0cb5 | 8 | This library is free software; you can redistribute it and/or |
sam_grove |
0:6219434a0cb5 | 9 | modify it under the terms of the GNU Lesser General Public |
sam_grove |
0:6219434a0cb5 | 10 | License as published by the Free Software Foundation; either |
sam_grove |
0:6219434a0cb5 | 11 | version 2.1 of the License, or (at your option) any later version. |
sam_grove |
0:6219434a0cb5 | 12 | |
sam_grove |
0:6219434a0cb5 | 13 | This library is distributed in the hope that it will be useful, |
sam_grove |
0:6219434a0cb5 | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
sam_grove |
0:6219434a0cb5 | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
sam_grove |
0:6219434a0cb5 | 16 | Lesser General Public License for more details. |
sam_grove |
0:6219434a0cb5 | 17 | |
sam_grove |
0:6219434a0cb5 | 18 | You should have received a copy of the GNU Lesser General Public |
sam_grove |
0:6219434a0cb5 | 19 | License along with this library; if not, write to the Free Software |
sam_grove |
0:6219434a0cb5 | 20 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
sam_grove |
0:6219434a0cb5 | 21 | */ |
sam_grove |
0:6219434a0cb5 | 22 | |
sam_grove |
0:6219434a0cb5 | 23 | /** @defgroup pdo Process Data Object (PDO) |
sam_grove |
0:6219434a0cb5 | 24 | * PDO is a communication object defined by the DPO communication parameter and PDA mapping parameter objects. |
sam_grove |
0:6219434a0cb5 | 25 | * It is an uncomfirmed communication service without protocol overhead. |
sam_grove |
0:6219434a0cb5 | 26 | * @ingroup comobj |
sam_grove |
0:6219434a0cb5 | 27 | */ |
sam_grove |
0:6219434a0cb5 | 28 | |
sam_grove |
0:6219434a0cb5 | 29 | #ifndef __pdo_h__ |
sam_grove |
0:6219434a0cb5 | 30 | #define __pdo_h__ |
sam_grove |
0:6219434a0cb5 | 31 | |
sam_grove |
0:6219434a0cb5 | 32 | #include <applicfg.h> |
sam_grove |
0:6219434a0cb5 | 33 | #include <def.h> |
sam_grove |
0:6219434a0cb5 | 34 | |
sam_grove |
0:6219434a0cb5 | 35 | #include "canopen_can.h" |
sam_grove |
0:6219434a0cb5 | 36 | |
sam_grove |
0:6219434a0cb5 | 37 | typedef struct struct_s_PDO_status s_PDO_status; |
sam_grove |
0:6219434a0cb5 | 38 | |
sam_grove |
0:6219434a0cb5 | 39 | #include "data.h" |
sam_grove |
0:6219434a0cb5 | 40 | |
sam_grove |
0:6219434a0cb5 | 41 | #ifdef __cplusplus |
sam_grove |
0:6219434a0cb5 | 42 | extern "C"{ |
sam_grove |
0:6219434a0cb5 | 43 | #endif |
sam_grove |
0:6219434a0cb5 | 44 | |
sam_grove |
0:6219434a0cb5 | 45 | /* Status of the TPDO : */ |
sam_grove |
0:6219434a0cb5 | 46 | #define PDO_INHIBITED 0x01 |
sam_grove |
0:6219434a0cb5 | 47 | #define PDO_RTR_SYNC_READY 0x01 |
sam_grove |
0:6219434a0cb5 | 48 | |
sam_grove |
0:6219434a0cb5 | 49 | /** The PDO structure */ |
sam_grove |
0:6219434a0cb5 | 50 | struct struct_s_PDO_status { |
sam_grove |
0:6219434a0cb5 | 51 | UNS8 transmit_type_parameter; |
sam_grove |
0:6219434a0cb5 | 52 | TIMER_HANDLE event_timer; |
sam_grove |
0:6219434a0cb5 | 53 | TIMER_HANDLE inhibit_timer; |
sam_grove |
0:6219434a0cb5 | 54 | Message last_message; |
sam_grove |
0:6219434a0cb5 | 55 | }; |
sam_grove |
0:6219434a0cb5 | 56 | |
sam_grove |
0:6219434a0cb5 | 57 | #define s_PDO_status_Initializer {0, TIMER_NONE, TIMER_NONE, Message_Initializer} |
sam_grove |
0:6219434a0cb5 | 58 | |
sam_grove |
0:6219434a0cb5 | 59 | /** definitions of the different types of PDOs' transmission |
sam_grove |
0:6219434a0cb5 | 60 | * |
sam_grove |
0:6219434a0cb5 | 61 | * SYNCHRO(n) means that the PDO will be transmited every n SYNC signal. |
sam_grove |
0:6219434a0cb5 | 62 | */ |
sam_grove |
0:6219434a0cb5 | 63 | #define TRANS_EVERY_N_SYNC(n) (n) /*n = 1 to 240 */ |
sam_grove |
0:6219434a0cb5 | 64 | #define TRANS_SYNC_ACYCLIC 0 /* Trans after reception of n SYNC. n = 1 to 240 */ |
sam_grove |
0:6219434a0cb5 | 65 | #define TRANS_SYNC_MIN 1 /* Trans after reception of n SYNC. n = 1 to 240 */ |
sam_grove |
0:6219434a0cb5 | 66 | #define TRANS_SYNC_MAX 240 /* Trans after reception of n SYNC. n = 1 to 240 */ |
sam_grove |
0:6219434a0cb5 | 67 | #define TRANS_RTR_SYNC 252 /* Transmission on request */ |
sam_grove |
0:6219434a0cb5 | 68 | #define TRANS_RTR 253 /* Transmission on request */ |
sam_grove |
0:6219434a0cb5 | 69 | #define TRANS_EVENT_SPECIFIC 254 /* Transmission on event */ |
sam_grove |
0:6219434a0cb5 | 70 | #define TRANS_EVENT_PROFILE 255 /* Transmission on event */ |
sam_grove |
0:6219434a0cb5 | 71 | |
sam_grove |
0:6219434a0cb5 | 72 | /** |
sam_grove |
0:6219434a0cb5 | 73 | * @brief Copy all the data to transmit in process_var |
sam_grove |
0:6219434a0cb5 | 74 | * Prepare the PDO defined at index to be sent |
sam_grove |
0:6219434a0cb5 | 75 | * *pwCobId : returns the value of the cobid. (subindex 1) |
sam_grove |
0:6219434a0cb5 | 76 | * @param *d Pointer on a CAN object data structure |
sam_grove |
0:6219434a0cb5 | 77 | * @param numPdo The PDO number |
sam_grove |
0:6219434a0cb5 | 78 | * @param *pdo Pointer on a CAN message structure |
sam_grove |
0:6219434a0cb5 | 79 | * @return 0 or 0xFF if error. |
sam_grove |
0:6219434a0cb5 | 80 | */ |
sam_grove |
0:6219434a0cb5 | 81 | UNS8 buildPDO(CO_Data* d, UNS8 numPdo, Message *pdo); |
sam_grove |
0:6219434a0cb5 | 82 | |
sam_grove |
0:6219434a0cb5 | 83 | /** |
sam_grove |
0:6219434a0cb5 | 84 | * @ingroup pdo |
sam_grove |
0:6219434a0cb5 | 85 | * @brief Transmit a PDO request frame on the network to the slave. |
sam_grove |
0:6219434a0cb5 | 86 | * @param *d Pointer on a CAN object data structure |
sam_grove |
0:6219434a0cb5 | 87 | * @param RPDOIndex Index of the receive PDO |
sam_grove |
0:6219434a0cb5 | 88 | * @return |
sam_grove |
0:6219434a0cb5 | 89 | * - CanFestival file descriptor is returned upon success. |
sam_grove |
0:6219434a0cb5 | 90 | * - 0xFF is returned if RPDO Index is not found. |
sam_grove |
0:6219434a0cb5 | 91 | |
sam_grove |
0:6219434a0cb5 | 92 | * @return 0xFF if error, other in success. |
sam_grove |
0:6219434a0cb5 | 93 | */ |
sam_grove |
0:6219434a0cb5 | 94 | UNS8 sendPDOrequest( CO_Data* d, UNS16 RPDOIndex ); |
sam_grove |
0:6219434a0cb5 | 95 | |
sam_grove |
0:6219434a0cb5 | 96 | /** |
sam_grove |
0:6219434a0cb5 | 97 | * @brief Compute a PDO frame reception |
sam_grove |
0:6219434a0cb5 | 98 | * bus_id is hardware dependant |
sam_grove |
0:6219434a0cb5 | 99 | * @param *d Pointer on a CAN object data structure |
sam_grove |
0:6219434a0cb5 | 100 | * @param *m Pointer on a CAN message structure |
sam_grove |
0:6219434a0cb5 | 101 | * @return 0xFF if error, else return 0 |
sam_grove |
0:6219434a0cb5 | 102 | */ |
sam_grove |
0:6219434a0cb5 | 103 | UNS8 proceedPDO (CO_Data* d, Message *m); |
sam_grove |
0:6219434a0cb5 | 104 | |
sam_grove |
0:6219434a0cb5 | 105 | /** |
sam_grove |
0:6219434a0cb5 | 106 | * @brief Used by the application to signal changes in process data |
sam_grove |
0:6219434a0cb5 | 107 | * that could be mapped to some TPDO. |
sam_grove |
0:6219434a0cb5 | 108 | * This do not necessarily imply PDO emission. |
sam_grove |
0:6219434a0cb5 | 109 | * Function iterates on all TPDO and look TPDO transmit |
sam_grove |
0:6219434a0cb5 | 110 | * type and content change before sending it. |
sam_grove |
0:6219434a0cb5 | 111 | * @param *d Pointer on a CAN object data structure |
sam_grove |
0:6219434a0cb5 | 112 | */ |
sam_grove |
0:6219434a0cb5 | 113 | UNS8 sendPDOevent (CO_Data* d); |
sam_grove |
0:6219434a0cb5 | 114 | UNS8 sendOnePDOevent (CO_Data* d, UNS8 pdoNum); |
sam_grove |
0:6219434a0cb5 | 115 | |
sam_grove |
0:6219434a0cb5 | 116 | /** |
sam_grove |
0:6219434a0cb5 | 117 | * @ingroup pdo |
sam_grove |
0:6219434a0cb5 | 118 | * @brief Function iterates on all TPDO and look TPDO transmit |
sam_grove |
0:6219434a0cb5 | 119 | * type and content change before sending it. |
sam_grove |
0:6219434a0cb5 | 120 | * @param *d Pointer on a CAN object data structure |
sam_grove |
0:6219434a0cb5 | 121 | * @param isSyncEvent |
sam_grove |
0:6219434a0cb5 | 122 | */ |
sam_grove |
0:6219434a0cb5 | 123 | UNS8 _sendPDOevent(CO_Data* d, UNS8 isSyncEvent); |
sam_grove |
0:6219434a0cb5 | 124 | |
sam_grove |
0:6219434a0cb5 | 125 | /** |
sam_grove |
0:6219434a0cb5 | 126 | * @brief Initialize PDO feature |
sam_grove |
0:6219434a0cb5 | 127 | * @param *d Pointer on a CAN object data structure |
sam_grove |
0:6219434a0cb5 | 128 | */ |
sam_grove |
0:6219434a0cb5 | 129 | void PDOInit(CO_Data* d); |
sam_grove |
0:6219434a0cb5 | 130 | |
sam_grove |
0:6219434a0cb5 | 131 | /** |
sam_grove |
0:6219434a0cb5 | 132 | * @brief Stop PDO feature |
sam_grove |
0:6219434a0cb5 | 133 | * @param *d Pointer on a CAN object data structure |
sam_grove |
0:6219434a0cb5 | 134 | */ |
sam_grove |
0:6219434a0cb5 | 135 | void PDOStop(CO_Data* d); |
sam_grove |
0:6219434a0cb5 | 136 | |
sam_grove |
0:6219434a0cb5 | 137 | /** |
sam_grove |
0:6219434a0cb5 | 138 | * @ingroup pdo |
sam_grove |
0:6219434a0cb5 | 139 | * @brief Set timer for PDO event |
sam_grove |
0:6219434a0cb5 | 140 | * @param *d Pointer on a CAN object data structure |
sam_grove |
0:6219434a0cb5 | 141 | * @param pdoNum The PDO number |
sam_grove |
0:6219434a0cb5 | 142 | */ |
sam_grove |
0:6219434a0cb5 | 143 | void PDOEventTimerAlarm(CO_Data* d, UNS32 pdoNum); |
sam_grove |
0:6219434a0cb5 | 144 | |
sam_grove |
0:6219434a0cb5 | 145 | /** |
sam_grove |
0:6219434a0cb5 | 146 | * @ingroup pdo |
sam_grove |
0:6219434a0cb5 | 147 | * @brief Inhibit timer for PDO event |
sam_grove |
0:6219434a0cb5 | 148 | * @param *d Pointer on a CAN object data structure |
sam_grove |
0:6219434a0cb5 | 149 | * @param pdoNum The PDO number |
sam_grove |
0:6219434a0cb5 | 150 | */ |
sam_grove |
0:6219434a0cb5 | 151 | void PDOInhibitTimerAlarm(CO_Data* d, UNS32 pdoNum); |
sam_grove |
0:6219434a0cb5 | 152 | |
sam_grove |
0:6219434a0cb5 | 153 | /* copy bit per bit in little endian */ |
sam_grove |
0:6219434a0cb5 | 154 | void CopyBits(UNS8 NbBits, UNS8* SrcByteIndex, UNS8 SrcBitIndex, UNS8 SrcBigEndian, UNS8* DestByteIndex, UNS8 DestBitIndex, UNS8 DestBigEndian); |
sam_grove |
0:6219434a0cb5 | 155 | |
sam_grove |
0:6219434a0cb5 | 156 | #ifdef __cplusplus |
sam_grove |
0:6219434a0cb5 | 157 | } |
sam_grove |
0:6219434a0cb5 | 158 | #endif |
sam_grove |
0:6219434a0cb5 | 159 | #endif |