Ejemplo n.º 1
0
void __ISR(_TIMER_2_VECTOR, IPL3SOFT) CO_TimerInterruptHandler(void){
    bool_t syncWas;

    CO_TMR_ISR_FLAG = 0;

    CO_timer1ms++;

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

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

        /* Re-enable CANrx, if it was disabled by SYNC callback */
        // TODO this and outer loop

        /* Further I/O or nonblocking application code may go here. */
        program1ms();

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

    /* verify timer overflow */
    if(CO_TMR_ISR_FLAG == 1){
        CO_errorReport(CO->em, CO_EM_ISR_TIMER_OVERFLOW, CO_EMC_SOFTWARE_INTERNAL, 0);
        CO_TMR_ISR_FLAG = 0;
    }

    /* calculate cycle time for performance measurement */
    uint16_t t = CO_TMR_TMR / (CO_PBCLK / 100);
    OD_performance[ODA_performance_timerCycleTime] = t;
    if(t > OD_performance[ODA_performance_timerCycleMaxTime])
        OD_performance[ODA_performance_timerCycleMaxTime] = t;
}
Ejemplo n.º 2
0
/* timer thread executes in constant intervals ********************************/
static void tmrTask_thread(void){

    for(;;) {

        /* sleep for interval */

        INCREMENT_1MS(CO_timer1ms);

        if(CO_CAN_OK) {
            bool_t syncWas;

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

            /* Reenable CANrx, if it was disabled by SYNC callback */

            /* Further I/O or nonblocking application code may go here. */

            /* Write outputs */
            CO_process_TPDO(CO, syncWas, TMR_TASK_INTERVAL);
        }

    }

    /* verify timer overflow */
    if(0){
        CO_errorReport(CO->em, CO_EM_ISR_TIMER_OVERFLOW, CO_EMC_SOFTWARE_INTERNAL, 0U);
    }
}
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;

		
}
Ejemplo n.º 4
0
/* timer interrupt function executes every millisecond ************************/
CO_TIMER_ISR(){

    /* clear interrupt flag bit */
    CO_TMR_ISR_FLAG = 0;

    CO_timer1ms++;

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

        /* 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;

        /* Further I/O or nonblocking application code may go here. */
        /* read RPDO and show it on example LEDS on Explorer16 */
        uint8_t leds = OD_writeOutput8Bit[0];
        LATAbits.LATA3 = (leds&0x08) ? 1 : 0;
        LATAbits.LATA4 = (leds&0x10) ? 1 : 0;
        LATAbits.LATA5 = (leds&0x20) ? 1 : 0;
        LATAbits.LATA6 = (leds&0x40) ? 1 : 0;
        LATAbits.LATA7 = (leds&0x80) ? 1 : 0;

        /* prepare TPDO from example buttons on Explorer16 */
        uint8_t but = 0;
        if(!PORTDbits.RD6)  but |= 0x08;
        if(!PORTDbits.RD7)  but |= 0x04;
        if(!PORTDbits.RD13) but |= 0x01;
        OD_readInput8Bit[0] = but;

#if 0
        /* Debug - disable CANrx for 650 ms, if button pressed. */
        static uint16_t tmrDebug = 0;
        if(!PORTDbits.RD13) {
            if(tmrDebug < 650) {
                CO_CAN_ISR_ENABLE = 0;
                tmrDebug++;
            }
            else {
                CO_CAN_ISR_ENABLE = 1;
            }
        }
        else {
            CO_CAN_ISR_ENABLE = 1;
            tmrDebug = 0;
        }
#endif

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

        /* verify timer overflow */
        if(CO_TMR_ISR_FLAG == 1){
            CO_errorReport(CO->em, CO_EM_ISR_TIMER_OVERFLOW, CO_EMC_SOFTWARE_INTERNAL, 0);
            CO_TMR_ISR_FLAG = 0;
        }
    }


    /* calculate cycle time for performance measurement */
    uint16_t t = CO_TMR_TMR / (CO_FCY / 100);
    OD_performance[ODA_performance_timerCycleTime] = t;
    if(t > OD_performance[ODA_performance_timerCycleMaxTime])
        OD_performance[ODA_performance_timerCycleMaxTime] = t;
}