void Mainloop (void) {//=======bescintenabled: Synchronous mode becatfirstoutputsreceived: Receive and send data completion bdcsyncactive: Distributed clock synchronization = = ============= Initial value faulse================= initial value faulse======================== initial value faulse=========///* When running on Freeru N-mode:bescintenabled = False, Bdcsyncactive = false//not enabled interrupt, free run mode when run on synchron-mode:bescintenabled = TRUE, Bdcsyncactive = false//synchronous mode Enable, synchronous mode uses interrupt processing for periodic data when running on dc-mode:bescintenabled = False, bdcsyncactive = TRUE * ////Distributed Clock Mode enable */if ((!bescintenabled | |! becatfirstoutputsreceived) &&!bdcsyncactive)/* Non-distributed clock synchronization mode, and non-interrupt synchronization mode or SM2, SM3 event not completed */{* * If the application is running in Ecat sync mode when , the function ecat_application will be called in the ESC interrupt (in MCIHW.C and SPIHW.C) in the Ecat synchronization mode, it can be checked separately, If the SM event is accepted at least once (becatfirstoutputreceived=1), then no interruption will be generated and the function ecat_application will be called here (interrupt prohibition, because when the ecat_application is executed, SM event can be generated) */if (!bescintenabled)/* Free run mode, interrupt not enabled, use own run mode to read data */ {/* application is running in ECAt Free run mode, first of all, we need to check if there is an output received */* because other application events can also be interrupted, so first determine */UINT16 alevent = Hw_getaleventregister (); /* Read the AL status to determine if there is output data, read low 8-bit high 8-bit */alevent = Swapword (alevent); /* will alevent high and low 8-position interchange position, so need to exchange high and low 8 bit */if (Alevent & process_output_event)/* To determine if ESC has data output 0x040 0 Detect SM2 event in 0x0221 address */{/* Set flag for state machine, output or input succeeded */Becatfirstoutput sreceived = TRUE; if (becatoutputupdaterunning)/* Detects whether it is in a running state, set in Startinputhangler */{ Pdo_outputmapping (); /* The value sent down by the receiving master is mainly LED light status */}} else if (npdoutputsize = = 0) /* If the output length is 0 and the input is read, the watchdog must reset */{if (Alevent & process_input_event) /* Determine if ESC has data output 0x0800 detect SM3 event in 0x0221 address */{ becatfirstoutputsreceived = TRUE; /* The output receives the success flag bit, the standby watchdog detects the reset using the */}}}/* Regardless of the free run mode or the synchronous operation mode, all do ecat_appli cation () */Disable_esc_int (); /* Turn off interrupt source int1*/ecat_application (); /* Apply peripheral control and perform SM3 event action when Becatinputupdatarunning=1 */Enable_esc_int (); /* Enable interrupt source int1*/}//The following because the error is blocked////* There is no interrupt service program to handle the hardware timer, so check the timer register to see if you want the cycle is over *///{//UINT Curtimer = Hw_gettimer (); /* Timer 7 Not configured interrupt, automatically call related program *///if (curtimer>= Ecat_timer_inc_p_ms)/* Configured period is 0x0271 625tick by detecting counter value after reaching expectation S/ms the *///{//Ecat_checktimer () is executed once per millisecond; /* Run status Light and error light condition settings, */////hw_cleartimer (); /* Timer 7 Register counter value clear 0 *///}//}/* Call the ETHERCAT function for non-cyclical data manipulation: State machine control and mailbox data operation */Ecat_main (); /* Call LowPriority Application Section *///Coe_main (); Checkifecaterror ();//check communication and synchronization, if an error occurs, update the AL status/al status code}
EtherCAT slave mainloop function