/** * Polling function. It should be called periodically for an application * when only SM2/DC interrupt is active. * Read and handle events for the EtherCAT state, status, mailbox and eeprom. */ void ecat_slv_poll (void) { /* 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(); /* Check the SM activation event */ ESC_sm_act_event(); /* Check mailboxes */ if (ESC_mbxprocess()) { ESC_coeprocess(); ESC_foeprocess(); ESC_xoeprocess(); } /* Call emulated eeprom handler if set */ if (ESCvar.esc_hw_eep_handler != NULL) { (ESCvar.esc_hw_eep_handler)(); } }
/** * Handler for SM change, SM0/1, AL CONTROL and EEPROM events, the application * control what interrupts that should be served and re-activated with * event mask argument */ void ecat_slv_worker (uint32_t event_mask) { do { /* Check the state machine */ ESC_state(); /* Check the SM activation event */ ESC_sm_act_event(); /* Check mailboxes */ while ((ESC_mbxprocess() > 0) || (ESCvar.txcue > 0)) { ESC_coeprocess(); ESC_foeprocess(); ESC_xoeprocess(); } /* Call emulated eeprom handler if set */ if (ESCvar.esc_hw_eep_handler != NULL) { (ESCvar.esc_hw_eep_handler)(); } CC_ATOMIC_SET(ESCvar.ALevent, ESC_ALeventread()); }while(ESCvar.ALevent & event_mask); ESC_ALeventmaskwrite(ESC_ALeventmaskread() | event_mask); }
/** 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 (); } }; }