Skip to content

Commit

Permalink
modified sample to test pd
Browse files Browse the repository at this point in the history
  • Loading branch information
vChavezB committed May 17, 2024
1 parent afe9d4a commit 5913ea8
Show file tree
Hide file tree
Showing 9 changed files with 2,630 additions and 61 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

109 changes: 109 additions & 0 deletions samples/ifm_sample_app/build_0/zephyr/isr_tables.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@

/* AUTO-GENERATED by gen_isr_tables.py, do not edit! */

#include <zephyr/toolchain.h>
#include <zephyr/linker/sections.h>
#include <zephyr/sw_isr_table.h>
#include <zephyr/arch/cpu.h>

typedef void (* ISR)(const void *);
uintptr_t __irq_vector_table _irq_vector_table[48] = {
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
((uintptr_t)&_isr_wrapper),
};
struct _isr_table_entry __sw_isr_table _sw_isr_table[48] = {
{(const void *)0x6fe1, (ISR)0x1156d}, /* 0 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 1 */
{(const void *)0x134d0, (ISR)0x11383}, /* 2 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 3 */
{(const void *)0x7e3d, (ISR)0x1156d}, /* 4 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 5 */
{(const void *)0x781d, (ISR)0x1156d}, /* 6 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 7 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 8 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 9 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 10 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 11 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 12 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 13 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 14 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 15 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 16 */
{(const void *)0x0, (ISR)0x6879}, /* 17 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 18 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 19 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 20 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 21 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 22 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 23 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 24 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 25 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 26 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 27 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 28 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 29 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 30 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 31 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 32 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 33 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 34 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 35 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 36 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 37 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 38 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 39 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 40 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 41 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 42 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 43 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 44 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 45 */
{(const void *)0x0, (ISR)z_irq_spurious}, /* 46 */
{(const void *)0x8581, (ISR)0x1156d}, /* 47 */
};
518 changes: 518 additions & 0 deletions samples/ifm_sample_app/build_0/zephyr/misc/generated/configs.c

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions samples/ifm_sample_app/prj.conf
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
CONFIG_CPP=y
CONFIG_REQUIRES_FULL_LIBCPP=y
CONFIG_REQUIRES_FULL_LIBC=y

CONFIG_STD_CPP17=y
CONFIG_THREAD_NAME=y
CONFIG_LOG=y
CONFIG_IOLINK=y
CONFIG_IOLINK_LOG_LEVEL_DBG=y
CONFIG_ASSERT=y
CONFIG_POSIX_API=y
CONFIG_MINIMAL_LIBC=y
CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE=32768
CONFIG_LOG_BUFFER_SIZE=16384
72 changes: 37 additions & 35 deletions samples/ifm_sample_app/src/iol_master_sample_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
#include "iolink_handler.h"
#include <iolm/zephyr.h>

static const struct device *const spi_dev = DEVICE_DT_GET(DT_NODELABEL(spi1));
static const struct device *const irq_port = DEVICE_DT_GET(DT_NODELABEL(gpio0));
static const struct device *const spi_dev = DEVICE_DT_GET(DT_ALIAS(iolm_spi));
static const struct gpio_dt_spec irq_dev = GPIO_DT_SPEC_GET(DT_ALIAS(iolm_irq), gpios);

#define IOLINK_HANDLER_THREAD_STACK_SIZE (2048)
#define IOLINK_HANDLER_THREAD_PRIO 5
#define IOLINK_HANDLER_THREAD_STACK_SIZE (8192)
#define IOLINK_HANDLER_THREAD_PRIO 1
static K_THREAD_STACK_DEFINE(iolm_handler_stack, IOLINK_HANDLER_THREAD_STACK_SIZE);


Expand Down Expand Up @@ -65,7 +65,6 @@ static iolink_hw_drv_t * main_14819_init(const char* name, const iolink_14819_cf
LOG_ERR ("APP: Failed to open SPI %s\n", name);
return NULL;
}
return drv;
if (_iolink_setup_int_zephyr (gpio_port, irq_pin, iolink_14819_isr, drv) < 0)
{
LOG_ERR ("APP: Failed to setup interrupt %s\n", name);
Expand All @@ -74,50 +73,50 @@ static iolink_hw_drv_t * main_14819_init(const char* name, const iolink_14819_cf
return drv;
}

int main(void)
{
os_thread_t * iolink_handler_thread;
iolink_hw_drv_t * hw[2];
static iolink_m_cfg_t iolink_cfg = {
.cb_arg = NULL,
.cb_smi = NULL,
.cb_pd = NULL,
/* Not needed, statically set with Kconfig*/
.master_thread_prio = 0,
.master_thread_stack_size = 0,
.dl_thread_prio = 0,
.dl_thread_stack_size = 0,
};

LOG_INF("Starting app");
static const iolink_14819_cfg_t iol_14819_0_cfg = {
os_thread_t * iolink_handler_thread;
iolink_hw_drv_t * hw[2];
static const iolink_14819_cfg_t iol_14819_0_cfg = {
.chip_address = IOLINK_APP_CHIP0_ADDRESS,
.spi_slave_name = spi_dev,
.CQCfgA = MAX14819_CQCFG_DRVDIS | MAX14819_CQCFG_SINKSEL(0x2),
.LPCnfgA = MAX14819_LPCNFG_LPEN,
.IOStCfgA = MAX14819_IOSTCFG_DICSINK | MAX14819_IOSTCFG_DIEC3TH,
.DrvCurrLim = 0x00,
.Clock = MAX14819_CLOCK_XTALEN | MAX14819_CLOCK_TXTXENDIS,
};
};

#ifdef IOLINK_APP_CHIP1_SPI
static const iolink_14819_cfg_t iol_14819_1_cfg = {
static const iolink_14819_cfg_t iol_14819_1_cfg = {
.chip_address = IOLINK_APP_CHIP1_ADDRESS,
.spi_slave_name = IOLINK_APP_CHIP1_SPI,
.CQCfgA = MAX14819_CQCFG_DRVDIS | MAX14819_CQCFG_SINKSEL(0x2),
.LPCnfgA = MAX14819_LPCNFG_LPEN,
.IOStCfgA = MAX14819_IOSTCFG_DICSINK | MAX14819_IOSTCFG_DIEC3TH,
.DrvCurrLim = 0x00,
.Clock = MAX14819_CLOCK_XTALEN | MAX14819_CLOCK_TXTXENDIS,
};
#endif

hw[0] = main_14819_init("/iolink0", &iol_14819_0_cfg, irq_port, IOLINK_APP_CHIP0_IRQ);
#ifdef IOLINK_APP_CHIP1_SPI
hw[1] = main_14819_init("/iolink1", &iol_14819_1_cfg, irq_port, IOLINK_APP_CHIP1_IRQ);
};
#endif

iolink_port_cfg_t port_cfgs[] = {
iolink_port_cfg_t port_cfgs[] = {
{
.name = "/iolink0/0",
.mode = &mode_ch[0],
.drv = hw[0],
.arg = (void*)0,
},
{
.name = "/iolink0/1",
.mode = &mode_ch[1],
.drv = hw[0],
.arg = (void*)1,
},
#ifdef IOLINK_APP_CHIP1_SPI
Expand All @@ -136,22 +135,26 @@ int main(void)
#endif
};

iolink_m_cfg_t iolink_cfg = {
.cb_arg = NULL,
.cb_smi = NULL,
.cb_pd = NULL,
.port_cnt = NELEMENTS (port_cfgs),
.port_cfgs = port_cfgs,
/* Not needed, statically set with Kconfig*/
.master_thread_prio = 0,
.master_thread_stack_size = 0,
.dl_thread_prio = 0,
.dl_thread_stack_size = 0,
};
int main(void)
{


LOG_INF("Starting app");
hw[0] = main_14819_init("/iolink0", &iol_14819_0_cfg, irq_dev.port, irq_dev.pin);
#ifdef IOLINK_APP_CHIP1_SPI
hw[1] = main_14819_init("/iolink1", &iol_14819_1_cfg, irq_dev.port, irq_dev.pin);
#endif
port_cfgs[0].drv = hw[0];
port_cfgs[1].drv = hw[0];


iolink_cfg.port_cnt = NELEMENTS (port_cfgs);
iolink_cfg.port_cfgs = port_cfgs;
LOG_INF("Total port cfg %d",iolink_cfg.port_cnt);

k_sleep(K_MSEC(200));


iolink_handler_thread = os_thread_create (
"iolink_handler_thread",
IOLINK_HANDLER_THREAD_PRIO,
Expand All @@ -160,6 +163,5 @@ int main(void)
main_handler_thread,
(void*)&iolink_cfg);
CC_ASSERT (iolink_handler_thread != NULL);

return 0;
}
41 changes: 23 additions & 18 deletions samples/ifm_sample_app/src/iolink_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static uint8_t verify_smi_masterident (
{
arg_block_void_t arg_block_void;

bzero (&arg_block_void, sizeof (arg_block_void_t));
memset (&arg_block_void, 0, sizeof (arg_block_void_t));
arg_block_void.arg_block.id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK;
iolink_error_t err = SMI_MasterIdentification_req (
app_port->portnumber,
Expand Down Expand Up @@ -156,7 +156,7 @@ static uint8_t iolink_config_port_dido (iolink_app_port_ctx_t * app_port, bool d
{
arg_block_portconfiglist_t port_cfg;

bzero (&port_cfg, sizeof (arg_block_portconfiglist_t));
memset (&port_cfg, 0, sizeof (arg_block_portconfiglist_t));

iolink_common_config (
&port_cfg,
Expand Down Expand Up @@ -210,7 +210,7 @@ uint8_t get_port_status (iolink_app_port_ctx_t * app_port)
{
arg_block_void_t arg_block_void;

bzero (&arg_block_void, sizeof (arg_block_void_t));
memset (&arg_block_void, 0, sizeof (arg_block_void_t));
arg_block_void.arg_block.id = IOLINK_ARG_BLOCK_ID_VOID_BLOCK;

iolink_error_t err = SMI_PortStatus_req (
Expand Down Expand Up @@ -266,7 +266,7 @@ static uint8_t iolink_start_port (iolink_app_port_ctx_t * app_port)
return 1;
}

if (port_status->vendorid == IFM_VENDOR_ID)
//if (port_status->vendorid == IFM_VENDOR_ID)
{
switch (port_status->deviceid)
{
Expand All @@ -290,6 +290,7 @@ static uint8_t iolink_start_port (iolink_app_port_ctx_t * app_port)
break;
}
}
/*
else
{
app_port->type = UNKNOWN;
Expand All @@ -302,6 +303,7 @@ static uint8_t iolink_start_port (iolink_app_port_ctx_t * app_port)
port_status->vendorid,
(int)port_status->deviceid);
}
*/

LOG_INFO (LOG_STATE_ON, "%s: Port %u: Start done!\n", __func__, portnumber);
os_mutex_unlock (app_port->status_mtx);
Expand Down Expand Up @@ -348,14 +350,14 @@ void iolink_handler (iolink_m_cfg_t m_cfg)
os_timer_create (1000 * 1000, iolink_retry_estcom, (void *)i, true);
}
}

bzero (port_mode, sizeof (port_mode));
bzero (&iolink_app_master, sizeof (iolink_app_master));
memset (port_mode, 0, sizeof (port_mode));
memset (&iolink_app_master, 0, sizeof (iolink_app_master));
iolink_app_master.app_event = app_event;

m_cfg.cb_arg = &iolink_app_master;
m_cfg.cb_smi = SMI_cnf_cb;
m_cfg.cb_pd = PD_cb;

iolink_m_t * master = iolink_m_init (&m_cfg);

if (master == NULL)
Expand Down Expand Up @@ -398,9 +400,10 @@ void iolink_handler (iolink_m_cfg_t m_cfg)
while (true)
{
uint32_t event_value;
printk("loop\n");
if (!os_event_wait (iolink_app_master.app_event, 0xFFFFFFFF, &event_value, 1000))
{
if (event_value != 1)
LOG_INF("IOLink Handler Event %x", event_value);
os_event_clr (iolink_app_master.app_event, event_value);

for (i = 0; i < m_cfg.port_cnt; i++)
Expand Down Expand Up @@ -514,25 +517,26 @@ static void handle_smi_portevent (
uint8_t portnumber = app_port->portnumber;
iolink_app_master_ctx_t * app_master = app_port->app_master;
uint8_t port_index = portnumber - 1;

LOG_INF("SMI event");
LOG_INF("Port event %d : %x",event->event_qualifier,event->event_code);
if (
((app_port->type == GOLDEN) || (app_port->type == UNKNOWN)) &&
event->event_code != IOLINK_EVENTCODE_NO_DEV)
{
uint8_t event_index;

os_mutex_lock (app_port->event_mtx);
event_index = app_port->events.count++;
CC_ASSERT (event_index < PORT_EVENT_COUNT);
app_port->events.diag_entry[event_index].event_qualifier =
event->event_qualifier;
app_port->events.diag_entry[event_index].event_code = event->event_code;
os_mutex_unlock (app_port->event_mtx);
//os_mutex_lock (app_port->event_mtx);
// event_index = app_port->events.count++;
//CC_ASSERT (event_index < PORT_EVENT_COUNT);
//app_port->events.diag_entry[event_index].event_qualifier =
// event->event_qualifier;
//app_port->events.diag_entry[event_index].event_code = event->event_code;
//os_mutex_unlock (app_port->event_mtx);
}

if (event->event_code != IOLINK_EVENTCODE_NO_DEV)
{
LOG_DEBUG (
LOG_INFO (
LOG_STATE_ON,
"%s (%d): type = %d, event_code = 0x%04X, count = %d\n",
__func__,
Expand All @@ -545,6 +549,7 @@ static void handle_smi_portevent (
switch (event->event_code)
{
case IOLINK_EVENTCODE_PORT_STATUS_CHANGE:
LOG_INF("Port status changed");
/* Port status changed - Use SMI_PortStatus() for details */
os_event_set (app_master->app_event, (EVENT_PORTE_0 << port_index));
break;
Expand Down
Loading

0 comments on commit 5913ea8

Please sign in to comment.