Skip to content

Commit

Permalink
Merge pull request #32 from nakarlsson/master
Browse files Browse the repository at this point in the history
Add sync support and extend esc_config for generic stack
  • Loading branch information
hefloryd authored Oct 30, 2017
2 parents c83c95a + 62772dd commit 4dfb81e
Show file tree
Hide file tree
Showing 43 changed files with 4,845 additions and 1,153 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ cmake_minimum_required (VERSION 2.8.4)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
project (SOES)

set (SOES_VERSION_MAJOR 1)
set (SOES_VERSION_MINOR 1)
set (SOES_VERSION_MAJOR 2)
set (SOES_VERSION_MINOR 0)
set (SOES_VERSION_PATCH 0)

# Generate version numbers
Expand Down
5 changes: 3 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
SOES Simple Open EtherCAT Slave
Copyright (C) 2007-2014 Arthur Ketels
Copyright (C) 2012-2014 rt-labs

Copyright (C) 2007-2017 Arthur Ketels
Copyright (C) 2012-2017 rt-labs

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.
Expand Down
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SOES is an EtherCAT slave stack written in c. Its purpose is to learn and
to use. All users are invited to study the source to get an understanding
how an EtherCAT slave functions.

Features as of 1.1.0:
Features as of 2.0.0:
- Address offset based HAL for easy ESC read/write access via any
interface
- Mailbox with data link layer
Expand All @@ -22,5 +22,12 @@ Features as of 1.1.0:
- Easy portable C-code suited for embedded applications
- Fixed PDO mapping
- FoE with bootstrap template
- Support for Little and Big endian targets.
- Polling for interrupts
- Support for Little and Big endian targets
- Run polling, mixed polling/interrupt or interrupt
- Support for SM Synchronization
- Support DC sync0 and DC Synchronization
- Add stack configuration via new configuration paramater to/or from
"stack"_init

TODO
- Update documentation
115 changes: 75 additions & 40 deletions applications/linux_lan9252demo/slave.c
Original file line number Diff line number Diff line change
@@ -1,38 +1,57 @@
#include <stddef.h>
#include "utypes.h"
#include "soes/esc.h"
#include "soes/esc_coe.h"
#include "soes/esc_foe.h"
#include "esc.h"
#include "esc_coe.h"
#include "esc_foe.h"
#include "config.h"
#include "slave.h"

#ifndef EEP_EMULATION
#define EEP_EMULATION 0 /* Set to 1 for EEPROM emulation */
#endif

#define WATCHDOG_RESET_VALUE 150
#define DEFAULTTXPDOMAP 0x1a00
#define DEFAULTRXPDOMAP 0x1600
#define DEFAULTTXPDOITEMS 1
#define DEFAULTRXPDOITEMS 1

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;
/* Global variables used by the stack */
uint8_t MBX[MBXBUFFERS * MAX(MBXSIZE,MBXSIZEBOOT)];
_MBXcontrol MBXcontrol[MBXBUFFERS];
_ESCvar ESCvar;

/* Application variables */
_Rbuffer Rb;
_Wbuffer Wb;
_Cbuffer Cb;

/* Private variables */
uint16_t txpdomap = DEFAULTTXPDOMAP;
uint16_t rxpdomap = DEFAULTRXPDOMAP;
uint8_t txpdoitems = DEFAULTTXPDOITEMS;
uint8_t rxpdoitems = DEFAULTTXPDOITEMS;

static unsigned int watchdog = WATCHDOG_RESET_VALUE;
static int watchdog = WATCHDOG_RESET_VALUE;
static void (*application_loop_callback)(void) = NULL;

/** Function to pre-qualify the incoming SDO download.
*
* @param[in] index = index of SDO download request to check
* @param[in] sub-index = sub-index of SDO download request to check
* @return 1 if the SDO Download is correct. 0 If not correct.
*/
int ESC_pre_objecthandler (uint16_t index, uint8_t subindex)
{
if ((index == 0x1c12) && (subindex > 0) && (rxpdoitems != 0))
{
SDO_abort (index, subindex, ABORT_READONLY);
return 0;
}
if ((index == 0x1c13) && (subindex > 0) && (txpdoitems != 0))
{
SDO_abort (index, subindex, ABORT_READONLY);
return 0;
}
return 1;
}

/** Mandatory: Hook called from the slave stack SDO Download handler to act on
* user specified Index and Sub-index.
*
Expand All @@ -54,7 +73,7 @@ void ESC_objecthandler (uint16_t index, uint8_t subindex)
{
rxpdomap = 0x1600;
}
RXPDOsize = SM2_sml = sizeRXPDO();
ESCvar.RXPDOsize = ESCvar.ESC_SM2_sml = sizeOfPDO(RX_PDO_OBJIDX);
break;
}
case 0x1c13:
Expand All @@ -68,7 +87,7 @@ void ESC_objecthandler (uint16_t index, uint8_t subindex)
{
txpdomap = 0x1A00;
}
TXPDOsize = SM3_sml = sizeTXPDO();
ESCvar.TXPDOsize = ESCvar.ESC_SM3_sml = sizeOfPDO(TX_PDO_OBJIDX);
break;
}
/* Handle post-write of parameter values */
Expand Down Expand Up @@ -100,13 +119,13 @@ void APP_safeoutput (void)
*/
void TXPDO_update (void)
{
ESC_write (SM3_sma, &Rb, TXPDOsize);
ESC_write (SM3_sma, &Rb, ESCvar.TXPDOsize);
}
/** Mandatory: Read Sync Manager 2 to local process data, Master Outputs.
*/
void RXPDO_update (void)
{
ESC_read (SM2_sma, &Wb, RXPDOsize);
ESC_read (SM2_sma, &Wb, ESCvar.RXPDOsize);
}

/** Mandatory: Function to update local I/O, call read ethercat outputs, call
Expand All @@ -119,7 +138,7 @@ void DIG_process (void)
{
watchdog--;
}
if (App.state & APPSTATE_OUTPUT)
if (ESCvar.App.state & APPSTATE_OUTPUT)
{
/* SM2 trigger ? */
if (ESCvar.ALevent & ESCREG_ALEVENT_SM2)
Expand All @@ -131,7 +150,7 @@ void DIG_process (void)
/* Set outputs */
cb_set_LEDs();
}
if (watchdog == 0)
if (watchdog <= 0)
{
DPRINT("DIG_process watchdog expired\n");
ESC_stopoutput();
Expand All @@ -145,7 +164,7 @@ void DIG_process (void)
{
watchdog = WATCHDOG_RESET_VALUE;
}
if (App.state)
if (ESCvar.App.state)
{
/* Update inputs */
cb_get_Buttons();
Expand All @@ -155,8 +174,6 @@ void DIG_process (void)

/********** TODO: Generic code beyond this point ***************/

static const char *spi_name = "/dev/lan9252";

/** Optional: Hook called after state change for application specific
* actions for specific state changes.
*/
Expand Down Expand Up @@ -204,6 +221,8 @@ void soes (void)

/* Check the state machine */
ESC_state();
/* Check the SM activation event */
ESC_sm_act_event();

/* Check mailboxes */
if (ESC_mbxprocess())
Expand All @@ -213,10 +232,6 @@ void soes (void)
ESC_xoeprocess();
}
DIG_process();
#if EEP_EMULATION
EEP_process ();
EEP_hw_process();
#endif /* EEP_EMULATION */

if (application_loop_callback != NULL)
{
Expand All @@ -231,19 +246,39 @@ void soes_init (void)
{
DPRINT ("SOES (Simple Open EtherCAT Slave)\n");

TXPDOsize = SM3_sml = sizeTXPDO();
RXPDOsize = SM2_sml = sizeRXPDO();
ESCvar.TXPDOsize = ESCvar.ESC_SM3_sml = sizeOfPDO(TX_PDO_OBJIDX);
ESCvar.RXPDOsize = ESCvar.ESC_SM2_sml = sizeOfPDO(RX_PDO_OBJIDX);

/* Setup post config hooks */
/* Setup config hooks */
static esc_cfg_t config =
{
.pre_state_change_hook = NULL,
.post_state_change_hook = post_state_change_hook
.user_arg = "/dev/lan9252",
.use_interrupt = 0,
.watchdog_cnt = 0,
.mbxsize = MBXSIZE,
.mbxsizeboot = MBXSIZEBOOT,
.mbxbuffers = MBXBUFFERS,
.mb[0] = {MBX0_sma, MBX0_sml, MBX0_sme, MBX0_smc, 0},
.mb[1] = {MBX1_sma, MBX1_sml, MBX1_sme, MBX1_smc, 0},
.mb_boot[0] = {MBX0_sma_b, MBX0_sml_b, MBX0_sme_b, MBX0_smc_b, 0},
.mb_boot[1] = {MBX1_sma_b, MBX1_sml_b, MBX1_sme_b, MBX1_smc_b, 0},
.pdosm[0] = {SM2_sma, 0, 0, SM2_smc, SM2_act},
.pdosm[1] = {SM3_sma, 0, 0, SM3_smc, SM3_act},
.pre_state_change_hook = NULL,
.post_state_change_hook = NULL,
.application_hook = NULL,
.safeoutput_override = NULL,
.pre_object_download_hook = NULL,
.post_object_download_hook = NULL,
.rxpdo_override = NULL,
.txpdo_override = NULL,
.esc_hw_interrupt_enable = NULL,
.esc_hw_interrupt_disable = NULL,
.esc_hw_eep_handler = NULL
};
ESC_config ((esc_cfg_t *)&config);

ESC_reset();
ESC_init ((void *)spi_name);

ESC_config (&config);
ESC_init (&config);

/* wait until ESC is started up */
while ((ESCvar.DLstatus & 0x0001) == 0)
Expand Down
Loading

0 comments on commit 4dfb81e

Please sign in to comment.