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