Commit 5c001ee5 authored by Jeroen Vreeken's avatar Jeroen Vreeken

Add logging for AL state and status

parent 75e4f331
/*
Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2019
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <string.h>
#include <controller/controller_block.h>
#include <ec/ec.h>
#include <ec/esc.h>
#include <ec/esc_esi.h>
#include <ec/esc_id.h>
#include <log/log.h>
struct controller_block_private {
unsigned char *rx_buffer;
struct esc_device *dev;
};
static void callback_rx(struct controller_block *block, void *data)
{
block->private->rx_buffer = data;
}
struct trinamic_type {
char *name;
uint32_t productcode;
};
static struct trinamic_type devlist[] = {
{ "TMC8460EVAL", ESC_ESI_PRODUCTCODE_TRINAMIC_TMC8460_EVAL },
};
static struct controller_block * block_trinamic_tmc8460eval_create(char *name, int argc, va_list ap)
{
struct controller_block *block;
int i;
int dev = -1;
char *type;
char *busname;
int devno;
struct esc_device *esc;
uint32_t vendor, product;
busname = va_arg(ap, char *);
devno = va_arg(ap, int);
type = va_arg(ap, char *);
for (i = 0; i < sizeof(devlist)/sizeof(struct trinamic_type); i++) {
if (!strcmp(type, devlist[i].name)) {
dev = i;
break;
}
}
if (dev < 0) {
log_send(LOG_T_ERROR, "Unsupported device: '%s'", type);
goto err_ethercat;
}
esc = esc_device_create(busname, devno, name);
vendor = esc_esi_vendorid_get(esc);
product = esc_esi_productcode_get(esc);
if (vendor != ESC_ESI_VENDORID_TRINAMIC ||
product != devlist[dev].productcode) {
log_send(LOG_T_ERROR, "%s: Device not found\n", name);
goto err_ethercat;
}
block = controller_block_alloc("trinamic_tmc8460eval", name,
sizeof(struct controller_block_private));
block->private->dev = esc;
esc->block = block;
esc->block_rx = block;
esc_esi_device_fill(esc);
esc->callback_rx = callback_rx;
esc_device_initialize_operational(esc);
if (controller_block_add(block))
goto err_add;
return block;
err_add:
controller_block_free(block);
err_ethercat:
return NULL;
}
BLOCK_CREATE(trinamic_tmc8460eval) = {
.create = block_trinamic_tmc8460eval_create,
.args = { "char*,int,char*", NULL },
};
......@@ -26,7 +26,8 @@ EC_BLOCKS = \
beckhoff_el5001 \
beckhoff_el5101 \
beckhoff_el7031 \
stoeber
stoeber \
trinamic_tmc8460eval \
EC_SRCS += $(addsuffix .c,$(addprefix $(DIR)/block_,$(EC_BLOCKS)))
......
......@@ -146,6 +146,14 @@ void describe_esc(struct ec *ec, struct ec_dgram_addr *ec_addr)
if (r == 1) {
printf("\tSync/Latch PDI config: 0x%02x\n", val8);
}
ec_addr->addr.position.off = ESC_ADDR_MAP_ESC_CONFIGURATION;
r = ec_datagram_read(ec, ec_addr, &val8, 1);
if (r == 1) {
printf("\tESC config: 0x%02x\n", val8);
}
}
if (option_portcheck || option_verbose) {
......@@ -164,10 +172,13 @@ void describe_esc(struct ec *ec, struct ec_dgram_addr *ec_addr)
link_port3 = dl_status & ESC_DL_STATUS_LINK_PORT3;
if (option_verbose) printf("\tDL Status: 0x%04x\n", dl_status);
printf("\tport0: %s\n", link_port0 ? "Link detected" : "No link");
printf("\tport1: %s\n", link_port1 ? "Link detected" : "No link");
printf("\tport2: %s\n", link_port2 ? "Link detected" : "No link");
printf("\tport3: %s\n", link_port3 ? "Link detected" : "No link");
if (option_verbose) printf("\t\tEEPROM: %s\n", dl_status & ESC_DL_STATUS_EEPROM_LOADED ? "Loaded" : "Not loaded");
if (option_verbose) printf("\t\tWatchdog: %s\n", dl_status & ESC_DL_STATUS_WATCHDOG_RELOADED ? "Reloaded" : "Expired");
if (option_verbose) printf("\t\tEnhanced link detection: %s\n", dl_status & ESC_DL_STATUS_ENHANCED_LINK_DETECT ? "Activated" : "Deactivated");
printf("\t\tport0: %s\n", link_port0 ? "Link detected" : "No link");
printf("\t\tport1: %s\n", link_port1 ? "Link detected" : "No link");
printf("\t\tport2: %s\n", link_port2 ? "Link detected" : "No link");
printf("\t\tport3: %s\n", link_port3 ? "Link detected" : "No link");
if (option_portcheck) {
uint32_t t0;
......@@ -228,6 +239,13 @@ void describe_esc(struct ec *ec, struct ec_dgram_addr *ec_addr)
}
}
if (option_verbose) {
enum esc_al_state state = esc_al_state_get(dev);
enum esc_al_status status = esc_al_status_code_get(dev);
printf("\tAL state: %s\n", esc_al_state2str(state));
printf("\tAL status: %s\n", esc_al_status2str(status));
}
vendorid = esc_esi_vendorid_get(dev);
productcode = esc_esi_productcode_get(dev);
......
......@@ -131,8 +131,13 @@ int esc_al_state_set(struct esc_device *esc, enum esc_al_state newstate,
rd_state, esc_al_state2str(rd_state));
/* timeout... */
return rd_state;
} else
} else {
log_send(LOG_T_ERROR,
"%s: Writing to AL_CONTROL register failed: %d", esc->name, ret);
log_send(LOG_T_DEBUG,
"%s: Current state: %s", esc->name, esc_al_state2str(esc_al_state_get(esc)));
return -1;
}
}
enum esc_al_status esc_al_status_code_get(struct esc_device *esc)
......@@ -197,8 +202,9 @@ int esc_init(struct esc_device *esc)
memcpy(&addr, &esc->addr, sizeof(struct ec_dgram_addr));
if (esc_al_state_set(esc, ESC_AL_STATE_INIT, &timeout) < 0)
log_send(LOG_T_ERROR, "Could not go to state init");
if (esc_al_state_set(esc, ESC_AL_STATE_INIT, &timeout) < 0) {
log_send(LOG_T_ERROR, "Could not go to state init. AL status: %s", esc_al_status2str(esc_al_status_code_get(esc)));
}
addr.addr.position.off = ESC_ADDR_MAP_SYNCMANAGERS_SUPPORTED;
ret = ec_datagram_read(esc->ec, &addr, &nr_syncmgr, 1);
......
......@@ -258,8 +258,7 @@ int esc_device_initialize_pre_operational(struct esc_device *dev)
struct timespec timeout = { 1, 0 };
if (esc_al_state_set(dev, ESC_AL_STATE_INIT, &timeout) < 0)
log_send(LOG_T_ERROR, "%s: Could not go to state init",
dev->name);
log_send(LOG_T_ERROR, "%s: Could not go to state init. AL status: %s", dev->name, esc_al_status2str(esc_al_status_code_get(dev)));
if (dev->tx_pdo) {
dev->sm[dev->tx_pdo_sm].ctrl =
......@@ -313,8 +312,7 @@ int esc_device_initialize_pre_operational(struct esc_device *dev)
}
if (esc_al_state_set(dev, ESC_AL_STATE_PRE_OPERATIONAL, &timeout)< 0) {
log_send(LOG_T_ERROR,
"%s: Could not go to state pre operational", dev->name);
log_send(LOG_T_ERROR, "%s: Could not go to state pre operational. AL status: %s", dev->name, esc_al_status2str(esc_al_status_code_get(dev)));
r = -1;
}
......@@ -343,16 +341,14 @@ int esc_device_initialize_operational(struct esc_device *dev)
r = esc_al_state_set(dev, ESC_AL_STATE_SAFE_OPERATIONAL, &timeout);
if (r < 0) {
log_send(LOG_T_ERROR,
"%s: Could not go to state safe operational", dev->name);
log_send(LOG_T_ERROR, "%s: Could not go to state safe operational. AL status: %s", dev->name, esc_al_status2str(esc_al_status_code_get(dev)));
goto err;
}
dev->state = ESC_AL_STATE_SAFE_OPERATIONAL;
r = esc_al_state_set(dev, ESC_AL_STATE_OPERATIONAL, &timeout);
if (r < 0) {
log_send(LOG_T_ERROR,
"%s: Could not go to state operational", dev->name);
log_send(LOG_T_ERROR, "%s: Could not go to state operational. AL status: %s", dev->name, esc_al_status2str(esc_al_status_code_get(dev)));
goto err;
}
dev->state = ESC_AL_STATE_OPERATIONAL;
......
......@@ -42,6 +42,9 @@
#define ESC_FEATURE_SEPERATE_FCS_HANDLING 0x0080
#define ESC_FEATURE_ENHANCED_DC_SYNC_ACTIVATION 0x0100
#define ESC_ADDR_MAP_DL_STATUS 0x0110
#define ESC_DL_STATUS_EEPROM_LOADED 0x0001
#define ESC_DL_STATUS_WATCHDOG_RELOADED 0x0002
#define ESC_DL_STATUS_ENHANCED_LINK_DETECT 0x0004
#define ESC_DL_STATUS_LINK_PORT0 0x0010
#define ESC_DL_STATUS_LINK_PORT1 0x0020
#define ESC_DL_STATUS_LINK_PORT2 0x0040
......@@ -51,6 +54,7 @@
#define ESC_ADDR_MAP_AL_STATUS 0x0130
#define ESC_ADDR_MAP_AL_STATUS_ERR_IND 0x0010
#define ESC_ADDR_MAP_AL_STATUS_CODE 0x0134
#define ESC_ADDR_MAP_ESC_CONFIGURATION 0x0141
#define ESC_ADDR_MAP_SYNC_LATCH_PDI_CONFIG 0x0151
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment