Beispiel #1
0
int main(void) {
    uint16_t ctimer;

    init_ports();
    init_timers();

    /* clear flags and enable interrupts */
    TIFR = _BV(OCF0A); /* timer 0 output compare A */
    GIFR = _BV(PCIF);  /* pin-change interrupt */
    sei(); /* enable interrupts */

    for (;;) {
        ATOMIC_BLOCK(ATOMIC_FORCEON) {
            ctimer = commtimer;
        }
        if (ctimer > COM_PERIOD_MAX)
            stalled = 1;

        if (stalled) {
            spinup();
            stalled = 0;
        }
        wdt_reset();
    }
}
Beispiel #2
0
int main(void) {
	//allow everything to settle/boot/etc
	//(mainly the mp3 chip takes a while to boot up)
	_delay_ms(2000);

	servo_init();
	keypad_init();
	display_init();
	thermistor_init();
	ssr_init();
	init_timers();
	mp3_init();

	tea_off();

	PMIC.CTRL |= PMIC_MEDLVLEN_bm | PMIC_LOLVLEN_bm | PMIC_HILVLEN_bm;
	sei();

	//another 100 for things to settle
	_delay_ms(100);

	//welcome
	mp3_play(10);

	while (1) {
		char key;
		if ((key = keypad_getc()))
			handle_key(key);
	}
}
Beispiel #3
0
/* Internal version of start_timer that does not protect itself, assuming this has already been done.
 * Otherwise does as explained above in start_timer.
 */
STATICFNDEF void start_timer_int(TID tid, int4 time_to_expir, void (*handler)(), int4 hdata_len, void *hdata)
{
	ABS_TIME at;

 	assert(0 != time_to_expir);
	sys_get_curr_time(&at);
	if (first_timeset)
	{
		init_timers();
		first_timeset = FALSE;
	}
	/* We expect no timer with id=<tid> to exist in the timer queue currently. This is asserted in "add_timer" call below.
	 * In pro though, we'll be safe and remove any tids that exist before adding a new entry with the same tid - 2009/10.
	 * If a few years pass without the assert failing, it might be safe then to remove the PRO_ONLY code below.
	 */
#	ifndef DEBUG
	if (timeroot && (timeroot->tid == tid))
		sys_canc_timer();
	remove_timer(tid); /* Remove timer from chain */
#	endif
	/* Check if # of free timer slots is less than minimum threshold. If so, allocate more of those while it is safe to do so */
	if ((GT_TIMER_EXPAND_TRIGGER > num_timers_free) && (1 > timer_stack_count))
		gt_timers_alloc();
	add_timer(&at, tid, time_to_expir, handler, hdata_len, hdata);	/* Link new timer into timer chain */
	if ((timeroot->tid == tid) || !timer_active)
		start_first_timer(&at);
}
Beispiel #4
0
int main( void ){
	init_timers();
	for(;;){
		utimer_test();
		utimer_handler();
	}
	return 0;
}
Beispiel #5
0
nemo_main()
{
  int n=getiparam("n");
  int iter=getiparam("iter");
  int m=getiparam("m");
  int seed = init_xrandom(getparam("seed"));
  int i,j,k,l;
  real *x, sum;
  real t0,t1,t2;

  init_timers(100);
  stamp_timers(0);

  x = (real *) allocate(n*sizeof(real));

  for (i=0; i<n; i++)         /* init the whole array */
    x[i] = xrandom(0.0,1.0);
  for (i=0; i<m; i++)         /* cache it in again ? */
    x[i] = xrandom(0.0,1.0);

  sum = 0.0;
  t0 = cputime();
  stamp_timers(1);
  if (m==0) {                         /* do it in one sweep, the N^2 algorithm */
    stamp_timers(2);
    for (l=0; l<iter;  l++)
      for (j=0; j<n; j++)
	for (i=0; i<n; i++)
	  sum += FUN(x[i],x[j]);
    stamp_timers(3);
  } else {                            /* N/M times a small M*M patch that may be in cache */
    stamp_timers(2);
    for (l=0; l<iter; l++)
      for (k=0; k<n-m; k++)
	for (j=k; j<k+m; j++)
	  for (i=k; i<k+m; i++)
	    sum += FUN(x[i],x[j]);
    stamp_timers(3);
  }
  stamp_timers(4);
  t1 = cputime();
  if (m)
    printf("%d %d %d sum=%lg Mops=%lg\n",
	 n,iter,m,sum,iter*m*m*n/(t1-t0)/60.0/1e6);
  else
    printf("%d %d %d sum=%lg Mops=%lg\n",
	 n,iter,m,sum,iter*n*n/(t1-t0)/60.0/1e6);
  stamp_timers(5);
  printf("%Ld %Ld %Ld %Ld %Ld\n",
	 diff_timers(0,1),
	 diff_timers(1,2),
	 diff_timers(2,3),
	 diff_timers(3,4),
	 diff_timers(4,5));
}
Beispiel #6
0
/*
 * Call to expire all timers associated with a given context.
 */
void expire_timer_context(void *ctx) {
	init_timers();

	/*
	 * We don't bother to check the return value; if the context
	 * already wasn't in the tree (presumably because no timers
	 * ever actually got scheduled for it) then that's fine and we
	 * simply don't need to do anything.
	 */
	del234(timer_contexts, ctx);
}
Beispiel #7
0
int main (void)
{
  uint16_t i;

  DDRB = 0xFF;

  init_timers();
  sei();
  PORTB = 0xFF;
  while (true);
}
Beispiel #8
0
int motor_pwm_init(void)
{
	const int ret = init_constants(config_get("mot_pwm_hz"));
	if (ret) {
		return ret;
	}

	init_timers();
	start_timers();

	motor_pwm_set_freewheeling();
	return 0;
}
int main(void)
{
	init_timers();
	init_ports();
	set_up_pwm();

   	UC0IE |= UCA0RXIE; // Enable USCI_A0 RX interrupt - Enable UART Recieve Commands

   	__bis_SR_register(GIE);


   	while (1){
   	}
}
Beispiel #10
0
void Server::init(long speed)
{
    uint8_t i;

    read_state = STATE_READ;
    buflen = 0;

    // Start timeout interrupt for TWI I/O functions
    init_timers();

    // Set pin directions
    for (i = 0; i < NCHAN_SSR; i++)
	pinMode(pins_ssr[i], OUTPUT);
    for (i = 0; i < NCHAN_PWM; i++)
	pinMode(pins_pwm[i], OUTPUT);

    // Turn SSRs and PWM off
    for (i = 0; i < NCHAN_SSR; i++)
	digitalWrite(pins_ssr[i], HIGH);
    for (i = 0; i < NCHAN_PWM; i++)
	analogWrite(pins_pwm[i], 0);

    // Needed for communications with the thermocouple's amplifier chip
    //	 By rights, this call should be in an initialization routine within
    //	 the cADC library, but the authors chose not to put it there.  Rather
    //	 than change the library too much, we'll put it here for the time
    //	 being.
    Wire.begin();

    // Initialize our serial device
    Serial.begin(speed ? speed : DEFAULT_BAUD);

    // Initialize the ambient temperature filtering
    amb.init(0);

    // Offsets
    // We don't store calibration settings in EEPROM.  If we need linear or
    // other corrections, we can perform them on the client device.
    adc.setCal(CAL_GAIN, UV_OFFSET);
    amb.setOffset(AMB_OFFSET);

    // Thermistors
    // Pull thermistor configs from EEPROM and effect the settings
    thermistor_data_t params;
    for (i = 0; i < NCHAN_TH; i++)
    {
	eeprom_thermistor_get(i, &params);
	thermistors[i].set(&params);
    }
}
Beispiel #11
0
/* Initialize board. */
static void board_init(void)
{
	init_pmu();
	init_timers();
	init_interrupts();
	init_trng();
	init_runlevel(PERMISSION_MEDIUM);

	/* TODO(crosbug.com/p/49959): For now, leave flash WP unlocked */
	GREG32(RBOX, EC_WP_L) = 1;

	/* Indication that firmware is running, for debug purposes. */
	GREG32(PMU, PWRDN_SCRATCH16) = 0xCAFECAFE;
}
Beispiel #12
0
LUALIB_API int luaopen_cron (lua_State *L)
{
    MS_PER_TICK = 1000UL / sysconf(_SC_CLK_TCK);
    init_timers(&timers, (unsigned long)times(0));

    lua_pushstring(L, CRON_TIMERS_TABLE);
    lua_newtable(L);
    lua_settable(L, LUA_REGISTRYINDEX);

    create_timer_metatable(L);

    luaL_register(L, LUA_CRONLIBNAME, lib);
    return 1;
}
Beispiel #13
0
int main() {
    init_timers();

    start = time(NULL);
    set_timer(1);
    set_timer(3);
    set_timer(4);
    set_timer(5);
    print_list();
    int volatile k = 0;
    for (int i = 0; i < 1000000; ++i)
        for (int j = 0; j < 2000; ++j)
            k += i * j;
    return EXIT_SUCCESS;
}
Beispiel #14
0
int main(void)
{
    int opt, sec;

    init_timers();

    while (1)
    {
        printf("输入工作的id 喝时间: ");
        fflush(stdout);
        scanf("%d %d", &opt, &sec);
        add_a_job(opt, test, sec);
    }
    return 0;
}
Beispiel #15
0
int
main (int argc, char **argv)
{
  float atime;
  CUstream stream;
  CUresult r;

  acc_init (acc_device_nvidia);

  (void) acc_get_device_num (acc_device_nvidia);

  init_timers (1);

  stream = (CUstream) acc_get_cuda_stream (0);
  if (stream != NULL)
    abort ();

  r = cuStreamCreate (&stream, CU_STREAM_DEFAULT);
  if (r != CUDA_SUCCESS)
    {
      fprintf (stderr, "cuStreamCreate failed: %d\n", r);
      abort ();
    }

  if (!acc_set_cuda_stream (0, stream))
    abort ();

  start_timer (0);

  acc_wait_all_async (0);

  acc_wait (0);

  atime = stop_timer (0);

  if (0.010 < atime)
    {
      fprintf (stderr, "actual time too long\n");
      abort ();
    }

  fini_timers ();

  acc_shutdown (acc_device_nvidia);

  exit (0);
}
Beispiel #16
0
int main(void){
	//Set LED pins to output
	DDRB |= ALL_LEDS;

	init_timers();

	while (1) {
		rgbCycle();
		_delay_ms(250);

		//I like the orange state and it only lasts for a second
		//so lets extend it a little bit more
		if(mState == RedToYellow)
		{
			//_delay_ms(250);
		}
	}
	return 0;
}
Beispiel #17
0
/* connect: connect to IRC */
bool TwitchBot::connect()
{
	char buf[MAX_MSG];

	if (!(bot_connected = !cconnect(&client, TWITCH_SERV, TWITCH_PORT)))
		return false;

	/* send required IRC data: PASS, NICK, USER */
	snprintf(buf, MAX_MSG, "PASS %s", bot_password);
	send_raw(&client, buf);
	snprintf(buf, MAX_MSG, "NICK %s", bot_name);
	send_raw(&client, buf);
	snprintf(buf, MAX_MSG, "USER %s", bot_name);
	send_raw(&client, buf);

	/* enable tags in PRIVMSGs */
	snprintf(buf, MAX_MSG, "CAP REQ :twitch.tv/tags");
	send_raw(&client, buf);

	/* receive join and part information */
	snprintf(buf, MAX_MSG, "CAP REQ :twitch.tv/membership");
	send_raw(&client, buf);

	/* allow access to additional twitch commands */
	snprintf(buf, MAX_MSG, "CAP REQ :twitch.tv/commands");
	send_raw(&client, buf);

	if (strlen(bot_channel) > 32) {
		fprintf(stderr, "error: channel name too long\n");
		disconnect();
		return false;
	}

	/* join channel */
	snprintf(buf, MAX_MSG, "JOIN %s", bot_channel);
	send_raw(&client, buf);

	tick_thread = std::thread(&TwitchBot::tick, this);
	init_timers(bot_channel + 1, bot_token, CID);

	return true;
}
Beispiel #18
0
void startup() {
	totalbytes = 0;
	               
	printf("Acidblood %s\n", VERSION);
	init_conf() ;
	init_signals() ;
	init_networking() ;
	conf_userdata=NULL ;
	conf_channels=NULL ;
	init_usercommands() ;
	init_ctcp() ;
	init_srvcommands() ;
	init_log();
	init_serverinfo() ;
	init_numeric() ;
	init_timers() ;
	init_events() ;
	read_main_config() ;
	init_modules() ;
}
int main(void)
{
	DDRB = 0xFF; // all set to output
	DDRD = 0xFF; // all set to output
	DDRC = 0xFF; // cathodes set as output

	//swich off all layers by applying voltage to the cathode pins thereby preventing current flow
	PORTC |= (1 << LAYER1) | (1 << LAYER2) | (1 << LAYER3);

	//initialize the timers (in this case just timer0)
	init_timers();
	init_leds();
	while (1)
	{
		//all the work is done in the interrupt service routine
		_delay_ms(5);
		updateLEDs();
	}
	return 1;
}
Beispiel #20
0
long schedule_timer(int ticks, timer_fn_t fn, void *ctx)
{
    long when;
    struct timer *t, *first;

    init_timers();

    now = GETTICKCOUNT();
    when = ticks + now;

    /*
     * Just in case our various defences against timing skew fail
     * us: if we try to schedule a timer that's already in the
     * past, we instead schedule it for the immediate future.
     */
    if (when - now <= 0)
	when = now + 1;

    t = snew(struct timer);
    t->fn = fn;
    t->ctx = ctx;
    t->now = when;
    t->when_set = now;

    if (t != add234(timers, t)) {
	sfree(t);		       /* identical timer already exists */
    } else {
	add234(timer_contexts, t->ctx);/* don't care if this fails */
    }

    first = (struct timer *)index234(timers, 0);
    if (first == t) {
	/*
	 * This timer is the very first on the list, so we must
	 * notify the front end.
	 */
	timer_change_notify(first->now);
    }

    return when;
}
Beispiel #21
0
int main(void) {

	init_menu();
	
	clear();
	init_motor();
	init_timers();
	encoders_init(IO_D2, IO_D3, IO_C4, IO_C5);

	sei();
	while (1) 
	{
		if(g_pd_release) {
			pd_task();
			g_pd_release = 0;
		}

		if(g_velocity_release) {
			velocity_task();
			g_velocity_release = 0;
		}

		if(g_encoder_release) {
			encoder_task();
			g_encoder_release = 0;
		}

		if(g_log_release) {
			log_task();
			g_log_release = 0;
		}

		if(g_interpolate_release) {
			interoplate_task();
			g_interpolate_release = 0;
		}

		serial_check();
		check_for_new_bytes_received();		
	}
}
Beispiel #22
0
int main(void){
	//Set LED pins to output
	DDRB |= ALL_LEDS;

	init_timers();

	while (1) {
		resetLedValues();
		mLedValues[RED_INDEX] = R_MAX;
		delay_seconds(RED_DELAY);

		resetLedValues();
		mLedValues[GREEN_INDEX] = G_MAX;
		delay_seconds(GREEN_DELAY);

		resetLedValues();
		mLedValues[YELLOW_INDEX] = Y_MAX;
		delay_seconds(YELLOW_DELAY);
	}
	return 0;
}
Beispiel #23
0
/*
 * Call to run any timers whose time has reached the present.
 * Returns the time (in ticks) expected until the next timer after
 * that triggers.
 */
int run_timers(long anow, long *next)
{
    struct timer *first;

    init_timers();

    now = GETTICKCOUNT();

    while (1) {
	first = (struct timer *)index234(timers, 0);

	if (!first)
	    return FALSE;	       /* no timers remaining */

	if (find234(timer_contexts, first->ctx, NULL) == NULL) {
	    /*
	     * This timer belongs to a context that has been
	     * expired. Delete it without running.
	     */
	    delpos234(timers, 0);
	    sfree(first);
	} else if (first->now - now <= 0 ||
	           now - (first->when_set - 10) < 0) {
	    /*
	     * This timer is active and has reached its running
	     * time. Run it.
	     */
	    delpos234(timers, 0);
	    first->fn(first->ctx, first->now);
	    sfree(first);
	} else {
	    /*
	     * This is the first still-active timer that is in the
	     * future. Return how long it has yet to go.
	     */
	    *next = first->now;
	    return TRUE;
	}
    }
}
Beispiel #24
0
/******************************************************************************
*                                    MAIN                                     *
*******************************************************************************
* Description: Firmware Project start.  This project:
*              (1) blinks the Mavric LED every .5 seconds
*
*   Arguments: None
*
*      Return: None
******************************************************************************/
int main(void)
{    
    ptrRxBufStart  = 0;
    ptrRxBufEnd    = 0;
    ptrCmdBuf      = 0;
    rxBuf[0]       = '\0';
        
    init_timers();
    init_usart0();
    init_twi();
    
    // enable printf
    stdout=stdin=&uartstr;
      
    // enable interrupts
    sei();
    
    initMux();

    DDRB = 0x01;    // enable PORTB 1 as an output (LED)
    
    printf("\r\n\r\nAerosole Devices Manufacturing Test Program\r\n");
    displaySerialCmdHelp();
    printf(">");

    while (1)
    {
        // blink LED if time has elapsed
        if(ms_count > 250)
        {
            ms_count = 0;
            toggleLED(); 
        } 
        
        getCommandData();           
    }
    
    return 0;
}
Beispiel #25
0
int do_fork()
{
  int pid,i;

  pid=fork();
  if (pid<0)
    perror("sorry, could not fork");
  if (pid==0)
    {
      destroy_image();
      x_screen_open(1);
      init_timers();
      conv_chunk(qlscreen.qm_lo,qlscreen.qm_hi);
      redraw_screen(0,0,qlscreen.xres,qlscreen.yres);
      XFlush(display);
      fork_files();
    }

  /* resetting the state of the keyboard seems the best */
  gKeyDown=0;
  for (i=0;i<8;i++) keyrow[i]=0;
  
  return pid;
}
asmlinkage void __init start_kernel(void)
{
	char * command_line;
	extern struct kernel_param __start___param[], __stop___param[];

	smp_setup_processor_id();

	/*
	 * Need to run as early as possible, to initialize the
	 * lockdep hash:
	 */
	lockdep_init();
	debug_objects_early_init();

	/*
	 * Set up the the initial canary ASAP:
	 */
	boot_init_stack_canary();

	cgroup_init_early();

	local_irq_disable();
	early_boot_irqs_off();
	early_init_irq_lock_class();

/*
 * Interrupts are still disabled. Do necessary setups, then
 * enable them
 */
	lock_kernel();
	tick_init();
	boot_cpu_init();
	page_address_init();
	printk(KERN_NOTICE "%s", linux_banner);
	setup_arch(&command_line);
	mm_init_owner(&init_mm, &init_task);
	setup_command_line(command_line);
	setup_nr_cpu_ids();
	setup_per_cpu_areas();
	smp_prepare_boot_cpu();	/* arch-specific boot-cpu hooks */

	build_all_zonelists(NULL);
	page_alloc_init();

	printk(KERN_NOTICE "Kernel command line: %s\n", boot_command_line);

//[email protected] 2011.11.14 begin
//support lcd compatible
//reviewed by [email protected]
#if defined(CONFIG_LCD_DRV_ALL)
	char *p = strstr(boot_command_line, "lcd=");
	if (p)
	{
		lcd_drv_index = p[4] - 'A';
		printk("lcd index = %d", lcd_drv_index);
	}
#endif
//[email protected] 2011.11.14 end

	parse_early_param();
	parse_args("Booting kernel", static_command_line, __start___param,
		   __stop___param - __start___param,
		   &unknown_bootoption);
	/*
	 * These use large bootmem allocations and must precede
	 * kmem_cache_init()
	 */
	pidhash_init();
	vfs_caches_init_early();
	sort_main_extable();
	trap_init();
	mm_init();
	/*
	 * Set up the scheduler prior starting any interrupts (such as the
	 * timer interrupt). Full topology setup happens at smp_init()
	 * time - but meanwhile we still have a functioning scheduler.
	 */
	sched_init();
	/*
	 * Disable preemption - early bootup scheduling is extremely
	 * fragile until we cpu_idle() for the first time.
	 */
	preempt_disable();
	if (!irqs_disabled()) {
		printk(KERN_WARNING "start_kernel(): bug: interrupts were "
				"enabled *very* early, fixing it\n");
		local_irq_disable();
	}
	rcu_init();
	radix_tree_init();
	/* init some links before init_ISA_irqs() */
	early_irq_init();
	init_IRQ();
	prio_tree_init();
	init_timers();
	hrtimers_init();
	softirq_init();
	timekeeping_init();
	time_init();
	profile_init();
	if (!irqs_disabled())
		printk(KERN_CRIT "start_kernel(): bug: interrupts were "
				 "enabled early\n");
	early_boot_irqs_on();
	local_irq_enable();

	/* Interrupts are enabled now so all GFP allocations are safe. */
	gfp_allowed_mask = __GFP_BITS_MASK;

	kmem_cache_init_late();

	/*
	 * HACK ALERT! This is early. We're enabling the console before
	 * we've done PCI setups etc, and console_init() must be aware of
	 * this. But we do want output early, in case something goes wrong.
	 */
	console_init();
	if (panic_later)
		panic(panic_later, panic_param);

	lockdep_info();

	/*
	 * Need to run this when irqs are enabled, because it wants
	 * to self-test [hard/soft]-irqs on/off lock inversion bugs
	 * too:
	 */
	locking_selftest();

#ifdef CONFIG_BLK_DEV_INITRD
	if (initrd_start && !initrd_below_start_ok &&
	    page_to_pfn(virt_to_page((void *)initrd_start)) < min_low_pfn) {
		printk(KERN_CRIT "initrd overwritten (0x%08lx < 0x%08lx) - "
		    "disabling it.\n",
		    page_to_pfn(virt_to_page((void *)initrd_start)),
		    min_low_pfn);
		initrd_start = 0;
	}
#endif
	page_cgroup_init();
	enable_debug_pagealloc();
	kmemtrace_init();
	kmemleak_init();
	debug_objects_mem_init();
	idr_init_cache();
	setup_per_cpu_pageset();
	numa_policy_init();
	if (late_time_init)
		late_time_init();
	sched_clock_init();
	calibrate_delay();
	pidmap_init();
	anon_vma_init();
#ifdef CONFIG_X86
	if (efi_enabled)
		efi_enter_virtual_mode();
#endif
	thread_info_cache_init();
	cred_init();
	fork_init(totalram_pages);
	proc_caches_init();
	buffer_init();
	key_init();
	security_init();
	dbg_late_init();
	vfs_caches_init(totalram_pages);
	signals_init();
	/* rootfs populating might need page-writeback */
	page_writeback_init();
#ifdef CONFIG_PROC_FS
	proc_root_init();
#endif
	cgroup_init();
	cpuset_init();
	taskstats_init_early();
	delayacct_init();

	check_bugs();

	acpi_early_init(); /* before LAPIC and SMP init */
	sfi_init_late();

	ftrace_init();

	/* Do the rest non-__init'ed, we're now alive */
	rest_init();
}
Beispiel #27
0
int
main (int argc, char **argv)
{
  CUdevice dev;
  CUfunction delay;
  CUmodule module;
  CUresult r;
  CUstream stream;
  unsigned long *a, *d_a, dticks;
  int nbytes;
  float atime, dtime;
  void *kargs[2];
  int clkrate;
  int devnum, nprocs;

  acc_init (acc_device_nvidia);

  devnum = acc_get_device_num (acc_device_nvidia);

  r = cuDeviceGet (&dev, devnum);
  if (r != CUDA_SUCCESS)
    {
      fprintf (stderr, "cuDeviceGet failed: %d\n", r);
      abort ();
    }

  r =
    cuDeviceGetAttribute (&nprocs, CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT,
			  dev);
  if (r != CUDA_SUCCESS)
    {
      fprintf (stderr, "cuDeviceGetAttribute failed: %d\n", r);
      abort ();
    }

  r = cuDeviceGetAttribute (&clkrate, CU_DEVICE_ATTRIBUTE_CLOCK_RATE, dev);
  if (r != CUDA_SUCCESS)
    {
      fprintf (stderr, "cuDeviceGetAttribute failed: %d\n", r);
      abort ();
    }

  r = cuModuleLoad (&module, "subr.ptx");
  if (r != CUDA_SUCCESS)
    {
      fprintf (stderr, "cuModuleLoad failed: %d\n", r);
      abort ();
    }

  r = cuModuleGetFunction (&delay, module, "delay");
  if (r != CUDA_SUCCESS)
    {
      fprintf (stderr, "cuModuleGetFunction failed: %d\n", r);
      abort ();
    }

  nbytes = nprocs * sizeof (unsigned long);

  dtime = 200.0;

  dticks = (unsigned long) (dtime * clkrate);

  a = (unsigned long *) malloc (nbytes);
  d_a = (unsigned long *) acc_malloc (nbytes);

  acc_map_data (a, d_a, nbytes);

  kargs[0] = (void *) &d_a;
  kargs[1] = (void *) &dticks;

  r = cuStreamCreate (&stream, CU_STREAM_DEFAULT);
  if (r != CUDA_SUCCESS)
	{
	  fprintf (stderr, "cuStreamCreate failed: %d\n", r);
	  abort ();
	}

  acc_set_cuda_stream (0, stream);

  init_timers (1);

  start_timer (0);

  r = cuLaunchKernel (delay, 1, 1, 1, 1, 1, 1, 0, stream, kargs, 0);
  if (r != CUDA_SUCCESS)
    {
      fprintf (stderr, "cuLaunchKernel failed: %d\n", r);
      abort ();
    }

  acc_wait (1);

  atime = stop_timer (0);

  if (atime < dtime)
    {
      fprintf (stderr, "actual time < delay time\n");
      abort ();
    }

  start_timer (0);

  acc_wait (1);

  atime = stop_timer (0);

  if (0.010 < atime)
    {
      fprintf (stderr, "actual time < delay time\n");
      abort ();
    }

  acc_unmap_data (a);

  fini_timers ();

  free (a);
  acc_free (d_a);

  acc_shutdown (acc_device_nvidia);

  return 0;
}
Beispiel #28
0
/*
 * Call to run any timers whose time has reached the present.
 * Returns the time (in ticks) expected until the next timer after
 * that triggers.
 */
int run_timers(long anow, long *next)
{
    struct timer *first;

    init_timers();

#ifdef TIMING_SYNC
    /*
     * In this ifdef I put some code which deals with the
     * possibility that `anow' disagrees with GETTICKCOUNT by a
     * significant margin. Our strategy for dealing with it differs
     * depending on platform, because on some platforms
     * GETTICKCOUNT is more likely to be right whereas on others
     * `anow' is a better gold standard.
     */
    {
	long tnow = GETTICKCOUNT();

	if (tnow + TICKSPERSEC/50 - anow < 0 ||
	    anow + TICKSPERSEC/50 - tnow < 0
	    ) {
#if defined TIMING_SYNC_ANOW
	    /*
	     * If anow is accurate and the tick count is wrong,
	     * this is likely to be because the tick count is
	     * derived from the system clock which has changed (as
	     * can occur on Unix). Therefore, we resolve this by
	     * inventing an offset which is used to adjust all
	     * future output from GETTICKCOUNT.
	     * 
	     * A platform which defines TIMING_SYNC_ANOW is
	     * expected to have also defined this offset variable
	     * in (its platform-specific adjunct to) putty.h.
	     * Therefore we can simply reference it here and assume
	     * that it will exist.
	     */
	    tickcount_offset += anow - tnow;
#elif defined TIMING_SYNC_TICKCOUNT
	    /*
	     * If the tick count is more likely to be accurate, we
	     * simply use that as our time value, which may mean we
	     * run no timers in this call (because we got called
	     * early), or alternatively it may mean we run lots of
	     * timers in a hurry because we were called late.
	     */
	    anow = tnow;
#else
/*
 * Any platform which defines TIMING_SYNC must also define one of the two
 * auxiliary symbols TIMING_SYNC_ANOW and TIMING_SYNC_TICKCOUNT, to
 * indicate which measurement to trust when the two disagree.
 */
#error TIMING_SYNC definition incomplete
#endif
	}
    }
#endif

    now = anow;

    while (1) {
	first = (struct timer *)index234(timers, 0);

	if (!first)
	    return FALSE;	       /* no timers remaining */

	if (find234(timer_contexts, first->ctx, NULL) == NULL) {
	    /*
	     * This timer belongs to a context that has been
	     * expired. Delete it without running.
	     */
	    delpos234(timers, 0);
	    sfree(first);
	} else if (first->now - now <= 0) {
	    /*
	     * This timer is active and has reached its running
	     * time. Run it.
	     */
	    delpos234(timers, 0);
	    first->fn(first->ctx, first->now);
	    sfree(first);
	} else {
	    /*
	     * This is the first still-active timer that is in the
	     * future. Return how long it has yet to go.
	     */
	    *next = first->now;
	    return TRUE;
	}
    }
}
/*****************************************************************************
**   Main Function  main()
******************************************************************************/
int main (void) {

   /* Setup SysTick Timer for 10 msec interrupts  */
   if (SysTick_Config(SystemCoreClock / 100)) {
		while (1); /* Capture error */
   }

   if (!(SysTick->CTRL & SysTick_CTRL_CLKSOURCE_Msk)) {
        /* When external reference clock is used(CLKSOURCE in
		Systick Control and register bit 2 is set to 0), the
		SYSTICKCLKDIV must be a non-zero value and 2.5 times
		faster than the reference clock.
		When core clock, or system AHB clock, is used(CLKSOURCE
		in Systick Control and register bit 2 is set to 1), the
		SYSTICKCLKDIV has no effect to the SYSTICK frequency. See
		more on Systick clock and status register in Cortex-M3
		technical Reference Manual. */
		LPC_SYSCON->SYSTICKCLKDIV = 0x08;
	}


   GPIOInit();

   init_timers();


   // The LED on Xpresso
   /* Set port 0_7 to output */
   GPIOSetDir( LED_PORT, LED_BIT, 1 );
   GPIOSetValue( 0, 7, LEDvalue );

   // buttons
   buttons_init();

   power_mgr_init();

   // check for 'next' button
   if (GPIOGetValue(0, 6)) {
	   led_digits_init();
	   led_digits_enable();
	   //led_digits_set_blink(1);
	   led_red_set(1);
	   led_green_set(1);
   }
   else {
	   GPIOSetValue( 0, 7, 1 );
	   delay32Ms(0,500);
	   GPIOSetValue( 0, 7, 0 );
	   delay32Ms(0,500);
	   GPIOSetValue( 0, 7, 1 );
	   delay32Ms(0,500);
	   GPIOSetValue( 0, 7, 0 );
	   delay32Ms(0,500);
	   GPIOSetValue( 0, 7, 1 );
	   delay32Ms(0,500);
	   GPIOSetValue( 0, 7, 0 );
	   delay32Ms(0,500);
   }


   // BARCODE reader
   barcode_init();
   barcode_reset();

   // RFID reader
   rdm630_init();
   rdm630_reset();

   // UART
   UARTInit(115200);
   // Enable the UART Interrupt
   NVIC_EnableIRQ(UART_IRQn);
   LPC_UART->IER = IER_RBR | IER_RLS;

   logger_setEnabled(1);
   logger_logStringln("/O:entering main loop..."); // send online message (means i'm online)

   uint8_t counter = 0;
   for(counter = 0; counter < 100; counter++) {
	   led_digits_set_value(counter);
	   delay32Ms(0, 20);
   }

   for(counter = 0; counter < 10; counter++) {
	   led_digits_set_value_by_chars('0' + counter, '0' + counter);
	   delay32Ms(0, 200);
   }
   delay32Ms(0, 200);
   led_digits_enable();

   signal_boot_up();

   int8_t last_remaining_seconds = -1;
   while (1) {

       /* process logger */
       if (logger_dataAvailable() && UARTTxEmpty) {
         uint8_t iCounter;
         // fill transmit FIFO with 14 bytes
         for (iCounter = 0; iCounter < 14 && logger_dataAvailable(); iCounter++) {
            UARTSendByte(logger_read());
         }
       }

       power_mgr_process(msTicks);

       barcode_process(msTicks);

       rdm630_process(msTicks);

       buttons_process(msTicks);

       led_digits_process(msTicks);


       /*
	   if (power_mgr_is_shutting_down()) {
		   if (power_mgr_get_remaining_player_seconds() != last_remaining_seconds) {
			   last_remaining_seconds = power_mgr_get_remaining_player_seconds();
			   led_digits_set_value(last_remaining_seconds);
		   }
		   if (last_remaining_seconds == 0) {
			   led_green_set(0);
			   led_red_set(1);
			   led_digits_disable();
		   }
		   continue;
	   }
	   */


       main_process_barcode();

       main_process_rfid();

       main_process_buttons();

       main_process_uart();

   }
}
Beispiel #30
0
asmlinkage void __init start_kernel(void)
{
	char * command_line;
	extern struct kernel_param __start___param[], __stop___param[];

	smp_setup_processor_id();

	/*
	 * Need to run as early as possible, to initialize the
	 * lockdep hash:
	 */
	unwind_init();
	lockdep_init();

	local_irq_disable();
	early_boot_irqs_off();
	early_init_irq_lock_class();

/*
 * Interrupts are still disabled. Do necessary setups, then
 * enable them
 */
	lock_kernel();
	boot_cpu_init();
	page_address_init();
	printk(KERN_NOTICE);
	printk(linux_banner);
	setup_arch(&command_line);
	setup_per_cpu_areas();
	smp_prepare_boot_cpu();	/* arch-specific boot-cpu hooks */

	/*
	 * Set up the scheduler prior starting any interrupts (such as the
	 * timer interrupt). Full topology setup happens at smp_init()
	 * time - but meanwhile we still have a functioning scheduler.
	 */
	sched_init();
	/*
	 * Disable preemption - early bootup scheduling is extremely
	 * fragile until we cpu_idle() for the first time.
	 */
	preempt_disable();
	build_all_zonelists();
	page_alloc_init();
	printk(KERN_NOTICE "Kernel command line: %s\n", saved_command_line);
	parse_early_param();
	parse_args("Booting kernel", command_line, __start___param,
		   __stop___param - __start___param,
		   &unknown_bootoption);
	sort_main_extable();
	trap_init();
	rcu_init();
	init_IRQ();
	pidhash_init();
	init_timers();
	hrtimers_init();
	softirq_init();
	timekeeping_init();
	time_init();
	profile_init();
	if (!irqs_disabled())
		printk("start_kernel(): bug: interrupts were enabled early\n");
	early_boot_irqs_on();
	local_irq_enable();

	/*
	 * HACK ALERT! This is early. We're enabling the console before
	 * we've done PCI setups etc, and console_init() must be aware of
	 * this. But we do want output early, in case something goes wrong.
	 */
	console_init();
	if (panic_later)
		panic(panic_later, panic_param);

	lockdep_info();

	/*
	 * Need to run this when irqs are enabled, because it wants
	 * to self-test [hard/soft]-irqs on/off lock inversion bugs
	 * too:
	 */
	locking_selftest();

#ifdef CONFIG_BLK_DEV_INITRD
	if (initrd_start && !initrd_below_start_ok &&
			initrd_start < min_low_pfn << PAGE_SHIFT) {
		printk(KERN_CRIT "initrd overwritten (0x%08lx < 0x%08lx) - "
		    "disabling it.\n",initrd_start,min_low_pfn << PAGE_SHIFT);
		initrd_start = 0;
	}
#endif
	vfs_caches_init_early();
	cpuset_init_early();
	mem_init();
	kmem_cache_init();
	setup_per_cpu_pageset();
	numa_policy_init();
	if (late_time_init)
		late_time_init();
	calibrate_delay();
	pidmap_init();
	pgtable_cache_init();
	prio_tree_init();
	anon_vma_init();
#ifdef CONFIG_X86
	if (efi_enabled)
		efi_enter_virtual_mode();
#endif
	fork_init(num_physpages);
	proc_caches_init();
	buffer_init();
	unnamed_dev_init();
	key_init();
	security_init();
	vfs_caches_init(num_physpages);
	radix_tree_init();
	signals_init();
	/* rootfs populating might need page-writeback */
	page_writeback_init();
#ifdef CONFIG_PROC_FS
	proc_root_init();
#endif
	cpuset_init();
	taskstats_init_early();
	delayacct_init();

	check_bugs();

	acpi_early_init(); /* before LAPIC and SMP init */

	/* Do the rest non-__init'ed, we're now alive */
	rest_init();
}