int main(void) { system_init(); //! [setup_init] configure_tcc(); configure_tcc_callbacks(); configure_eic(); configure_event(); //! [setup_init] //! [main] //! [enable_global_interrupts] system_interrupt_enable_global(); //! [enable_global_interrupts] //! [main_loop] while (true) { } //! [main_loop] //! [main] }
static void * x_thread_main (void *closure) { x_global_t *xg = closure; XEvent event; struct pollfd fds[2]; int timeout; sigset_t mask; sigemptyset (&mask); sigaddset (&mask, SIGALRM); sigaddset (&mask, SIGIO); sigaddset (&mask, SIGCHLD); sigaddset (&mask, SIGINT); pthread_sigmask (SIG_BLOCK, &mask, NULL); fds[0].fd = ConnectionNumber (xg->dpy); fds[0].events = POLLIN; fds[1].fd = xg->pipe[0]; fds[1].events = POLLIN; while (xg->running) { while (XPending (xg->dpy)) { XNextEvent (xg->dpy, &event); switch (event.type) { case ConfigureNotify: configure_event (xg, &event.xconfigure); break; case Expose: expose_event (xg, &event.xexpose); break; case MotionNotify: motion_notify_event (xg, &event.xmotion); break; case ButtonPress: case ButtonRelease: button_event (xg, &event.xbutton); break; case KeyPress: case KeyRelease: key_event (xg, &event.xkey); break; case ClientMessage: client_message_event (xg, &event.xclient); break; case FocusIn: case FocusOut: focus_change_event (xg, &event.xfocus); break; } } timeout = -1; while (xg->repaint) { int when = now (); timeout = xg->repaint->when - when; if (timeout > 0) break; timeout = -1; repaint_timeout (xg, when); } poll (fds, 2, timeout); if (fds[1].revents & POLLIN) { char stuffed[128]; read (fds[1].fd, stuffed, sizeof (stuffed)); } } close (xg->pipe[0]); close (xg->pipe[1]); XCloseDisplay (xg->dpy); free (xg); return 0; }
/** * \brief Main Application Routine \n * - Initialize the system clocks \n * NOTE: The clock should be configured in conf_clock.h \n * - Configure port pins (PA14 and PA16) are used here \n * - Enable Global Interrupt \n * - Configure and enable USART \n * - Configure and enable ADC \n * - Configure and enable DMAC and EVSYS if DMAC mode is chosen \n * - Start first ADC conversion \n * - Count idle loop count in forever loop \n */ int main(void) { /* Initialize system clocks */ system_init(); #if defined(ENABLE_PORT_TOGGLE) /* Configure PORT pins PA14 and PA16 are configured here * NOTE: Use oscilloscope to probe the pin. */ configure_port(); #endif /* ENable Global interrupt */ system_interrupt_enable_global(); /* Start SysTick Timer */ systick_init(); /* Configure SERCOM - USART */ configure_usart(); /* Configure and enable ADC */ configure_adc(); /* Configure and enable EVSYS */ configure_event(); /* Configure and enable DMA channel and descriptor */ configure_dma(); /* Get the time stamp 1 before starting ADC transfer */ time_stamp1 = SysTick->VAL; /* * Trigger first ADC conversion through software. * NOTE: In case of using DMA, further conversions are triggered through * event generated when previous ADC result is transferred to destination * (can be USART DATA register [or] RAM buffer). * When DMA is not used, further conversions are triggered via software in * ADC handler after each result ready. */ adc_start_conversion(&adc_instance); while (1){ #if defined (ENABLE_PORT_TOGGLE) /* Use oscilloscope to probe the pin. */ port_base->OUTTGL.reg = (1UL << PIN_PA16 % 32 ); #endif /* Increment idle count whenever application reached while(1) loop */ idle_loop_count++; /* * Check if 1024 bytes transfer is done in either case (I.e. with or without * using DMA. * 'adc_conv_done' flag is set to true in the ADC handler once * 'adc_sample_count' reaches BLOCK_COUNT. * 'adc_dma_transfer_is_done' is set to true once DMA transfer is done * in DMA call back for channel zero when 'ADC_DMAC_USART' is chosen. * When choosing ADC_DMAC_MEM_MEM_USART mode, 'adc_dma_transfer_is_done' * is set to true in DMA channel call back for channel 2. * DMA channel is disabled once reaching BLOCK_COUNT (with DMA cases). * ADC is disabled once reaching BLOBK_COUNT samples (without DMA cases). */ if (adc_dma_transfer_is_done == true){ /* * Calculate number of cycles taken from the time stamp * taken before start of the conversion and after 1024 transfer * is completed. * NOTE: This value in relation to the idle_loop_count is * used in calculating CPU usage. */ cycles_taken = calculate_cycles_taken(time_stamp1,time_stamp2); /* Write the CPU cycles taken on USART */ usart_write_buffer_wait(&usart_instance, (uint8_t *)&cycles_taken, sizeof(cycles_taken)); /* Print idle loop count on USART */ usart_write_buffer_wait(&usart_instance,(uint8_t *)&idle_loop_count, sizeof(idle_loop_count)); /* * Enter into forever loop as all transfers are completed and * DMAC/ADC is disabled */ while(1); } } }//end of main