/** Mandatory: Function to update local I/O, call read ethercat outputs, call * write ethercat inputs. Implement watch-dog counter to count-out if we have * made state change affecting the App.state. */ void DIG_process (void) { if (wd_cnt) { wd_cnt--; } if (App.state & APPSTATE_OUTPUT) { /* SM2 trigger ? */ if (ESCvar.ALevent & ESCREG_ALEVENT_SM2) { ESCvar.ALevent &= ~ESCREG_ALEVENT_SM2; RXPDO_update (); wd_cnt = WD_RESET; /* dummy output point */ //gpio_set(GPIO_LED, Wb.LED & BIT(0)); } if (!wd_cnt) { DPRINT("DIG_process watchdog tripped\n"); ESC_stopoutput (); /* watchdog, invalid outputs */ ESC_ALerror (ALERR_WATCHDOG); /* goto safe-op with error bit set */ ESC_ALstatus (ESCsafeop | ESCerror); } } else { wd_cnt = WD_RESET; } if (App.state) { //Rb.button = gpio_get(GPIO_WAKEUP); Rb.button = (flash_drv_get_active_swap() && 0x8); Cb.reset_counter++; Rb.encoder = Cb.reset_counter; TXPDO_update (); } }
/** Mandatory: Function to update local I/O, call read ethercat outputs, call * write ethercat inputs. Implement watch-dog counter to count-out if we have * made state change affecting the App.state. */ void DIG_process (uint8_t flags) { /* Handle watchdog */ if((flags & DIG_PROCESS_WD_FLAG) > 0) { if (CC_ATOMIC_GET(watchdog) > 0) { CC_ATOMIC_SUB(watchdog, 1); } if ((CC_ATOMIC_GET(watchdog) <= 0) && ((CC_ATOMIC_GET(ESCvar.App.state) & APPSTATE_OUTPUT) > 0)) { DPRINT("DIG_process watchdog expired\n"); ESC_stopoutput(); /* watchdog, invalid outputs */ ESC_ALerror (ALERR_WATCHDOG); /* goto safe-op with error bit set */ ESC_ALstatus (ESCsafeop | ESCerror); } else if(((CC_ATOMIC_GET(ESCvar.App.state) & APPSTATE_OUTPUT) == 0)) { CC_ATOMIC_SET(watchdog, ESCvar.watchdogcnt); } } /* Handle Outputs */ if ((flags & DIG_PROCESS_OUTPUTS_FLAG) > 0) { if(((CC_ATOMIC_GET(ESCvar.App.state) & APPSTATE_OUTPUT) > 0) && (ESCvar.ALevent & ESCREG_ALEVENT_SM2)) { RXPDO_update(); CC_ATOMIC_SET(watchdog, ESCvar.watchdogcnt); if(ESCvar.dcsync > 0) { CC_ATOMIC_ADD(ESCvar.synccounter, 1); } /* Set outputs */ cb_set_LEDgroup0(); cb_set_LEDgroup1(); } else if (ESCvar.ALevent & ESCREG_ALEVENT_SM2) { RXPDO_update(); } } /* Call application */ if ((flags & DIG_PROCESS_APP_HOOK_FLAG) > 0) { if((CC_ATOMIC_GET(ESCvar.App.state) & APPSTATE_OUTPUT) > 0) { CC_ATOMIC_SUB(ESCvar.synccounter, 1); } if((ESCvar.dcsync > 0) && ((CC_ATOMIC_GET(ESCvar.synccounter) < -ESCvar.synccounterlimit) || (CC_ATOMIC_GET(ESCvar.synccounter) > ESCvar.synccounterlimit))) { if((CC_ATOMIC_GET(ESCvar.App.state) & APPSTATE_OUTPUT) > 0) { DPRINT("sync error = %d\n", ESCvar.synccounter); ESC_stopoutput(); /* Sync error */ ESC_ALerror (ALERR_SYNCERROR); /* goto safe-op with error bit set */ ESC_ALstatus (ESCsafeop | ESCerror); CC_ATOMIC_SET(ESCvar.synccounter, 0); } } /* Call application callback if set */ if (ESCvar.application_hook != NULL) { (ESCvar.application_hook)(); } } /* Handle Inputs */ if ((flags & DIG_PROCESS_INPUTS_FLAG) > 0) { if(CC_ATOMIC_GET(ESCvar.App.state) > 0) { /* Update inputs */ cb_get_Buttons(); TXPDO_update(); } } }