/** ESC and CPU related HW init * * @param[in] arg = esc_cfg provided by the application */ void ESC_init (const esc_cfg_t * config) { eep_config_t ecat_config; ESC_reset(); scu_configure_ethercat_signals(&port_control); /* read config from emulated EEPROM */ memset(&ecat_config, 0, sizeof(eep_config_t)); EEP_read (0, (uint8_t *) &ecat_config, sizeof(eep_config_t)); ESC_enable(); /* words 0x0-0x3 */ ecat0->EEP_DATA[0U] = ecat_config.dword[0U]; ecat0->EEP_DATA[1U] = ecat_config.dword[1U]; ecat0->EEP_CONT_STAT |= (uint16_t)(BIT(10)); /* ESI EEPROM Reload */ /* words 0x4-0x7 */ ecat0->EEP_DATA[0U] = ecat_config.dword[2U]; ecat0->EEP_DATA[1U] = ecat_config.dword[3U]; ecat0->EEP_CONT_STAT |= (uint16_t)(BIT(10)); /* ESI EEPROM Reload */ while (ecat0->EEP_CONT_STAT & BIT(12)) /* ESI EEPROM loading status */ { /* Wait until the EEPROM_Loaded signal is active */ } /* Configure CPU interrupts */ if(config->use_interrupt != 0) { // ecat_isr_sem = sem_create(0); // task_spawn ("soes_isr", isr_run, 9, 2048, NULL); use_all_interrupts = 0; ecat0->AL_EVENT_MASK = 0; ecat0->AL_EVENT_MASK = (ESCREG_ALEVENT_SMCHANGE | ESCREG_ALEVENT_EEP | ESCREG_ALEVENT_CONTROL | ESCREG_ALEVENT_SM0 | ESCREG_ALEVENT_SM1); int_connect (IRQ_ECAT0_SR0, ecat_isr, NULL); int_enable (IRQ_ECAT0_SR0); // /* Activate for running external sync IRQ */ // scu_put_peripheral_in_reset (SCU_PERIPHERAL_ERU1); // scu_ungate_clock_to_peripheral (SCU_PERIPHERAL_ERU1); // scu_release_peripheral_from_reset (SCU_PERIPHERAL_ERU1); // // eru_configure(&cfg); // /* Let the stack decide when to enable */ // int_disable(cfg.irq); } }
/** 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 (void *arg) { DPRINT ("SOES (Simple Open EtherCAT Slave)\n"); 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 = post_state_change_hook }; ESC_config ((esc_cfg_t *)&config); ESC_reset(); ESC_init (spi_name); task_delay (tick_from_ms (200)); /* wait until ESC is started up */ while ((ESCvar.DLstatus & 0x0001) == 0) { ESC_read (ESCREG_DLSTATUS, (void *) &ESCvar.DLstatus, sizeof (ESCvar.DLstatus)); ESCvar.DLstatus = etohs (ESCvar.DLstatus); } /* Pre FoE to set up Application information */ bootstrap_foe_init (); /* Init FoE */ FOE_init(); /* reset ESC to init state */ ESC_ALstatus (ESCinit); ESC_ALerror (ALERR_NONE); ESC_stopmbx (); ESC_stopinput (); ESC_stopoutput (); DPRINT ("Application_loop GO\n"); /* application run loop */ while (1) { /* 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(local_boot_state) { if (ESC_mbxprocess ()) { ESC_foeprocess (); ESC_xoeprocess (); } bootstrap_state (); } else { if (ESC_mbxprocess ()) { ESC_coeprocess (); ESC_xoeprocess (); } DIG_process (); } }; }