LOCAL STATUS taskHookAdd ( FUNCPTR hook, /* routine to be added to table */ FUNCPTR table[], /* table to which to add */ int maxEntries /* max entries in table */ ) { FAST int ix; taskLock (); /* disable task switching */ /* find slot after last hook in table */ for (ix = 0; ix < maxEntries; ++ix) { if (table[ix] == NULL) { table[ix] = hook; taskUnlock (); /* re-enable task switching */ return (OK); } } /* no free slot found */ taskUnlock (); /* re-enable task switching */ errnoSet (S_taskLib_TASK_HOOK_TABLE_FULL); return (ERROR); }
STATUS taskSwapHookAdd ( FUNCPTR swapHook /* routine to be called at every task switch */ ) { FAST int ix; taskLock (); /* disable task switching */ /* find slot after last hook in table */ for (ix = 0; ix < VX_MAX_TASK_SWAP_RTNS; ++ix) { if (taskSwapTable[ix] == NULL) { taskSwapTable[ix] = swapHook; taskSwapReference[ix] = 0; taskUnlock (); /* re-enable task switching */ return (OK); } } /* no free slot found */ taskUnlock (); /* re-enable task switching */ errnoSet (S_taskLib_TASK_HOOK_TABLE_FULL); return (ERROR); }
LOCAL STATUS taskHookDelete ( FUNCPTR hook, /* routine to be deleted from table */ FUNCPTR table[], /* table from which to delete */ int maxEntries /* max entries in table */ ) { FAST int ix; taskLock (); /* disable task switching */ /* find hook in hook table */ for (ix = 0; ix < maxEntries; ++ix) { if (table [ix] == hook) { /* move all the remaining hooks up one slot in the table */ do table [ix] = table [ix + 1]; while (table [++ix] != NULL); taskUnlock (); /* re-enable task switching */ return (OK); } } /* hook not found in table */ taskUnlock (); /* re-enable task switching */ errnoSet (S_taskLib_TASK_HOOK_NOT_FOUND); return (ERROR); }
/* release semaphore when done */ int release_access (short int *sem, double timeout) { int tst; ULONG timeout_ticks, start_ticks, current_ticks, elapsed_ticks; timeout_ticks = (ULONG) (timeout * sysClkRateGet ()); start_ticks = tickGet (); elapsed_ticks = 0; while (elapsed_ticks <= timeout_ticks) { tst = decrement_read_status (sem); if (tst == 0) { taskUnlock (); return 0; /* success */ } else { if (tst < 0) { taskUnlock (); rcs_print_error ("invalid semaphore on 0x%x", (int) sem); return -1; /* invalid semaphore */ } } current_ticks = tickGet (); elapsed_ticks = current_ticks - start_ticks; } taskUnlock (); rcs_print_error ("timed out while releasing access on semphore 0x%x", (int) sem); return -1; /* timeout failure */ }
int context_stop(Context * ctx) { ContextExtensionVxWorks * ext = EXT(ctx); struct event_info * info; VXDBG_CTX vxdbg_ctx; assert(is_dispatch_thread()); assert(ctx->parent != NULL); assert(!ctx->stopped); assert(!ctx->exited); assert(!ext->regs_dirty); if (ctx->pending_intercept) { trace(LOG_CONTEXT, "context: stop ctx %#lx, id %#x", ctx, ext->pid); } else { trace(LOG_CONTEXT, "context: temporary stop ctx %#lx, id %#x", ctx, ext->pid); } taskLock(); if (taskIsStopped(ext->pid)) { /* Workaround for situation when a task was stopped without notifying TCF agent */ int n = 0; SPIN_LOCK_ISR_TAKE(&events_lock); n = events_cnt; SPIN_LOCK_ISR_GIVE(&events_lock); if (n > 0) { trace(LOG_CONTEXT, "context: already stopped ctx %#lx, id %#x", ctx, ext->pid); taskUnlock(); return 0; } } else { vxdbg_ctx.ctxId = ext->pid; vxdbg_ctx.ctxType = VXDBG_CTX_TASK; if (vxdbgStop(vxdbg_clnt_id, &vxdbg_ctx) != OK) { int error = errno; taskUnlock(); if (error == S_vxdbgLib_INVALID_CTX) return 0; trace(LOG_ALWAYS, "context: can't stop ctx %#lx, id %#x: %s", ctx, ext->pid, errno_to_str(error)); return -1; } } assert(taskIsStopped(ext->pid)); info = event_info_alloc(EVENT_HOOK_STOP); if (info != NULL) { info->stopped_ctx.ctxId = ext->pid; event_info_post(info); } taskUnlock(); return 0; }
STATUS taskDeleteHookAdd ( FUNCPTR deleteHook /* routine to be called when a task is deleted */ ) { FAST int ix; STATUS status = OK; taskLock (); /* disable task switching */ if (taskDeleteTable [VX_MAX_TASK_DELETE_RTNS] != NULL) { /* no free slot found */ errnoSet (S_taskLib_TASK_HOOK_TABLE_FULL); status = ERROR; } else { /* move all the hooks down one slot in the table */ for (ix = VX_MAX_TASK_DELETE_RTNS - 2; ix >= 0; --ix) taskDeleteTable [ix + 1] = taskDeleteTable [ix]; taskDeleteTable [0] = deleteHook; } taskUnlock (); /* re-enable task switching */ return (status); }
/* acquire access to a semaphored data buffer */ int acquire_access (short int *sem, double timeout) { ULONG timeout_ticks=0; ULONG start_ticks =0; ULONG current_ticks=0; ULONG elapsed_ticks=0; if (timeout == 0.0) { timeout_ticks = 1; start_ticks = tickGet (); elapsed_ticks = 0; } else if (timeout > 0.0) { timeout_ticks = (int) (timeout * sysClkRateGet ()); start_ticks = tickGet (); elapsed_ticks = 0; } /* loop until timeout_count expires */ while (elapsed_ticks <= timeout_ticks && (timeout >= 0.0)) { taskLock (); if (!increment_read_status (sem)) { return 0; /* success */ } else { taskUnlock (); taskDelay (1); if (timeout >= 0.0) { current_ticks = tickGet (); elapsed_ticks = current_ticks - start_ticks; } } } taskUnlock (); rcs_print_error ("timed out while acquiring access on semaphore 0x%x\n", (int) sem); return -1; /* indicate timeout failure */ }
int recorderResume (Recorder * r) { if (!recorderActive (r)) return 1; taskLock (&r->recording_task); r->paused = 0; taskUnlock (&r->recording_task); return 0; }
void CVMthreadInterruptWait(CVMThreadID *thread) { taskLock(); thread->interrupted = CVM_TRUE; if (thread->in_wait) { vxworksSyncInterruptWait(thread); } taskUnlock(); }
STATUS taskSwapHookAttach ( FUNCPTR swapHook, /* swap hook for conection */ int tid, /* task to connect to swap hook */ BOOL in, /* conection for swap in */ BOOL out /* conection for swap out */ ) { int ix; taskLock (); /* disable task switching */ /* find hook in hook table */ for (ix = 0; ix < VX_MAX_TASK_SWAP_RTNS; ++ix) { if (taskSwapTable [ix] == swapHook) { taskSwapReference[ix] += (in) ? 1 : 0; /* reference swap hook */ taskSwapReference[ix] += (out) ? 1 : 0; /* reference swap hook */ if (taskSwapMaskSet (tid, ix, in, out) != OK) { taskSwapReference[ix] -= (in) ? 1 : 0; /* deref. swap hook */ taskSwapReference[ix] -= (out) ? 1 : 0; /* deref. swap hook */ taskUnlock (); /* reenable switching */ return (ERROR); } else { taskUnlock (); /* reenable switching */ return (OK); } } } /* hook not found in table */ taskUnlock (); /* re-enable task switching */ errnoSet (S_taskLib_TASK_HOOK_NOT_FOUND); return (ERROR); }
void Task2415::SwapAndWait(void) { TasksSwapped++; taskUnlock(); taskDelay(2); taskLock(); if (TasksSwapped % 2 == 0) { Wait(STALL_LOOP_TIME); } }
void Task2415::SwapAndWait(void) { // tell vxWorks that it can switch over to some other task now! taskUnlock(); // sleep this task for a while, vxWorks will mark this task as inactive // and switch over! taskDelay(2); // tell vxWorks that we wanna get back to this task taskLock(); }
CVMBool CVMthreadIsInterrupted(CVMThreadID *thread, CVMBool clearInterrupted) { CVMBool wasInterrupted; taskLock(); wasInterrupted = thread->interrupted; if (clearInterrupted) { thread->interrupted = CVM_FALSE; } taskUnlock(); return wasInterrupted; }
int context_continue(Context * ctx) { ContextExtensionVxWorks * ext = EXT(ctx); VXDBG_CTX vxdbg_ctx; assert(is_dispatch_thread()); assert(ctx->parent != NULL); assert(ctx->stopped); assert(!ctx->pending_intercept); assert(!ctx->exited); assert(taskIsStopped(ext->pid)); trace(LOG_CONTEXT, "context: continue ctx %#lx, id %#x", ctx, ext->pid); if (ext->regs_dirty) { if (taskRegsSet(ext->pid, ext->regs) != OK) { int error = errno; trace(LOG_ALWAYS, "context: can't set regs ctx %#lx, id %#x: %s", ctx, ext->pid, errno_to_str(error)); return -1; } ext->regs_dirty = 0; } vxdbg_ctx.ctxId = ext->pid; vxdbg_ctx.ctxType = VXDBG_CTX_TASK; taskLock(); if (vxdbgCont(vxdbg_clnt_id, &vxdbg_ctx) != OK) { int error = errno; taskUnlock(); trace(LOG_ALWAYS, "context: can't continue ctx %#lx, id %#x: %s", ctx, ext->pid, errno_to_str(error)); return -1; } assert(!taskIsStopped(ext->pid)); taskUnlock(); send_context_started_event(ctx); return 0; }
STATUS taskSwapHookDelete ( FUNCPTR swapHook /* routine to be deleted from list */ ) { int ix; taskLock (); /* disable task switching */ /* find hook in hook table */ for (ix = 0; ix < VX_MAX_TASK_SWAP_RTNS; ++ix) { if (taskSwapTable [ix] == swapHook) { if (taskSwapReference [ix] != 0) /* reference swap hook */ { taskUnlock (); /* re-enable task switching */ errnoSet (S_taskLib_TASK_SWAP_HOOK_REFERENCED); return (ERROR); } else { taskSwapTable [ix] = NULL; /* take out of table */ taskUnlock (); /* re-enable task switching */ return (OK); } } } /* hook not found in table */ taskUnlock (); /* re-enable task switching */ errnoSet (S_taskLib_TASK_HOOK_NOT_FOUND); return (ERROR); }
int Zprintf0(int force, char *buf) { int l; int n; int ret; int msgret; char *str; char junk; str = buf; l = sipx_min(ABSOLUTE_MAX_LOG_MSG_LEN, strlen(buf)); ret = l; if (0 == MpMisc.LogQ) { ret = force ? fwrite(str, 1, ret, stderr) : 0; return ret; } if (force || logging) { if ((ret > MpMisc.logMsgSize) && !intContext()) { taskLock(); } while (l > 0) { n = sipx_min(l, MpMisc.logMsgSize); msgret = msgQSend(MpMisc.LogQ, buf, n, VX_NO_WAIT, MSG_PRI_NORMAL); if (ERROR == msgret) { // int r2 = msgQReceive(MpMisc.LogQ, &junk, 1, VX_NO_WAIT); // osPrintf("discard message; r1=%d, r2=%d, q=0x%X: '%s'\n", // msgret, r2, MpMisc.LogQ, buf); numDiscarded++; msgret = msgQSend(MpMisc.LogQ, buf, n, VX_NO_WAIT, MSG_PRI_NORMAL); } if ((ERROR == msgret) && force) { fwrite(str, 1, ret, stderr); l = 0; } else { l -= n; buf += n; } } if ((ret > MpMisc.logMsgSize) && !intContext()) { taskUnlock(); } } else { ret = 0; } return ret; }
void taskExit( int code ) { /* Store return code */ taskIdCurrent->exitCode = code; /* Lock task */ taskLock(); /* Destroy task */ taskDestroy(NULL, TRUE, WAIT_FOREVER, FALSE); /* Unlock task */ taskUnlock(); }
/************************************************************** * * mBufferClear - clear the fast buffer pool * * * This routine clears the fast buffer pool. All buffers * are "deallocated". * * RETURNS: * VOID * * Author Greg Brissey 3/02/04 */ VOID mBufferClear(register MBUFFER_ID mBufferId) /* MBUFFER_ID mBufferId - Fast Buffer Pool Id */ { unsigned long startAddr; register int i,nBufs,size; if (mBufferId != NULL) { taskLock(); for ( i=0; i < mBufferId->numLists; i++) { rngLFlush(mBufferId->freeList[i]); } fillRngwAddrs(mBufferId); taskUnlock(); } }
/* *=========================================================================== * ipcom_spinlock_unlock *=========================================================================== * Description: * Parameters: * Returns: * */ IP_FASTTEXT IP_PUBLIC void ipcom_spinlock_unlock(Ipcom_spinlock sl_handle) { #ifdef IPCOM_USE_SMP Ipcom_vxworks_spinlock_t *sl = (Ipcom_vxworks_spinlock_t*) sl_handle; VX_MEM_BARRIER_RW(); /* build a memory fence for load and store */ if (vxAtomicInc(&sl->count) < 0) /* Contention for this lock, let's wakeup one of the tasks that is blocked on this lock */ semGive(sl->sem); #else IPCOM_UNUSED_ARG(sl_handle); ip_assert(sl_handle == IPCOM_SPINLOCK_TAG); taskUnlock(); #endif }
void osl_init(void) { uint ticks_per_us, tick1=1, tick2=0, n; volatile int i=1000000; static bool init_done=FALSE; if (init_done) return; /*** calibrate the delay loop ***/ /* get the ticks per us */ ticks_per_us = 1000000/sysClkRateGet(); taskLock(); /* get the curr tick count (retry if wrapped) */ while(tick2 < tick1) { tick1 = tickGet(); /* Loop 1000000 times */ while (i--); /* get new tick count */ tick2 = tickGet(); } taskUnlock(); /* calculate loop count per uS */ n = tick2-tick1; if (!n) n=1; loop_us = 1000000/(n*ticks_per_us); init_done = TRUE; }
int main(){ int index_boucle; //Initialise les types de béton beton_type_1.agregat_1 = 16; beton_type_1.agregat_2 = 32; beton_type_1.agregat_3 = 0; beton_type_1.ciment_1 = 20; beton_type_1.ciment_2 = 0; beton_type_1.eau = 32; beton_type_2.agregat_1 = 22; beton_type_2.agregat_2 = 31; beton_type_2.agregat_3 = 0; beton_type_2.ciment_1 = 17; beton_type_2.ciment_2 = 0; beton_type_2.eau = 30; beton_type_3.agregat_1 = 30; beton_type_3.agregat_2 = 0; beton_type_3.agregat_3 = 20; beton_type_3.ciment_1 = 0; beton_type_3.ciment_2 = 20; beton_type_3.eau = 30; versement_eau_possible = 1; versement_eau_en_cours = 0; //Semaphore de test (driver) sem_capacite_silo_agregat_courrante = semMCreate(SEM_Q_FIFO); sem_capacite_silo_ciment_courrante = semMCreate(SEM_Q_FIFO); sem_capacite_silo_eau_courrante = semMCreate(SEM_Q_FIFO); sem_capacite_malaxeur = semMCreate(SEM_Q_FIFO); sem_vitesse_moteur = semMCreate(SEM_Q_FIFO); //Initialise les sémaphores d'exclusion mutulle sem_exl_tampon_cmd = semMCreate(SEM_Q_FIFO); sem_exl_tampon_fonct_calcul = semMCreate(SEM_Q_FIFO); sem_exl_tampon_qte_silos = semMCreate(SEM_Q_FIFO); sem_exl_versement_eau_possible = semMCreate(SEM_Q_FIFO); //Initialise les sémaphores d'initialisation de la cimenterie sem_init_remplissage_silo_agr_1 = semBCreate(SEM_Q_FIFO, 0); sem_init_remplissage_silo_agr_2 = semBCreate(SEM_Q_FIFO, 0); sem_init_remplissage_silo_agr_3 = semBCreate(SEM_Q_FIFO, 0); sem_init_remplissage_silo_cim_1 = semBCreate(SEM_Q_FIFO, 0); sem_init_remplissage_silo_cim_2 = semBCreate(SEM_Q_FIFO, 0); sem_init_remplissage_silo_eau = semBCreate(SEM_Q_FIFO, 0); //Initialise les sémaphores de synchronisation des tâches sem_fin_agregat = semBCreate(SEM_Q_FIFO, 0); sem_fin_ciment = semBCreate(SEM_Q_FIFO, 0); sem_fin_eau = semBCreate(SEM_Q_FIFO, 0); sem_fin_versement_eau = semBCreate(SEM_Q_FIFO, 0); sem_fin_malaxeur = semBCreate(SEM_Q_FIFO, 0); sem_debut_malaxeur = semBCreate(SEM_Q_FIFO, 0); sem_calcul_agregat = semBCreate(SEM_Q_FIFO, 0); sem_calcul_ciment = semBCreate(SEM_Q_FIFO, 0); sem_calcul_eau = semBCreate(SEM_Q_FIFO, 0); sem_int_min_agr_1 = semBCreate(SEM_Q_FIFO, 0); sem_int_min_agr_2 = semBCreate(SEM_Q_FIFO, 0); sem_int_min_agr_3 = semBCreate(SEM_Q_FIFO, 0); sem_int_max_agr_1 = semBCreate(SEM_Q_FIFO, 0); sem_int_max_agr_2 = semBCreate(SEM_Q_FIFO, 0); sem_int_max_agr_3 = semBCreate(SEM_Q_FIFO, 0); sem_int_min_cim_1 = semBCreate(SEM_Q_FIFO, 0); sem_int_min_cim_2 = semBCreate(SEM_Q_FIFO, 0); sem_int_max_cim_1 = semBCreate(SEM_Q_FIFO, 0); sem_int_max_cim_2 = semBCreate(SEM_Q_FIFO, 0); sem_int_plus_eau = semBCreate(SEM_Q_FIFO, 0); sem_int_moins_eau = semBCreate(SEM_Q_FIFO, 0); sem_int_max_eau = semBCreate(SEM_Q_FIFO, 0); sem_int_min_eau = semBCreate(SEM_Q_FIFO, 0); sem_int_plus_bal_agr = semBCreate(SEM_Q_FIFO, 0); sem_int_moins_bal_agr = semBCreate(SEM_Q_FIFO, 0); sem_int_plus_bal_cim = semBCreate(SEM_Q_FIFO, 0); sem_int_moins_bal_cim = semBCreate(SEM_Q_FIFO, 0); sem_demande_versement_agregat = semBCreate(SEM_Q_FIFO, 0); sem_demande_versement_ciment = semBCreate(SEM_Q_FIFO, 0); sem_demande_versement_eau = semBCreate(SEM_Q_FIFO, 0); file_debut_remplissage_balance_agregat = msgQCreate(10, 512, MSG_Q_FIFO); sem_fin_remplissage_balance_agregat = semBCreate(SEM_Q_FIFO, 0); sem_ferm_balance_agregat = semBCreate(SEM_Q_FIFO, 0); sem_ferm_balance_ciment = semBCreate(SEM_Q_FIFO, 0); file_debut_remplissage_balance_ciment = msgQCreate(10, 512, MSG_Q_FIFO); sem_fin_remplissage_balance_ciment = semBCreate(SEM_Q_FIFO, 0); //sémaphore de synchro des balances sem_pret_balance_agregat = semBCreate(SEM_Q_FIFO, 0); sem_pret_balance_ciment = semBCreate(SEM_Q_FIFO, 0); sem_ouverture_balance_agregat = semBCreate(SEM_Q_FIFO, 0); sem_ouverture_balance_ciment = semBCreate(SEM_Q_FIFO, 0); sem_fin_vers_balance_agregat = semBCreate(SEM_Q_FIFO, 0); sem_fin_vers_balance_ciment = semBCreate(SEM_Q_FIFO, 0); sem_melange_homogene = semBCreate(SEM_Q_FIFO, 0); sem_cmd_en_cours = semBCreate(SEM_Q_FIFO, 0); sem_debut_camion = semBCreate(SEM_Q_FIFO, 0); sem_position_camion_ok = semBCreate(SEM_Q_FIFO, 0); sem_position_camion_ok = semBCreate(SEM_Q_FIFO, 0); sem_vide_malaxeur = semBCreate(SEM_Q_FIFO, 0); sem_stop_bal_tapis_agrEtCim = semBCreate(SEM_Q_FIFO, 0); sem_reprise_bal_tapis_agrEtCim = semBCreate(SEM_Q_FIFO, 0); //Initialise le contenu des tampons for(index_boucle = 0; index_boucle < NB_COMMANDE * 3; index_boucle += 1){ tampon_cmd[index_boucle] = 0; } for(index_boucle = 0; index_boucle < NB_SILOS; index_boucle += 1){ tampon_qte_silos[index_boucle] = 0; } tampon_fonct_calcul[index_tampon_fonct_calcul_cmd_plus_recente] = -1; tampon_fonct_calcul[index_tampon_fonct_calcul_cmd_en_cours] = -1; tampon_fonct_calcul[index_tampon_fonct_calcul_cmd_eau_en_cours] = 0; tampon_fonct_calcul[index_tampon_fonct_calcul_cmd_agregat_en_cours] = 0; tampon_fonct_calcul[index_tampon_fonct_calcul_cmd_ciment_en_cours] = 0; //Empeche la réquisition (préemption) taskLock(); taskSpawn("driver_affichage_test",150, 0x100,2000,(FUNCPTR) driver_affichage_test, 0,0,0,0,0,0,0,0,0,0); taskSpawn("gestion_IHM",200, 0x100,2000,(FUNCPTR) gestion_IHM, 0,0,0,0,0,0,0,0,0,0); taskSpawn("gestion_evenement_fin_malax",200, 0x100,2000,(FUNCPTR) gestion_evenement_fin_malax, 0,0,0,0,0,0,0,0,0,0); taskSpawn("gestion_evenement_fin_agregat",200, 0x100,2000,(FUNCPTR) gestion_evenement_fin_agregat, 0,0,0,0,0,0,0,0,0,0); taskSpawn("gestion_evenement_fin_ciment",200, 0x100,2000,(FUNCPTR) gestion_evenement_fin_ciment, 0,0,0,0,0,0,0,0,0,0); taskSpawn("gestion_evenement_fin_eau",200, 0x100,2000,(FUNCPTR) gestion_evenement_fin_eau, 0,0,0,0,0,0,0,0,0,0); taskSpawn("calcul_qte_eau",200, 0x100,2000,(FUNCPTR) calcul_qte_eau, 0,0,0,0,0,0,0,0,0,0); taskSpawn("calcul_qte_agregat",200, 0x100,2000,(FUNCPTR) calcul_qte_agregat, 0,0,0,0,0,0,0,0,0,0); taskSpawn("calcul_qte_ciment",200, 0x100,2000,(FUNCPTR) calcul_qte_ciment, 0,0,0,0,0,0,0,0,0,0); taskSpawn("versement_agregat_silos_et_balance",200, 0x100,2000,(FUNCPTR) versement_agregat_silos_et_balance, 0,0,0,0,0,0,0,0,0,0); taskSpawn("remplissage_silo_agregat_1",200, 0x100,2000,(FUNCPTR) remplissage_silo_agregat_1, 0,0,0,0,0,0,0,0,0,0); taskSpawn("remplissage_silo_agregat_2",200, 0x100,2000,(FUNCPTR) remplissage_silo_agregat_2, 0,0,0,0,0,0,0,0,0,0); taskSpawn("remplissage_silo_agregat_3",200, 0x100,2000,(FUNCPTR) remplissage_silo_agregat_3, 0,0,0,0,0,0,0,0,0,0); taskSpawn("versement_ciment_silos_et_balance",200, 0x100,2000,(FUNCPTR) versement_ciment_silos_et_balance, 0,0,0,0,0,0,0,0,0,0); taskSpawn("remplissage_silo_ciment_1",200, 0x100,2000,(FUNCPTR) remplissage_silo_ciment_1, 0,0,0,0,0,0,0,0,0,0); taskSpawn("remplissage_silo_ciment_2",200, 0x100,2000,(FUNCPTR) remplissage_silo_ciment_2, 0,0,0,0,0,0,0,0,0,0); taskSpawn("remplissage_balance_agregats",200, 0x100,2000,(FUNCPTR) remplissage_balance_agregats, 0,0,0,0,0,0,0,0,0,0); taskSpawn("remplissage_balance_ciment",200, 0x100,2000,(FUNCPTR) remplissage_balance_ciment, 0,0,0,0,0,0,0,0,0,0); taskSpawn("arret_et_reprise_versement_balances",200, 0x100,2000,(FUNCPTR) arret_et_reprise_versement_balances, 0,0,0,0,0,0,0,0,0,0); taskSpawn("gestion_synchro_balances",200, 0x100,2000,(FUNCPTR) gestion_synchro_balances, 0,0,0,0,0,0,0,0,0,0); taskSpawn("versement_eau",200, 0x100,2000,(FUNCPTR) versement_eau, 0,0,0,0,0,0,0,0,0,0); taskSpawn("remplissage_eau",200, 0x100,2000,(FUNCPTR) remplissage_eau, 0,0,0,0,0,0,0,0,0,0); taskSpawn("gestion_position_camion",200, 0x100,2000,(FUNCPTR) gestion_position_camion, 0,0,0,0,0,0,0,0,0,0); taskSpawn("gestion_versement_malaxeur",200, 0x100,2000,(FUNCPTR) gestion_versement_malaxeur, 0,0,0,0,0,0,0,0,0,0); taskSpawn("gestion_moteur_malaxeur",200, 0x100,2000,(FUNCPTR) gestion_moteur_malaxeur, 0,0,0,0,0,0,0,0,0,0); //Réautorise la réquisition taskUnlock(); return 0; }
static void * do_record (void *p) { Recorder *r = p; int rv, fadv_ctr = 0; taskLock (&r->recording_task); r->start_time = time (NULL); debugPri (1, "do_record\n"); while (taskRunning (&r->recording_task)) { taskUnlock (&r->recording_task); rv = selectorWaitData (r->port, 300); taskLock (&r->recording_task); if (rv) { debugPri (10, "pthread_cond_timedwait: %s\n", strerror (rv)); } else { uint8_t *d[256]; int num = 0; int i; selectorLock (r->sel); while ((num < 256) && (d[num] = selectorReadElementUnsafe (r->port))) num++; selectorUnlock (r->sel); for (i = 0; i < num; i++) { if (selectorEIsEvt (d[i])) { int j; switch (selectorEvtId (d[i])) { case E_TUNING: case E_CONFIG: //we're changing frequency, abort recording debugPri (1, "Freq change, Stopping recorder\n"); selectorLock (r->sel); for (j = 0; j < num; j++) selectorReleaseElementUnsafe (r->sel, d[j]); selectorUnlock (r->sel); dvbDmxOutRmv (r->o); // dvbTsOutputClear (r->dvb, r->port); fclose (r->output); r->o = NULL; r->port = NULL; r->sel = NULL; r->output = NULL; taskUnlock (&r->recording_task); return NULL; break; default: break; } } else { if (!tsIsStuffing (selectorEPayload (d[i]))) { if (!r->paused) { if (1 != fwrite (selectorEPayload (d[i]), TS_LEN, 1, r->output)) { r->err = 1; errMsg ("fwrite error: %s\n", strerror (errno)); } if (fadv_ctr > FADV_INTERVAL) { //this seems to work. but it is ugly (FADV_INTERVAL is defined in config.h) posix_fadvise (fileno (r->output), 0, 0, POSIX_FADV_DONTNEED); fadv_ctr = 0; } fadv_ctr++; } } } } selectorLock (r->sel); for (i = 0; i < num; i++) { selectorReleaseElementUnsafe (r->sel, d[i]); } selectorUnlock (r->sel); } } debugPri (1, "Stopping recorder\n"); dvbDmxOutRmv (r->o); // dvbTsOutputClear (r->dvb, r->port); fclose (r->output); r->o = NULL; r->port = NULL; r->sel = NULL; r->output = NULL; taskUnlock (&r->recording_task); return NULL; }
static int __wind_task_unlock(struct task_struct *curr, struct pt_regs *regs) { taskUnlock(); return 0; }
/****************************************************************************** ** Function: CFE_PSP_Get_Timebase() ** ** Purpose: ** Provides a common interface to system timebase. This routine ** is in the BSP because it is sometimes implemented in hardware and ** sometimes taken care of by the RTOS. ** ** Arguments: ** ** Return: ** Timebase register value */ void CFE_PSP_Get_Timebase(uint32 *Tbu, uint32* Tbl) { uint32 upper = 0; uint32 lower = 0; int32 key = 0; /* ** We don't want an interrupt to occur when the time requested. ** According to notes from vxWorks, intLock does not stop reschededuling ** of the calling task, so we have lock the task as well. ** ** sysTimestampLock() automatically blocks interrupts during execution. ** ** taskLock() is not valid on SMP systems and taskCpuLock (VxWorks 6.6+) ** should be used instead. */ if(g_bTimerInitialized == TRUE) { #if _WRS_VXWORKS_MINOR >= 6 if (taskCpuLock() == OK) #else if (taskLock() == OK) #endif { /* ** Tbu is the upper 32 bits of a 64 bit counter. ** Tbl is the lower 32 bits of a 64 bit counter. ** The resolution of our timer is given by: ** one timer tick = 1 / sysTimestampFreq() in seconds */ upper = g_nSecondsCount; lower = sysTimestampLock(); lower /= sysTimestampFreq() / 1000000UL; #if _WRS_VXWORKS_MINOR >= 6 taskCpuUnlock(); #else taskUnlock(); #endif } else { /* ** What if you can't lock the task */ OS_printf("CFE PSP Get Timebase: Unable to lock task!"); } } else { OS_printf("CFE PSP Get Timebase: Timer is not initialized!"); } if(Tbu != NULL) { *Tbu = upper; } if(Tbl != NULL) { *Tbl = lower; } }
/************************************************************** * * mBufferGet - get the next available buffer * * * This routine returns the next available buffer address. * * * RETURNS: * The Address of a available buffer. * * Author Greg Brissey 3/02/04 */ char *mBufferGet(register MBUFFER_ID mBufferId, unsigned int size) /* MBUFFER_ID mBufferId - Fast Buffer to allocate from */ { int i,stat; long *indxAddr; char *bufAddr; register int toP; MEM_PART_STATS memStats; #ifdef INSTRUMENT wvEvent(EVENT_FBUF_GET,NULL,NULL); #endif taskLock(); /* critical code */ bufAddr = 0; for ( i=0; i < mBufferId->numLists; i++) { DPRINT2(1,"mBufferGet: size %d, cluster size %d\n",size,mBufferId->listSizes[i]); if ( (size+16) < mBufferId->listSizes[i] ) { stat = RNG_LONG_GET(mBufferId->freeList[i], (long*) &bufAddr,toP); DPRINT3(1," mBufferGet: stat %d, Cluster: %d, Addr: 0x%lx\n",stat, mBufferId->listSizes[i],bufAddr); if ( stat != 0) { DPRINT(1," mBufferGet(): Obtain cluster entry\n"); mBufferId->clCnt[i] += 1; taskUnlock(); return(bufAddr); } else { mBufferId->clFailCnt[i] += 1; continue; /* if we want to try next size up */ /* return(NULL); */ } } } memPartInfoGet(memSysPartId,&memStats); DPRINT2(0," MemStat's Alloc'd: %lu bytes, Free: %lu bytes\n", memStats.numBytesAlloc, memStats.numBytesFree); /* DPRINT2(-1," Alloc: %lu blocks, Free: %lu blocks\n", memStats.numBlocksAlloc, memStats.numBlocksFree); */ DPRINT(0," mBufferGet(): No clusters, Malloc buffer\n"); /* bufAddr = malloc( size + sizeof(long) ); */ /* bufAddr = (char *) memalign(4, size + sizeof(long) ); /* align to 4 bytes */ /* if we are going over the limit i.e. will drive memory free below memReserveLevel, then FAIL */ if ( (memStats.numBytesFree - size) > mBufferId->memReserveLevel) { bufAddr = (char *) memalign(_CACHE_ALIGN_SIZE, size + sizeof(long) ); /* align to 4 bytes */ if (bufAddr != NULL) { indxAddr = (long *) bufAddr; *indxAddr = 0xbada110c; /*99 in front of buffer place size index */ bufAddr += sizeof(long); mBufferId->numMallocs++; DPRINT3(1,"Malloc: indx: 0x%lx, val: %ld, bufAddr: 0x%lx\n", indxAddr, *indxAddr, bufAddr); if (size > mBufferId->maxMalloc) mBufferId->maxMalloc = size; } } else { DPRINT1(-1," mBufferGet(): to malloc would drive free system memory below reserve of: %lu bytes\n", mBufferId->memReserveLevel); bufAddr = NULL; } taskUnlock(); return(bufAddr); }
/************************************************************** * * mBufferReturn - returns a buffer to the buffer pool * * * This routine returns the buffer back to the buffer pool * so that it may be reused. The contents of the returned * buffer are not altered. * If there is no space available in the free list * the calling task will BLOCK. This won't happen unless * a buffer is accidentaly freed multiple times. * WARNING: * Don't return buffers multiple times or the buffer can * be multiply allocated. Not Good. * * * RETURNS: * VOID * * Author Greg Brissey 3/02/04 */ int mBufferReturn(MBUFFER_ID mBufferId,long item) /* MBUFFER_ID mBufferId - Fast Buffer to deallocate back to */ /* long item - Buffer Address being returned (deallocated) */ { long *sizeAddr; int index; register int toP; int stat; /* * RNG_LONG_PUT(fBufferId->freeList, item, toP); */ if (item == 0) { errLogRet(LOGIT,debugInfo,"mBufferReturn(): Error: Given NULL pointer to Return\n"); return -1; } #ifdef INSTRUMENT wvEvent(EVENT_FBUF_PUT,NULL,NULL); #endif stat = 0; taskLock(); sizeAddr = (long*) (item - sizeof(long)); /* size index is just ahead of buffer address */ /* fprintf(" item: 0x%lx, sizeAddr: 0x%lx, value: %ld\n", item,sizeAddr,*sizeAddr); */ index = *sizeAddr; DPRINT3(1,"mBufferReturn() - address: 0x%lx, sizeAddr: 0x%lx, keyIndex: 0x%lx\n", item,sizeAddr,index); if (index == 0xbada110c ) /* 99 */ { DPRINT2(0,"mBufferReturn(): Free buffer: 0x%lx, keyL 0x%lx\n", sizeAddr,index); free(sizeAddr); stat = 1; } else if ( (index & 0xffff0000) == 0xc0de0000) /* cluster index */ { index = index & 0x0000ffff; if ((index >= 0) && (index < mBufferId->numLists)) { DPRINT1(1," mBufferReturn() - into ringbuffer, cluster index: %d \n",index); stat = RNG_LONG_PUT(mBufferId->freeList[index],item,toP); } else { errLogRet(LOGIT,debugInfo, "mBufferReturn(): Error: IndexKey= 0x%lx illegal, legal values: %d - %d, (memory curruption)\n",index,0,mBufferId->numLists); stat = -1; } } else { errLogRet(LOGIT,debugInfo, "mBufferReturn(): Error: IndexKey= 0x%lx illegal.legal keys: 0xbada11loc or 0xc0de+index (memory curruption)\n",index); stat = -1; } taskUnlock(); return stat; }
/** *\brief does background work * */ static void * offline_task (void *x) { OfflineTask *rt = x; rt->state = 0; rt->current_tp = 0; rt->num_tp = 0; rt->num_pos = 0; rt->current_pos = 0; taskLock (&rt->t); while (taskRunning (&rt->t)) { time_t current_time; debugMsg ("offline_task iteration\n"); current_time = time (NULL); switch (rt->state) { case 0: if ((rt->adjust_interval != 0) && ((current_time - rt->last_adjust) > rt->adjust_interval)) { offline_task_adj_time (rt); rt->last_adjust = time (NULL); } if (rt->acq_duration != 0) { rt->state = 1; } break; case 1: //start vt acquisition if (!offline_task_vt_init (rt)) { if (!srvTuneTpi (rt->p, rt->current_pos, &rt->tpi[rt->current_tp])) { pgmdbScanTp (&rt->p->program_database); #ifdef WITH_VT selectorSndEv (&rt->p->dvb.ts_dmx.s, E_ALL_VT); #endif } rt->acq_start = current_time; rt->current_tp++; rt->state = 2; } else { rt->state = 0; } break; case 2: //next tp if (current_time > (rt->acq_start + rt->acq_duration)) { if (!offline_task_vt (rt)) { debugMsg ("tuning\n"); if (!srvTuneTpi (rt->p, rt->current_pos, &rt->tpi[rt->current_tp])) { debugMsg ("scanning\n"); pgmdbScanTp (&rt->p->program_database); #ifdef WITH_VT debugMsg ("E_ALL_VT\n"); selectorSndEv (&rt->p->dvb.ts_dmx.s, E_ALL_VT); #endif } else debugMsg ("tuning failed\n"); rt->acq_start = current_time; rt->current_tp++; } else { //acquisition complete(tried all transponders) if (0 != rt->idle_duration) { dvbUnTune (&rt->p->dvb); while (!pgmdbUntuned (&rt->p->program_database)) { debugPri (1, "pgmdbUntuned\n"); usleep (500000); } rt->idle_start = current_time; rt->state = 3; } else rt->state = 0; } } break; case 3: if (current_time > (rt->idle_start + rt->idle_duration)) rt->state = 0; break; default: break; } taskUnlock (&rt->t); sleep (2); taskLock (&rt->t); } dvbUnTune (&rt->p->dvb); while (!pgmdbUntuned (&rt->p->program_database)) { debugPri (1, "pgmdbUntuned\n"); usleep (500000); } taskUnlock (&rt->t); utlFAN (rt->tpi); rt->tpi = NULL; return NULL; }
int srvRstat (Connection * c) { uint8_t tag; DListE *e; PgmState *p = c->p; RecTask *rt = &p->recorder_task; ipcSndS (c->sockfd, SRV_NOERR); /* first iterate thru all connections and send their rec. status can I find the address of the socket? getpeername... getsockname.. */ e = dlistFirst (&p->conn_active); while (e) { Connection *c2 = (Connection *) e; if (recorderActive (&c2->quickrec)) { RState rs; struct sockaddr a; socklen_t len; tag = 0xff; ipcSndS (c->sockfd, tag); memset (&a, 0, sizeof (a)); len = sizeof (a); getpeername (c2->sockfd, &a, &len); //FIXXME: is it in net or host order? ipcSndS (c->sockfd, a.sa_family); ioBlkWr (c->sockfd, a.sa_data, sizeof (a.sa_data)); //here, 14 bytes ipcSndS (c->sockfd, c2->super); recorderGetState (&c2->quickrec, &rs); //TODO: make sure recorder is not stopped asynch.. not properly synchronized? ipcSndS (c->sockfd, c2->quickrec.pnr); ipcSndS (c->sockfd, rs.time); ipcSndS (c->sockfd, rs.size); } e = dlistENext (e); } tag = 0; ipcSndS (c->sockfd, tag); //start of scheduled recordings recTaskLock (rt); e = dlistFirst (&rt->active); while (e) { EitRec *er = dlistEPayload (e); taskLock (&er->t); tag = 0xfc; ipcSndS (c->sockfd, tag); rsSndEntry (er->e, c->sockfd); tag = er->eit_state; ipcSndS (c->sockfd, tag); ipcSndS (c->sockfd, er->start); ipcSndS (c->sockfd, er->last_eit_seen); ipcSndS (c->sockfd, er->last_id_seen); if (recorderActive (&er->rec)) //active, recording { RState rs; tag = 0xfd; ipcSndS (c->sockfd, tag); //active, running recorderGetState (&er->rec, &rs); ipcSndS (c->sockfd, er->rec.pnr); ipcSndS (c->sockfd, rs.time); ipcSndS (c->sockfd, rs.size); } else { tag = 0xfe; ipcSndS (c->sockfd, tag); //active, not running } taskUnlock (&er->t); e = dlistENext (e); } recTaskUnlock (rt); tag = 1; ipcSndS (c->sockfd, tag); //done return 0; }
STATUS taskDestroy( int taskId, BOOL freeStack, unsigned timeout, BOOL forceDestroy ) { STATUS status; int i, level; TCB_ID tcbId; if (INT_RESTRICT() != OK) { errnoSet (S_intLib_NOT_ISR_CALLABLE); return ERROR; } /* Get task context */ tcbId = taskTcb(taskId); if (tcbId == NULL) return ERROR; /* If task self destruct and excption lib installed */ if (tcbId == taskIdCurrent) { /* Wait for safe to destroy */ while (tcbId->safeCount > 0) taskUnsafe(); /* Kill it */ status = excJobAdd( (VOIDFUNCPTR) taskDestroy, (ARG) tcbId, (ARG) freeStack, (ARG) WAIT_NONE, (ARG) FALSE, (ARG) 0, (ARG) 0 ); /* Block here and suspend */ while(status == OK) taskSuspend(0); } /* End if task self destruct and exception lib installed */ taskDestroyLoop: /* Lock interrupts */ INT_LOCK(level); /* Check id */ if (TASK_ID_VERIFY(tcbId) != OK) { /* errno set by taskIdVerify() */ /* Unlock interrupts */ INT_UNLOCK(level); return ERROR; } /* Mask all signals */ if (tcbId->pSignalInfo != NULL) tcbId->pSignalInfo->sigt_blocked = 0xffffffff; /* Block here for safe and running locked tasks */ while ( (tcbId->safeCount > 0) || ( (tcbId->status == TASK_READY) && (tcbId->lockCount > 0) ) ) { /* Enter kernel mode */ kernelState = TRUE; /* Unlock interrupts */ INT_UNLOCK(level); /* Check if force deletion, or suicide */ if (forceDestroy || (tcbId == taskIdCurrent)) { /* Remove protections */ tcbId->safeCount = 0; tcbId->lockCount = 0; /* Check if flush of safety queue is needed */ if (Q_FIRST(&tcbId->safetyQ) != NULL) vmxPendQFlush(&tcbId->safetyQ); /* Exit trough kernel */ vmxExit(); } else { /* Not forced deletion or suicide */ /* Put task on safe queue */ if (vmxPendQPut(&tcbId->safetyQ, timeout) != OK) { /* Exit trough kernel */ vmxExit(); errnoSet (S_taskLib_INVALID_TIMEOUT); return ERROR; } /* Exit trough kernel */ status = vmxExit(); /* Check for restart */ if (status == SIG_RESTART) { timeout = (sigTimeoutRecalc)(timeout); goto taskDestroyLoop; } /* Check if unsuccessful */ if (status == ERROR) { /* timer should have set errno to S_objLib_TIMEOUT */ return ERROR; } } /* End else forced or suicide */ /* Lock interrupts */ INT_LOCK(level); /* Now verify class id again */ if (TASK_ID_VERIFY(tcbId) != OK) { /* errno set by taskIdVerify() */ /* Unlock interrupts */ INT_UNLOCK(level); return ERROR; } } /* End while blocked by safety */ /* Now only one cadidate is selected for deletion */ /* Make myself safe */ taskSafe(); /* Protet deletion cadidate */ tcbId->safeCount++; /* Check if not suicide */ if (tcbId != taskIdCurrent) { /* Enter kernel mode */ kernelState = TRUE; /* Unlock interrupts */ INT_UNLOCK(level); /* Suspend victim */ vmxSuspend(tcbId); /* Exit trough kernel */ vmxExit(); } else { /* Unlock interrupts */ INT_UNLOCK(level); } /* Run deletion hooks */ for (i = 0; i < MAX_TASK_DELETE_HOOKS; i++) if (taskDeleteHooks[i] != NULL) (*taskDeleteHooks[i])(tcbId); /* Lock task */ taskLock(); /* If dealloc and options dealloc stack */ if ( freeStack && (tcbId->options & TASK_OPTIONS_DEALLOC_STACK) ) { #if (_STACK_DIR == _STACK_GROWS_DOWN) objFree(taskClassId, tcbId->pStackEnd); #else /* _STACK_GROWS_UP */ objFree(taskClassId, tbcId - TASK_EXTRA_BYTES); #endif /* _STACK_DIR */ } /* Lock interrupts */ INT_LOCK(level); /* Invalidate id */ objCoreTerminate(&tcbId->objCore); /* Enter kernel mode */ kernelState = TRUE; /* Unlock interrupts */ INT_UNLOCK(level); /* Delete task */ status = vmxDelete(tcbId); /* Check if safe quque needs to be flushed */ if (Q_FIRST(&tcbId->safetyQ) != NULL) vmxPendQFlush(&tcbId->safetyQ); /* Exit trough kernel */ vmxExit(); /* Unprotect */ taskUnlock(); taskUnsafe(); return OK; }
/****************************************************************************** * * usrTimeAdj - routinely adjust system time with the Real-Time Clock * */ STATUS usrTimeAdj( int interval ) { static time_t lastFreq, lastTime, lastPeriod ; FAST time_t freq, t, t1; long dif; struct tm tm ; struct timespec tv ; if( interval == 0) interval = 120 ; freq = sysClkRateGet(); FOREVER { /* sleep until the next iteration */ taskDelay( interval * freq ); taskLock() ; sysRtcGet( &tm ); freq = sysClkRateGet(); t = time (NULL); taskUnlock(); if( t == ERROR ) { char buf[48]; int i=sizeof(buf); asctime_r( &tm, buf, &i ); logMsg("mktime error %s", (int) buf, 0,0,0,0,0); } t1 = mktime( &tm ); dif = t1 - t; /* how many seconds skew */ /* logMsg("t=%d t1=%d dif=%d\n", t, t1, dif, 0,0,0); */ /* if there is a serious difference, do a step adjustment */ if ((abs(dif) > 1) || (freq != lastFreq) ) { if(usrTimeDebug) { char buf[48]; int i=sizeof(buf); asctime_r( &tm, buf, &i ); logMsg("syncing clock %s", (int) buf, 0,0,0,0,0); } usrTimeSync(); /* update statics for next iteration */ lastFreq = freq ; lastPeriod = tv.tv_nsec = 1000000000 / freq ; lastTime = time(NULL) ; } #ifdef __XXX__ else if( dif != 0) { FAST time_t tmp ; /* otherwise, gradually adjust clock to RTC speed */ tv.tv_sec = 0; /* this expression must be carefully ordered, not to * get involved with 64-bit arithmetic which is * incomplete in the current version's library. */ tmp = lastPeriod / ((t - lastTime)*freq); tv.tv_nsec += tmp * dif ; clock_setres( CLOCK_REALTIME, &tv ); if(usrTimeDebug) logMsg("dif %d old period %d ns, new period %d ns, interval %d\n", dif, lastPeriod, tv.tv_nsec, t - lastTime, 0, 0 ); /* update statics for next iteration */ lastFreq = freq ; lastPeriod = tv.tv_nsec ; lastTime = t ; } #endif /*__XXX__*/ } /* FOREVER */ }