/** * \brief Example 2 main application routine */ int main( void ) { /* Initialize interrupt controller, board and sysclock */ pmic_init(); sysclk_init(); /* Enable global interrupts */ cpu_irq_enable(); /* Set up first PWM channel */ /* Set PWM to TC E0, channel A (PE0 = LED0), 75 Hz */ pwm_init(&pwm_1_cfg, PWM_TCE0, PWM_CH_A, 75); /* Set callback function on TC overflow */ pwm_overflow_int_callback(&pwm_1_cfg, pwm_callback_1); /* Set up second PWM channel */ /* Set PWM to TC E1, channel A (PE4 = LED4), 250 Hz */ pwm_init(&pwm_2_cfg, PWM_TCE1, PWM_CH_A, 250); /* Set callback function on TC overflow */ pwm_overflow_int_callback(&pwm_2_cfg, pwm_callback_2); /* Start PWM */ pwm_start(&pwm_1_cfg, duty_cycle_percent_1); pwm_start(&pwm_2_cfg, duty_cycle_percent_2); while(1) { /* Do nothing. Everything is handled by interrupts. */ } }
int main(void) { board_init(); sysclk_init(); /* Turn off LEDs to start with */ LED_Off(LED0_GPIO); LED_Off(LED1_GPIO); LED_Off(LED2_GPIO); LED_Off(LED3_GPIO); /* Enable all three interrupt levels of the PMIC. * Alternatively, use pmic_init() to achieve the same. */ pmic_enable_level(PMIC_LVL_LOW | PMIC_LVL_MEDIUM | PMIC_LVL_HIGH); /* Enable the timer/counter's clock. */ sysclk_enable_module(SYSCLK_PORT_C, SYSCLK_TC0); /* Initialize count, period and compare registers of the timer/counter. */ TCC0.CNT = 0x0000; TCC0.PER = 0xffff; TCC0.CCA = 0x5555; TCC0.CCB = 0xaaaa; /* Set up timer/counter in normal mode with two compare channels. */ TCC0.CTRLB = TC0_CCAEN_bm | TC0_CCBEN_bm | TC_WGMODE_NORMAL_gc; /* Set levels for overflow and compare channel interrupts. */ TCC0.INTCTRLA = TC_OVFINTLVL_HI_gc; TCC0.INTCTRLB = TC_CCAINTLVL_LO_gc | TC_CCBINTLVL_MED_gc; /* Start the timer/counter and enable interrupts. */ TCC0.CTRLA = TC_CLKSEL_DIV64_gc; cpu_irq_enable(); while (1) { /* Do nothing - LED toggling is managed by interrupts. */ } }
int main(void) { irq_initialize_vectors(); #if SAMD || SAMR21 system_init(); delay_init(); #else sysclk_init(); board_init(); #endif SYS_Init(); //sio2host_init(); configure_console(); printf("we made it"); cpu_irq_enable(); LED_On(LED0); appInit(); while (1) { SYS_TaskHandler(); //APP_TaskHandler(); } }
int main(void) { irq_initialize_vectors(); cpu_irq_enable(); sleepmgr_init(); system_init(); log_init(); l("configure_pins"); setup_led(); l("ui_init"); ui_init(); l("ui_powerdown"); ui_powerdown(); // Start USB stack to authorize VBus monitoring l("udc_start"); udc_start(); while (true) { sleepmgr_enter_sleep(); } }
/*! \brief Main function. Execution starts here. */ int main(void) { irq_initialize_vectors(); cpu_irq_enable(); // Initialize the sleep manager sleepmgr_init(); sysclk_init(); board_init(); ui_init(); ui_powerdown(); // Start USB stack to authorize VBus monitoring udc_start(); // The main loop manages only the power mode // because the USB management is done by interrupt while (true) { sleepmgr_enter_sleep(); } }
/*! \brief Main function. Execution starts here. */ int main(void) { irq_initialize_vectors(); cpu_irq_enable(); #if !SAMD21 && !SAMR21 sysclk_init(); board_init(); #else system_init(); #endif // Initialize the sleep manager sleepmgr_init(); ui_init(); ui_powerdown(); // Start USB stack to authorize VBus monitoring udc_start(); // The main loop manages only the power mode // because the USB management is done by interrupt while (true) { #ifdef USB_DEVICE_LOW_SPEED // No USB "Keep a live" interrupt available in low speed // to scan mouse interface then use main loop if (main_b_mouse_enable) { static volatile uint16_t virtual_sof_sub = 0; static uint16_t virtual_sof = 0; if (sysclk_get_cpu_hz()/50000 == virtual_sof_sub++) { virtual_sof_sub = 0; static uint16_t virtual_sof = 0; ui_process(virtual_sof++); } } #else /* #ifdef USB_DEVICE_LOW_SPEED */ sleepmgr_enter_sleep(); #endif } }
/** * \brief Run Wireless Module unit tests * * Initializes the clock system, board and USB. * Then runs the wireless task continuously. */ int main(void) { irq_initialize_vectors(); sysclk_init(); /* Initialize the board. * The board-specific conf_board.h file contains the configuration of * the board initialization. */ board_init(); sw_timer_init(); tal_init(); /* Enable interrupts */ cpu_irq_enable(); stdio_usb_init(); while (1) { tal_task(); } }
static void initialize_EPD_timer(void) { uint32_t rc; /* Configure the PMC to enable the Timer/Counter (TC) module. */ sysclk_enable_peripheral_clock(EPD_TC_TIMER_ID); /** TC Configuration structure. */ struct tc_control_reg tc_control_par = { /** TC Compare Output Mode */ .co_mode = CO_NORMAL, /** TC Waveform Generation Mode */ .wg_mode = CTC_Mode1, /** TC Clock Selection, Prescalar select */ .cs_select = EPD_TC_ClockSignalSel }; /** Init TC to timer ctc mode. */ tc_initc(EPD_TC_TIMER_ID, EPD_TC_TIMER_CHANNEL, &tc_control_par); /** Configure OVF value */ rc = (sysclk_get_peripheral_bus_hz(EPD_TC_TIMER_ID) / divisors[EPD_TC_ClockSignalSel] ) / 1000 ; tc_write_cc(EPD_TC_TIMER_ID, EPD_TC_TIMER_CHANNEL, rc); /** Configure and enable interrupt on TC CTC compare match */ tc_set_compa_interrupt_callback(EPD_TC_TIMER_ID, EPD_timer_handler); tc_enable_compa_int(EPD_TC_TIMER_ID); cpu_irq_enable(); tc_start(EPD_TC_TIMER_ID, &tc_control_par); EPD_Counter=0; /** Configure the PMC to enable the Timer/Counter (TC) module. */ sysclk_enable_peripheral_clock(EPD_TC_TIMER_ID); }
/** * \brief Initialize the twi master module * * \param twi Base address of the TWI (i.e. &TWIC). * \param *opt Options for initializing the twi module * (see \ref twi_options_t) * \retval STATUS_OK Transaction is successful * \retval ERR_INVALID_ARG Invalid arguments in \c opt. */ status_code_t twi_master_init(TWI_t * twi, const twi_options_t * opt) { uint8_t const ctrla = CONF_TWIM_INTLVL | TWI_MASTER_RIEN_bm | TWI_MASTER_WIEN_bm | TWI_MASTER_ENABLE_bm; twi->MASTER.BAUD = opt->speed_reg; twi->MASTER.CTRLA = ctrla; twi->MASTER.STATUS = TWI_MASTER_BUSSTATE_IDLE_gc; transfer.locked = false; transfer.status = STATUS_OK; /* Enable configured PMIC interrupt level. */ PMIC.CTRL |= CONF_PMIC_INTLVL; cpu_irq_enable(); return STATUS_OK; }
void init() { // board init sysclk_init(); board_init(); busy_delay_init(BOARD_OSC0_HZ); // interrupts init cpu_irq_disable(); INTC_init_interrupts(); INTC_register_interrupt(&interrupt_J3, AVR32_GPIO_IRQ_3, AVR32_INTC_INT1); cpu_irq_enable(); // stdio init stdio_usb_init(&CONFIG_USART_IF); // Specify that stdout and stdin should not be buffered. #if defined(__GNUC__) && defined(__AVR32__) setbuf(stdout, NULL); setbuf(stdin, NULL); #endif }
/*! \brief Initialize sensor board target resources * * This function should be called to ensure proper initialization * of sensor hardware connected to an Atmel AVR32 or XMEGA platform. * * \return Nothing. */ void sensor_board_init(void) { /* Configure all defined Xplained Sensor board I/O pins. * * \todo * Determine whether the interrupt event flag (rising edge, falling * edge, toggle, etc.) should be a statically configurable parameter * for devices requiring more flexibility in how events are detected. */ #if (EXT_BOARD == SENSORS_XPLAINED_INERTIAL_1) || \ (EXT_BOARD == SENSORS_XPLAINED_INERTIAL_2) || \ (EXT_BOARD == SENSORS_XPLAINED_INERTIAL_A1) gpio_configure_pin(SENSOR_BOARD_PIN3, PIN_INPUT_FLAGS); gpio_configure_pin(SENSOR_BOARD_PIN4, PIN_INPUT_FLAGS); gpio_configure_pin(SENSOR_BOARD_PIN5, PIN_INPUT_FLAGS); #elif (EXT_BOARD == SENSORS_XPLAINED_PRESSURE_1) gpio_configure_pin(SENSOR_BOARD_PIN3, PIN_OUTPUT_FLAGS); gpio_configure_pin(SENSOR_BOARD_PIN4, PIN_INPUT_FLAGS); #elif (EXT_BOARD == SENSORS_XPLAINED_LIGHTPROX_1) gpio_configure_pin(SENSOR_BOARD_PIN3, PIN_INPUT_FLAGS); #elif (EXT_BOARD == SENSORS_XPLAINED_BREADBOARD) gpio_configure_pin(SENSOR_BOARD_PIN4, PIN_INPUT_FLAGS); #endif /* Global Interrupt Disable */ cpu_irq_disable(); /* Initialize interrupt vector table support. */ irq_initialize_vectors(); /* Global Interrupt Enable */ cpu_irq_enable(); }
/** * Main function, initialization and main message loop * * @return error code */ int main (void) { irq_initialize_vectors(); /* Initialize the board. * The board-specific conf_board.h file contains the configuration of * the board initialization. */ board_init(); sysclk_init(); sw_timer_init(); if (nwk_init() != NWK_SUCCESS) { app_alert(); } zid_indication_callback_init(); cpu_irq_enable(); /* * The global interrupt has to be enabled here as TAL uses the timer * delay which in turn requires interrupt to be enabled */ serial_interface_init(); /* Loop forever, the interrupts are doing the rest */ while (1) { nwk_task(); serial_data_handler(); } /* No return statement here, because this code is unreachable */ }
/**************************************************************************//** * \brief Initialize QTouch. ******************************************************************************/ void BSP_InitQTouch(BSP_TouchEventHandler_t handler) { /* initialise host app, pins, watchdog, etc */ init_system(); /* Reset touch sensing */ qt_reset_sensing(); /*Configure Burst Length*/ burst_len_config(); config_sensors(); /* Initialise and set touch params */ qt_init_sensing(); qt_set_parameters(); init_timer_isr(); buzzer_init(); /* Address to pass address of user functions */ /* This function is called after the library has made capacitive * measurements, * but before it has processed them. The user can use this hook to * apply filter * functions to the measured signal values.(Possibly to fix sensor * layout faults) */ /* This function is also used to send signal values to simulate Accelero * meter, * Just for demo purpose */ qt_filter_callback = qt_avr477_filter_cb; cpu_irq_enable(); handler = handler; }
/*! \brief Main function. Execution starts here. */ int main(void) { irq_initialize_vectors(); cpu_irq_enable(); /* Initialize ASF services */ sleepmgr_init(); sysclk_init(); board_init(); gfx_mono_init(); sd_mmc_init(); rtc_init(); stdio_usb_init(); /* Initialize STDIO and start USB */ udc_stop(); /* Stop USB by default */ main_introduction(); /* Initialize tasks */ app_touch_init(); app_cpu_load_init(); app_sampling_init(); /* The main loop */ while (true) { /* Enter in sleep mode */ app_cpu_load_enter_sleep(); sleepmgr_enter_sleep(); /* Execute tasks */ app_usb_task(); app_microsd_task(); app_sampling_task(); app_touch_task(); app_cpu_load_task(); } }
/** * Main function, initialization and main message loop * */ int main (void) { irq_initialize_vectors(); /* Initialize the board. * The board-specific conf_board.h file contains the configuration of * the board initialization. */ sysclk_init(); board_init(); sw_timer_init(); if (nwk_init()!= NWK_SUCCESS) { app_alert(); } zid_indication_callback_init(); /* * The stack is initialized above, hence the global interrupts are enabled * here. */ cpu_irq_enable(); /* Initializing udc stack as HID composite device*/ udc_start(); sw_timer_get_id(&APP_TIMER); /* Endless while loop */ while (1) { app_task(); /* Application task */ nwk_task(); /* RF4CE network layer task */ } }
/** * \brief main function */ int main (void) { /* Initialize basic board support features. * - Initialize system clock sources according to device-specific * configuration parameters supplied in a conf_clock.h file. * - Set up GPIO and board-specific features using additional configuration * parameters, if any, specified in a conf_board.h file. */ sysclk_init(); board_init(); // Initialize interrupt vector table support. irq_initialize_vectors(); // Enable interrupts cpu_irq_enable(); /* Call a local utility routine to initialize C-Library Standard I/O over * a USB CDC protocol. Tunable parameters in a conf_usb.h file must be * supplied to configure the USB device correctly. */ stdio_usb_init(); // Get and echo characters forever. uint8_t ch; while (true) { scanf("%c",&ch); // get one input character if (ch) { printf("%c",ch); // echo to output } } }
/*! \brief Main function. */ int main(void) { sysclk_init(); /* Initialize the board. * The board-specific conf_board.h file contains the configuration of * the board initialization. */ board_init(); /* Config the USART_SPI in master mode. */ usart_spi_init(USART_SPI_EXAMPLE); usart_spi_setup_device(USART_SPI_EXAMPLE, &USART_SPI_DEVICE_EXAMPLE, SPI_MODE_0, USART_SPI_EXAMPLE_BAUDRATE, 0); usart_spi_enable(USART_SPI_EXAMPLE); /* Config the SPI module in slave mode. */ spi_slave_init(SPI_SLAVE_EXAMPLE, SPI_MODE_0); spi_enable(SPI_SLAVE_EXAMPLE); /* Enable global interrupt */ cpu_irq_enable(); /* Show the test result by LED. */ if (spi_usart_master_transfer() == true && spi_slave_transfer() == true) { ioport_set_pin_level(SPI_SLAVE_EXAMPLE_LED_PIN, IOPORT_PIN_LEVEL_LOW); } else { ioport_set_pin_level(SPI_SLAVE_EXAMPLE_LED_PIN, IOPORT_PIN_LEVEL_HIGH); } while (1) { /* Do nothing */ } }
int main(void) { const usart_serial_options_t usart_serial_options = { .baudrate = CONF_TEST_BAUDRATE, .charlength = CONF_TEST_CHARLENGTH, .paritytype = CONF_TEST_PARITY, .stopbits = CONF_TEST_STOPBITS, }; /* Usual initializations */ board_init(); sysclk_init(); sleepmgr_init(); irq_initialize_vectors(); cpu_irq_enable(); stdio_serial_init(CONF_TEST_USART, &usart_serial_options); printf("\x0C\n\r-- ADC Calibration Example"); printf(" (Compiled: %s %s)\n\r", __DATE__, __TIME__); /* ADC and DAC initializations */ main_dac_init(); main_adc_init(); printf("\n\rConversion samples without correction:\n\r"); main_conversions(); /* Measure and enable corrections */ main_adc_correction(); printf("Conversion samples with correction:\n\r"); main_conversions(); while (1) { } }
int main (void) { sysclk_init(); ioport_init(); ioport_set_pin_dir(LED_BLUE, IOPORT_DIR_OUTPUT); ioport_set_pin_dir(LED_GREEN, IOPORT_DIR_OUTPUT); ioport_set_pin_dir(LED_WHITE, IOPORT_DIR_OUTPUT); ioport_configure_pin(BUTTON_0, IOPORT_PULL_UP); ioport_configure_pin(BUTTON_1, IOPORT_PULL_UP); force_boot_loader(); irq_initialize_vectors(); cpu_irq_enable(); udc_start(); //board_init(); while(1) { ioport_toggle_pin_level(LED_GREEN); delay_ms(100); ioport_set_pin_level(LED_BLUE, ioport_get_pin_level(BUTTON_0)); ioport_set_pin_level(LED_WHITE, ioport_get_pin_level(BUTTON_1)); char usb_in = udi_cdc_getc(); char usb_out [17]= "WHAT YOU TYPED: \r";//udi_cdc_getc(); for (int i=0;i<16;i++) { udi_cdc_putc(usb_out[i]); } udi_cdc_putc(usb_in); udi_cdc_putc('\r'); } }
//--------------------------------- //----- static function definitions // __attribute__((__interrupt__)) static void irq_pdca(void) { #if 1 #else // Disable all interrupts. // Disable_global_interrupt(); cpu_irq_disable(); // Disable interrupt channel. pdca_disable_interrupt_transfer_complete(AVR32_PDCA_CHANNEL_SPI_RX); //unselects the SD/MMC memory. sd_mmc_spi_read_close_PDCA(); //.... example has a 5000 clock gimpy delay here. // using delay_us instead delay_ms(10); // delay_ms(2); // Disable unnecessary channel pdca_disable(AVR32_PDCA_CHANNEL_SPI_TX); pdca_disable(AVR32_PDCA_CHANNEL_SPI_RX); // Enable all interrupts. cpu_irq_enable(); // Enable_global_interrupt(); // print_dbg("\r\n handled PDCA interrupt. \r\n"); fsEndTransfer = true; #endif }
//! host_disable_all_pipes //! //! This function disables all pipes for the host controller. //! Useful to execute upon disconnection. //! //! @return Void //! void host_disable_all_pipes(void) { #if USB_HOST_PIPE_INTERRUPT_TRANSFER == ENABLE bool sav_glob_int_en; #endif U8 p; #if USB_HOST_PIPE_INTERRUPT_TRANSFER == ENABLE // Disable global interrupts if ((sav_glob_int_en = cpu_irq_is_enabled())) cpu_irq_disable(); #endif for (p = 0; p < MAX_PEP_NB; p++) { // Disable the pipe <p> (disable interrupt, free memory, reset pipe, ...) Host_disable_pipe_interrupt(p); Host_reset_pipe(p); Host_unallocate_memory(p); Host_disable_pipe(p); } #if USB_HOST_PIPE_INTERRUPT_TRANSFER == ENABLE (void)Is_host_pipe_enabled(MAX_PEP_NB - 1); // Restore the global interrupts to the initial state if (sav_glob_int_en) cpu_irq_enable(); #endif }
// top-level peripheral init static void init_avr32(void) { volatile avr32_tc_t *tc = APP_TC; // clocks // setup clocks sysclk_init(); // not sure why but when need to explictly enable clock for static mem ctlr sysclk_enable_pbb_module(SYSCLK_SMC_REGS); flashc_set_bus_freq(FCPU_HZ); // need this for high-speed operation flashc_set_wait_state(1); /// interrupts // print_dbg("\r\n irq_initialize_vectors() "); irq_initialize_vectors(); // disable all interrupts for now // print_dbg("\r\n cpu_irq_disable() "); cpu_irq_disable(); // serial usb print_dbg("\r\n init_ftdi_usart() "); init_ftdi_usart(); // external sram print_dbg("\r\n smc_init(FHSB_HZ) "); smc_init(FHSB_HZ); // initialize spi1: OLED, ADC, SD/MMC print_dbg("\r\n init_spi1() "); init_spi1(); // initialize PDCA controller print_dbg("\r\n init_local_pdca() "); init_local_pdca(); // initialize blackfin resources print_dbg("\r\n init_bfin_resources() "); init_bfin_resources(); // initialize application timer print_dbg("\r\n init_tc(tc) "); init_tc(tc); // initialize other GPIO print_dbg("\r\n init_gpio() "); init_gpio(); // register interrupts print_dbg("\r\n register_interrupts() "); register_interrupts(); // initialize the OLED screen print_dbg("\r\n init_oled() "); init_oled(); // enable interrupts print_dbg("\r\n cpu_irq_enable() "); cpu_irq_enable(); // usb host controller init_usb_host(); // initialize usb classes print_dbg("\r\n init_monome "); init_monome(); // init_midi(); // init_hid(); }
/*! \brief Initializes STDIO. */ static void init_stdio(void) { #if (defined __GNUC__) && (defined __AVR32__) static const gpio_map_t STDIO_USART_GPIO_MAP = { {STDIO_USART_RX_PIN, STDIO_USART_RX_FUNCTION}, {STDIO_USART_TX_PIN, STDIO_USART_TX_FUNCTION} }; // Initialize the USART used for STDIO. set_usart_base((void *)STDIO_USART); gpio_enable_module(STDIO_USART_GPIO_MAP, sizeof(STDIO_USART_GPIO_MAP) / sizeof(STDIO_USART_GPIO_MAP[0])); usart_init(STDIO_USART_BAUDRATE); #elif (defined __ICCAVR32__) static const gpio_map_t STDIO_USART_GPIO_MAP = { {STDIO_USART_RX_PIN, STDIO_USART_RX_FUNCTION}, {STDIO_USART_TX_PIN, STDIO_USART_TX_FUNCTION} }; static const usart_options_t STDIO_USART_OPTIONS = { .baudrate = STDIO_USART_BAUDRATE, .charlength = 8, .paritytype = USART_NO_PARITY, .stopbits = USART_1_STOPBIT, .channelmode = USART_NORMAL_CHMODE }; // Initialize the USART used for STDIO. extern volatile avr32_usart_t *volatile stdio_usart_base; stdio_usart_base = STDIO_USART; gpio_enable_module(STDIO_USART_GPIO_MAP, sizeof(STDIO_USART_GPIO_MAP) / sizeof(STDIO_USART_GPIO_MAP[0])); usart_init_rs232(STDIO_USART, &STDIO_USART_OPTIONS, FPBA_HZ); #endif } #if (defined __GNUC__) /*! \brief Low-level initialization routine called during startup, before the * main function. * * This version comes in replacement to the default one provided by the Newlib * add-ons library. * Newlib add-ons' _init_startup only calls init_exceptions, but Newlib add-ons' * exception and interrupt vectors are defined in the same section and Newlib * add-ons' interrupt vectors are not compatible with the interrupt management * of the INTC module. * More low-level initializations are besides added here. */ int _init_startup(void) { // Import the Exception Vector Base Address. extern void _evba; // Load the Exception Vector Base Address in the corresponding system register. Set_system_register(AVR32_EVBA, (int)&_evba); // Enable exceptions. Enable_global_exception(); // Initialize interrupt handling. irq_initialize_vectors(); cpu_irq_enable(); init_stdio(); // Don't-care value for GCC. return 1; } #elif (defined __ICCAVR32__) /*! \brief Low-level initialization routine called during startup, before the * main function. */ int __low_level_init(void) { // Enable exceptions. Enable_global_exception(); // Initialize interrupt handling. irq_initialize_vectors(); cpu_irq_enable(); init_stdio(); // Request initialization of data segments. return 1; }
int main(void) { const usart_serial_options_t usart_serial_options = { .baudrate = CONF_TEST_BAUDRATE, .charlength = CONF_TEST_CHARLENGTH, .paritytype = CONF_TEST_PARITY, .stopbits = CONF_TEST_STOPBITS, }; char binary[16 + 1]; uint8_t i; bool oversampling_is_enabled; /* Usual initializations */ board_init(); sysclk_init(); sleepmgr_init(); irq_initialize_vectors(); cpu_irq_enable(); stdio_serial_init(CONF_TEST_USART, &usart_serial_options); printf("\x0C\n\r-- ADC Over-sampling Example --\n\r"); printf("-- Compiled: %s %s --\n\r\n\r", __DATE__, __TIME__); printf("Commands:\n\r"); printf("- key 'o' to enable over-sampling\n\r"); printf("- key 'd' to disable over-sampling\n\r"); /* ADC initializations */ main_adc_init(); main_adc_oversampling_stop(); oversampling_is_enabled = false; while (1) { if (usart_rx_is_complete(CONF_TEST_USART)) { char key = getchar(); if (key == 'o') { main_adc_oversampling_start(); oversampling_is_enabled = true; } if (key == 'd') { main_adc_oversampling_stop(); oversampling_is_enabled = false; } } /* Wait sample with or without over-sampling */ uint16_t sample; adc_wait_for_interrupt_flag(&ADCA, ADC_CH0); sample = adc_get_unsigned_result(&ADCA, ADC_CH0); if (!oversampling_is_enabled) { sample <<= 4; } i = 15; do { binary[i] = '0' + (sample & 1); sample >>= 1; } while (i--); binary[16] = 0; printf("ADC Value: %sb\r", binary); } }
/** * \brief TC Initialization * * Initializes and start the TC module with the following: * - Counter in Up mode with automatic reset on RC compare match. * - fPBA/8 is used as clock source for TC * - Enables RC compare match interrupt * \param tc Base address of the TC module */ static void tc_init(volatile avr32_tc_t *tc) { // Options for waveform generation. static const tc_waveform_opt_t waveform_opt = { // Channel selection. .channel = EXAMPLE_TC_CHANNEL, // Software trigger effect on TIOB. .bswtrg = TC_EVT_EFFECT_NOOP, // External event effect on TIOB. .beevt = TC_EVT_EFFECT_NOOP, // RC compare effect on TIOB. .bcpc = TC_EVT_EFFECT_NOOP, // RB compare effect on TIOB. .bcpb = TC_EVT_EFFECT_NOOP, // Software trigger effect on TIOA. .aswtrg = TC_EVT_EFFECT_NOOP, // External event effect on TIOA. .aeevt = TC_EVT_EFFECT_NOOP, // RC compare effect on TIOA. .acpc = TC_EVT_EFFECT_NOOP, /* * RA compare effect on TIOA. * (other possibilities are none, set and clear). */ .acpa = TC_EVT_EFFECT_NOOP, /* * Waveform selection: Up mode with automatic trigger(reset) * on RC compare. */ .wavsel = TC_WAVEFORM_SEL_UP_MODE_RC_TRIGGER, // External event trigger enable. .enetrg = false, // External event selection. .eevt = 0, // External event edge selection. .eevtedg = TC_SEL_NO_EDGE, // Counter disable when RC compare. .cpcdis = false, // Counter clock stopped with RC compare. .cpcstop = false, // Burst signal selection. .burst = false, // Clock inversion. .clki = false, // Internal source clock 3, connected to fPBA / 8. .tcclks = TC_CLOCK_SOURCE_TC3 }; // Options for enabling TC interrupts static const tc_interrupt_t tc_interrupt = { .etrgs = 0, .ldrbs = 0, .ldras = 0, .cpcs = 1, // Enable interrupt on RC compare alone .cpbs = 0, .cpas = 0, .lovrs = 0, .covfs = 0 }; // Initialize the timer/counter. tc_init_waveform(tc, &waveform_opt); /* * Set the compare triggers. * We configure it to count every 1 milliseconds. * We want: (1 / (fPBA / 8)) * RC = 1 ms, hence RC = (fPBA / 8) / 1000 * to get an interrupt every 10 ms. */ tc_write_rc(tc, EXAMPLE_TC_CHANNEL, (sysclk_get_pba_hz() / 8 / 1000)); // configure the timer interrupt tc_configure_interrupts(tc, EXAMPLE_TC_CHANNEL, &tc_interrupt); // Start the timer/counter. tc_start(tc, EXAMPLE_TC_CHANNEL); } /*! \brief Main function: * - Configure the CPU to run at 12MHz * - Configure the USART * - Register the TC interrupt (GCC only) * - Configure, enable the CPCS (RC compare match) interrupt, and start a * TC channel in waveform mode * - In an infinite loop, update the USART message every second. */ int main(void) { volatile avr32_tc_t *tc = EXAMPLE_TC; uint32_t timer = 0; /** * \note the call to sysclk_init() will disable all non-vital * peripheral clocks, except for the peripheral clocks explicitly * enabled in conf_clock.h. */ sysclk_init(); // Enable the clock to the selected example Timer/counter peripheral module. sysclk_enable_peripheral_clock(EXAMPLE_TC); // Initialize the USART module for trace messages init_dbg_rs232(sysclk_get_pba_hz()); // Disable the interrupts cpu_irq_disable(); #if defined (__GNUC__) // Initialize interrupt vectors. INTC_init_interrupts(); // Register the RTC interrupt handler to the interrupt controller. INTC_register_interrupt(&tc_irq, EXAMPLE_TC_IRQ, EXAMPLE_TC_IRQ_PRIORITY); #endif // Enable the interrupts cpu_irq_enable(); // Initialize the timer module tc_init(tc); while (1) { // Update the display on USART every second. if ((update_timer) && (!(tc_tick%1000))) { timer++; // Set cursor to the position (1; 5) print_dbg("\x1B[5;1H"); // Print the timer value print_dbg("ATMEL AVR UC3 - Timer/Counter Example 3\n\rTimer: "); print_dbg_ulong(timer); print_dbg(" s"); // Reset the timer update flag to wait till next timer interrupt update_timer = false; } } }
//int main(void) { ////main function int main (void) { u32 waitForCard = 0; // set up avr32 hardware and peripherals init_avr32(); print_dbg("\r\n SRAM size: 0x"); print_dbg_hex(smc_get_cs_size(1)); cpu_irq_disable(); /// test the SRAM sram_test(); cpu_irq_enable(); //memory manager init_mem(); print_dbg("\r\n init_mem"); // wait for sdcard print_dbg("\r\n SD check... "); while (!sd_mmc_spi_mem_check()) { waitForCard++; } print_dbg("\r\nfound SD card. "); // intialize the FAT filesystem print_dbg("\r\n init fat"); fat_init(); // setup control logic print_dbg("\r\n init ctl"); init_ctl(); /* // initialize the application */ /* app_init(); */ /* print_dbg("\r\n init app"); */ // initialize flash: firstrun = init_flash(); print_dbg("r\n init flash, firstrun: "); print_dbg_ulong(firstrun); screen_startup(); // find and load dsp from sdcard files_search_dsp(); print_dbg("\r\n starting event loop.\r\n"); // dont do startup startup = 0; while(1) { check_events(); } }
/** * \brief main function */ int main(void) { struct dma_channel_config config; uint32_t checksum; pmic_init(); board_init(); sysclk_init(); sleepmgr_init(); // Randomly selected data source[0] = 0xAA; source[1] = 0xBB; source[2] = 0xCC; source[3] = 0xDD; source[4] = 0xEE; source[5] = 0xFF; // Calculate checksum for the data checksum = crc_io_checksum((void*)source, 6, CRC_16BIT); // Append the checksum to the data, big endian crc16_append_value(checksum, source+6); //Enable the CRC module for DMA crc_dma_checksum_start(DMA_CHANNEL, CRC_16BIT); // Enable DMA dma_enable(); // Set callback function for DMA completion dma_set_callback(DMA_CHANNEL, example_crc_dma_transfer_done); // Make sure config is all zeroed out so we don't get any stray bits memset(&config, 0, sizeof(config)); /** * This example will configure a DMA channel with the following * settings: * - Low interrupt priority * - 1 byte burst length * - DMA_BUFFER_SIZE bytes for each transfer * - Reload source and destination address at end of each transfer * - Increment source and destination address during transfer * - Source address is set to \ref source * - Destination address is set to \ref destination */ dma_channel_set_interrupt_level(&config, PMIC_LVL_LOW); dma_channel_set_burst_length(&config, DMA_CH_BURSTLEN_1BYTE_gc); dma_channel_set_transfer_count(&config, DMA_BUFFER_SIZE); dma_channel_set_src_reload_mode(&config, DMA_CH_SRCRELOAD_TRANSACTION_gc); dma_channel_set_dest_reload_mode(&config, DMA_CH_DESTRELOAD_TRANSACTION_gc); dma_channel_set_src_dir_mode(&config, DMA_CH_SRCDIR_INC_gc); dma_channel_set_dest_dir_mode(&config, DMA_CH_DESTDIR_INC_gc); dma_channel_set_source_address(&config, (uint16_t)(uintptr_t)source); dma_channel_set_destination_address(&config, (uint16_t)(uintptr_t)destination); dma_channel_write_config(DMA_CHANNEL, &config); // Use the configuration above by enabling the DMA channel in use. dma_channel_enable(DMA_CHANNEL); // Enable interrupts cpu_irq_enable(); // Trigger the DMA transfer dma_channel_trigger_block_transfer(DMA_CHANNEL); // Light the first LED to indicate that the DMA has started. gpio_set_pin_low(LED0_GPIO); while (true) { /* * Force a NOP instruction for an eventual placement of a debug * session breakpoint. */ asm("nop\n"); } }
/** * \brief Initializes the TC subsystem ready to generate a LED PWM wave. * * Initializes the on-chip TC module in PWM generation mode, and configures the * board LED as an output so that the LED brightness can be adjusted. */ static void pwm_timer_init(void) { // Assign output pin to timer/counter 0 channel B gpio_enable_module_pin(AVR32_TC0_B0_0_0_PIN, AVR32_TC0_B0_0_0_FUNCTION); // Timer waveform options const tc_waveform_opt_t waveform_options = { //! Channel selection. .channel = 0, //! Software trigger effect on TIOB. .bswtrg = TC_EVT_EFFECT_NOOP, //! External event effect on TIOB. .beevt = TC_EVT_EFFECT_NOOP, //! RC compare effect on TIOB. .bcpc = TC_EVT_EFFECT_CLEAR, //! RB compare effect on TIOB. .bcpb = TC_EVT_EFFECT_SET, //! Software trigger effect on TIOA. .aswtrg = TC_EVT_EFFECT_NOOP, //! External event effect on TIOA. .aeevt = TC_EVT_EFFECT_NOOP, //! RC compare effect on TIOA. .acpc = TC_EVT_EFFECT_NOOP, //! RA compare effect on TIOA. .acpa = TC_EVT_EFFECT_NOOP, //! Waveform selection .wavsel = TC_WAVEFORM_SEL_UP_MODE_RC_TRIGGER, //! External event trigger enable. .enetrg = false, //! External event selection (non-zero for Channel B to work) .eevt = !0, //! External event edge selection. .eevtedg = TC_SEL_NO_EDGE, //! Counter disable when RC compare. .cpcdis = false, //! Counter clock stopped with RC compare. .cpcstop = false, //! Burst signal selection. .burst = false, //! Clock inversion selection. .clki = false, //! Internal source clock 5, fPBA/128. .tcclks = TC_CLOCK_SOURCE_TC5, }; // Setup timer/counter waveform mode sysclk_enable_peripheral_clock(&AVR32_TC0); tc_init_waveform(&AVR32_TC0, &waveform_options); // Write the TOP (RC) and COMPARE (RB) values tc_write_rb(&AVR32_TC0, 0, 1); // Set RB value. tc_write_rc(&AVR32_TC0, 0, 255); // Set RC value. // Start the timer PWM channel tc_start(&AVR32_TC0, 0); } /** * \brief Application main routine */ int main(void) { board_init(); sysclk_init(); irq_initialize_vectors(); cpu_irq_enable(); pwm_timer_init(); touch_init(); while (true) { touch_handler(); } }
int main (void) { sysclk_init(); board_init(); pmic_init(); gfx_mono_init(); adc_sensors_init(); // Enable display backlight gpio_set_pin_high(NHD_C12832A1Z_BACKLIGHT); cpu_irq_enable(); while(true){ if(state==1){ start_game(); }else if(state==2){ tc_enable(&TCC0); tc_set_overflow_interrupt_callback(&TCC0, sun_count); tc_set_wgm(&TCC0, TC_WG_NORMAL); tc_write_period(&TCC0, 13500); tc_set_overflow_interrupt_level(&TCC0, TC_INT_LVL_LO); tc_write_clock_source(&TCC0, TC_CLKSEL_DIV256_gc); tc_enable(&TCC1); tc_set_overflow_interrupt_callback(&TCC1, button_press); tc_set_wgm(&TCC1, TC_WG_NORMAL); tc_write_period(&TCC1, 62500); tc_set_overflow_interrupt_level(&TCC1, TC_INT_LVL_LO); tc_write_clock_source(&TCC1, TC_CLKSEL_DIV8_gc); gfx_mono_draw_string("SUN: 0", 0, 0, &sysfont); gfx_mono_draw_string(">", 0, cursor_position, &sysfont); gfx_mono_draw_string("Score: 0", 63, 0, &sysfont); randomPeta(); char* score_string = NULL; uint16_t old_score = 0; for(j = 0; j <= 70; j++){ if(sun_value > 10){ lightsensor_measure(); while (!lightsensor_data_is_ready()) { // Wait until the conversion is complete } if(lightsensor_get_raw_value() > 250){ sun_value -= 10; sunBurst(); gfx_mono_draw_filled_rect(12,8,114,24,GFX_PIXEL_CLR); } } if(score > old_score){ sprintf(score_string, "%3d", score); gfx_mono_draw_string(score_string, 100, 0, &sysfont); old_score = score; } if(lose){ state=3; break; }else if(zombie==0){ state=4; break; } tampilkanPeta(); tampilkanTembak(); delay_ms(1000); } }else if(state==3){ cpu_irq_disable(); gfx_mono_draw_filled_rect(0,0,128,32,GFX_PIXEL_CLR); while(true){ gfx_mono_draw_string("GAME OVER",36,8,&sysfont) ; gfx_mono_draw_string("You Lose",39,20,&sysfont) ; } }else if(state==4){ cpu_irq_disable(); gfx_mono_draw_filled_rect(0,0,128,32,GFX_PIXEL_CLR); while(true){ gfx_mono_draw_string("GAME OVER",36,2,&sysfont) ; gfx_mono_draw_string("You Win",42,12,&sysfont) ; gfx_mono_draw_string("Score = ",30,22,&sysfont) ; char* score_string = NULL; sprintf(score_string, "%3d", score); gfx_mono_draw_string(score_string, 79, 22, &sysfont); } } } }
int main(void) { ioport_init(); board_init(); sysclk_init(); irq_initialize_vectors(); cpu_irq_enable(); stdio_usb_init(); delay_ms(200); // Power on LED on board ioport_set_pin_level(GPIO_LED_GREEN, IOPORT_PIN_LEVEL_HIGH); ad9834_init(); while(true) { enum ad9834_waveform waveform; float frequency, vout; // start_frequency, end_frequency, //uint32_t delay; // Read command from PC Byte cmd = usb_data_read_byte(); switch (cmd) { case CMD_FREQ: frequency = usb_data_read_float(); ad9834_set_frequency(frequency); break; case CMD_VOUT: vout = usb_data_read_float(); ad9834_set_output_voltage(vout); break; case CMD_WAVEFORM: waveform = (enum ad9834_waveform)usb_data_read_byte(); ad9834_set_waveform(waveform); break; case CMD_FREQ_REG: ad9834_set_frequency_register(usb_data_read_byte()); break; /* Not implemented yet case CMD_PHASE: // ad9834_set_phase() break; case CMD_PHASE_REG: // ad9834_set_phase_register(usb_data_read_byte()) break; case CMD_SWEEP: start_frequency = usb_data_read_float(); end_frequency = usb_data_read_float(); delay = usb_data_read_uint32(); for (uint32_t frequency = start_frequency; frequency < end_frequency; frequency += 1) { ad9834_set_frequency(frequency); delay_us(delay); } usb_data_write_byte(MSG_DONE); break; case CMD_RESET: break; */ default: // Do nothing if not recognized command break; } } }