peter@413: /* peter@413: This file is part of CanFestival, a library implementing CanOpen Stack. peter@413: peter@413: Copyright (C): Andreas GLAUSER peter@413: peter@413: See COPYING file for copyrights details. peter@413: peter@413: This library is free software; you can redistribute it and/or peter@413: modify it under the terms of the GNU Lesser General Public peter@413: License as published by the Free Software Foundation; either peter@413: version 2.1 of the License, or (at your option) any later version. peter@413: peter@413: This library is distributed in the hope that it will be useful, peter@413: but WITHOUT ANY WARRANTY; without even the implied warranty of peter@413: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU peter@413: Lesser General Public License for more details. peter@413: peter@413: You should have received a copy of the GNU Lesser General Public peter@413: License along with this library; if not, write to the Free Software peter@413: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA peter@413: */ peter@413: peter@413: // DS 401 Digital IO handling according DS 401 V2.1 "Device Profile for Generic I/O Modules" peter@413: peter@413: // Includes for the Canfestival peter@413: #include "ds401.h" peter@413: peter@413: unsigned char digital_input_handler(CO_Data* d, unsigned char *newInput, unsigned char size) peter@413: { peter@413: unsigned char loops, i, input, transmission = 0; peter@413: peter@413: loops = (sizeof(Read_Inputs_8_Bit) <= size) ? sizeof(Read_Inputs_8_Bit) : size; peter@413: peter@413: for (i=0; i < loops; i++) peter@413: { peter@413: input = *newInput ^ Polarity_Input_8_Bit[i]; peter@413: if (Read_Inputs_8_Bit[i] != input) peter@413: { peter@413: if (Global_Interrupt_Enable_Digital) peter@413: { peter@413: if ((Interrupt_Mask_Any_Change_8_Bit[i] & (Read_Inputs_8_Bit[i] ^ input)) peter@413: || (Interrupt_Mask_Low_to_High_8_Bit[i] & ~Read_Inputs_8_Bit[i] & input) peter@413: || (Interrupt_Mask_High_to_Low_8_Bit[i] & Read_Inputs_8_Bit[i] & ~input)) peter@413: transmission = 1; peter@413: } peter@413: // update object dict peter@413: Read_Inputs_8_Bit[i] = input; peter@413: } peter@413: newInput++; peter@413: } peter@413: if (transmission) peter@413: sendPDOevent(d); peter@413: peter@413: return 1; peter@413: } peter@413: peter@413: unsigned char digital_output_handler(CO_Data* d, unsigned char *newOutput, unsigned char size) peter@413: { peter@413: unsigned char loops, i, error, type; peter@413: unsigned char varsize = 1; peter@413: peter@413: loops = (sizeof(Write_Outputs_8_Bit) <= size) ? sizeof(Write_Outputs_8_Bit) : size; peter@413: peter@413: for (i=0; i < loops; i++) peter@413: { peter@413: getODentry(d, 0x1001, 0x0, &error, &varsize, &type, RO); peter@413: if ((getState(d) == Stopped) || (error != 0)) // node stopped or error peter@413: { peter@413: Write_Outputs_8_Bit[i] &= (~Error_Mode_Outputs_8_Bit[i] | Error_Value_Outputs_8_Bit[i]); peter@413: Write_Outputs_8_Bit[i] |= (Error_Mode_Outputs_8_Bit[i] & Error_Value_Outputs_8_Bit[i]); peter@413: } peter@413: *newOutput = Write_Outputs_8_Bit[i] ^ Change_Polarity_Outputs_8_Bit[i]; peter@413: newOutput++; peter@413: } peter@413: return 1; peter@413: } peter@413: peter@413: unsigned char analog_input_handler(CO_Data* d, unsigned int *newInput, unsigned char size) peter@413: { peter@413: return 0; peter@413: } peter@413: peter@413: unsigned char analog_output_handler(CO_Data* d, unsigned int *newOutput, unsigned char size) peter@413: { peter@413: return 0; peter@413: } peter@413: peter@413: peter@413: