PUBLIC void rt_PktServer(RTWExtModeInfo *ei, int_T numSampTimes, boolean_T *stopReq) { for(;;) { rt_PktServerWork(ei,numSampTimes,stopReq); } }
PUBLIC void* rt_PktServer(void *thPtr) { pktServerArgT *pktServerArg; pktServerArg = (pktServerArgT *)thPtr; for(;;) { rt_PktServerWork(pktServerArg->ei,pktServerArg->numSampTimes,pktServerArg->stopReq); } }
void rtExtModeOneStep(RTWExtModeInfo *ei, int_T numSampTimes, boolean_T *stopReqPtr) { /* * In a multi-tasking environment, this would be removed from the base rate * and called as a "background" task. */ if (modelStatus != TARGET_STATUS_PAUSED) { rt_PktServerWork(ei,numSampTimes,stopReqPtr); #ifndef EXTMODE_DISABLESIGNALMONITORING rt_UploadServerWork(numSampTimes); #endif } }
/* Function ==================================================================== * Pause the process (w/o hogging the cpu) until receive step packet (which * means the startModel flag moves to true) or until we are no longer * in the paused state. The packet/upload server must continue to process * events (otherwise the host would not be able to communicate with the target). */ void rtExtModePauseIfNeeded(RTWExtModeInfo *ei, int_T numSampTimes, boolean_T *stopReqPtr) { while((modelStatus == TARGET_STATUS_PAUSED) && !startModel && !(*stopReqPtr)) { rt_ExtModeSleep(0L, 375000L); rt_PktServerWork(ei,numSampTimes,stopReqPtr); #ifndef EXTMODE_DISABLESIGNALMONITORING rt_UploadServerWork(numSampTimes); #endif } startModel = FALSE; /* reset to FALSE - if we were stepped we want to * stop again next time we get * back here. */ } /* end rtExtModePauseIfNeeded */
// This task is run at priority level 1, essentially a background // task. void rtExtModeOneStep(UArg arg0, ExtStepArgs *arg1) { // Process external mode packets and upload data //TSK_prolog( TSK_self() ); RTWExtModeInfo *ei = arg1->ei; int_T numSampTimes = arg1->numSampTimes; boolean_T *stopReqPtr = arg1->stopReqPtr; while (extmodeSimStatus != EXTMODE_STOPPED) { rt_PktServerWork(ei, numSampTimes, stopReqPtr); rt_UploadServerWork(numSampTimes); } rt_ExtModeShutdown(numSampTimes); //TSK_epilog( TSK_self() ); /* TODO: */ Clock_delete( &rt_task_handle ); rt_TermModel(); // Signal completion of Pkt / Upload server work Semaphore_post(extStartStopSem); }
/* Function ==================================================================== * Pause the process (w/o hogging the cpu) until receive start packet * from the host. The packet/upload server must continue to process * events (otherwise the host would not be able to communicate with the target). */ void rtExtModeWaitForStartPkt(RTWExtModeInfo *ei, int_T numSampTimes, boolean_T *stopReqPtr) { /* * Pause until receive model start packet. */ if (ExtWaitForStartPkt()) { while(!startModel && !(*stopReqPtr)) { rt_ExtModeSleep(0L, 375000L); rt_PktServerWork(ei,numSampTimes,stopReqPtr); #ifndef EXTMODE_DISABLESIGNALMONITORING rt_UploadServerWork(numSampTimes); #endif } } if (modelStatus != TARGET_STATUS_PAUSED) { modelStatus = TARGET_STATUS_RUNNING; } else { /* leave in pause mode */ } }
// External mode startup function void rtExtModeC6000Startup( RTWExtModeInfo *ei, int_T numSampTimes, boolean_T *stopReqPtr) { Task_Params attr; Task_Params_init(&attr); Semaphore_Params sem_params; Semaphore_Params_init(&sem_params); sem_params.mode = ti_sysbios_knl_Semaphore_Mode_BINARY; sExtStepArgs.ei = ei; sExtStepArgs.numSampTimes = numSampTimes; sExtStepArgs.stopReqPtr = stopReqPtr; attr.arg1 = (UArg) &sExtStepArgs; // Set external mode state to extmodeSimStatus = EXTMODE_STARTUP; // Initialize semaphores used for external mode // communication uploadSem = Semaphore_create(1, &sem_params, NULL); extStartStopSem = Semaphore_create(1, NULL, NULL); // Pause until Ethernet network initialization completes //waitNetworkStartup(); extmodeSimStatus = EXTMODE_NET_INITIALIZED; // Initialize user data structure rtExtModeInitUD(); rt_ExtModeInit(); // Create external mode task attr.priority = 1; attr.stack = (Ptr) &stack_pkt_tid[0]; attr.stackSize = EXT_MODE_TSK_STACK_SIZE; extern_pkt_tid = Task_create( (Task_FuncPtr) rtExtModeOneStep, &attr, NULL ); if (extern_pkt_tid == NULL) { printf("handle taskpawn error"); } /* * Pause until receive model start packet - if external mode. * Make sure the external mode tasks are running so that * we are listening for commands from the host. */ extmodeSimStatus = EXTMODE_WAITING_START_PACKET; modelStatus = TARGET_STATUS_WAITING_TO_START; if (ExtWaitForStartPkt()) { printf("\nWaiting for start packet from host.\n"); // rt_PktServerWork() function posts a semaphore when // it receives start packet from host // this function in turn runs as part of rt_PktServer task //Semaphore_pend(extStartStopSem, BIOS_WAIT_FOREVER); while (rt_PktServerWork(ei, numSampTimes, stopReqPtr) != EXT_MODEL_START) { }; } modelStatus = TARGET_STATUS_RUNNING; extmodeSimStatus = EXTMODE_RUNNING; }