예제 #1
0
static struct gyro_context *gyro_context_alloc_object(void)
{

	struct gyro_context *obj = kzalloc(sizeof(*obj), GFP_KERNEL);

	GYRO_LOG("gyro_context_alloc_object++++\n");
	if (!obj) {
		GYRO_ERR("Alloc gyro object error!\n");
		return NULL;
	}
	atomic_set(&obj->delay, 200); /*5Hz,  set work queue delay time 200ms */
	atomic_set(&obj->wake, 0);
	INIT_WORK(&obj->report, gyro_work_func);
	obj->gyro_workqueue = NULL;
	obj->gyro_workqueue = create_workqueue("gyro_polling");
	if (!obj->gyro_workqueue) {
		kfree(obj);
		return NULL;
	}
	initTimer(&obj->hrTimer, gyro_poll);
	obj->is_first_data_after_enable = false;
	obj->is_polling_run = false;
	obj->is_batch_enable = false;
	obj->cali_sw[GYRO_AXIS_X] = 0;
	obj->cali_sw[GYRO_AXIS_Y] = 0;
	obj->cali_sw[GYRO_AXIS_Z] = 0;
	mutex_init(&obj->gyro_op_mutex);
	GYRO_LOG("gyro_context_alloc_object----\n");
	return obj;
}
예제 #2
0
static struct baro_context *baro_context_alloc_object(void)
{

	struct baro_context *obj = kzalloc(sizeof(*obj), GFP_KERNEL);

	BARO_LOG("baro_context_alloc_object++++\n");
	if (!obj) {
		BARO_ERR("Alloc baro object error!\n");
		return NULL;
	}
	atomic_set(&obj->delay, 200);	/*5Hz set work queue delay time 200 ms */
	atomic_set(&obj->wake, 0);
	INIT_WORK(&obj->report, baro_work_func);
	obj->baro_workqueue = NULL;
	obj->baro_workqueue = create_workqueue("baro_polling");
	if (!obj->baro_workqueue) {
		kfree(obj);
		return NULL;
	}
	initTimer(&obj->hrTimer, baro_poll);
	obj->is_first_data_after_enable = false;
	obj->is_polling_run = false;
	mutex_init(&obj->baro_op_mutex);
	obj->is_batch_enable = false;	/* for batch mode init */

	BARO_LOG("baro_context_alloc_object----\n");
	return obj;
}
예제 #3
0
void init(void) {
    initLeds();
    initTimer();
    initPWM();
    initSpi();
    LIS302DL_Init();
}
예제 #4
0
/**************************************************************************//**
 * @brief Main function
 *****************************************************************************/
int main(void)
{  
  /* Chip revision alignment and errata fixes */
  CHIP_Init();
  
  /* Set system frequency to 1 MHz */
  CMU_HFRCOBandSet(cmuHFRCOBand_1MHz);
  
  /* Initialize LCD */
  SegmentLCD_Init(false); 

  /* Initialize TIMER0 */
  initTimer();
  
  /* Enable Sleep-om-Exit */
  SCB->SCR |= SCB_SCR_SLEEPONEXIT_Msk;
  
  /* Initialize interrupt count */
  interruptCount = 0;
  
  /* Enter EM1 until all TIMER0 interrupts are done
   * Notice that we only enter sleep once, as the MCU will fall asleep
   * immediately when the ISR is done without returning to main as long as
   * SLEEPONEXIT is set */
  EMU_EnterEM1();
  
  /* Signal that program is done */
  SegmentLCD_Write("DONE");
  while(1);
}
예제 #5
0
파일: main.c 프로젝트: icblnk/avr
void main()
{
    // Pin to measure impulse time
    //DDRB |= (0 << PINB0);
    //PORTB = (0 << PINB0);
    // LED pin
    DDRD |= (1 << PIND7);
    PORTD |= (0 << PIND7);

    // Trig pin
    PORTD |= (1 << PIND6);
    DDRD |= (1 << PIND6);

    blinkLed(5);
    initUSART();
    initTimer();

    USART_print("Main started\n");

    while(1) {
        PORTD |= 1 << PIND6;
        _delay_us(12);
        PORTD &= ~(1 << PIND6);
        _delay_ms(2000);
    }
}
예제 #6
0
파일: lab2.c 프로젝트: droydi/hack
/**********************************
* main, 
***********************************
*   Remember to keep this short
**********************************/
int main(void)
{  
	node head;                         // make the head node for the dynamic list start point

	head.prior=NULL;
	head.next=NULL;
	head_dyn_list=&head;               // set the global head_dyn_list to point to start node
	
	point_dyn_list=head_dyn_list;      //set point_dyn_list to point to start node
	
	initPort();
	while((0 == ((PIND) & (1 << 0))) );  // wait for PIND0 to go high
	initTimer3();                       // Init timer3 this is used for emulating a test run.
	initTimer();                        // timer1 is used for the second counter.
	while((1==((PIND) & (1 << 0))))     // run until PIND0 go low
	{	
		if(nyEvent.nyloper == 1)        // this variable is used to signal that a new event has happened
		{
		   handelNyEvent(&nyEvent);	
		   nyEvent.nyloper = 0;         // reset the new event variable  
		}
		
	}
	stopTimer_1(); 
	soterEtterNummer();            // TODO this is the function that you need to write!!                  
	return 0;
}
예제 #7
0
Timer *createTimer(TimerCallBackFunction callback,int timeout,void *data)
{
   Timer *timer = (Timer *)kmalloc(sizeof(Timer));
   initTimer(timer,callback,timeout,data);
   timer->onStack = 0; /*It will be free auto.*/
   return timer;
}
예제 #8
0
파일: main.c 프로젝트: ngg123/barndoor
int main() {
  int driverPointer = 0;
  // Stop the watchdog
  WDTCTL = WDTPW |  WDTHOLD;
  // enable output for pins connected to LEDs on Launchpad
  // init the peripherals
  initClocks();	
  initTimer();

  P1DIR |= BIT0 | BIT1 | BIT2 | BIT4;
  P1OUT |= BIT0 | BIT1 | BIT2 | BIT4;
  P1REN &= ~(BIT0|BIT1|BIT2|BIT4);

  // enable interrupts
  __bis_status_register(GIE);
  

  while(1) {
    __nop();
    __bis_status_register(CPUOFF);
    if (P1IN & BIT3){
      driverPointer +=1;
      TACCR0 = SIDEREAL_RATE;
    } else {
      driverPointer -= 1;
      TACCR0 = 300;
    }
    driverPointer = driverPointer & ((sizeof DRIVER_TABLE / sizeof *DRIVER_TABLE)-1);
    
    setDriver(DRIVER_TABLE[driverPointer]);
  }
}
예제 #9
0
int main (void)
{
    // Inits timer 0 (needed for the LCD funcions and for the waiting function)
    initTimer();
    FIO4DIR = 0xff;    // Bits 0 to 7 will be set: LEDs as outputs

    int mask, dir;
    mask = 1;          // Sets bit 0 (turns on LED 1)
    dir = 0;
    do
    {
        wait(100);                    // Wastes time...
        if(!(FIO4PIN & 0x100)) dir=1; // SW1: will set direction to the right
        if(!(FIO4PIN & 0x200)) dir=0; // SW2: will set direction to the left
        FIO4SET = 0xff;               // Turns off all LEDs
        FIO4CLR = mask;               // Turns on the current LED in the sequence
        if(dir)    {
            mask >>= 1;               // Shifts lit LED to the right
            if(!mask) mask = 0x80;    // Finished? Reset to last LED (bit 7)
        }
        else    {
            mask <<= 1;               // Shifts lit LED to the left
            if(mask & 0x100) mask=1;  // Finished? Reset to first LED (bit 1)
        }
    } while(1);
예제 #10
0
파일: main.c 프로젝트: noelbnicolas/Lab6
int main(void) {
	WDTCTL = WDTPW|WDTHOLD;

	initTimer();

	while(1) {
	  RobotMovement(FORWARD);
	  _delay_cycles(1000000);
	  Stop();
	  _delay_cycles(1000000);
	  RobotMovement(LEFT);
	  _delay_cycles(250000);
	  Stop();
	  _delay_cycles(1000000);
	  RobotMovement(RIGHT);
	  _delay_cycles(250000);
	  Stop();
	  _delay_cycles(1000000);
	  RobotMovement(REVERSE);
	  _delay_cycles(1000000);
	  Stop();
	  _delay_cycles(1000000);
	  RobotMovement(LEFT);
	  _delay_cycles(1000000);
	  Stop();
	  _delay_cycles(1000000);
	  RobotMovement(RIGHT);
	  _delay_cycles(1000000);
	  Stop();
	  _delay_cycles(1000000);
	}

	return 0 ;
}
예제 #11
0
int main(void) {
  // -------- Inits --------- //
  clock_prescale_set(clock_div_1);                  /* CPU clock 8 MHz */
  initUSART();
  _delay_ms(1000);
  initTimer();
  DDRB = (1 << PB0) | (1 << PB1) | (1 << PB2) | (1 << PB3);

  // ------ Event loop ------ //
  while (1) {

                         /* Smooth movements, trapezoidal acceleration */
    trapezoidMove(2 * TURN);                         /* two full turns */
    trapezoidMove(-TURN / 2);                             /* half turn */
    trapezoidMove(TURN / 4);                           /* quarter turn */
    trapezoidMove(-TURN / 8);                                /* eighth */
    _delay_ms(TURN);
    trapezoidMove(-TURN / 4);                         /* the other way */
    trapezoidMove(TURN / 8);
    trapezoidMove(TURN / 2);                /* half turn back to start */
    _delay_ms(1000);

  }                                                  /* End event loop */
  return (0);                            /* This line is never reached */
}
예제 #12
0
void VideoConverter::started()
{
	initTimer();

	videoItem->setAsConverting(this);
	emit conversionStarted(videoItem);
}
예제 #13
0
static struct acc_context *acc_context_alloc_object(void)
{

	struct acc_context *obj = kzalloc(sizeof(*obj), GFP_KERNEL);

	ACC_LOG("acc_context_alloc_object++++\n");
	if (!obj) {
		ACC_ERR("Alloc accel object error!\n");
		return NULL;
	}
	atomic_set(&obj->delay, 200);	/*5Hz ,  set work queue delay time 200ms */
	atomic_set(&obj->wake, 0);
	INIT_WORK(&obj->report, acc_work_func);
	obj->accel_workqueue = NULL;
	obj->accel_workqueue = create_workqueue("accel_polling");
	if (!obj->accel_workqueue) {
		kfree(obj);
		return NULL;
	}
	initTimer(&obj->hrTimer, acc_poll);
	obj->is_first_data_after_enable = false;
	obj->is_polling_run = false;
	mutex_init(&obj->acc_op_mutex);
	obj->is_batch_enable = false;/* for batch mode init */
	obj->cali_sw[ACC_AXIS_X] = 0;
	obj->cali_sw[ACC_AXIS_Y] = 0;
	obj->cali_sw[ACC_AXIS_Z] = 0;
	ACC_LOG("acc_context_alloc_object----\n");
	return obj;
}
예제 #14
0
/*
 *  ======== Watchdog_init ========
 */
Void Watchdog_init( Void (*timerFxn)(Void) )
{
    Hwi_Params          hwiParams;
    UInt                key;
    Timer_Handle        tHandle;
    Types_FreqHz        tFreq;
    Watchdog_TimerRegs  *timer;
    Int                 i;

    tHandle = Timer_Object_get(NULL, 0);
    Timer_getFreq(tHandle, &tFreq);  /* get timer frequency */

    for (i = 0; i < Watchdog_module->wdtCores; i++) {  /* loop for SMP cores */
        timer = (Watchdog_TimerRegs *) Watchdog_module->device[i].baseAddr;

        /* Check if timer is enabled by host-side */
        if ((REG32(Watchdog_module->device[i].clkCtrl) &
            WATCHDOG_WDT_CLKCTRL_IDLEST_MASK) ==
                                    WATCHDOG_WDT_CLKCTRL_IDLEST_MASK) {
            System_printf("Watchdog disabled: TimerBase = 0x%x ClkCtrl = 0x%x\n",
                                    timer, Watchdog_module->device[i].clkCtrl);
            continue;  /* for next core */
        }

        /* Configure the timer */
        initTimer(timer, TRUE);

        /* Enable interrupt in BIOS */
        Hwi_Params_init(&hwiParams);
        hwiParams.priority = 1;
        hwiParams.eventId = Watchdog_module->device[i].eventId;
        hwiParams.maskSetting = Hwi_MaskingOption_LOWER;
        key = Hwi_disable();
        Hwi_create(Watchdog_module->device[i].intNum, (Hwi_FuncPtr) timerFxn,
                                                            &hwiParams, NULL);
        Hwi_enableInterrupt(Watchdog_module->device[i].intNum);
        Hwi_restore(key);

        /* Enable timer */
        while (timer->twps & WATCHDOG_TIMER_TWPS_W_PEND_TCLR);
        timer->tclr |= 1;
        Watchdog_module->status[i] = Watchdog_Mode_ENABLED;

#ifdef SMP
        System_printf("Watchdog enabled: TimerBase = 0x%x SMP-Core = %d "
                                            "Freq = %d\n", timer, i, tFreq.lo);
#else
        System_printf("Watchdog enabled: TimerBase = 0x%x Freq = %d\n",
                                                            timer, tFreq.lo);
#endif
    }

    /* Register callback function */
    if (!IpcPower_registerCallback(IpcPower_Event_RESUME, Watchdog_restore,
                                    NULL)) {
        System_printf("Watchdog_restore registered as a resume callback\n");
    }

    return;
}
예제 #15
0
void main(void) {
    initIO();
    initOscillator();
    initTimer();

    while (1) {
        /* Check to see if the timer has counted beyond 32768 */
        if (TMR1H == 0x80) {
            // reset the timer
            TMR1H = 0;
            TMR1L = 0;

            incrementSeconds();
        }

        /* Check for button input */
        // all buttons are active low
        if (TMR0 >= (unsigned) 192) {
            if (oldButtonS == 0 && _button_s == 1) second = 0;
            if (oldButtonM == 0 && _button_m == 1) incrementMinutes();
            if (oldButtonH == 0 && _button_h == 1) incrementHours();

            oldButtonS = _button_s;
            oldButtonM = _button_m;
            oldButtonH = _button_h;
        }

        /* Update display */
        updateDisplay();
    }
}
예제 #16
0
파일: main.c 프로젝트: 20Mhz/avr_examples
// Functions
int initDevice() {
	int status=0;
	// Setup UART
	initUSART0STDIO(UBRR_MACRO);
	// Setup ADC
	initADC();
	// Setup BT
	initBT();
	// Wait for BT Connection
	#ifndef SIM
	while(!status)
		status = PING  & (1 << PING0);
	#endif
	// Enable Timer
	 initTimer();
	// Enable I2C
	initI2C();
	// Init wifi
	_delay_ms(310);
	DDRE |= (0x10|0x80|0x20) ; // PE4 = ~RST; PE7= ~WP; PE5=HIB;
	PORTE &= ~(0x80); // assert reset and WP
	PORTE |= (0x10 | 0x80); // deassert reset and WP
	PORTE &= ~(0x20); // De assert HIB
	// Enable ZG2100 Interrupt (use INT6)
	// Init wifi
	zg_init();
	ZG2100_ISR_ENABLE();
	// Enable Interrupts
	sei();
	return 0;
}
예제 #17
0
void main(void) {

    unsigned int j;
    unsigned int anEvent[MAX_EVENTS];

    initTimer();                /* initialize timer */
    FSM(RESET);                 /* initialize fsm   */

    while (1) {

        /* wait for next timer interrupt */
        waitTimerTic(); 
     
       /* evaluate all events */
        anEvent[0] = getRightKeyEvent();
        anEvent[1] = getTimerEvent();

        /* for all events call fsm */
        for (j = 0; j < MAX_EVENTS; j++) {
            if (anEvent[j] != NOEVENT) {
               FSM(anEvent[j]);
               anEvent[j] = NOEVENT;
            }
        }
    } 
}
예제 #18
0
int main(void){
  initIO();			//Initialize I/O
  initTimer();
  initComparator();	//Initialize the analog comparator
  lcd_init(LCD_DISP_ON);
  /*
  char buff[7];
  itoa(T_CLOCK,buff,10);
  lcd_puts(buff);
  itoa(ERROR_MARGIN,buff,10);
  lcd_puts(buff);
  */
  
 
  while(1) { 
 
    if (bit_flag) { 
      //lcd_puts("0" + last_bit);	//This math turns a single-digit char into it's ASCII equivalent
      if (last_bit != 0x0F) lcd_putc(last_bit);
      //else lcd_puts("0");
      bit_flag = 0;
    }
    
    if (sync_lost) {
      if (sync_lost == 2) lcd_puts("LOST-2T");
      else lcd_puts("LOST-T");
      lcd_gotoxy(0,1);
      char buff[7];
      itoa(timervalue,buff,10);
      lcd_puts(buff);
      while(1) {}
    }
    
  }
}
예제 #19
0
파일: main.c 프로젝트: avida/mediahouse
void Setup()
{
	initTimer();
	SetupNVIC();
	initTIM6Timer();
	//InitConsole();
	//LCDInit();
}
예제 #20
0
int main() {
  int i,k,n;
  char *text;
  unsigned char *trans;
  FILE *f;
  
  initTimer();
  
  // Open file
  f = fopen("/tmp/dbtss", "r");
  if(f == 0) {
    printf("File not found.\n");
    return 0;
  }
  // Obtain file size.
  fseek (f, 0 , SEEK_END);
  n = ftell (f);    
  rewind (f);
  printf("File size: %d\n", n);

  text = malloc(sizeof(char)*(n));
  k = fread(text, 1, n, f);
  printf("Read size: %d\n", k);
  fclose(f);
  
  addTimer("End reading");

  // Translate
  trans = malloc(sizeof(char)*(n+50));
  translate(trans, text, n, "ACGT|");
  addTimer("End translating");

  free(text);

  // Initialize tail
  for(i=n; i<n+50; i++)
    trans[i]=5;
  addTimer("End initialize tail");

  // Sort
  int *result = malloc(sizeof(int)*n);
  count_radix(trans, result, n, 5);

  addTimer("End sorting");

  printTimer();

  freeTimer();

  //  for(i=0; i<n; i++){
  //    for(k=0; k<3; k++)
      //      printf("%i", trans[result[i]+k]);
      //    printf("\n");
  //  }

  return 0;

}
예제 #21
0
파일: game.c 프로젝트: idr77/SnakeGame
bool playGame(Affichage A, Damier *map, Snake *snake, Sound sound)
{
	int end = 0;
	bool win = FALSE;
	Position newPos = initPosition();
	Input input = initInput();
	Chrono chrono = initChrono();
	Timer timer = initTimer();
	
	
	setProiesToMap(map);
	
	drawTile(A, TILE_TITLE);
	drawTextChrono(chrono, A);
	drawMap(A, *map, newPosition(MAXCASES/2 + 3,MAXCASES/2), *snake);

	startChrono(&chrono);
	while (1)
	{
		
		setTimer(&timer);
		newPos = updatePositions(map, snake, &input);
		
		if (input.end)
			break;

		if (testPosMap(newPos))
		{
			end = addPositionSnake(map, snake, newPos, sound);
			if (end)
			{
				win = FALSE;
				break;
			}
		}
		
		setPositionsToMap(map, snake);
		drawChrono(chrono, A);
		drawMap(A, *map, newPos, *snake);
		
		if(endChrono(chrono))
		{
			win = FALSE;
			break;
		}
		
		if (endGame(map))
		{
			win = TRUE;
			break;
		}
		
		reguleFPS(&timer);
	}
	
	deleteChrono(&chrono);
	return win;
}
예제 #22
0
int main(int argc, char** argv)
{
    Timer totalTime;
    int matrixSize;
    int mat1[SIZE][SIZE], mat2[SIZE][SIZE], prod[SIZE][SIZE];
	int i, j;

    // Check argument size
    if (argc < 2) {
    	printf("You should give the matrix size as argument.\n");
    	return -1;
    }

    // Check matrix size
    matrixSize = atoi(argv[1]);
    if (matrixSize < 1 || matrixSize > 100) {
    	printf("Matrix should be between 1 and 100.\n");
    	return -1;
    }

    // Init timer
    initTimer(&totalTime, "Total Time");
	
	// Init matrices
	for (i = 0;i < matrixSize; i++)
	{
		for (j = 0; j < matrixSize; j++)
		{
			mat1[i][j] = i+j*2;
		}
	}

	for(i = 0; i < matrixSize; i++)
	{
		for (j = 0; j < matrixSize; j++)
		{
			mat2[i][j] = i+j*3;
		}
	}

    startTimer(&totalTime);
	matMult(mat1, mat2, prod, matrixSize);
    stopTimer(&totalTime);

	for (i = 0;i < matrixSize; i++)
	{
		printf("\n");
		for (j = 0; j < matrixSize; j++)
		{
			printf("\t%d ", prod[i][j]);
		}
	}
	
	printf("\n\n");
	printTimer(&totalTime);
	printf("Done !!! \n");
	return 0;
}
예제 #23
0
파일: dialog.cpp 프로젝트: Iownnoname/qt
Dialog::Dialog(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::Dialog)
{
    ui->setupUi(this);
    initTimer();
    initTray();
    initLayout();
}
예제 #24
0
void TimerSprite::reset() {
	this->stopAllActions();
	initTimer();
	this->runAction(
			CCSequence::createWithTwoActions(
					CCProgressFromTo::create(time, 100.0f, 0.0f),
					CCCallFunc::create(this,
							callfunc_selector(TimerSprite::timeout))));
}
예제 #25
0
void Matrix::init()
{
	initRules();
	initField();
	initStats();
	initTetrominoes();
	initState();
	initTimer();
}
예제 #26
0
파일: InfoBar.cpp 프로젝트: Forkast/BTech
/* constructor */
InfoBar::InfoBar()
{
	initSettings();
	initWidget();
	initImageWindow();
	initStatWindow();
	initHexWindow();
	initLayout();
	initTimer();
}
예제 #27
0
void KLinPopup::customEvent(QCustomEvent *e)
{
	if (e->type() == QEvent::User+1) {
		popupFileTimerDone();
	} else if (e->type() == QEvent::User+2) {
		hasInotify = false;
		initTimer();
		popupFileTimer->start(1, true);
	}
}
예제 #28
0
void main() {
    initChip();
    initTimer();
    while(1)    //Endless loop
      {

        PORTB = counter ;    //Give value to PORTB

      }
}
예제 #29
0
파일: game.cpp 프로젝트: hjqqq/tetrimino
Game::Game(PlayerData *_playerData, Game **_allGame):
    playerData(_playerData),
    allGame(_allGame),
    show(new Show(_playerData))
{
    initTimer();
    initCounter();
    initStatus();
    gameStatus = PREPARE;
}
예제 #30
0
/********************************************************************************
	Main
********************************************************************************/
int main(void) {
    // initialize usart module
	usart_init();

    // enable interrupts
    sei();

    // Init GPIO
    initGPIO();

    // Init Timer 1
    initTimer();

    // Init Timer 0 & 2
    initTimers();

	OCR0A = 255;
	OCR0B = 255;
	OCR2A = 255;
	OCR2B = 255;

    _delay_ms(1000);

	OCR0A = 0;
	OCR0B = 0;
	OCR2A = 0;
	OCR2B = 0;

    fixZeroValueOCR();

	// Console friendly output
    printf("Start...");
    printf(CONSOLE_PREFIX);

    // Init NRF24L01+
    radio.begin();
    radio.setRetries(15,15);
    radio.setPayloadSize(8);
    radio.setPALevel(RF24_PA_MAX);
    radio.setChannel(115);

    radio.openWritingPipe(pipes[0]);
    radio.openReadingPipe(1,pipes[1]);

    radio.startListening();

    // Some RF module diagnostics logs
    radio.printDetails();

	// main loop
    while (1) {
    	// main usart loop for console
    	usart_check_loop();
    }
}