Beispiel #1
0
int
main (int argc, char **argv)
{
	struct event timeout;
	struct timeval tv;
 
	/* Initalize the event library */
	event_init();

	/* Initalize one event */
	evtimer_set(&timeout, timeout_cb, &timeout);

	evutil_timerclear(&tv);
	tv.tv_sec = 2;
	event_add(&timeout, &tv);

	lasttime = time(NULL);
	
	event_dispatch();

	return (0);
}
Beispiel #2
0
 // 填充 LIBEVENT_THREAD 结构体, 其中包括:
 //     填充 struct event
 //     初始化线程工作队列
 //     初始化互斥量
 //     等
static void setup_thread(LIBEVENT_THREAD *me) {
    me->base = event_init();
    if (! me->base) {
        fprintf(stderr, "Can't allocate event base\n");
        exit(1);
    }

    /* Listen for notifications from other threads */
    // 在线程数据结构初始化的时候, 为 me->notify_receive_fd 读管道注册读事件, 回调函数是 thread_libevent_process()
    event_set(&me->notify_event, me->notify_receive_fd,
              EV_READ | EV_PERSIST, thread_libevent_process, me);
    event_base_set(me->base, &me->notify_event);

    if (event_add(&me->notify_event, 0) == -1) {
        fprintf(stderr, "Can't monitor libevent notify pipe\n");
        exit(1);
    }

    // 初始化该线程的工作队列
    me->new_conn_queue = malloc(sizeof(struct conn_queue));
    if (me->new_conn_queue == NULL) {
        perror("Failed to allocate memory for connection queue");
        exit(EXIT_FAILURE);
    }
    cq_init(me->new_conn_queue);

    // 初始化该线程的状态互斥量
    if (pthread_mutex_init(&me->stats.mutex, NULL) != 0) {
        perror("Failed to initialize mutex");
        exit(EXIT_FAILURE);
    }

    me->suffix_cache = cache_create("suffix", SUFFIX_SIZE, sizeof(char*),
                                    NULL, NULL);
    if (me->suffix_cache == NULL) {
        fprintf(stderr, "Failed to create suffix cache\n");
        exit(EXIT_FAILURE);
    }
}
Beispiel #3
0
int main(int argc, char *argv[])
{

  (void) signal(SIGINT, main_exit);

  //set IMU neutrals
  RATES_ASSIGN(imu.gyro_neutral,  IMU_GYRO_P_NEUTRAL,  IMU_GYRO_Q_NEUTRAL,  IMU_GYRO_R_NEUTRAL);
  VECT3_ASSIGN(imu.accel_neutral, IMU_ACCEL_X_NEUTRAL, IMU_ACCEL_Y_NEUTRAL, IMU_ACCEL_Z_NEUTRAL);
  VECT3_ASSIGN(imu.mag_neutral,   IMU_MAG_X_NEUTRAL,   IMU_MAG_Y_NEUTRAL,   IMU_MAG_Z_NEUTRAL);

  if (spi_link_init()) {
    TRACE(TRACE_ERROR, "%s", "failed to open SPI link \n");
    return -1;
  }

  /* Initalize the event library */
  event_init();

  control_init();
  estimator_init();

  //  file_logger_init("my_log.data");

  gcs_com_init();

  if (fms_periodic_init(main_periodic)) {
    TRACE(TRACE_ERROR, "%s", "failed to start periodic generator\n");
    return -1;
  }

  //main_parse_cmd_line(argc, argv);

  event_dispatch();
  //should never occur!
  printf("goodbye! (%d)\n", foo);

  return 0;
}
Beispiel #4
0
int
main(int argc, char *argv[])
{
    struct sockaddr_un sun;
    struct event event;
    int sock;
    int on = 1;

    if (argc != 2)
	usage();

    sun.sun_family = AF_UNIX;
    if (strlcpy(sun.sun_path, argv[1],
		sizeof(sun.sun_path)) >= sizeof(sun.sun_path))
	errx(1, "socket path is too long");

    sock = socket(AF_UNIX, SOCK_STREAM, 0);
    if (sock == -1)
	err(1, "socket");

    if (bind(sock, (struct sockaddr *)&sun, sizeof(sun)) == -1)
	err(1, "bind");

    if (ioctl(sock, FIONBIO, &on) == -1)
	err(1, "listener ioctl(FIONBIO)");

    if (listen(sock, 5) == -1)
	err(1, "listen");

    event_init();

    event_set(&event, sock, EV_READ | EV_PERSIST, echo_accept, NULL);
    event_add(&event, NULL);

    event_dispatch();

    return (0);
}
Beispiel #5
0
int main(int argc, char** argv) {
	printf("Thread %d booting\n", thread_id());
	if(thread_id() == 0) {
		time_init();
		event_init();
		ginit(argc, argv);
	}
	
	thread_barrior();
	
	init(argc, argv);
	
	thread_barrior();

	/* Start of User Code Area */

	int fd;
	file_init();
	file_opendir("/", open_cb, &fd);
	if(thread_id() == 0) {
		while(1) {
			event_loop();
		}
	}
	/* End of User Code Area */

	thread_barrior();
	
	destroy();
	
	thread_barrior();
	
	if(thread_id() == 0) {
		gdestroy(argc, argv);
	}
	
	return 0;
}
Beispiel #6
0
int main(int argc, char **argv)
{
    init_app(argc, argv, "osd");

    event_init();

    char *hdd_cfg = cfg_getstr("HDD_CONF_FILENAME", "etc/hdd.conf");
    hdd_init(hdd_cfg);

    char *self_host = cfg_getstr("OSD2CLIENT_LISTEN_HOST", "*");
    int self_port = cfg_getint32("OSD2CLIENT_LISTEN_PORT", 9527);
    rpc_client_setup(self_host, self_port, MACHINE_OSD);

    struct evhttp *httpd;

    char *listen_host = cfg_getstr("OSD2CLIENT_LISTEN_HOST", "*");
    int port = cfg_getint32("OSD2CLIENT_LISTEN_PORT", 9527);

    httpd = evhttp_start(listen_host, port);
    if (httpd == NULL) {
        logging(LOG_ERROR, "start server error %m");
        exit(1);
    } else {
        printf("Start osd at %s:%d\n", listen_host, port);
    }
    evhttp_set_cb(httpd, "/shutdown", shutdown_handler, NULL);
    evhttp_set_gencb(httpd, gen_handler, NULL);


    struct timeval five_seconds = {2,0};
    struct event *update_clustermap_event= event_new(NULL, -1, EV_PERSIST, update_clustermap_from_cmgr_on_timer_cb, NULL);
    event_add(update_clustermap_event, &five_seconds);

    event_dispatch();

    evhttp_free(httpd);
    return 0;
}
void gpio_keypad_init(struct gpio_keypad_info *kpinfo)
{
	int key_count;
	int output_val;
	int output_cfg;
	int i;
	int len;

	ASSERT(kpinfo->keymap && kpinfo->input_gpios && kpinfo->output_gpios);
	key_count = kpinfo->ninputs * kpinfo->noutputs;

	len = sizeof(struct gpio_kp) + (sizeof(unsigned long) *
					BITMAP_NUM_WORDS(key_count));
	keypad = malloc(len);
	ASSERT(keypad);

	memset(keypad, 0, len);
	keypad->keypad_info = kpinfo;

	output_val = (!!(kpinfo->flags & GPIOKPF_ACTIVE_HIGH)) ^
		     (!!(kpinfo->flags & GPIOKPF_DRIVE_INACTIVE));
	output_cfg = kpinfo->flags & GPIOKPF_DRIVE_INACTIVE ? GPIO_OUTPUT : 0;
	for (i = 0; i < kpinfo->noutputs; i++) {
		gpio_set(kpinfo->output_gpios[i], output_val);
		gpio_config(kpinfo->output_gpios[i], output_cfg);
	}
	for (i = 0; i < kpinfo->ninputs; i++)
		gpio_config(kpinfo->input_gpios[i], GPIO_INPUT);

	keypad->current_output = kpinfo->noutputs;

	event_init(&keypad->full_scan, false, EVENT_FLAG_AUTOUNSIGNAL);
	timer_initialize(&keypad->timer);
	timer_set_oneshot(&keypad->timer, 0, gpio_keypad_timer_func, NULL);

	/* wait for the keypad to complete one full scan */
	event_wait(&keypad->full_scan);
}
Beispiel #8
0
/**
 * Inititialize ccnet client structure, connect daemon and initialize
 * event loop.
 */
CcnetClient *
ccnet_init (const char *confdir)
{
    CcnetClient *client;

    client = ccnet_client_new ();
    if ( (ccnet_client_load_confdir(client, confdir)) < 0 ) {
        ccnet_warning ("Read config dir error\n");
        return NULL;
    }


    if (ccnet_client_connect_daemon (client, CCNET_CLIENT_ASYNC) < 0) {
        ccnet_warning ("Connect to ccnet daemon error\n");
        exit(1);
    }

    ccnet_client_run_synchronizer (client);

    event_init ();

    return client;
}
Beispiel #9
0
Datei: thread.c Projekt: aosp/dvp
ack_t* sosal_add_ack(thread_t  pThrdHdl)
{
    ack_t* pNew;

    pNew = malloc(sizeof(ack_t));
    if(!pNew) {
        SOSAL_PRINT(SOSAL_ZONE_ERROR, "ERROR! Can't allocate memory for new join ACK!\n");
        return NULL;
    }

    pNew->next = pThrdHdl->pAckList;
    pThrdHdl->pAckList = pNew;

    pNew->exit_event_ack = malloc(sizeof(event_t));
    if(!pNew->exit_event_ack) {
        free(pNew);
        SOSAL_PRINT(SOSAL_ZONE_ERROR, "ERROR! Can't allocate memory for new join ACK event!\n");
        return NULL;
    }

    event_init(pNew->exit_event_ack, false_e);
    return (pNew);
}
Beispiel #10
0
/*
 * Global initialization.  Basically just initialize event/dns.
 */
void
robin_init(void)
{
	extern void *current_base;
	static int once = 0;
	const char *filename;

	if (once)
		return;
	once = 1;

	/* some trickery to only init event once */
	if (current_base == NULL)
		event_init();
	dns_init();
	tbox_init();

	/* load some defaults */
	if ((filename = getenv(ROBIN_CONFENV)))
		tbloadconf(filename, rfs_conflist);
	else
		tbloadconf(ROBIN_CONFFILE, rfs_conflist);
}
Beispiel #11
0
EventBase::EventBase()
  : runOnceCallbacks_(nullptr)
  , stop_(false)
  , loopThread_(0)
  , evb_(static_cast<event_base*>(event_init()))
  , queue_(nullptr)
  , fnRunner_(nullptr)
  , maxLatency_(0)
  , avgLoopTime_(2000000)
  , maxLatencyLoopTime_(avgLoopTime_)
  , nextLoopCnt_(-40)       // Early wrap-around so bugs will manifest soon
  , latestLoopCnt_(nextLoopCnt_)
  , startWork_(0)
  , observer_(nullptr)
  , observerSampleCount_(0) {
  if (UNLIKELY(evb_ == nullptr)) {
    LOG(ERROR) << "EventBase(): Failed to init event base.";
    folly::throwSystemError("error in EventBase::EventBase()");
  }
  VLOG(5) << "EventBase(): Created.";
  initNotificationQueue();
  RequestContext::getStaticContext();
}
Beispiel #12
0
int
main(int argc, char **argv)
{
    struct timeval tv;
    int i;

    /* Initalize the event library */
    event_init();

    for (i = 0; i < NEVENT; i++) {
        ev[i] = malloc(sizeof(struct event));

        /* Initalize one event */
        evtimer_set(ev[i], time_cb, ev[i]);
        tv.tv_sec = 0;
        tv.tv_usec = rand_int(50000);
        evtimer_add(ev[i], &tv);
    }

    event_dispatch();

    return (called < NEVENT);
}
Beispiel #13
0
int jsonrpc_io_child_process(int cmd_pipe, char* _servers)
{
	if (parse_servers(_servers, &server_group) != 0)
	{
		LM_ERR("servers parameter could not be parsed\n");
		return -1;
	}

	event_init();
	
	struct event pipe_ev;
	set_non_blocking(cmd_pipe);
	event_set(&pipe_ev, cmd_pipe, EV_READ | EV_PERSIST, cmd_pipe_cb, &pipe_ev);
	event_add(&pipe_ev, NULL);

	if (!connect_servers(server_group))
	{
		LM_WARN("failed to connect to any servers\n");
	}

	event_dispatch();
	return 0;
}
Beispiel #14
0
int main(int argc, char *argv[]) {
  cfg.portnumber = cfg.otherport = 80;
  cfg.pass_udp = cfg.echo_udp = 0;
  cfg.pass_tcp = 0;
  cfg.have_otherhost = 0;
  cfg.hexmode = 1;
  cfg.timeout.tv_sec = 1; cfg.timeout.tv_usec = 0;
  memset(cfg.otherhostaddr, 0, sizeof(cfg.otherhostaddr));
  cfg.otherhostaddr[0] = 127;
  cfg.otherhostaddr[1] = 0;
  cfg.otherhostaddr[2] = 0;
  cfg.otherhostaddr[3] = 1;

  if (!parse_cmdline(argc, argv))
    return EXIT_FAILURE;

  event_init();
  init_passthru();
  fflush(NULL);
  signal(SIGINT, flush_all_f_buffers);
  event_dispatch();
  return EXIT_SUCCESS;
}
Beispiel #15
0
int main()
{
    uint32_t mask;
    struct time_t timeout;

    sys_start();
    event_init(&event);

    /* Initialize and start a periodic timer. */
    timeout.seconds = 1;
    timeout.nanoseconds = 0;
    timer_init(&timer, &timeout, timer_cb, NULL, TIMER_PERIODIC);
    timer_start(&timer);
    
    while (1) {
        mask = TIMEOUT_EVENT;
        event_read(&event, &mask, sizeof(mask));

        std_printf(FSTR("timeout\r\n"));
    }
    
    return (0);
}
Beispiel #16
0
ACL_EVENT *acl_event_new_kernel_thr(int delay_sec, int delay_usec)
{
#ifdef	ACL_EVENTS_KERNEL_STYLE
	ACL_EVENT *eventp;
	int   fdsize;

	fdsize = event_limit(0);
#if (ACL_EVENTS_KERNEL_STYLE == ACL_EVENTS_STYLE_EPOLL)
	eventp = event_epoll_alloc_thr(fdsize);
#else
	eventp = event_new_kernel_thr(fdsize);
#endif
	event_init(eventp, fdsize, delay_sec, delay_usec);
	return eventp;
#else
	const char *myname = "acl_event_new_kernel_thr";

	delay_sec = delay_sec;
	delay_usec = delay_usec;
	acl_msg_fatal("%s(%d): not support!", myname, __LINE__);
	return NULL;
#endif
}
Beispiel #17
0
static void
rspamd_http_server_func (gint fd, const gchar *path, rspamd_inet_addr_t *addr,
		struct rspamd_cryptobox_keypair *kp, struct rspamd_keypair_cache *c)
{
	struct rspamd_http_connection_router *rt;
	struct event_base *ev_base = event_init ();
	struct event accept_ev, term_ev;

	rt = rspamd_http_router_new (rspamd_server_error, rspamd_server_finish,
			NULL, ev_base, path, c);
	g_assert (rt != NULL);

	rspamd_http_router_set_key (rt, kp);
	event_set (&accept_ev, fd, EV_READ | EV_PERSIST, rspamd_server_accept, rt);
	event_base_set (ev_base, &accept_ev);
	event_add (&accept_ev, NULL);

	evsignal_set (&term_ev, SIGTERM, rspamd_http_term_handler, ev_base);
	event_base_set (ev_base, &term_ev);
	event_add (&term_ev, NULL);

	event_base_loop (ev_base, 0);
}
Beispiel #18
0
int setup_thread(thread_cg * t_cg){
    t_cg->base = event_init();
    if(! t_cg->base){
        fprintf(stderr, "can't alloc event base\n");
        exit(1);
    }
    event_set(&t_cg->notify_event, t_cg->read_fd, EV_READ | EV_PERSIST, thread_libevent_process, t_cg);
    event_base_set(t_cg->base, &t_cg->notify_event);

    if (event_add(&t_cg->notify_event, 0) == -1)
    {
        fprintf(stderr, "Can't monitor libevent notify pipe\n");
        exit(1);
    }
    t_cg->new_conn_queue = malloc(sizeof(struct conn_queue));
    if (t_cg->new_conn_queue == NULL) {
        perror("Failed to allocate memory for connection queue");
        exit(EXIT_FAILURE);
    }
    cq_init(t_cg->new_conn_queue);
    //未完成,应该还是需要实现连接管理的
    
}
Beispiel #19
0
int main(void)
{
	struct AATree aatree;
	struct CBTree *cbtree;
	struct md5_ctx md5;
	char buf[128];

	aatree_init(&aatree, NULL, NULL);
	cbtree = cbtree_create(NULL, NULL, NULL, USUAL_ALLOC);
	daemonize(NULL, NULL);
	hash_lookup3("foo", 3);
	if (!event_init())
		log_debug("test");
	if (!parse_ini_file("foo", NULL, NULL))
		log_debug("test");
	log_stats("1");
	file_size("foo");
	md5_reset(&md5);
	strlcpy(buf, "foo", sizeof(buf));
	printf("xmalloc: %p\n", xmalloc(128));
	if (0) die("0");
	return 0;
}
int
main (int argc, char **argv)
{
	struct event ev;

	if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
		return (1);

	if (socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1)
		return (1);

	/* Initalize the event library */
	event_init();

	/* Initalize one event */
	event_set(&ev, pair[1], EV_WRITE, write_cb, &ev);

	event_add(&ev, NULL);

	event_dispatch();

	return (test_okay);
}
Beispiel #21
0
int main(void)
{
    init();
    event_init();
    pinMode(13, OUTPUT);
    pinMode(12, OUTPUT);
    pinMode(SERVO, OUTPUT) ;                                   // set servo pin to output

    servo_slow();
    delay(7500);
    //blink_led13();
    blink_led12();

    for (;;) {
        for (; speed < 250; speed ++) {
            delay(100);
        }
        for (; speed > 0; speed --) {
            delay(100);
        }
        for (;;) {}
    }
}
Beispiel #22
0
int
main(int argc, char **argv)
{
	struct event ev;
	const char *test = "test string";
	evutil_socket_t pair[2];

#ifdef WIN32
	WORD wVersionRequested;
	WSADATA wsaData;
	int	err;

	wVersionRequested = MAKEWORD(2, 2);

	err = WSAStartup(wVersionRequested, &wsaData);
#endif

	if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1)
		return (1);


	if (send(pair[0], test, (int)strlen(test)+1, 0) < 0)
		return (1);
	shutdown(pair[0], SHUT_WR);

	/* Initalize the event library */
	event_init();

	/* Initalize one event */
	event_set(&ev, pair[1], EV_READ | EV_TIMEOUT, read_cb, &ev);

	event_add(&ev, &timeout);

	event_dispatch();

	return (test_okay);
}
int
main(int argc, char **argv)
{
	struct event ev0, ev1, ev2, ev3;
	int pair[2];
	
	if (pipe(pair) == -1) 
	{
		if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1)
		 {
			perror("pipe");
			exit(1);		
		}
	}


	struct event_base *base = event_init();

	event_set(&ev0, pair[0], EV_READ, read_cb, &ev0);
	event_set(&ev1, pair[1], EV_WRITE, write_cb, &ev1);
	event_set(&ev2, pair[1], EV_WRITE, write_cb2, &ev2);
	event_set(&ev3, pair[1], EV_WRITE, write_cb3, &ev3);

	event_add(&ev0, NULL);
	event_add(&ev1, NULL);
	event_add(&ev2, NULL);
	event_add(&ev3, NULL);


	// add_event(pair[1], EV_WRITE, write_cb);
	// add_event(pair[0], EV_READ, read_cb);


	event_base_dispatch(base);

	return (0);
}
Beispiel #24
0
int
main(int argc, char **argv)
{
	struct timeval tv;
	int i;
#ifdef _WIN32
	WORD wVersionRequested;
	WSADATA wsaData;

	wVersionRequested = MAKEWORD(2, 2);

	(void) WSAStartup(wVersionRequested, &wsaData);
#endif

	evutil_weakrand_seed_(&weakrand_state, 0);

	/* Initalize the event library */
	event_init();

	for (i = 0; i < NEVENT; i++) {
		ev[i] = malloc(sizeof(struct event));
		assert(ev[i] != NULL);

		/* Initalize one event */
		evtimer_set(ev[i], time_cb, ev[i]);
		tv.tv_sec = 0;
		tv.tv_usec = rand_int(50000);
		evtimer_add(ev[i], &tv);
	}

	event_dispatch();


	printf("%d, %d\n", called, NEVENT);
	return (called < NEVENT);
}
Beispiel #25
0
static void
rspamd_http_server_func (const gchar *path, rspamd_inet_addr_t *addr,
		rspamd_mempool_mutex_t *mtx, gpointer kp, struct rspamd_keypair_cache *c)
{
	struct rspamd_http_connection_router *rt;
	struct event_base *ev_base = event_init ();
	struct event accept_ev;
	gint fd;

	rt = rspamd_http_router_new (rspamd_server_error, rspamd_server_finish,
			NULL, ev_base, path, c);
	g_assert (rt != NULL);

	rspamd_http_router_set_key (rt, kp);

	g_assert ((fd = rspamd_inet_address_listen (addr, SOCK_STREAM, TRUE)) != -1);
	event_set (&accept_ev, fd, EV_READ | EV_PERSIST, rspamd_server_accept, rt);
	event_base_set (ev_base, &accept_ev);
	event_add (&accept_ev, NULL);


	rspamd_mempool_unlock_mutex (mtx);
	event_base_loop (ev_base, 0);
}
int main(int argc, char *argv[])
{
	g_content_type = "contenttype";

#ifdef WIN32
	// initialize winsock
	WSADATA wsaData;
	WSAStartup(MAKEWORD(2,0), &wsaData);
#endif // WIN32

	event_init();

	g_cage = boost::shared_ptr<libcage::cage>(new libcage::cage());

	//g_cage->set_global();

	if(argc >= 4)
	{
		if(!g_cage->open(PF_INET, atoi(argv[1])))
		{
			std::cout<<"open port faild"<<std::endl;
			return -1;
		}
		g_cage->join(boost::lexical_cast<std::string>(argv[2]),
			 atoi(argv[3]), join_callback);
	}

	evtimer_set(&g_event, nat_state_callback, NULL);

	timeval ti;
	ti.tv_sec = 0;
	ti.tv_usec = 0;
	evtimer_add(&g_event, &ti);
	event_dispatch();
	return 0;
}
int main() {
  struct bufferevent *bev;
  int childfd[2];
  int pid;

  event_init();

  pipe(childfd);

  /* have a bufferevent watch our child's stdout */
  bev = bufferevent_new(childfd[0], bufread, NULL, NULL, "childwatch");
  bufferevent_enable(bev, EV_READ);
  startproc(childfd[1]);
  
  filewatch();

  struct event sigevent;
  signal_set(&sigevent, SIGCHLD, _sigchld, &childfd);
  signal_add(&sigevent, NULL);

  event_dispatch();

  return 0;
}
Beispiel #28
0
void t_lib_libevent_add_a_event_twice_diff_type(void) {
	struct event_base *eb;
	struct event ev1;
	struct timeval tv;

	eb = event_init();

	tv.tv_sec = 0;
	tv.tv_usec = 1000;

	event_set(&ev1, 0, EV_READ|EV_TIMEOUT, cb1, NULL);
	//event_add(&ev1, &tv); //不能重复添加
	printf("111\n");

	event_set(&ev1, 0, EV_READ, cb2, NULL);
	event_add(&ev1, &tv);
	printf("222\n");

	//event_base_dispatch(eb);

	event_del(&ev1);
	event_base_free(eb);
	return;
}
Beispiel #29
0
int main()
{
    int    listenfd;
    settings.num_threads=3;
    /* initialize main thread libevent instance */
    main_base = event_init();
    
    /* start up worker threads if MT mode */
    methread_init(settings.num_threads, main_base);
    
    /* create the listening socket, bind it, and init */
    listenfd = listening_socket(listenfd);
    printf("%ld :pthread_self.\n",pthread_self());
    
    /* Give the sockets a moment to open. I know this is dumb, but the error
     * is only an advisory.
     */
    usleep(1000);
    
    /* enter the event loop */
    event_dispatch_loop(listenfd);
    
    close(listenfd);
}
Beispiel #30
0
/**
 * @brief Initializes all the subsystems.
 */
static void init (void)
{
   /* Disable some subsystems. */
   PRR = _BV(PRTWI) | /* Disable the TWI. */
         _BV(PRTIM2) | /* Disable the Timer 2. */
         _BV(PRTIM0) | /* Disable the Timer 0. */
         _BV(PRUSART1) | /* Disable the USART 1. */
         _BV(PRTIM1) | /* Disable the Timer 1. */
         _BV(PRSPI) | /* Disable the SPI. */
         _BV(PRUSART0) | /* Disable the USART 0. */
         _BV(PRADC); /* Disable ADC. */

   /* Initialize the LED. */
   LED0_INIT();

   /*
    * Initialize subsystems.
    */
   mod_init();    /* Modules. */
   adc_init();    /* ADC. */
   pwm_init();    /* PWM IO. */
   comm_init();   /* Communication with UART0. */
   event_init();  /* Events. */

   /*
    * Optional subsystems.
    */
   timer_init(); /* Timer infrastructure on TIMER0. */
   /*servo_init();*/ /* Servo motors on TIMER1. */

   /* Set sleep mode. */
   set_sleep_mode( SLEEP_MODE_IDLE );

   /* Enable interrupts. */
   sei();
}