void CALLBACK TimerProc(void* lpParametar,
	BOOLEAN TimerOrWaitFired)
{

	CO_timer1ms++;

	if (CO->CANmodule[0]->CANnormal) {
		bool_t syncWas;
		int i;

		/* Process Sync and read inputs */
		syncWas = CO_process_SYNC_RPDO(CO, 1000);

		/* Re-enable CANrx, if it was disabled by SYNC callback */
		CO_CAN_ISR_ENABLE = 1;
#if CO_NO_CAN_MODULES >= 2
		CO_CAN_ISR2_ENABLE = 1;
#endif

		/* Further I/O or nonblocking application code may go here. */
#if CO_NO_TRACE > 0
		OD_time.epochTimeOffsetMs++;
		for (i = 0; i<OD_traceEnable && i<CO_NO_TRACE; i++) {
			CO_trace_process(CO->trace[i], OD_time.epochTimeOffsetMs);
		}
#endif
		program1ms();

		/* Write outputs */
		CO_process_TPDO(CO, syncWas, 1000);

	}

	LARGE_INTEGER Frequency;
	LARGE_INTEGER StartingTime;
	LARGE_INTEGER ElapsedMicroseconds;

	QueryPerformanceFrequency(&Frequency);
	QueryPerformanceCounter(&StartingTime);
	ElapsedMicroseconds.QuadPart = StartingTime.QuadPart - li_timer.QuadPart;
	ElapsedMicroseconds.QuadPart *= 1000000;
	ElapsedMicroseconds.QuadPart /= Frequency.QuadPart;

	double t = ElapsedMicroseconds.QuadPart / 1000.0;
	t = 1000.0 / t;

	OD_performance[ODA_performance_timerCycleTime] = t;

	if (t > OD_performance[ODA_performance_timerCycleMaxTime])
			OD_performance[ODA_performance_timerCycleMaxTime] = t;
	
	li_timer = StartingTime;

		
}
Example #2
0
/* Realtime thread for CAN receive and taskTmr ********************************/
static void* rt_thread(void* arg) {

    /* Endless loop */
    while(CO_endProgram == 0) {
        int ready;
        struct epoll_event ev;

        ready = epoll_wait(rt_thread_epoll_fd, &ev, 1, -1);

        if(ready != 1) {
            if(errno != EINTR) {
                CO_error(0x12100000L + errno);
            }
        }

        else if(CANrx_taskTmr_process(ev.data.fd)) {
            int i;

            /* code was processed in the above function. Additional code process below */
            INCREMENT_1MS(CO_timer1ms);

            /* Monitor variables with trace objects */
            CO_time_process(&CO_time);
#if CO_NO_TRACE > 0
            for(i=0; i<OD_traceEnable && i<CO_NO_TRACE; i++) {
                CO_trace_process(CO->trace[i], *CO_time.epochTimeOffsetMs);
            }
#endif

            /* Execute optional additional application code */
            app_program1ms();

            /* Detect timer large overflow */
            if(OD_performance[ODA_performance_timerCycleMaxTime] > TMR_TASK_OVERFLOW_US && rtPriority > 0 && CO->CANmodule[0]->CANnormal) {
                CO_errorReport(CO->em, CO_EM_ISR_TIMER_OVERFLOW, CO_EMC_SOFTWARE_INTERNAL, 0x22400000L | OD_performance[ODA_performance_timerCycleMaxTime]);
            }
        }

        else {
            /* No file descriptor was processed. */
            CO_error(0x12200000L);
        }
    }

    return NULL;
}