Esempio n. 1
0
void __init tc3162_time_init(void)
{
	//mips_timer_state = tc3162_timer_state;
	mips_timer_ack = tc3162_timer_ack;

	timerSet(1, TIMERTICKS_10MS, ENABLE, TIMER_TOGGLEMODE, TIMER_HALTDISABLE);
}
Esempio n. 2
0
void TimerWidget::setTimer()
{
   mediaPlayer->stop();
   stopFlashing();

   setTimer(lineEdit->text());
   emit timerSet(getTimerValue());
}
Esempio n. 3
0
static void hw_reset(void)
{
#ifdef CONFIG_TC3162_ADSL
    /* stop adsl */
	if (adsl_dev_ops)
	    adsl_dev_ops->set(ADSL_SET_DMT_CLOSE, NULL, NULL); 
#endif

    /* stop each module dma task */
	VPint(CR_INTC_IMR) = 0x0;
	VPint(CR_TIMER_CTL) = 0x0;

	/* stop mac dma */
#ifndef CONFIG_MIPS_TC3262
	VPint(CR_MAC_MACCR) = 0;
#endif

	/* stop atm sar dma */	
	TSARM_GFR &= ~((1 << 1) | (1 << 0));

	/* reset USB */
	/* reset USB DMA */
	VPint(CR_USB_SYS_CTRL_REG) |= (1 << 31);
	/* reset USB SIE */
	VPint(CR_USB_DEV_CTRL_REG) |= (1 << 30);
	mdelay(5);

	/* restore USB SIE */
	VPint(CR_USB_DEV_CTRL_REG) &= ~(1 << 30);
	mdelay(5);
	VPint(CR_USB_SYS_CTRL_REG) &= ~(1 << 31);

#ifdef CONFIG_MIPS_TC3162U
	/*stop pcie*/
	VPint(CR_AHB_PCIC) &= 0x9fffffff;
	/*reset usb 2.0 device*/
	/*stop interrupt*/
	VPint(CR_USB20_INTR_ENABLE_REG) = 0x0;
	/*do usb reset*/
	VPint(CR_USB20_SYS_CTRL_REG) |= (1 << 31);
	mdelay(1);
	VPint(CR_USB20_SYS_CTRL_REG) &= ~(1 << 31);
	/*sw disconnect*/
	VPint(CR_USB20_DEV_CTRL_REG) |= (1 << 31);
#endif

	/* watchdog reset */
//#ifdef CONFIG_MIPS_TC3262
	timerSet(5, 10 * TIMERTICKS_10MS, ENABLE, TIMER_TOGGLEMODE, TIMER_HALTDISABLE);
	timer_WatchDogConfigure(ENABLE, ENABLE);

	while (1);
//#endif
}
Esempio n. 4
0
InstructionWidget::InstructionWidget(QWidget* parent) :
   QWidget(parent), insObs(0), timer(new TimerWidget(this))
{
   setupUi(this);
   timer->setVisible(false);

   connect( checkBox_showTimer, SIGNAL(stateChanged(int)), this, SLOT(setHasTimer()) );
   connect( checkBox_completed, SIGNAL(stateChanged(int)), this, SLOT(setCompleted()) );
   connect( timer, SIGNAL(timerSet(QString)), this, SLOT(setTimerValue(QString)) );
   connect( textEdit, SIGNAL(textChanged()), this, SLOT(setDirections()) );
}
Esempio n. 5
0
void __init plat_time_init(void)
{
	unsigned int est_freq;

	timerSet(1, TIMERTICKS_10MS, ENABLE, TIMER_TOGGLEMODE, TIMER_HALTDISABLE);

	est_freq = estimate_cpu_frequency ();

	printk("CPU frequency %d.%02d MHz\n", est_freq/1000000,
	       (est_freq%1000000)*100/1000000);

    cpu_khz = est_freq / 1000;
}
Esempio n. 6
0
//=======================================================================================
char processWait(){
	enum {FIRST, SECOND};
	static char local_state = FIRST;

	switch (local_state){
		case FIRST:
			timerSet(TIMER_RADIO_WAIT, 0, TIMER_VALUE_RADIO_WAIT); // run nock noise timer
			local_state = SECOND;
		break;

		case SECOND:
			if (timerIsElapsed(TIMER_RADIO_WAIT) != TRUE) return FALSE;
			local_state = FIRST;
			return TRUE;
		break;

		default: break;
	}
	return FALSE;
}
Esempio n. 7
0
/*
 * Print a running summary of interface statistics.
 * Repeat display every interval seconds, showing statistics
 * collected over that interval.  Assumes that interval is non-zero.
 * First line printed at top of screen is always cumulative.
 */
static void
sidewaysintpr(unsigned int interval)
{
	register struct iftot *ip, *total;
	register int line;
	struct iftot *lastif, *sum, *interesting, ifnow, *now = &ifnow;
	struct variable_list *var;
	oid varname[MAX_OID_LEN], *instance, *ifentry;
	size_t varname_len;
	int ifnum, cfg_nnets;

	lastif = iftot;
	sum = iftot + MAXIF - 1;
	total = sum - 1;
	interesting = iftot;
	var = getvarbyname(Session, oid_cfg_nnets, sizeof(oid_cfg_nnets) / sizeof(oid));
	if (var) {
	    cfg_nnets = *var->val.integer;
	    snmp_free_var(var);
	}
	else
	    return;
	memmove(varname, oid_ifname, sizeof(oid_ifname));
	varname_len = sizeof(oid_ifname) / sizeof(oid);
	for (ifnum = 1, ip = iftot; ifnum <= cfg_nnets; ifnum++) {
		char *cp;

		ip->ift_name[0] = '(';
		varname[10] = ifnum;
		var = getvarbyname(Session, varname, varname_len);
		if (var){
		    if (var->val_len >= (sizeof(ip->ift_name) - 3))
		        var->val_len = (sizeof(ip->ift_name) - 4);
		    memmove(ip->ift_name + 1, var->val.string, var->val_len);
		    snmp_free_var(var);
		}
                cp = (char *) strchr(ip->ift_name, ' ');
                if ( cp != NULL )
                  *cp = '\0';
		if (intrface && strcmp(ip->ift_name + 1, intrface) == 0)
			interesting = ip;
		ip->ift_name[15] = '\0';
		cp = (char *) strchr(ip->ift_name, '\0');
		sprintf(cp, ")");
		ip++;
		if (ip >= iftot + MAXIF - 2)
			break;
	}
	lastif = ip;

	timerSet(interval);

banner:
	printf("     input   %-6.6s     output       ", interesting->ift_name);
	if (lastif - iftot > 0)
		printf("                 input  (Total)     output");
	for (ip = iftot; ip < iftot + MAXIF; ip++) {
		ip->ift_ip = 0;
		ip->ift_ie = 0;
		ip->ift_op = 0;
		ip->ift_oe = 0;
		ip->ift_co = 0;
	}
	putchar('\n');
	printf("%10.10s %8.8s %10.10s %8.8s %8.8s ",
		"packets", "errs", "packets", "errs", "colls");
	if (lastif - iftot > 0)
		printf("%10.10s %8.8s %10.10s %8.8s %8.8s ",
			"packets", "errs", "packets", "errs", "colls");
	putchar('\n');
	fflush(stdout);
	line = 0;
loop:
	sum->ift_ip = 0;
	sum->ift_ie = 0;
	sum->ift_op = 0;
	sum->ift_oe = 0;
	sum->ift_co = 0;
	memmove(varname, oid_ifinucastpkts, sizeof(oid_ifinucastpkts));
	varname_len = sizeof(oid_ifinucastpkts) / sizeof(oid);
	ifentry = varname + 9;
	instance = varname + 10;
	for (ifnum = 1, ip = iftot; ifnum <= cfg_nnets && ip < lastif; ip++, ifnum++) {
		memset(now, 0, sizeof(*now));
		*instance = ifnum;
		*ifentry = INUCASTPKTS;
		var = getvarbyname(Session, varname, varname_len);
		if (var) {
		    now->ift_ip = *var->val.integer;
		    snmp_free_var(var);
		}
		*ifentry = INNUCASTPKTS;
		var = getvarbyname(Session, varname, varname_len);
		if (var) {
		    now->ift_ip += *var->val.integer;
		    snmp_free_var(var);
		}
		*ifentry = INERRORS;
		var = getvarbyname(Session, varname, varname_len);
		if (var) {
		    now->ift_ie = *var->val.integer;
		    snmp_free_var(var);
		}
		*ifentry = OUTUCASTPKTS;
		var = getvarbyname(Session, varname, varname_len);
		if (var) {
		    now->ift_op = *var->val.integer;
		    snmp_free_var(var);
		}
		*ifentry = OUTNUCASTPKTS;
		var = getvarbyname(Session, varname, varname_len);
		if (var) {
		    now->ift_op += *var->val.integer;
		    snmp_free_var(var);
		}
		*ifentry = OUTERRORS;
		var = getvarbyname(Session, varname, varname_len);
		if (var) {
		    now->ift_oe = *var->val.integer;
		    snmp_free_var(var);
		}

		if (ip == interesting)
			printf("%10d %8d %10d %8d %8d ",
				now->ift_ip - ip->ift_ip,
				now->ift_ie - ip->ift_ie,
				now->ift_op - ip->ift_op,
				now->ift_oe - ip->ift_oe,
				now->ift_co - ip->ift_co);
		ip->ift_ip = now->ift_ip;
		ip->ift_ie = now->ift_ie;
		ip->ift_op = now->ift_op;
		ip->ift_oe = now->ift_oe;
		ip->ift_co = now->ift_co;
		sum->ift_ip += ip->ift_ip;
		sum->ift_ie += ip->ift_ie;
		sum->ift_op += ip->ift_op;
		sum->ift_oe += ip->ift_oe;
		sum->ift_co += ip->ift_co;
	}
	if (lastif - iftot > 0)
		printf("%10d %8d %10d %8d %8d ",
			sum->ift_ip - total->ift_ip,
			sum->ift_ie - total->ift_ie,
			sum->ift_op - total->ift_op,
			sum->ift_oe - total->ift_oe,
			sum->ift_co - total->ift_co);
	*total = *sum;
	putchar('\n');
	fflush(stdout);
	line++;

	timerPause();
	timerSet(interval);

	if (line == 21)
		goto banner;
	goto loop;
	/*NOTREACHED*/
}
Esempio n. 8
0
void colibrateDetector(){

	enum {GOTOPAUSE, PAUSE, CHECKEXT, PROCESSBUTTON, PROCESSNOCK};
	static char state = GOTOPAUSE;
	
	switch (state){

		case GOTOPAUSE:

			#ifdef LOGGDEBUG
			loggerWriteToMarker((LogMesT)" GOTOPAUSE \r*", '*');
			#endif

			ledOff(LEDRED1);
			ledOff(LEDRED2);
			ledOff(LEDGREEN1);
			ledOff(LEDGREEN2);

			timerSet(TIMER_NOCK, 0, 30);
			state = PAUSE;
			break;

		case PAUSE:

			if (timerIsElapsed(TIMER_NOCK) == TRUE){
				state = CHECKEXT;
			}
			break;

		case CHECKEXT:

			if(buttonIsPressed(BUTTONDOOR) == TRUE){

				#ifdef LOGGDEBUG
				loggerWriteToMarker((LogMesT)" setNextSence \r*", '*');
				#endif

				setNextSence();
				changeFlag(FLAG_NOCK, FALSE);

				ledOn(LEDRED1);
				ledOn(LEDRED2);
				_delay_ms(300);
				ledOff(LEDRED1);
				ledOff(LEDRED2);


				state = GOTOPAUSE;
				return;
			}

			if (getFlag(FLAG_NOCK) == TRUE){
				state = PROCESSNOCK;
			}
				
			break;

		case PROCESSNOCK:
			
			#ifdef LOGGDEBUG
			loggerWriteToMarker((LogMesT)" PROCESSNOCK \r*", '*');
			#endif

			ledOn(LEDGREEN1);
			ledOn(LEDGREEN2);
			_delay_ms(300);
			ledOff(LEDGREEN1);
			ledOff(LEDGREEN2);

					
			changeFlag(FLAG_NOCK, FALSE);
			state = CHECKEXT;

			break;

		default: break;
	} 

}
Esempio n. 9
0
Q_DECL_EXPORT int main(int argc, char *argv[])
{
    QScopedPointer<QGuiApplication> app(Sailfish::createApplication(argc, argv));
    QScopedPointer<QQuickView> view(Sailfish::createView("main.qml"));
    QScopedPointer<QQuickView> viewPage2(Sailfish::createView("pages/SecondPage.qml"));
    //------------------

    //Label do ktorego sa wrzucane komunikaty z serwera (tekstowe)
    LabelClass * lblC = new LabelClass();
    //Label odpowiedzialny za obsługe zegara
    LabelClock * lblClock = new LabelClock();
    //Zbior labeli odpowiedzialny za zmiane stanu etykiet informacyjnych
    LabelSet  * lblSet = new LabelSet();


    //Powiazanie obiektow LabelClass i LabelClock z elementami interfejsu
    view->rootContext()->setContextProperty("LabelClass",lblC);
    view->rootContext()->setContextProperty("LabelClock",lblClock);

    //----------------------
    //Powiazanie obiektow etykiet z elementami interfejsu.
     QObject * lblLoud = view->rootObject()->findChild<QObject*>("lblLoud");
     lblSet->lblLoud = lblLoud;
     QObject * lblQuit = view->rootObject()->findChild<QObject*>("lblQuit");
     lblSet->lblQuit = lblQuit;
     QObject * lblFast = view->rootObject()->findChild<QObject*>("lblFast");
     lblSet->lblFast = lblFast;
     QObject * lblSlow = view->rootObject()->findChild<QObject*>("lblSlow");
     lblSet ->lblSlow = lblSlow;
     QObject * lblNext = view->rootObject()->findChild<QObject*>("lblNext");
     lblSet ->lblNext = lblNext;
    //----------------------
    //Utworzenie obiektu serwera
    Server * s = new Server(0,lblC,lblSet);
    //nasluchiwanie serwera
    s->listen();
    //--------------------

    //Oniekt klasy Common zawierajacej metody
    Common common;

    lblClock->setbtnName("Rozpocznij prezentację");
    lblClock->settime("0:0:0");

    //--------------------

    //Wyszukanie Page z main.qml.
    QObject *itemPage = view->rootObject()->findChild<QObject*>("pol3");

    //----------------------
    //Powiazanie sygnalow ze slotami
    QObject::connect(itemPage, SIGNAL(qmlSignalTimerChange(QString)),lblClock, SLOT(timerSet(QString)));
    QObject::connect(itemPage, SIGNAL(qmlSignal(QString)),&common, SLOT(cppSlot(QString)));
    QObject::connect(itemPage, SIGNAL(qmlSignal(QString)), &common,SLOT(cppDisconect(QString)));
    QObject::connect(itemPage, SIGNAL(qmlSignalStartClock()),lblClock, SLOT(timerStop()));

    //----------------------

    Sailfish::showView(view.data());


    return app->exec();
}
Esempio n. 10
0
void
TTwaitForChar(void)
{
#if MEOPT_MOUSE
    union REGS rg ;

    if(meMouseCfg & meMOUSE_ENBLE)
    {
        meUShort mc ;
        meUInt arg ;
        /* If mouse state flags that the mouse should be visible then we
         * must make it visible. We had to make it invisible to get the
         * screen-updates correct
         */
        if(mouseState & MOUSE_STATE_SHOW)
        {
            mouseState |= MOUSE_STATE_VISIBLE ;
            rg.x.ax = 0x0001 ;
            int86(0x33, &rg, &rg) ;
        }
        
        /* If no keys left then if theres currently no mouse timer and
         * theres a button press (No mouse-time key) then check for a
         * time-mouse-? key, if found add a timer start a mouse checking
         */
        if(!isTimerActive(MOUSE_TIMER_ID) &&
           ((mc=(mouseState & MOUSE_STATE_BUTTONS)) != 0))
        {
            mc = ME_SPECIAL | TTmodif | (SKEY_mouse_time+mouseKeys[mc]) ;
            if((!TTallKeys && (decode_key(mc,&arg) != -1)) || (TTallKeys & 0x2))
            {
                /* Start a timer and move to timed state 1 */
                /* Start a new timer to clock in at 'delay' intervals */
                /* printf("Setting mouse timer for delay  %1x %1x %d\n",TTallKeys,meTimerState[MOUSE_TIMER_ID],delayTime) ;*/
                timerSet(MOUSE_TIMER_ID,-1,delayTime);
            }
        }
    }
#endif
#if MEOPT_CALLBACK
    /* IDLE TIME: Check the idle time events */        
    if(kbdmode == meIDLE)
        /* Check the idle event */
        doIdlePickEvent() ;
#endif
    
    for(;;)
    {
        handleTimerExpired() ;
        if(TTahead())
            break ;
#if MEOPT_MOUSE
        if(meMouseCfg & meMOUSE_ENBLE)
        {
            meShort row, col, but ;
            meUShort cc ;
            
            /* Get new mouse status. It appears that the fractional bits of
             * the mouse change across reads. ONLY Compare the non-fractional
             * components.
             */
            rg.x.ax = 0x0003 ;
            int86(0x33, &rg, &rg) ;
            but = rg.x.bx & MOUSE_STATE_BUTTONS ;
            col = rg.x.cx>>3 ;
            row = rg.x.dx>>3 ;
            
            /* Check for mouse state changes */
            if(((mouseState ^ but) & MOUSE_STATE_BUTTONS) || 
               (mouse_X != col) || (mouse_Y != row))
            {
                int ii ;
                
                /* Get shift status */
                rg.h.ah = 0x02;
                int86(0x16,&rg,&rg) ;
                TTmodif = ((rg.h.al & 0x01) << 8) | ((rg.h.al & 0x0E) << 7) ;
                
                /* Record the new mouse positions */
                mouse_X = col ;
                mouse_Y = row ;
                
                /* Check for button changes, these always create keys */
                if((mouseState ^ but) & MOUSE_STATE_BUTTONS)
                {
                    /* Iterate down the bit pattern looking for changes
                     * of state */
                    for (ii=1 ; ii<8 ; ii<<=1)
                    {
                        /* Test each key and add to the stack */
                        if((mouseState ^ but) & ii)
                        {
                            /* Up or down press ?? */
                            if(but & ii)
                                cc = ME_SPECIAL+SKEY_mouse_pick_1-1 ;     /* Down  */
                            else
                                cc = ME_SPECIAL+SKEY_mouse_drop_1-1 ;     /* Up !! */
                            cc = TTmodif | (cc + mouseKeys[ii]) ;
                            addKeyToBuffer(cc) ;
                        }
                    }
                    /* Correct the mouse state */
                    mouseState = (mouseState & ~MOUSE_STATE_BUTTONS) | but ;
                }
                else
                {
                    meUInt arg;                 /* Decode key argument */
                    /* Check for a mouse-move key */
                    cc = (ME_SPECIAL+SKEY_mouse_move+mouseKeys[but]) | TTmodif ;
                    /* Are we after all movements or mouse-move bound ?? */
                    if((!TTallKeys && (decode_key(cc,&arg) != -1)) || (TTallKeys & 0x1))
                        addKeyToBuffer(cc) ;        /* Add key to keyboard buffer */
                    else
                    {
                        /* Mouse has been moved so we must make it visible */
                        if(!(mouseState & MOUSE_STATE_VISIBLE))
                        {
                            mouseState |= MOUSE_STATE_VISIBLE ;
                            rg.x.ax = 0x0001 ;
                            int86(0x33, &rg, &rg) ;
                        }
                        continue ;
                    }
                }
                /* As we are adding a mouse key, the mouse is active
                 * so add the 'show' flag, so on entry next time
                 * the mouse will automatically become visible.
                 */
                mouseState |= MOUSE_STATE_SHOW ;
                break ;
            }
        }
#endif
    } /* ' for' */
Esempio n. 11
0
//------------------------------------------------------------------------------
static uint8_t serialProcess(Application *app)
{
    uint16_t count = RingBuffer_GetCount(&app->buffer_);
    if(count == 0)
        return true;

    uint8_t cmd = RingBuffer_Peek(&app->buffer_);
    switch(cmd)
    {
        case 'L':
            RingBuffer_Remove(&app->buffer_);
            LEDs_ToggleLEDs(LEDS_LED1);
            break;

        case 'R':
            RingBuffer_Remove(&app->buffer_);
            asicReset();
            asicResetSpi();
            app->state.state = STATE_RESET;
            sendCmdReply(app, cmd, (uint8_t *)&app->state, sizeof(State));
            break;

        case 'I':
            RingBuffer_Remove(&app->buffer_);
            sendCmdReply(app, cmd, (uint8_t *)&ID, sizeof(ID));
            break;

        case 'A':
            RingBuffer_Remove(&app->buffer_);
            app->state.state = STATE_RESET;
            asicStop();
            sendCmdReply(app, cmd, (uint8_t *)&app->state, sizeof(State));
            break;

        case 'S':
            RingBuffer_Remove(&app->buffer_);
            sendCmdReply(app, cmd, (uint8_t *)&app->state, sizeof(State));
            break;

        case 'W':
            if(count > 44) // 32 bytes midstate + 12 bytes data
            {
                RingBuffer_Remove(&app->buffer_);

                uint8_t i = 0;
                uint8_t *midstate = (uint8_t *)app->worktask.midstate;
                uint8_t *data = (uint8_t *)app->worktask.data;
                for(i=0; i<32; i++)
                {
                    midstate[i] = RingBuffer_Remove(&app->buffer_);
                }
                for(i=0; i<12; i++)
                {
                    data[i] = RingBuffer_Remove(&app->buffer_);
                }

                asicPrecalc(app->worktask.midstate, app->worktask.data, app->worktask.precalc);

                app->state.state = STATE_WORKING;
                app->state.nonce_valid = 0;
                app->state.nonce = 0;

                asicReset();
                asicResetSpi();
                pushWork(app, &app->worktask);
                timerSet(&app->work_timer, 16000);

                sendCmdReply(app, cmd, (uint8_t *)&app->state, sizeof(State));
            }
            break;

        default:
            RingBuffer_Remove(&app->buffer_);
            break;
    }

    return true;
}
Esempio n. 12
0
void UserInterface::time(void)
{
    bool switch_pressed = false;

    switch (_switch_state)
    {
        case SWITCH_STATE__NONE:
            break;

        case SWITCH_STATE__DEPRESSED:
            return;

        case SWITCH_STATE__SHORT_PRESS:
            _timer_pause ^= 1;
            switch_pressed = true;
            _sleep = millis();
            break;

        case SWITCH_STATE__LONG_PRESS:
            FastLED.clear(true);
            timerStop();
            _timer_state = TIMER_STATE__INIT;
            _timer_pause = 1;
            Display::time(0, _minutes);
            _sleep = millis();
            break;
    }

    switch (_timer_state)
    {
        case TIMER_STATE__INIT:
            if ((_minutes == 0) || _timer_pause)
                return;

            timerSet();
            timerStart();

            _timer_state = TIMER_STATE__TIMER;
            break;

        case TIMER_STATE__TIMER:
            if (s_seconds == 0)
            {
                timerStop();
                _timer_state = TIMER_STATE__ALERT;
            }
            else if (switch_pressed)
            {
                if (_timer_pause)
                    timerStop();
                else
                    timerStart();
            }
            break;

        case TIMER_STATE__ALERT:
            if (switch_pressed)
            {
                _timer_state = TIMER_STATE__DONE;
                _timer_pause = 0;
            }
            else
            {
                timerAlert();  // Blocking until switch pressed
            }
            break;

        case TIMER_STATE__DONE:
            if (switch_pressed)
            {
                Display::time(0, _minutes);
                _timer_pause = 1;
                _timer_state = TIMER_STATE__INIT;
            }  
            break;
    }
}
Esempio n. 13
0
PASTIX_INT simuInit(SimuCtrl *simuctrl, SymbolMatrix *symbptr, PASTIX_INT clustnbr, PASTIX_INT procnbr,
             PASTIX_INT cblknbr, PASTIX_INT bloknbr, Cand *candtab)
{
    PASTIX_INT i, j;
    PASTIX_INT p;
    PASTIX_INT ftgtcur;
    PASTIX_INT candnbr;
    PASTIX_INT step;

    simuctrl->cblknbr  = cblknbr;
    simuctrl->ftgtprio = 0;
    simuctrl->tasktab  = NULL;
    simuctrl->ftgtcnt  = 0;

    /** Processor initialisation **/
    MALLOC_INTERN(simuctrl->proctab, procnbr, SimuProc);
    for(i=0;i<procnbr;i++)
        {
          timerSet(TIMER(i), 0.0); /** for paragraph numeric tolerance **/
          simuctrl->proctab[i].prionum   = 0;
          MALLOC_INTERN(simuctrl->proctab[i].taskheap,  1, Queue);
          MALLOC_INTERN(simuctrl->proctab[i].taskheap2, 1, Queue);
          queueInit(simuctrl->proctab[i].taskheap,  100);
          queueInit(simuctrl->proctab[i].taskheap2, 100);

          MALLOC_INTERN(simuctrl->proctab[i].tasktab, 1, ExtendVectorINT);
          extendint_Init(simuctrl->proctab[i].tasktab, bloknbr/procnbr + 1);
        }

    /** Cluster initialization **/
    MALLOC_INTERN(simuctrl->clustab, clustnbr, SimuCluster);
    step = procnbr / clustnbr;
    for(i=0;i<clustnbr;i++)
      {
        simuctrl->clustab[i].fprocnum = i*step;
        simuctrl->clustab[i].lprocnum = simuctrl->clustab[i].fprocnum + step - 1;
        MALLOC_INTERN(simuctrl->clustab[i].ftgtsend, clustnbr, ExtendVectorINT);
        simuctrl->clustab[i].prionum  = 0;
        for(p=0;p<clustnbr;p++)
          extendint_Init(&(simuctrl->clustab[i].ftgtsend[p]), cblknbr/(2*clustnbr)+1);
      }
    simuctrl->clustab[clustnbr-1].lprocnum = procnbr-1;

    MALLOC_INTERN(simuctrl->ownetab, cblknbr, PASTIX_INT);
    MALLOC_INTERN(simuctrl->blprtab, bloknbr, PASTIX_INT);

    /* affect a negative value to cblk not mapped */
    for(i=0;i<cblknbr;i++)
      simuctrl->ownetab[i] = -1;
    for(i=0;i<bloknbr;i++)
      simuctrl->blprtab[i] = -1;


    MALLOC_INTERN(simuctrl->cblktab, cblknbr+1, SimuCblk);
    MALLOC_INTERN(simuctrl->bloktab, bloknbr+1, SimuBlok);
    ftgtcur = 0;

    for(i=0;i<cblknbr;i++)
      {
        candnbr = candtab[i].lccandnum - candtab[i].fccandnum + 1;
        simuctrl->cblktab[i].ctrbcnt = 0;

        for(j=symbptr->cblktab[i].bloknum;j<symbptr->cblktab[i+1].bloknum;j++)
          {
            simuctrl->bloktab[j].ftgtnum = ftgtcur;
            simuctrl->bloktab[j].tasknum = -1;
            simuctrl->bloktab[j].ctrbcnt = 0;
            /*if(candnbr > 1)*/
            ftgtcur += candnbr;
          }
      }
    /* one extracblk for avoiding side effect */
    simuctrl->bloktab[bloknbr].ftgtnum = ftgtcur;
    simuctrl->ftgtnbr = ftgtcur;

    if(simuctrl->ftgtnbr > 0)
        {
          /** Allocate and Initialize the timer for the reception of each ftgt on a candidate cluster **/
          MALLOC_INTERN(simuctrl->ftgttimetab, simuctrl->ftgtnbr, SimuTimer);
          for(i=0;i<simuctrl->ftgtnbr;i++)
            timerSet(&(simuctrl->ftgttimetab[i]), 0.0);

          MALLOC_INTERN(simuctrl->ftgttab, ftgtcur, SimuFtgt);
          for(i=0;i<simuctrl->ftgtnbr;i++)
            {
              simuctrl->ftgttab[i].clustnum = -1;
              timerSet(&(simuctrl->ftgttab[i].timerecv), 0.0);
              simuctrl->ftgttab[i].costsend = 0.0;
              simuctrl->ftgttab[i].costadd  = 0.0;
              bzero(simuctrl->ftgttab[i].ftgt.infotab,MAXINFO*sizeof(PASTIX_INT));
              simuctrl->ftgttab[i].ftgt.infotab[FTGT_FCOLNUM] = INTVALMAX;
              simuctrl->ftgttab[i].ftgt.infotab[FTGT_FROWNUM] = INTVALMAX;
              simuctrl->ftgttab[i].ftgt.infotab[FTGT_CTRBNBR] = 0;
              simuctrl->ftgttab[i].ftgt.infotab[FTGT_CTRBCNT] = 0;
            }
        }
    else
        {
            simuctrl->ftgttab     = NULL;
            simuctrl->tasktimetab = NULL;
            simuctrl->ftgttimetab = NULL;
        }

    return 1;
}
Esempio n. 14
0
void evalFunctions()
#endif
{
  MASK_FUNC_TYPE newActiveFunctions  = 0;
  MASK_CFN_TYPE  newActiveSwitches = 0;

#if defined(ROTARY_ENCODERS) && defined(GVARS)
  static rotenc_t rePreviousValues[ROTARY_ENCODERS];
#endif

#if defined(OVERRIDE_CHANNEL_FUNCTION)
  for (uint8_t i=0; i<NUM_CHNOUT; i++) {
    safetyCh[i] = OVERRIDE_CHANNEL_UNDEFINED;
  }
#endif

#if defined(GVARS)
  for (uint8_t i=0; i<NUM_STICKS; i++) {
    trimGvar[i] = -1;
  }
#endif

  for (uint8_t i=0; i<NUM_CFN; i++) {
    const CustomFunctionData *cfn = &functions[i];
    int8_t swtch = CFN_SWITCH(cfn);
    if (swtch) {
      MASK_CFN_TYPE  switch_mask = ((MASK_CFN_TYPE)1 << i);

#if defined(CPUARM)
      bool active = getSwitch(swtch, IS_PLAY_FUNC(CFN_FUNC(cfn)) ? GETSWITCH_MIDPOS_DELAY : 0);
#else
      bool active = getSwitch(swtch);
#endif

      if (HAS_ENABLE_PARAM(CFN_FUNC(cfn))) {
        active &= (bool)CFN_ACTIVE(cfn);
      }

      if (active || IS_PLAY_BOTH_FUNC(CFN_FUNC(cfn))) {

        switch (CFN_FUNC(cfn)) {

#if defined(OVERRIDE_CHANNEL_FUNCTION)
          case FUNC_OVERRIDE_CHANNEL:
            safetyCh[CFN_CH_INDEX(cfn)] = CFN_PARAM(cfn);
            break;
#endif

          case FUNC_TRAINER:
          {
            uint8_t mask = 0x0f;
            if (CFN_CH_INDEX(cfn) > 0) {
              mask = (1<<(CFN_CH_INDEX(cfn)-1));
            }
            newActiveFunctions |= mask;
            break;
          }

          case FUNC_INSTANT_TRIM:
            newActiveFunctions |= (1 << FUNCTION_INSTANT_TRIM);
            if (!isFunctionActive(FUNCTION_INSTANT_TRIM)) {
#if defined(GUI)
              if (g_menuStack[0] == menuMainView
#if defined(FRSKY)
                || g_menuStack[0] == menuTelemetryFrsky
#endif
#if defined(PCBTARANIS)
                || g_menuStack[0] == menuMainViewChannelsMonitor
                || g_menuStack[0] == menuChannelsView
#endif
              )
#endif
              {
                instantTrim();
              }
            }
            break;

          case FUNC_RESET:
            switch (CFN_PARAM(cfn)) {
              case FUNC_RESET_TIMER1:
              case FUNC_RESET_TIMER2:
#if defined(CPUARM)
              case FUNC_RESET_TIMER3:
#endif
                timerReset(CFN_PARAM(cfn));
                break;
              case FUNC_RESET_FLIGHT:
                flightReset();
                break;
#if defined(FRSKY)
              case FUNC_RESET_TELEMETRY:
                telemetryReset();
                break;
#endif
#if ROTARY_ENCODERS > 0
              case FUNC_RESET_ROTENC1:
#if ROTARY_ENCODERS > 1
              case FUNC_RESET_ROTENC2:
#endif
                g_rotenc[CFN_PARAM(cfn)-FUNC_RESET_ROTENC1] = 0;
                break;
#endif
            }
#if defined(CPUARM)
            if (CFN_PARAM(cfn)>=FUNC_RESET_PARAM_FIRST_TELEM) {
              TelemetryItem * telemetryItem = & telemetryItems[CFN_PARAM(cfn)-FUNC_RESET_PARAM_FIRST_TELEM];
              telemetryItem->clear();
            }
#endif
            break;

#if defined(CPUARM)
          case FUNC_SET_TIMER:
          {
            timerSet(CFN_TIMER_INDEX(cfn), CFN_PARAM(cfn));
            break;
          }
#endif

#if 0 //defined(DANGEROUS_MODULE_FUNCTIONS)
          case FUNC_RANGECHECK:
          case FUNC_BIND:
          case FUNC_MODULE_OFF:
          {
            unsigned int moduleIndex = CFN_PARAM(cfn);
            if (moduleIndex < NUM_MODULES) {
              moduleFlag[moduleIndex] = 1 + CFN_FUNC(cfn) - FUNC_RANGECHECK;
            }
            break;
          }
#endif

#if defined(GVARS)
          case FUNC_ADJUST_GVAR:
            if (CFN_GVAR_MODE(cfn) == 0) {
              SET_GVAR(CFN_GVAR_INDEX(cfn), CFN_PARAM(cfn), mixerCurrentFlightMode);
            }
            else if (CFN_GVAR_MODE(cfn) == 2) {
              SET_GVAR(CFN_GVAR_INDEX(cfn), GVAR_VALUE(CFN_PARAM(cfn), mixerCurrentFlightMode), mixerCurrentFlightMode);
            }
            else if (CFN_GVAR_MODE(cfn) == 3) {
              if (!(functionsContext.activeSwitches & switch_mask)) {
                SET_GVAR(CFN_GVAR_INDEX(cfn), GVAR_VALUE(CFN_GVAR_INDEX(cfn), getGVarFlightPhase(mixerCurrentFlightMode, CFN_GVAR_INDEX(cfn))) + (CFN_PARAM(cfn) ? +1 : -1), mixerCurrentFlightMode);
              }
            }
            else if (CFN_PARAM(cfn) >= MIXSRC_TrimRud && CFN_PARAM(cfn) <= MIXSRC_TrimAil) {
              trimGvar[CFN_PARAM(cfn)-MIXSRC_TrimRud] = CFN_GVAR_INDEX(cfn);
            }
#if defined(ROTARY_ENCODERS)
            else if (CFN_PARAM(cfn) >= MIXSRC_REa && CFN_PARAM(cfn) < MIXSRC_TrimRud) {
              int8_t scroll = rePreviousValues[CFN_PARAM(cfn)-MIXSRC_REa] - (g_rotenc[CFN_PARAM(cfn)-MIXSRC_REa] / ROTARY_ENCODER_GRANULARITY);
              if (scroll) {
                SET_GVAR(CFN_GVAR_INDEX(cfn), GVAR_VALUE(CFN_GVAR_INDEX(cfn), getGVarFlightPhase(mixerCurrentFlightMode, CFN_GVAR_INDEX(cfn))) + scroll, mixerCurrentFlightMode);
              }
            }
#endif
            else {
              SET_GVAR(CFN_GVAR_INDEX(cfn), calcRESXto100(getValue(CFN_PARAM(cfn))), mixerCurrentFlightMode);
            }
            break;
#endif

#if defined(CPUARM) && defined(SDCARD)
          case FUNC_VOLUME:
          {
            getvalue_t raw = getValue(CFN_PARAM(cfn));
            //only set volume if input changed more than hysteresis
            if (abs(requiredSpeakerVolumeRawLast - raw) > VOLUME_HYSTERESIS) {
              requiredSpeakerVolumeRawLast = raw;
            }
            requiredSpeakerVolume = ((1024 + requiredSpeakerVolumeRawLast) * VOLUME_LEVEL_MAX) / 2048;
            break;
          }
#endif

#if defined(CPUARM) && defined(SDCARD)
          case FUNC_PLAY_SOUND:
          case FUNC_PLAY_TRACK:
          case FUNC_PLAY_VALUE:
#if defined(HAPTIC)
          case FUNC_HAPTIC:
#endif
          {
            tmr10ms_t tmr10ms = get_tmr10ms();
            uint8_t repeatParam = CFN_PLAY_REPEAT(cfn);
            if (!IS_SILENCE_PERIOD_ELAPSED() && repeatParam == CFN_PLAY_REPEAT_NOSTART) {
              functionsContext.lastFunctionTime[i] = tmr10ms;
            }
            if (!functionsContext.lastFunctionTime[i] || (repeatParam && repeatParam!=CFN_PLAY_REPEAT_NOSTART && (signed)(tmr10ms-functionsContext.lastFunctionTime[i])>=100*repeatParam)) {
              if (!IS_PLAYING(i+1)) {
                functionsContext.lastFunctionTime[i] = tmr10ms;
                if (CFN_FUNC(cfn) == FUNC_PLAY_SOUND) {
                  AUDIO_PLAY(AU_FRSKY_FIRST+CFN_PARAM(cfn));
                }
                else if (CFN_FUNC(cfn) == FUNC_PLAY_VALUE) {
                  PLAY_VALUE(CFN_PARAM(cfn), i+1);
                }
#if defined(HAPTIC)
                else if (CFN_FUNC(cfn) == FUNC_HAPTIC) {
                  haptic.event(AU_FRSKY_LAST+CFN_PARAM(cfn));
                }
#endif
                else {
                  playCustomFunctionFile(cfn, i+1);
                }
              }
            }
            break;
          }

          case FUNC_BACKGND_MUSIC:
            newActiveFunctions |= (1 << FUNCTION_BACKGND_MUSIC);
            if (!IS_PLAYING(i+1)) {
              playCustomFunctionFile(cfn, i+1);
            }
            break;

          case FUNC_BACKGND_MUSIC_PAUSE:
            newActiveFunctions |= (1 << FUNCTION_BACKGND_MUSIC_PAUSE);
            break;

#elif defined(VOICE)
          case FUNC_PLAY_SOUND:
          case FUNC_PLAY_TRACK:
          case FUNC_PLAY_BOTH:
          case FUNC_PLAY_VALUE:
          {
            tmr10ms_t tmr10ms = get_tmr10ms();
            uint8_t repeatParam = CFN_PLAY_REPEAT(cfn);
            if (!functionsContext.lastFunctionTime[i] || (CFN_FUNC(cfn)==FUNC_PLAY_BOTH && active!=(bool)(functionsContext.activeSwitches&switch_mask)) || (repeatParam && (signed)(tmr10ms-functionsContext.lastFunctionTime[i])>=1000*repeatParam)) {
              functionsContext.lastFunctionTime[i] = tmr10ms;
              uint8_t param = CFN_PARAM(cfn);
              if (CFN_FUNC(cfn) == FUNC_PLAY_SOUND) {
                AUDIO_PLAY(AU_FRSKY_FIRST+param);
              }
              else if (CFN_FUNC(cfn) == FUNC_PLAY_VALUE) {
                PLAY_VALUE(param, i+1);
              }
              else {
#if defined(GVARS)
                if (CFN_FUNC(cfn) == FUNC_PLAY_TRACK && param > 250)
                  param = GVAR_VALUE(param-251, getGVarFlightPhase(mixerCurrentFlightMode, param-251));
#endif
                PUSH_CUSTOM_PROMPT(active ? param : param+1, i+1);
              }
            }
            if (!active) {
              // PLAY_BOTH would change activeFnSwitches otherwise
              switch_mask = 0;
            }
            break;
          }
#else
          case FUNC_PLAY_SOUND:
          {
            tmr10ms_t tmr10ms = get_tmr10ms();
            uint8_t repeatParam = CFN_PLAY_REPEAT(cfn);
            if (!functionsContext.lastFunctionTime[i] || (repeatParam && (signed)(tmr10ms-functionsContext.lastFunctionTime[i])>=1000*repeatParam)) {
              functionsContext.lastFunctionTime[i] = tmr10ms;
              AUDIO_PLAY(AU_FRSKY_FIRST+CFN_PARAM(cfn));
            }
            break;
          }
#endif

#if defined(FRSKY) && defined(VARIO)
          case FUNC_VARIO:
            newActiveFunctions |= (1 << FUNCTION_VARIO);
            break;
#endif

#if defined(HAPTIC) && !defined(CPUARM)
          case FUNC_HAPTIC:
          {
            tmr10ms_t tmr10ms = get_tmr10ms();
            uint8_t repeatParam = CFN_PLAY_REPEAT(cfn);
            if (!functionsContext.lastFunctionTime[i] || (repeatParam && (signed)(tmr10ms-functionsContext.lastFunctionTime[i])>=1000*repeatParam)) {
              functionsContext.lastFunctionTime[i] = tmr10ms;
              haptic.event(AU_FRSKY_LAST+CFN_PARAM(cfn));
            }
            break;
          }
#endif

#if defined(SDCARD)
          case FUNC_LOGS:
            if (CFN_PARAM(cfn)) {
              newActiveFunctions |= (1 << FUNCTION_LOGS);
              logDelay = CFN_PARAM(cfn);
            }
            break;
#endif

          case FUNC_BACKLIGHT:
            newActiveFunctions |= (1 << FUNCTION_BACKLIGHT);
            break;

#if defined(PCBTARANIS)
          case FUNC_SCREENSHOT:
            if (!(functionsContext.activeSwitches & switch_mask)) {
              requestScreenshot = true;
            }
            break;
#endif

#if defined(DEBUG)
          case FUNC_TEST:
            testFunc();
            break;
#endif
        }

        newActiveSwitches |= switch_mask;
      }
      else {
        functionsContext.lastFunctionTime[i] = 0;
      }
    }
  }

  functionsContext.activeSwitches   = newActiveSwitches;
  functionsContext.activeFunctions  = newActiveFunctions;

#if defined(ROTARY_ENCODERS) && defined(GVARS)
  for (uint8_t i=0; i<ROTARY_ENCODERS; i++) {
    rePreviousValues[i] = (g_rotenc[i] / ROTARY_ENCODER_GRANULARITY);
  }
#endif
}