![](/media/cache/profiles/IMG_2753.JPG.50x50_q85.jpg)
Can_open_slavenode
source/ds401.c@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): Andreas GLAUSER |
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 | // DS 401 Digital IO handling according DS 401 V2.1 "Device Profile for Generic I/O Modules" |
sam_grove |
0:6219434a0cb5 | 24 | |
sam_grove |
0:6219434a0cb5 | 25 | // Includes for the Canfestival |
sam_grove |
0:6219434a0cb5 | 26 | #include "ds401.h" |
sam_grove |
0:6219434a0cb5 | 27 | |
sam_grove |
0:6219434a0cb5 | 28 | unsigned char digital_input_handler(CO_Data* d, unsigned char *newInput, unsigned char size) |
sam_grove |
0:6219434a0cb5 | 29 | { |
sam_grove |
0:6219434a0cb5 | 30 | unsigned char loops, i, input, transmission = 0; |
sam_grove |
0:6219434a0cb5 | 31 | |
sam_grove |
0:6219434a0cb5 | 32 | loops = (sizeof(Read_Inputs_8_Bit) <= size) ? sizeof(Read_Inputs_8_Bit) : size; |
sam_grove |
0:6219434a0cb5 | 33 | |
sam_grove |
0:6219434a0cb5 | 34 | for (i=0; i < loops; i++) |
sam_grove |
0:6219434a0cb5 | 35 | { |
sam_grove |
0:6219434a0cb5 | 36 | input = *newInput ^ Polarity_Input_8_Bit[i]; |
sam_grove |
0:6219434a0cb5 | 37 | if (Read_Inputs_8_Bit[i] != input) |
sam_grove |
0:6219434a0cb5 | 38 | { |
sam_grove |
0:6219434a0cb5 | 39 | if (Global_Interrupt_Enable_Digital) |
sam_grove |
0:6219434a0cb5 | 40 | { |
sam_grove |
0:6219434a0cb5 | 41 | if ((Interrupt_Mask_Any_Change_8_Bit[i] & (Read_Inputs_8_Bit[i] ^ input)) |
sam_grove |
0:6219434a0cb5 | 42 | || (Interrupt_Mask_Low_to_High_8_Bit[i] & ~Read_Inputs_8_Bit[i] & input) |
sam_grove |
0:6219434a0cb5 | 43 | || (Interrupt_Mask_High_to_Low_8_Bit[i] & Read_Inputs_8_Bit[i] & ~input)) |
sam_grove |
0:6219434a0cb5 | 44 | transmission = 1; |
sam_grove |
0:6219434a0cb5 | 45 | } |
sam_grove |
0:6219434a0cb5 | 46 | // update object dict |
sam_grove |
0:6219434a0cb5 | 47 | Read_Inputs_8_Bit[i] = input; |
sam_grove |
0:6219434a0cb5 | 48 | } |
sam_grove |
0:6219434a0cb5 | 49 | newInput++; |
sam_grove |
0:6219434a0cb5 | 50 | } |
sam_grove |
0:6219434a0cb5 | 51 | if (transmission) |
sam_grove |
0:6219434a0cb5 | 52 | { |
sam_grove |
0:6219434a0cb5 | 53 | /* force emission of PDO by artificially changing last emitted*/ |
sam_grove |
0:6219434a0cb5 | 54 | d->PDO_status[0].last_message.cob_id = 0; |
sam_grove |
0:6219434a0cb5 | 55 | sendPDOevent(d); |
sam_grove |
0:6219434a0cb5 | 56 | } |
sam_grove |
0:6219434a0cb5 | 57 | |
sam_grove |
0:6219434a0cb5 | 58 | return 1; |
sam_grove |
0:6219434a0cb5 | 59 | } |
sam_grove |
0:6219434a0cb5 | 60 | |
sam_grove |
0:6219434a0cb5 | 61 | unsigned char digital_output_handler(CO_Data* d, unsigned char *newOutput, unsigned char size) |
sam_grove |
0:6219434a0cb5 | 62 | { |
sam_grove |
0:6219434a0cb5 | 63 | unsigned char loops, i, error, type; |
sam_grove |
0:6219434a0cb5 | 64 | /* fixed warning due to data size mismatch - not much of an issue since the |
sam_grove |
0:6219434a0cb5 | 65 | data is last on the stack unless another function was called... */ |
sam_grove |
0:6219434a0cb5 | 66 | //unsigned char varsize = 1; |
sam_grove |
0:6219434a0cb5 | 67 | uint32_t varsize = 1; |
sam_grove |
0:6219434a0cb5 | 68 | |
sam_grove |
0:6219434a0cb5 | 69 | loops = (sizeof(Write_Outputs_8_Bit) <= size) ? sizeof(Write_Outputs_8_Bit) : size; |
sam_grove |
0:6219434a0cb5 | 70 | |
sam_grove |
0:6219434a0cb5 | 71 | for (i=0; i < loops; i++) |
sam_grove |
0:6219434a0cb5 | 72 | { |
sam_grove |
0:6219434a0cb5 | 73 | /* warning because varsize is 8bits and the parameter is a pointer (32bit) |
sam_grove |
0:6219434a0cb5 | 74 | used for address to return a value */ |
sam_grove |
0:6219434a0cb5 | 75 | getODentry(d, 0x1001, 0x0, &error, &varsize, &type, RO); |
sam_grove |
0:6219434a0cb5 | 76 | if ((getState(d) == Stopped) || (error != 0)) // node stopped or error |
sam_grove |
0:6219434a0cb5 | 77 | { |
sam_grove |
0:6219434a0cb5 | 78 | Write_Outputs_8_Bit[i] &= (~Error_Mode_Outputs_8_Bit[i] | Error_Value_Outputs_8_Bit[i]); |
sam_grove |
0:6219434a0cb5 | 79 | Write_Outputs_8_Bit[i] |= (Error_Mode_Outputs_8_Bit[i] & Error_Value_Outputs_8_Bit[i]); |
sam_grove |
0:6219434a0cb5 | 80 | } |
sam_grove |
0:6219434a0cb5 | 81 | *newOutput = Write_Outputs_8_Bit[i] ^ Change_Polarity_Outputs_8_Bit[i]; |
sam_grove |
0:6219434a0cb5 | 82 | newOutput++; |
sam_grove |
0:6219434a0cb5 | 83 | } |
sam_grove |
0:6219434a0cb5 | 84 | return 1; |
sam_grove |
0:6219434a0cb5 | 85 | } |
sam_grove |
0:6219434a0cb5 | 86 | |
sam_grove |
0:6219434a0cb5 | 87 | unsigned char analog_input_handler(CO_Data* d, unsigned int *newInput, unsigned char size) |
sam_grove |
0:6219434a0cb5 | 88 | { |
sam_grove |
0:6219434a0cb5 | 89 | return 0; |
sam_grove |
0:6219434a0cb5 | 90 | } |
sam_grove |
0:6219434a0cb5 | 91 | |
sam_grove |
0:6219434a0cb5 | 92 | unsigned char analog_output_handler(CO_Data* d, unsigned int *newOutput, unsigned char size) |
sam_grove |
0:6219434a0cb5 | 93 | { |
sam_grove |
0:6219434a0cb5 | 94 | return 0; |
sam_grove |
0:6219434a0cb5 | 95 | } |
sam_grove |
0:6219434a0cb5 | 96 | |
sam_grove |
0:6219434a0cb5 | 97 | |
sam_grove |
0:6219434a0cb5 | 98 |