/* * ======== msTimer_init ======== * Sets up a BIOS timer with millisec period */ void msTimer_init(void) { Timer_Params params; if (initialized) { return; } Timer_Params_init(¶ms); params.period = 1000; params.periodType = Timer_PeriodType_MICROSECS; params.runMode = Timer_RunMode_CONTINUOUS; params.startMode = Timer_StartMode_AUTO; hdl = Timer_create(-1, (ti_sysbios_hal_Timer_FuncPtr)tick, ¶ms, NULL); if (!hdl) { System_abort("msTimer_init: Timer creation failed.\n"); } /* Set flag indicating that initialization has completed */ initialized = 1; }
void Timer::begin(void (*timerFunction)(void), uint32_t timerPeriod_ms) { Error_Block eb; Error_init(&eb); // xdc_UInt TimerId = 3; // OK=3, NOK=2,1,0 MSP432=4 timers, only timer 3 available // Timer_ANY to take any available timer xdc_UInt TimerId = Timer_ANY; Timer_Params params; Timer_Params_init(¶ms); params.periodType = Timer_PeriodType_MICROSECS; params.period = timerPeriod_ms * 1000; // 1 ms = 1000 us params.startMode = Timer_StartMode_USER; // Timer_start TimerHandle = Timer_create(TimerId, (Timer_FuncPtr)timerFunction, ¶ms, &eb); if (TimerHandle == NULL) { // Serial.println("*** Timer create failed"); System_abort("Timer create failed"); } }
Int main() { Task_Handle signal_task; Clock_Params clkParams; Timer_Params user_sys_tick_params; Timer_Handle user_sys_tick_timer; Error_Block eb; #ifdef MODEL_PROFILING int32_t t_begin, t_end; #endif Error_init(&eb); /* Create a periodic Clock Instance with period = 1 system time units */ Clock_Params_init(&clkParams); clkParams.period = 1; clkParams.startFlag = TRUE; Clock_create(rt_task, 2, &clkParams, NULL); /* Create timer for user system tick */ Timer_Params_init(&user_sys_tick_params); model_is_running = 0.0; if(model_tsamp <= 0.0) model_tsamp = MODEL_TSAMP; user_sys_tick_params.period = (uint32_t)(model_tsamp * USEC_PER_SEC); user_sys_tick_params.periodType = Timer_PeriodType_MICROSECS; user_sys_tick_params.arg = 1; user_sys_tick_timer = Timer_create(1, (ti_sysbios_hal_Timer_FuncPtr)Clock_tick, &user_sys_tick_params, NULL); if (user_sys_tick_timer == NULL) System_abort("Unable to create user system tick timer!"); signal_task = (Task_Handle)signal_init(&eb); if (signal_task == NULL) System_abort("Signal task: Task_create() failed!\n"); #ifdef MODEL_PROFILING mdaq_profile_init(); t_begin = mdaq_profile_read_timer32(); #endif /* Init model */ NAME(MODEL, _init)(); #ifdef MODEL_PROFILING t_end = mdaq_profile_read_timer32(); mdaq_profile_save(t_end - t_begin,0); #endif /* Open mdaqnet and wait for connection */ mdaqnet_open(); model_is_running = 1.0; BIOS_start(); }
/* Function: main ============================================================= * * Abstract: * Execute model on a generic target such as a workstation. */ int_T main(int_T argc, const char *argv[]) { /* External mode */ // rtParseArgsForExtMode(argc, argv); /******************************************* * warn if the model will run indefinitely * *******************************************/ #if MAT_FILE==0 && EXT_MODE==0 printf("warning: the simulation will run with no stop time; " "to change this behavior select the 'MAT-file logging' option\n"); fflush(NULL); #endif (void)printf("\n** starting the model **\n"); /************************ * Initialize the model * ************************/ rt_InitModel(); /* External mode */ rtSetTFinalForExtMode(&rtmGetTFinal(RT_MDL)); rtExtModeCheckInit(NUMST); Clock_Params clkParams; Timer_Params user_sys_tick_params; Timer_Handle user_sys_tick_timer; /* Create timer for user system tick */ Timer_Params_init(&user_sys_tick_params); user_sys_tick_params.period = STEP_SIZE; user_sys_tick_params.periodType = Timer_PeriodType_MICROSECS; user_sys_tick_params.arg = 1; user_sys_tick_timer = Timer_create(1, (ti_sysbios_hal_Timer_FuncPtr)Clock_tick, &user_sys_tick_params, NULL); if(user_sys_tick_timer == NULL) { System_abort("Unable to create user system tick timer!"); } /* Create a periodic Clock Instance with period = 1 system time units */ Clock_Params_init(&clkParams); clkParams.period = 1; clkParams.startFlag = TRUE; Clock_create(clk0Fxn, 10, &clkParams, NULL); // rtExtModeWaitForStartPkt(rtmGetRTWExtModeInfo(RT_MDL), // NUMST, // (boolean_T *)&rtmGetStopRequested(RT_MDL)); /*********************************************************************** * Execute (step) the model. You may also attach rtOneStep to an ISR, * * in which case you replace the call to rtOneStep with a call to a * * background task. Note that the generated code sets error status * * to "Simulation finished" when MatFileLogging is specified in TLC. * ***********************************************************************/ // while (rtmGetErrorStatus(RT_MDL) == NULL && // !rtmGetStopRequested(RT_MDL)) { // // // rtExtModePauseIfNeeded(rtmGetRTWExtModeInfo(RT_MDL), // // NUMST, // // (boolean_T *)&rtmGetStopRequested(RT_MDL)); // // if (rtmGetStopRequested(RT_MDL)) break; // // /* external mode */ // rtExtModeOneStep(rtmGetRTWExtModeInfo(RT_MDL), // NUMST, // (boolean_T *)&rtmGetStopRequested(RT_MDL)); // // rt_OneStep(); // } rtExtModeC6000Startup(rtmGetRTWExtModeInfo(RT_MDL), NUMST, (boolean_T *)&rtmGetStopRequested(RT_MDL)); BIOS_start(); }