Sam Grove
/
canopen_slavenode
CANfestival - an open source CANopen framework
framework/include/can_driver.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 | #ifndef __can_driver_h__ |
sam_grove |
0:6219434a0cb5 | 24 | #define __can_driver_h__ |
sam_grove |
0:6219434a0cb5 | 25 | |
sam_grove |
0:6219434a0cb5 | 26 | struct struct_s_BOARD; |
sam_grove |
0:6219434a0cb5 | 27 | |
sam_grove |
0:6219434a0cb5 | 28 | typedef struct struct_s_BOARD s_BOARD; |
sam_grove |
0:6219434a0cb5 | 29 | |
sam_grove |
0:6219434a0cb5 | 30 | #include "applicfg.h" |
sam_grove |
0:6219434a0cb5 | 31 | #include "can.h" |
sam_grove |
0:6219434a0cb5 | 32 | |
sam_grove |
0:6219434a0cb5 | 33 | /** |
sam_grove |
0:6219434a0cb5 | 34 | * @brief The CAN board configuration |
sam_grove |
0:6219434a0cb5 | 35 | * @ingroup can |
sam_grove |
0:6219434a0cb5 | 36 | */ |
sam_grove |
0:6219434a0cb5 | 37 | |
sam_grove |
0:6219434a0cb5 | 38 | //struct struct_s_BOARD { |
sam_grove |
0:6219434a0cb5 | 39 | // char busname[100]; /**< The bus name on which the CAN board is connected */ |
sam_grove |
0:6219434a0cb5 | 40 | // char baudrate[4]; /**< The board baudrate */ |
sam_grove |
0:6219434a0cb5 | 41 | //}; |
sam_grove |
0:6219434a0cb5 | 42 | |
sam_grove |
0:6219434a0cb5 | 43 | struct struct_s_BOARD { |
sam_grove |
0:6219434a0cb5 | 44 | char * busname; /**< The bus name on which the CAN board is connected */ |
sam_grove |
0:6219434a0cb5 | 45 | char * baudrate; /**< The board baudrate */ |
sam_grove |
0:6219434a0cb5 | 46 | }; |
sam_grove |
0:6219434a0cb5 | 47 | |
sam_grove |
0:6219434a0cb5 | 48 | #ifndef DLL_CALL |
sam_grove |
0:6219434a0cb5 | 49 | #if !defined(WIN32) || defined(__CYGWIN__) |
sam_grove |
0:6219434a0cb5 | 50 | #define DLL_CALL(funcname) funcname##_driver |
sam_grove |
0:6219434a0cb5 | 51 | #else |
sam_grove |
0:6219434a0cb5 | 52 | //Windows was missing the definition of the calling convention |
sam_grove |
0:6219434a0cb5 | 53 | #define DLL_CALL(funcname) __stdcall funcname##_driver |
sam_grove |
0:6219434a0cb5 | 54 | #endif |
sam_grove |
0:6219434a0cb5 | 55 | #endif //DLL_CALL |
sam_grove |
0:6219434a0cb5 | 56 | |
sam_grove |
0:6219434a0cb5 | 57 | #ifndef FCT_PTR_INIT |
sam_grove |
0:6219434a0cb5 | 58 | #define FCT_PTR_INIT |
sam_grove |
0:6219434a0cb5 | 59 | #endif |
sam_grove |
0:6219434a0cb5 | 60 | |
sam_grove |
0:6219434a0cb5 | 61 | |
sam_grove |
0:6219434a0cb5 | 62 | UNS8 DLL_CALL(canReceive)(CAN_HANDLE, Message *)FCT_PTR_INIT; |
sam_grove |
0:6219434a0cb5 | 63 | UNS8 DLL_CALL(canSend)(CAN_HANDLE, Message const *)FCT_PTR_INIT; |
sam_grove |
0:6219434a0cb5 | 64 | CAN_HANDLE DLL_CALL(canOpen)(s_BOARD *)FCT_PTR_INIT; |
sam_grove |
0:6219434a0cb5 | 65 | int DLL_CALL(canClose)(CAN_HANDLE)FCT_PTR_INIT; |
sam_grove |
0:6219434a0cb5 | 66 | UNS8 DLL_CALL(canChangeBaudRate)(CAN_HANDLE, char *)FCT_PTR_INIT; |
sam_grove |
0:6219434a0cb5 | 67 | |
sam_grove |
0:6219434a0cb5 | 68 | #if defined DEBUG_MSG_CONSOLE_ON || defined NEED_PRINT_MESSAGE |
sam_grove |
0:6219434a0cb5 | 69 | #include "def.h" |
sam_grove |
0:6219434a0cb5 | 70 | |
sam_grove |
0:6219434a0cb5 | 71 | #define _P(fc) case fc: MSG(#fc" ");break; |
sam_grove |
0:6219434a0cb5 | 72 | |
sam_grove |
0:6219434a0cb5 | 73 | static inline void print_message(Message const *m) |
sam_grove |
0:6219434a0cb5 | 74 | { |
sam_grove |
0:6219434a0cb5 | 75 | int i; |
sam_grove |
0:6219434a0cb5 | 76 | UNS8 fc; |
sam_grove |
0:6219434a0cb5 | 77 | MSG("id:%02x ", m->cob_id & 0x7F); |
sam_grove |
0:6219434a0cb5 | 78 | fc = m->cob_id >> 7; |
sam_grove |
0:6219434a0cb5 | 79 | switch(fc) |
sam_grove |
0:6219434a0cb5 | 80 | { |
sam_grove |
0:6219434a0cb5 | 81 | case SYNC: |
sam_grove |
0:6219434a0cb5 | 82 | if(m->cob_id == 0x080) |
sam_grove |
0:6219434a0cb5 | 83 | MSG("SYNC "); |
sam_grove |
0:6219434a0cb5 | 84 | else |
sam_grove |
0:6219434a0cb5 | 85 | MSG("EMCY "); |
sam_grove |
0:6219434a0cb5 | 86 | break; |
sam_grove |
0:6219434a0cb5 | 87 | #ifdef CO_ENABLE_LSS |
sam_grove |
0:6219434a0cb5 | 88 | case LSS: |
sam_grove |
0:6219434a0cb5 | 89 | if(m->cob_id == 0x7E5) |
sam_grove |
0:6219434a0cb5 | 90 | MSG("MLSS "); |
sam_grove |
0:6219434a0cb5 | 91 | else |
sam_grove |
0:6219434a0cb5 | 92 | MSG("SLSS "); |
sam_grove |
0:6219434a0cb5 | 93 | break; |
sam_grove |
0:6219434a0cb5 | 94 | #endif |
sam_grove |
0:6219434a0cb5 | 95 | _P(TIME_STAMP) |
sam_grove |
0:6219434a0cb5 | 96 | _P(PDO1tx) |
sam_grove |
0:6219434a0cb5 | 97 | _P(PDO1rx) |
sam_grove |
0:6219434a0cb5 | 98 | _P(PDO2tx) |
sam_grove |
0:6219434a0cb5 | 99 | _P(PDO2rx) |
sam_grove |
0:6219434a0cb5 | 100 | _P(PDO3tx) |
sam_grove |
0:6219434a0cb5 | 101 | _P(PDO3rx) |
sam_grove |
0:6219434a0cb5 | 102 | _P(PDO4tx) |
sam_grove |
0:6219434a0cb5 | 103 | _P(PDO4rx) |
sam_grove |
0:6219434a0cb5 | 104 | _P(SDOtx) |
sam_grove |
0:6219434a0cb5 | 105 | _P(SDOrx) |
sam_grove |
0:6219434a0cb5 | 106 | _P(NODE_GUARD) |
sam_grove |
0:6219434a0cb5 | 107 | _P(NMT) |
sam_grove |
0:6219434a0cb5 | 108 | } |
sam_grove |
0:6219434a0cb5 | 109 | if( fc == SDOtx) |
sam_grove |
0:6219434a0cb5 | 110 | { |
sam_grove |
0:6219434a0cb5 | 111 | switch(m->data[0] >> 5) |
sam_grove |
0:6219434a0cb5 | 112 | { |
sam_grove |
0:6219434a0cb5 | 113 | /* scs: server command specifier */ |
sam_grove |
0:6219434a0cb5 | 114 | _P(UPLOAD_SEGMENT_RESPONSE) |
sam_grove |
0:6219434a0cb5 | 115 | _P(DOWNLOAD_SEGMENT_RESPONSE) |
sam_grove |
0:6219434a0cb5 | 116 | _P(INITIATE_DOWNLOAD_RESPONSE) |
sam_grove |
0:6219434a0cb5 | 117 | _P(INITIATE_UPLOAD_RESPONSE) |
sam_grove |
0:6219434a0cb5 | 118 | _P(ABORT_TRANSFER_REQUEST) |
sam_grove |
0:6219434a0cb5 | 119 | } |
sam_grove |
0:6219434a0cb5 | 120 | }else if( fc == SDOrx) |
sam_grove |
0:6219434a0cb5 | 121 | { |
sam_grove |
0:6219434a0cb5 | 122 | switch(m->data[0] >> 5) |
sam_grove |
0:6219434a0cb5 | 123 | { |
sam_grove |
0:6219434a0cb5 | 124 | /* ccs: client command specifier */ |
sam_grove |
0:6219434a0cb5 | 125 | _P(DOWNLOAD_SEGMENT_REQUEST) |
sam_grove |
0:6219434a0cb5 | 126 | _P(INITIATE_DOWNLOAD_REQUEST) |
sam_grove |
0:6219434a0cb5 | 127 | _P(INITIATE_UPLOAD_REQUEST) |
sam_grove |
0:6219434a0cb5 | 128 | _P(UPLOAD_SEGMENT_REQUEST) |
sam_grove |
0:6219434a0cb5 | 129 | _P(ABORT_TRANSFER_REQUEST) |
sam_grove |
0:6219434a0cb5 | 130 | } |
sam_grove |
0:6219434a0cb5 | 131 | } |
sam_grove |
0:6219434a0cb5 | 132 | MSG(" rtr:%d", m->rtr); |
sam_grove |
0:6219434a0cb5 | 133 | MSG(" len:%d", m->len); |
sam_grove |
0:6219434a0cb5 | 134 | for (i = 0 ; i < m->len ; i++) |
sam_grove |
0:6219434a0cb5 | 135 | MSG(" %02x", m->data[i]); |
sam_grove |
0:6219434a0cb5 | 136 | MSG("\n"); |
sam_grove |
0:6219434a0cb5 | 137 | } |
sam_grove |
0:6219434a0cb5 | 138 | |
sam_grove |
0:6219434a0cb5 | 139 | #endif |
sam_grove |
0:6219434a0cb5 | 140 | |
sam_grove |
0:6219434a0cb5 | 141 | #endif |