]> rtime.felk.cvut.cz Git - CanFestival-3.git/blob - examples/AVR/Slave/ds401.c
New named folder, first DS401 profile module, Makefile
[CanFestival-3.git] / examples / AVR / Slave / ds401.c
1 /*
2 This file is part of CanFestival, a library implementing CanOpen Stack.
3
4 Copyright (C): Andreas GLAUSER
5
6 See COPYING file for copyrights details.
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 */
22
23 // DS 401 Digital IO handling according DS 401 V2.1 "Device Profile for Generic I/O Modules"
24
25 // Includes for the Canfestival
26 #include "ds401.h"
27
28 unsigned char digital_input_handler(CO_Data* d, unsigned char *newInput, unsigned char size)
29 {
30   unsigned char loops, i, input, transmission = 0;
31
32   loops = (sizeof(Read_Inputs_8_Bit) <= size) ? sizeof(Read_Inputs_8_Bit) : size;
33
34   for (i=0; i < loops; i++)
35   {
36     input = *newInput ^ Polarity_Input_8_Bit[i];
37     if (Read_Inputs_8_Bit[i] != input)
38     {
39       if (Global_Interrupt_Enable_Digital)
40       {
41         if ((Interrupt_Mask_Any_Change_8_Bit[i] & (Read_Inputs_8_Bit[i] ^ input)) 
42          || (Interrupt_Mask_Low_to_High_8_Bit[i] & ~Read_Inputs_8_Bit[i] & input)
43          || (Interrupt_Mask_High_to_Low_8_Bit[i] & Read_Inputs_8_Bit[i] & ~input))
44            transmission = 1;
45       }
46       // update object dict
47       Read_Inputs_8_Bit[i] = input;
48     }
49     newInput++;
50   }
51   if (transmission)
52     sendPDOevent(d);
53
54   return 1;
55 }
56
57 unsigned char digital_output_handler(CO_Data* d, unsigned char *newOutput, unsigned char size)
58 {
59   unsigned char loops, i, error, type;
60   unsigned char varsize = 1;
61
62   loops = (sizeof(Write_Outputs_8_Bit) <= size) ? sizeof(Write_Outputs_8_Bit) : size;
63
64   for (i=0; i < loops; i++)
65   {
66     getODentry(d, 0x1001, 0x0, &error, &varsize, &type, RO);
67     if ((getState(d) == Stopped) || (error != 0))       // node stopped or error
68     {
69       Write_Outputs_8_Bit[i] &= (~Error_Mode_Outputs_8_Bit[i] | Error_Value_Outputs_8_Bit[i]);
70       Write_Outputs_8_Bit[i] |= (Error_Mode_Outputs_8_Bit[i] & Error_Value_Outputs_8_Bit[i]);
71     }
72     *newOutput = Write_Outputs_8_Bit[i] ^ Change_Polarity_Outputs_8_Bit[i];
73     newOutput++;
74   }
75   return 1;
76 }
77
78 unsigned char analog_input_handler(CO_Data* d, unsigned int *newInput, unsigned char size)
79 {
80   return 0;
81 }
82
83 unsigned char analog_output_handler(CO_Data* d, unsigned int *newOutput, unsigned char size)
84 {
85   return 0;
86 }
87
88
89