added xmc4300 demo project
parent
31f390bca0
commit
5c3184cbd6
|
@ -0,0 +1,170 @@
|
|||
|
||||
TARGET = xmc4300-ecat-slave
|
||||
|
||||
DEVICE = XMC4300
|
||||
VARIANT = F100x256
|
||||
|
||||
EC_SII = sii_eeprom.bin
|
||||
|
||||
SRC = \
|
||||
main.c \
|
||||
objectlist.c \
|
||||
soes.c \
|
||||
../../soes/esc.c \
|
||||
../../soes/esc_coe.c \
|
||||
../../soes/esc_eep.c \
|
||||
../../soes/hal/xmc4/esc_hw.c \
|
||||
../../soes/hal/xmc4/esc_hw_eep.c \
|
||||
Libraries/XMCLib/src/xmc_gpio.c \
|
||||
Libraries/XMCLib/src/xmc4_gpio.c \
|
||||
Libraries/XMCLib/src/xmc4_scu.c \
|
||||
Libraries/XMCLib/src/xmc_ecat.c \
|
||||
Libraries/XMCLib/src/xmc4_flash.c \
|
||||
Libraries/XMCLib/src/xmc_fce.c \
|
||||
Libraries/Newlib/syscalls.c \
|
||||
Startup/system_$(DEVICE).c \
|
||||
|
||||
ASRC = \
|
||||
Startup/startup_$(DEVICE).S \
|
||||
|
||||
BINS = \
|
||||
$(EC_SII)\
|
||||
|
||||
|
||||
LINKER_SCRIPT = ./linker_script.ld
|
||||
|
||||
# JLink options
|
||||
JLINK_SPEED = 1000
|
||||
JLINK_IFACE = swd
|
||||
|
||||
# Define all object files.
|
||||
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) $(BINS:.bin=.o)
|
||||
|
||||
# Define all listing files.
|
||||
LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
|
||||
|
||||
# Define all dependency files.
|
||||
DEP = $(ASRC:.S=.d) $(SRC:.c=.d)
|
||||
|
||||
CPPFLAGS = -D$(DEVICE)_$(VARIANT)
|
||||
CPPFLAGS += -MMD -MP -MF $(@:.o=.d) -MT $(@)
|
||||
|
||||
CPPFLAGS += -I./Libraries/XMCLib/inc
|
||||
CPPFLAGS += -I./Libraries/CMSIS/Include
|
||||
CPPFLAGS += -I./Libraries/CMSIS/Infineon/$(DEVICE)_series/Include
|
||||
CPPFLAGS += -I.
|
||||
CPPFLAGS += -I./Libraries
|
||||
CPPFLAGS += -I../../soes
|
||||
CPPFLAGS += -I../../soes/hal/xmc4
|
||||
CPPFLAGS += -I../../soes/include/sys/gcc
|
||||
|
||||
ARCHFLAGS = -mfloat-abi=softfp -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mthumb
|
||||
|
||||
OBJFLAGS = -Wall -fmessage-length=0 -Wa,-adhlns=$(@:.o=.lst) $(ARCHFLAGS)
|
||||
|
||||
CFLAGS = $(CPPFLAGS) $(OBJFLAGS) -Os -ffunction-sections -fdata-sections -std=gnu99 -pipe
|
||||
ASFLAGS = -x assembler-with-cpp $(CPPFLAGS) $(OBJFLAGS)
|
||||
|
||||
LDFLAGS = -T$(LINKER_SCRIPT) -nostartfiles -Xlinker --gc-sections
|
||||
LDFLAGS += -specs=nano.specs -specs=nosys.specs
|
||||
LDFLAGS += -Wl,-Map,$(TARGET).map
|
||||
LDFLAGS += $(ARCHFLAGS)
|
||||
|
||||
# Define programs and commands.
|
||||
SHELL = sh
|
||||
REMOVE = rm -f
|
||||
CC = arm-none-eabi-gcc
|
||||
OBJCOPY = arm-none-eabi-objcopy
|
||||
OBJDUMP = arm-none-eabi-objdump
|
||||
SIZE = arm-none-eabi-size
|
||||
JLINK = JLinkExe
|
||||
|
||||
# Define Messages
|
||||
# English
|
||||
MSG_SIZE = Size:
|
||||
MSG_FLASH_FILE = Creating load file for Flash:
|
||||
MSG_FLASH = Programming target flash memory:
|
||||
MSG_FLASH_ERASE = Erasing target flash memory:
|
||||
MSG_EXTENDED_LISTING = Creating Extended Listing:
|
||||
MSG_LINKING = Linking:
|
||||
MSG_COMPILING = Compiling:
|
||||
MSG_ASSEMBLING = Assembling:
|
||||
MSG_OBJCOPY = ObjCopy:
|
||||
MSG_CLEANING = Cleaning project:
|
||||
|
||||
# Default target.
|
||||
all: $(TARGET).hex size
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
%.o : %.c
|
||||
@echo
|
||||
@echo $(MSG_COMPILING) $<
|
||||
$(CC) -c $(CFLAGS) -o $@ $<
|
||||
|
||||
# Assemble: create object files from assembler source files.
|
||||
%.o : %.S
|
||||
@echo
|
||||
@echo $(MSG_ASSEMBLING) $<
|
||||
$(CC) -c $(ASFLAGS) -o $@ $<
|
||||
|
||||
# ObjCopy: create object files from binary files.
|
||||
%.o : %.bin
|
||||
@echo
|
||||
@echo $(MSG_OBJCOPY) $<
|
||||
$(OBJCOPY) -I binary -O elf32-littlearm -B arm $< $@
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
$(TARGET).elf: $(OBJ)
|
||||
@echo
|
||||
@echo $(MSG_LINKING) $@
|
||||
$(CC) $(LDFLAGS) -o $@ $(OBJ)
|
||||
|
||||
# Create final output file from ELF output file.
|
||||
$(TARGET).hex: $(TARGET).elf
|
||||
@echo
|
||||
@echo $(MSG_FLASH_FILE) $@
|
||||
$(OBJCOPY) -O ihex $< $@
|
||||
|
||||
# Create extended listing file from ELF output file.
|
||||
$(TARGET).lss: $(TARGET).elf
|
||||
@echo
|
||||
@echo $(MSG_EXTENDED_LISTING) $@
|
||||
$(OBJDUMP) -h -S $(TARGET).elf > $(TARGET).lss
|
||||
|
||||
# Display size of file.
|
||||
size: $(TARGET).elf
|
||||
@echo
|
||||
@echo $(MSG_SIZE)
|
||||
$(SIZE) --format=berkeley $(TARGET).elf
|
||||
@echo
|
||||
|
||||
# Flash the target device.
|
||||
flash: $(TARGET).hex
|
||||
@echo
|
||||
@echo $(MSG_FLASH)
|
||||
echo -e "device $(DEVICE)-$(VARIANT)\nspeed $(JLINK_SPEED)\nsi $(JLINK_IFACE)\nloadfile $(TARGET).hex\ng\nqc\n" | $(JLINK)
|
||||
|
||||
# Erase the target flash
|
||||
erase:
|
||||
@echo
|
||||
@echo $(MSG_FLASH_ERASE)
|
||||
echo -e "device $(DEVICE)-$(VARIANT)\nspeed $(JLINK_SPEED)\nsi $(JLINK_IFACE)\nerase\nqc\n" | $(JLINK)
|
||||
|
||||
# Target: clean project.
|
||||
clean:
|
||||
@echo
|
||||
@echo $(MSG_CLEANING)
|
||||
$(REMOVE) $(TARGET).map
|
||||
$(REMOVE) $(TARGET).elf
|
||||
$(REMOVE) $(TARGET).hex
|
||||
$(REMOVE) $(TARGET).lss
|
||||
$(REMOVE) $(OBJ)
|
||||
$(REMOVE) $(LST)
|
||||
$(REMOVE) $(DEP)
|
||||
|
||||
# Include the dependency files.
|
||||
-include $(DEP)
|
||||
|
||||
# Listing of phony targets.
|
||||
.PHONY: all clean size flash erase
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
<?xml version="1.0"?>
|
||||
<EtherCATInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="EtherCATInfo.xsd" Version="1.2">
|
||||
<Vendor>
|
||||
<Id>#x1337</Id>
|
||||
<Name>rt-labs AB</Name>
|
||||
</Vendor>
|
||||
<Descriptions>
|
||||
<Groups>
|
||||
<Group>
|
||||
<Type>ATENSLAVE</Type>
|
||||
<Name>ATO</Name>
|
||||
</Group>
|
||||
</Groups>
|
||||
<Devices>
|
||||
<Device Physics="YY">
|
||||
<Type ProductCode="#x12783456" RevisionNo="#x00000001">ATO sample application</Type>
|
||||
<Name><![CDATA[ATEN-ATO output slave]]></Name>
|
||||
<GroupType>ATENSLAVE</GroupType>
|
||||
<Fmmu>Outputs</Fmmu>
|
||||
<Fmmu>Inputs</Fmmu>
|
||||
<Sm DefaultSize="128" StartAddress="#x1000" ControlByte="#x26" Enable="1">MBoxOut</Sm>
|
||||
<Sm DefaultSize="128" StartAddress="#x1080" ControlByte="#x22" Enable="1">MBoxIn</Sm>
|
||||
<Sm StartAddress="#x1100" ControlByte="#x24" Enable="1">Outputs</Sm>
|
||||
<Sm StartAddress="#x1180" ControlByte="#x20" Enable="1">Inputs</Sm>
|
||||
<Mailbox DataLinkLayer="1">
|
||||
<CoE SdoInfo="1" CompleteAccess="0" PdoUpload="1"/>
|
||||
</Mailbox>
|
||||
<Dc>
|
||||
<OpMode>
|
||||
<Name>DcOff</Name>
|
||||
<Desc>DC unused</Desc>
|
||||
<AssignActivate>#x0000</AssignActivate>
|
||||
</OpMode>
|
||||
</Dc>
|
||||
<Eeprom>
|
||||
<ByteSize>3968</ByteSize>
|
||||
<ConfigData>050E0306102700</ConfigData>
|
||||
</Eeprom>
|
||||
</Device>
|
||||
</Devices>
|
||||
</Descriptions>
|
||||
</EtherCATInfo>
|
|
@ -0,0 +1,15 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "xmc_gpio.h"
|
||||
|
||||
#include "soes.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
soes_init();
|
||||
|
||||
while(1) {
|
||||
soes_task();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,170 @@
|
|||
/*
|
||||
* SOES Simple Open EtherCAT Slave
|
||||
*
|
||||
* Copyright (C) 2007-2013 Arthur Ketels
|
||||
*
|
||||
* SOES is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License version 2 as published by the Free
|
||||
* Software Foundation.
|
||||
*
|
||||
* SOES is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* As a special exception, if other files instantiate templates or use macros
|
||||
* or inline functions from this file, or you compile this file and link it
|
||||
* with other works to produce a work based on this file, this file does not
|
||||
* by itself cause the resulting work to be covered by the GNU General Public
|
||||
* License. However the source code for this file must still be made available
|
||||
* in accordance with section (3) of the GNU General Public License.
|
||||
*
|
||||
* This exception does not invalidate any other reasons why a work based on
|
||||
* this file might be covered by the GNU General Public License.
|
||||
*
|
||||
* The EtherCAT Technology, the trade name and logo "EtherCAT" are the intellectual
|
||||
* property of, and protected by Beckhoff Automation GmbH.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief
|
||||
* CoE Object Dictionary.
|
||||
*
|
||||
* Part of application, describe the slave and its process data.
|
||||
*/
|
||||
|
||||
#include "esc_coe.h"
|
||||
#include "utypes.h"
|
||||
#include <stddef.h>
|
||||
|
||||
extern _Rbuffer Rb;
|
||||
extern _Wbuffer Wb;
|
||||
extern _Cbuffer Cb;
|
||||
extern uint32_t encoder_scale;
|
||||
extern uint32_t encoder_scale_mirror;
|
||||
|
||||
static const char acName1000[] = "Device Type";
|
||||
static const char acName1008[] = "Manufacturer Device Name";
|
||||
static const char acName1009[] = "Manufacturer Hardware Version";
|
||||
static const char acName100A[] = "Manufacturer Software Version";
|
||||
static const char acName1018[] = "Identity Object";
|
||||
static const char acName1018_01[] = "Vendor ID";
|
||||
static const char acName1018_02[] = "Product Code";
|
||||
static const char acName1018_03[] = "Revision Number";
|
||||
static const char acName1018_04[] = "Serial Number";
|
||||
static const char acNameMO[] = "Mapped object";
|
||||
static const char acName1600[] = "Receive PDO mapping";
|
||||
static const char acName1A00[] = "Transmit PDO mapping";
|
||||
static const char acName1C00[] = "Sync Manager Communication type";
|
||||
static const char acName1C00_01[] = "Communications type SM0";
|
||||
static const char acName1C00_02[] = "Communications type SM1";
|
||||
static const char acName1C00_03[] = "Communications type SM2";
|
||||
static const char acName1C00_04[] = "Communications type SM3";
|
||||
static const char acName1C10[] = "Sync Manager 0 PDO Assignment";
|
||||
static const char acName1C11[] = "Sync Manager 1 PDO Assignment";
|
||||
static const char acName1C12[] = "Sync Manager 2 PDO Assignment";
|
||||
static const char acName1C13[] = "Sync Manager 3 PDO Assignment";
|
||||
static const char acNameNOE[] = "Number of entries";
|
||||
static const char acName6000[] = "Digital Inputs";
|
||||
static const char acName6000_01[] = "Button";
|
||||
static const char acName6000_02[] = "Encoder";
|
||||
static const char acName7000[] = "Digital outputs";
|
||||
static const char acName7000_01[] = "LED";
|
||||
static const char acName7100[] = "Parameters";
|
||||
static const char acName7100_01[] = "Encoder scale";
|
||||
static const char acName7100_02[] = "Encoder scale mirror";
|
||||
static const char acName8001[] = "Slave commands";
|
||||
static const char acName8001_01[] = "Reset counter";
|
||||
|
||||
static char ac1008_00[] = "SOES test application";
|
||||
static char ac1009_00[] = "0.0.2";
|
||||
static char ac100A_00[] = "0.9.3";
|
||||
|
||||
const _objd SDO1000[] =
|
||||
{ {0x00, DTYPE_UNSIGNED32, 32, ATYPE_RO, &acName1000[0], 0x00000000, NULL} };
|
||||
const _objd SDO1008[] =
|
||||
{ {0x00, DTYPE_VISIBLE_STRING, sizeof (ac1008_00) << 3, ATYPE_RO, &acName1008[0], 0, &ac1008_00[0]}
|
||||
};
|
||||
const _objd SDO1009[] =
|
||||
{ {0x00, DTYPE_VISIBLE_STRING, sizeof (ac1009_00) << 3, ATYPE_RO, &acName1009[0], 0, &ac1009_00[0]}
|
||||
};
|
||||
const _objd SDO100A[] =
|
||||
{ {0x00, DTYPE_VISIBLE_STRING, sizeof (ac100A_00) << 3, ATYPE_RO, &acName100A[0], 0, &ac100A_00[0]}
|
||||
};
|
||||
const _objd SDO1018[] =
|
||||
{ {0x00, DTYPE_UNSIGNED8, 8, ATYPE_RO, &acNameNOE[0], 0x04, NULL},
|
||||
{0x01, DTYPE_UNSIGNED32, 32, ATYPE_RO, &acName1018_01[0], 0x00001337, NULL},
|
||||
{0x02, DTYPE_UNSIGNED32, 32, ATYPE_RO, &acName1018_02[0], 0x12783456, NULL},
|
||||
{0x03, DTYPE_UNSIGNED32, 32, ATYPE_RO, &acName1018_03[0], 0x00000001, NULL},
|
||||
{0x04, DTYPE_UNSIGNED32, 32, ATYPE_RO, &acName1018_04[0], 0x00000000, NULL}
|
||||
};
|
||||
const _objd SDO1600[] =
|
||||
{ {0x00, DTYPE_UNSIGNED8, 8, ATYPE_RO, &acNameNOE[0], 0x01, NULL},
|
||||
{0x01, DTYPE_UNSIGNED32, 32, ATYPE_RO, &acNameMO[0], 0x70000108, NULL}
|
||||
};
|
||||
const _objd SDO1A00[] =
|
||||
{ {0x00, DTYPE_UNSIGNED8, 8, ATYPE_RO, &acNameNOE[0], 0x02, NULL},
|
||||
{0x01, DTYPE_UNSIGNED32, 32, ATYPE_RO, &acNameMO[0], 0x60000108, NULL},
|
||||
{0x02, DTYPE_UNSIGNED32, 32, ATYPE_RO, &acNameMO[0], 0x60000220, NULL}
|
||||
|
||||
};
|
||||
const _objd SDO1C00[] =
|
||||
{ {0x00, DTYPE_UNSIGNED8, 8, ATYPE_RO, &acNameNOE[0], 0x04, NULL},
|
||||
{0x01, DTYPE_UNSIGNED8, 8, ATYPE_RO, &acName1C00_01[0], 0x01, NULL},
|
||||
{0x02, DTYPE_UNSIGNED8, 8, ATYPE_RO, &acName1C00_02[0], 0x02, NULL},
|
||||
{0x03, DTYPE_UNSIGNED8, 8, ATYPE_RO, &acName1C00_03[0], 0x03, NULL},
|
||||
{0x04, DTYPE_UNSIGNED8, 8, ATYPE_RO, &acName1C00_04[0], 0x04, NULL}
|
||||
};
|
||||
const _objd SDO1C10[] =
|
||||
{ {0x00, DTYPE_UNSIGNED8, 8, ATYPE_RO, &acName1C10[0], 0x00, NULL}
|
||||
};
|
||||
const _objd SDO1C11[] =
|
||||
{ {0x00, DTYPE_UNSIGNED8, 8, ATYPE_RO, &acName1C11[0], 0x00, NULL}
|
||||
};
|
||||
const _objd SDO1C12[] =
|
||||
{ {0x00, DTYPE_UNSIGNED8, 8, ATYPE_RO, &acNameNOE[0], 0x01, NULL},
|
||||
{0x01, DTYPE_UNSIGNED16, 16, ATYPE_RO, &acNameMO[0], 0x1600, NULL}
|
||||
};
|
||||
const _objd SDO1C13[] =
|
||||
{ {0x00, DTYPE_UNSIGNED8, 8, ATYPE_RO, &acNameNOE[0], 0x01, NULL},
|
||||
{0x01, DTYPE_UNSIGNED16, 16, ATYPE_RO, &acNameMO[0], 0x1A00, NULL}
|
||||
};
|
||||
const _objd SDO6000[] =
|
||||
{ {0x00, DTYPE_UNSIGNED8, 8, ATYPE_RO, &acNameNOE[0], 0x02, NULL},
|
||||
{0x01, DTYPE_UNSIGNED8, 8, ATYPE_RO, &acName6000_01[0], 0, &(Rb.button)},
|
||||
{0x02, DTYPE_UNSIGNED32, 32, ATYPE_RO, &acName6000_02[0], 0, &(Rb.encoder)}
|
||||
};
|
||||
const _objd SDO7000[] =
|
||||
{ {0x00, DTYPE_UNSIGNED8, 8, ATYPE_RO, &acNameNOE[0], 0x01, NULL},
|
||||
{0x01, DTYPE_UNSIGNED8, 8, ATYPE_RW, &acName7000_01[0], 0, &(Wb.LED)}
|
||||
};
|
||||
const _objd SDO7100[] =
|
||||
{ {0x00, DTYPE_UNSIGNED8, 8, ATYPE_RO, &acNameNOE[0], 0x02, NULL},
|
||||
{0x01, DTYPE_UNSIGNED32, 32, ATYPE_RW, &acName7100_01[0], 0, &(encoder_scale)},
|
||||
{0x02, DTYPE_UNSIGNED32, 32, ATYPE_RO, &acName7100_02[0], 0, &(encoder_scale_mirror)}
|
||||
};
|
||||
|
||||
const _objd SDO8001[] =
|
||||
{ {0x00, DTYPE_UNSIGNED8, 8, ATYPE_RO, &acNameNOE[0], 0x01, NULL},
|
||||
{0x01, DTYPE_UNSIGNED32, 32, ATYPE_RW, &acName8001_01[0], 0, &(Cb.reset_counter)},
|
||||
};
|
||||
|
||||
const _objectlist SDOobjects[] =
|
||||
{ {0x1000, OTYPE_VAR, 0, 0, &acName1000[0], &SDO1000[0]},
|
||||
{0x1008, OTYPE_VAR, 0, 0, &acName1008[0], &SDO1008[0]},
|
||||
{0x1009, OTYPE_VAR, 0, 0, &acName1009[0], &SDO1009[0]},
|
||||
{0x100A, OTYPE_VAR, 0, 0, &acName100A[0], &SDO100A[0]},
|
||||
{0x1018, OTYPE_RECORD, 4, 0, &acName1018[0], &SDO1018[0]},
|
||||
{0x1600, OTYPE_RECORD, 0x01, 0, &acName1600[0], &SDO1600[0]},
|
||||
{0x1A00, OTYPE_RECORD, 0x02, 0, &acName1A00[0], &SDO1A00[0]},
|
||||
{0x1C00, OTYPE_ARRAY, 4, 0, &acName1C00[0], &SDO1C00[0]},
|
||||
{0x1C10, OTYPE_ARRAY, 0, 0, &acName1C10[0], &SDO1C10[0]},
|
||||
{0x1C11, OTYPE_ARRAY, 0, 0, &acName1C11[0], &SDO1C11[0]},
|
||||
{0x1C12, OTYPE_ARRAY, 1, 0, &acName1C12[0], &SDO1C12[0]},
|
||||
{0x1C13, OTYPE_ARRAY, 1, 0, &acName1C13[0], &SDO1C13[0]},
|
||||
{0x6000, OTYPE_ARRAY, 0x02, 0, &acName6000[0], &SDO6000[0]},
|
||||
{0x7000, OTYPE_ARRAY, 0x01, 0, &acName7000[0], &SDO7000[0]},
|
||||
{0x7100, OTYPE_ARRAY, 0x02, 0, &acName7100[0], &SDO7100[0]},
|
||||
{0x8001, OTYPE_ARRAY, 0x01, 0, &acName8001[0], &SDO8001[0]},
|
||||
{0xffff, 0xff, 0xff, 0xff, NULL, NULL}
|
||||
};
|
Binary file not shown.
|
@ -0,0 +1,10 @@
|
|||
#ifndef _sii_eeprom_h_
|
||||
#define _sii_eeprom_h_
|
||||
|
||||
extern const uint8_t _binary_sii_eeprom_bin_start;
|
||||
extern const uint8_t _binary_sii_eeprom_bin_end;
|
||||
|
||||
#define SII_EE_DEFLT (&_binary_sii_eeprom_bin_start)
|
||||
#define SII_EE_DEFLT_SIZE (&_binary_sii_eeprom_bin_end - &_binary_sii_eeprom_bin_start)
|
||||
|
||||
#endif
|
|
@ -0,0 +1,296 @@
|
|||
/*
|
||||
* SOES Simple Open EtherCAT Slave
|
||||
*
|
||||
* Copyright (C) 2007-2013 Arthur Ketels
|
||||
*
|
||||
* SOES is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License version 2 as published by the Free
|
||||
* Software Foundation.
|
||||
*
|
||||
* SOES is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* As a special exception, if other files instantiate templates or use macros
|
||||
* or inline functions from this file, or you compile this file and link it
|
||||
* with other works to produce a work based on this file, this file does not
|
||||
* by itself cause the resulting work to be covered by the GNU General Public
|
||||
* License. However the source code for this file must still be made available
|
||||
* in accordance with section (3) of the GNU General Public License.
|
||||
*
|
||||
* This exception does not invalidate any other reasons why a work based on
|
||||
* this file might be covered by the GNU General Public License.
|
||||
*
|
||||
* The EtherCAT Technology, the trade name and logo "EtherCAT" are the intellectual
|
||||
* property of, and protected by Beckhoff Automation GmbH.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief
|
||||
* The application.
|
||||
*
|
||||
* The application, the main loop that service EtherCAT.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "esc.h"
|
||||
#include "esc_coe.h"
|
||||
#include "esc_eep.h"
|
||||
#include "esc_hw_eep.h"
|
||||
|
||||
#include "utypes.h"
|
||||
#include "soes.h"
|
||||
|
||||
#define WD_RESET 1000
|
||||
#define DEFAULTTXPDOMAP 0x1a00
|
||||
#define DEFAULTRXPDOMAP 0x1600
|
||||
#define DEFAULTTXPDOITEMS 1
|
||||
#define DEFAULTRXPDOITEMS 1
|
||||
|
||||
static const XMC_GPIO_CONFIG_t gpio_config_btn = {
|
||||
.mode = XMC_GPIO_MODE_INPUT_INVERTED_PULL_UP,
|
||||
.output_level = 0,
|
||||
.output_strength = 0
|
||||
};
|
||||
|
||||
static const XMC_GPIO_CONFIG_t gpio_config_led = {
|
||||
.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL,
|
||||
.output_level = XMC_GPIO_OUTPUT_LEVEL_LOW,
|
||||
.output_strength = XMC_GPIO_OUTPUT_STRENGTH_STRONG_SOFT_EDGE
|
||||
};
|
||||
|
||||
uint32_t encoder_scale;
|
||||
uint32_t encoder_scale_mirror;
|
||||
|
||||
volatile _ESCvar ESCvar;
|
||||
_MBX MBX[MBXBUFFERS];
|
||||
_MBXcontrol MBXcontrol[MBXBUFFERS];
|
||||
uint8_t MBXrun=0;
|
||||
uint16_t SM2_sml,SM3_sml;
|
||||
_Rbuffer Rb;
|
||||
_Wbuffer Wb;
|
||||
_Cbuffer Cb;
|
||||
_App App;
|
||||
uint16_t TXPDOsize,RXPDOsize;
|
||||
int wd_cnt = WD_RESET;
|
||||
volatile uint8_t digoutput;
|
||||
volatile uint8_t diginput;
|
||||
uint16_t txpdomap = DEFAULTTXPDOMAP;
|
||||
uint16_t rxpdomap = DEFAULTRXPDOMAP;
|
||||
uint8_t txpdoitems = DEFAULTTXPDOITEMS;
|
||||
uint8_t rxpdoitems = DEFAULTTXPDOITEMS;
|
||||
|
||||
/** Mandatory: Hook called from the slave stack SDO Download handler to act on
|
||||
* user specified Index and Sub-index.
|
||||
*
|
||||
* @param[in] index = index of SDO download request to handle
|
||||
* @param[in] sub-index = sub-index of SDO download request to handle
|
||||
*/
|
||||
void ESC_objecthandler (uint16_t index, uint8_t subindex)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0x1c12:
|
||||
{
|
||||
if (rxpdoitems > 1)
|
||||
{
|
||||
rxpdoitems = 1;
|
||||
}
|
||||
if ((rxpdomap != 0x1600) && (rxpdomap != 0x1601)
|
||||
&& (rxpdomap != 0x0000))
|
||||
{
|
||||
rxpdomap = 0x1600;
|
||||
}
|
||||
RXPDOsize = SM2_sml = sizeRXPDO ();
|
||||
break;
|
||||
}
|
||||
case 0x1c13:
|
||||
{
|
||||
if (txpdoitems > 1)
|
||||
{
|
||||
txpdoitems = 1;
|
||||
}
|
||||
if ((txpdomap != 0x1A00) && (txpdomap != 0x1A01)
|
||||
&& (rxpdomap != 0x0000))
|
||||
{
|
||||
txpdomap = 0x1A00;
|
||||
}
|
||||
TXPDOsize = SM3_sml = sizeTXPDO ();
|
||||
break;
|
||||
}
|
||||
case 0x7100:
|
||||
{
|
||||
switch (subindex)
|
||||
{
|
||||
case 0x01:
|
||||
{
|
||||
encoder_scale_mirror = encoder_scale;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 0x8001:
|
||||
{
|
||||
switch (subindex)
|
||||
{
|
||||
case 0x01:
|
||||
{
|
||||
Cb.reset_counter = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Mandatory: Hook called from the slave stack ESC_stopoutputs to act on state changes
|
||||
* forcing us to stop outputs. Here we can set them to a safe state.
|
||||
* set
|
||||
*/
|
||||
void APP_safeoutput (void)
|
||||
{
|
||||
DPRINT ("APP_safeoutput called\n");
|
||||
Wb.LED = 0;
|
||||
}
|
||||
/** Mandatory: Write local process data to Sync Manager 3, Master Inputs.
|
||||
*/
|
||||
void TXPDO_update (void)
|
||||
{
|
||||
ESC_write (SM3_sma, &Rb.button, TXPDOsize);
|
||||
}
|
||||
/** Mandatory: Read Sync Manager 2 to local process data, Master Outputs.
|
||||
*/
|
||||
void RXPDO_update (void)
|
||||
{
|
||||
ESC_read (SM2_sma, &Wb.LED, RXPDOsize);
|
||||
}
|
||||
|
||||
/** Mandatory: Function to update local I/O, call read ethercat outputs, call
|
||||
* write ethercat inputs. Implement watch-dog counter to count-out if we have
|
||||
* made state change affecting the App.state.
|
||||
*/
|
||||
void DIG_process (void)
|
||||
{
|
||||
if (wd_cnt)
|
||||
{
|
||||
wd_cnt--;
|
||||
}
|
||||
if (App.state & APPSTATE_OUTPUT)
|
||||
{
|
||||
/* SM2 trigger ? */
|
||||
if (ESCvar.ALevent & ESCREG_ALEVENT_SM2)
|
||||
{
|
||||
ESCvar.ALevent &= ~ESCREG_ALEVENT_SM2;
|
||||
RXPDO_update ();
|
||||
wd_cnt = WD_RESET;
|
||||
/* dummy output point */
|
||||
if (Wb.LED) {
|
||||
XMC_GPIO_SetOutputHigh(P_LED);
|
||||
} else {
|
||||
XMC_GPIO_SetOutputLow(P_LED);
|
||||
}
|
||||
}
|
||||
if (!wd_cnt)
|
||||
{
|
||||
DPRINT("DIG_process watchdog tripped\n");
|
||||
ESC_stopoutput ();
|
||||
/* watchdog, invalid outputs */
|
||||
ESC_ALerror (ALERR_WATCHDOG);
|
||||
/* goto safe-op with error bit set */
|
||||
ESC_ALstatus (ESCsafeop | ESCerror);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
wd_cnt = WD_RESET;
|
||||
}
|
||||
if (App.state)
|
||||
{
|
||||
Rb.button = XMC_GPIO_GetInput(P_BTN);
|
||||
Cb.reset_counter++;
|
||||
Rb.encoder = ESCvar.Time;
|
||||
TXPDO_update ();
|
||||
}
|
||||
}
|
||||
|
||||
/** SOES main loop. Start by initializing the stack software followed by
|
||||
* the application loop for cyclic read the EtherCAT state and staus, update
|
||||
* of I/O.
|
||||
*/
|
||||
void soes_init (void)
|
||||
{
|
||||
DPRINT ("SOES (Simple Open EtherCAT Slave)\n");
|
||||
|
||||
ESC_reset();
|
||||
|
||||
// configure I/O
|
||||
XMC_GPIO_Init(P_BTN, &gpio_config_btn);
|
||||
XMC_GPIO_Init(P_LED, &gpio_config_led);
|
||||
|
||||
TXPDOsize = SM3_sml = sizeTXPDO ();
|
||||
RXPDOsize = SM2_sml = sizeRXPDO ();
|
||||
|
||||
/* Setup post config hooks */
|
||||
static esc_cfg_t config =
|
||||
{
|
||||
.pre_state_change_hook = NULL,
|
||||
.post_state_change_hook = NULL
|
||||
};
|
||||
ESC_config ((esc_cfg_t *)&config);
|
||||
|
||||
ESC_init (NULL);
|
||||
|
||||
/* wait until ESC is started up */
|
||||
do {
|
||||
ESC_read (ESCREG_DLSTATUS, (void *) &ESCvar.DLstatus,
|
||||
sizeof (ESCvar.DLstatus));
|
||||
ESCvar.DLstatus = etohs (ESCvar.DLstatus);
|
||||
} while ((ESCvar.DLstatus & 0x0001) == 0);
|
||||
|
||||
/* reset ESC to init state */
|
||||
ESC_ALstatus (ESCinit);
|
||||
ESC_ALerror (ALERR_NONE);
|
||||
ESC_stopmbx ();
|
||||
ESC_stopinput ();
|
||||
ESC_stopoutput ();
|
||||
}
|
||||
|
||||
void soes_task (void)
|
||||
{
|
||||
/* On init restore PDO mappings to default size */
|
||||
if((ESCvar.ALstatus & 0x0f) == ESCinit)
|
||||
{
|
||||
txpdomap = DEFAULTTXPDOMAP;
|
||||
rxpdomap = DEFAULTRXPDOMAP;
|
||||
txpdoitems = DEFAULTTXPDOITEMS;
|
||||
rxpdoitems = DEFAULTTXPDOITEMS;
|
||||
}
|
||||
/* Read local time from ESC*/
|
||||
ESC_read (ESCREG_LOCALTIME, (void *) &ESCvar.Time, sizeof (ESCvar.Time));
|
||||
ESCvar.Time = etohl (ESCvar.Time);
|
||||
|
||||
/* Check the state machine */
|
||||
ESC_state ();
|
||||
|
||||
/* If else to two separate execution paths
|
||||
* If we're running BOOSTRAP
|
||||
* - MailBox
|
||||
* - FoE
|
||||
* Else we're running normal execution
|
||||
* - MailBox
|
||||
* - CoE
|
||||
*/
|
||||
if (ESC_mbxprocess ())
|
||||
{
|
||||
ESC_coeprocess ();
|
||||
ESC_xoeprocess ();
|
||||
}
|
||||
DIG_process ();
|
||||
EEP_process ();
|
||||
EEP_hw_process();
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
#ifndef _SOES_H_
|
||||
#define _SOES_H_
|
||||
|
||||
#include <xmc_gpio.h>
|
||||
#include <xmc_scu.h>
|
||||
|
||||
#define P_LED P4_1
|
||||
#define P_BTN P3_4
|
||||
|
||||
extern void soes_init (void);
|
||||
extern void soes_task (void);
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* SOES Simple Open EtherCAT Slave
|
||||
*
|
||||
* Copyright (C) 2007-2013 Arthur Ketels
|
||||
*
|
||||
* SOES is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License version 2 as published by the Free
|
||||
* Software Foundation.
|
||||
*
|
||||
* SOES is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* As a special exception, if other files instantiate templates or use macros
|
||||
* or inline functions from this file, or you compile this file and link it
|
||||
* with other works to produce a work based on this file, this file does not
|
||||
* by itself cause the resulting work to be covered by the GNU General Public
|
||||
* License. However the source code for this file must still be made available
|
||||
* in accordance with section (3) of the GNU General Public License.
|
||||
*
|
||||
* This exception does not invalidate any other reasons why a work based on
|
||||
* this file might be covered by the GNU General Public License.
|
||||
*
|
||||
* The EtherCAT Technology, the trade name and logo "EtherCAT" are the intellectual
|
||||
* property of, and protected by Beckhoff Automation GmbH.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief
|
||||
* Header file for Application types.
|
||||
*
|
||||
* Part of the application, host declarations of application types mapped against
|
||||
* ServiceData Objects and ProcessData Objects.
|
||||
*/
|
||||
|
||||
#ifndef __utypes_h__
|
||||
#define __utypes_h__
|
||||
|
||||
#include <cc.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t state;
|
||||
uint8_t button;
|
||||
uint32_t encoder;
|
||||
} _Rbuffer;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t LED;
|
||||
} _Wbuffer;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t reset_counter;
|
||||
} _Cbuffer;
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue