예제 #1
0
파일: demo.c 프로젝트: kerichsen/asf
int main(void)
{
  init_sys_clocks();

  init_dbg_rs232(FPBA_HZ);

  print_dbg("AVR UC3 DSP DEMO\r\n");

  irq_initialize_vectors();

  // GUI, Controller and DSP process init
  gui_init(FCPU_HZ, FHSB_HZ, FPBA_HZ, FPBB_HZ);
  gui_text_print(GUI_COMMENT_ID, TEXT_IDLE);
  gui_text_print(GUI_FILTER_ID, filter_active_get_description());
  controller_init(FCPU_HZ, FHSB_HZ, FPBA_HZ, FPBB_HZ);
  twi_init();
  dsp_process_init(FCPU_HZ, FHSB_HZ, FPBA_HZ, FPBB_HZ);

  cpu_irq_enable();

  // Main loop
  while (1)
  {
    gui_task();
    controller_task();
    dsp_process_task();
    state_machine_task();
  }
}
예제 #2
0
//! @{
void twis_init (void)
{
	twis_slave_fct_t twis_slave_fct;
#if BOARD == UC3L_EK
	/**
	* \internal For UC3L devices, TWI default pins are,
	* TWIMS0 -> PB05,PA21
	* TWIMS1 -> PB04
	* To enable TWI clock/data in another pin, these have
	* to be assigned to other peripherals or as GPIO.
	* \endinternal
	 */
	gpio_enable_gpio_pin(AVR32_PIN_PB05);
	gpio_enable_gpio_pin(AVR32_PIN_PA21);
#endif
	const gpio_map_t TWIS_GPIO_MAP = {
		{TEST_TWIS_TWCK_PIN, TEST_TWIS_TWCK_FUNCTION},
		{TEST_TWIS_TWD_PIN, TEST_TWIS_TWD_FUNCTION}
	};
	const twis_options_t TWIS_OPTIONS = {
		.pba_hz = FPBA_HZ,
		.speed = TWI_SPEED,
		.chip = SLAVE_ADDRESS,
		.smbus = false,
	};
	// Assign I/Os to SPI.
	gpio_enable_module (TWIS_GPIO_MAP,
			sizeof (TWIS_GPIO_MAP) / sizeof (TWIS_GPIO_MAP[0]));
	// Set pointer to user specific application routines
	twis_slave_fct.rx = &twis_slave_rx;
	twis_slave_fct.tx = &twis_slave_tx;
	twis_slave_fct.stop = &twis_slave_stop;
	// Initialize as master.
	twis_slave_init (TWIS, &TWIS_OPTIONS, &twis_slave_fct);
}
//! @}

/*! \brief Main function.
 */
/*! \remarks Main Function
 */
//! @{
int main (void)
{
	// Configure the system clock
	init_sys_clocks ();
	// Init debug serial line
	init_dbg_rs232 (FPBA_HZ);
	// Display a header to user
	print_dbg ("Slave Example\r\n");
	print_dbg ("Slave Started\r\n");
	// Initialize and enable interrupt
	irq_initialize_vectors();
	cpu_irq_enable();
	// Initialize the TWIS Module
	twis_init ();
	while (true);
}
예제 #3
0
/* \brief Initialize board.
 *
 */
void init_board(void)
{

#ifdef MAX_SPEED
	init_sys_clocks();
#else
  pcl_switch_to_osc(PCL_OSC0, FOSC0, OSC0_STARTUP);
#endif
	INTC_init_interrupts();

	init_dbg_rs232(FPBA_HZ);
	// Activate LED0 & LED1 & LED2 & LED3 pins in GPIO output
	// mode and switch them off.
	gpio_set_gpio_pin(LED0_GPIO);
	gpio_set_gpio_pin(LED1_GPIO);
	gpio_set_gpio_pin(LED2_GPIO);
	gpio_set_gpio_pin(LED3_GPIO);

	et024006_Init(FCPU_HZ, FCPU_HZ);
	gpio_set_gpio_pin(ET024006DHU_BL_PIN);
	et024006_DrawFilledRect(0, 0, ET024006_WIDTH, ET024006_HEIGHT, WHITE);
}
예제 #4
0
/*! \brief Main function. Execution starts here.
 *
 * \retval 42 Fatal error.
 */
int main(void)
{
    init_hmatrix();

    // Configure standard I/O streams as unbuffered.
#if (defined __GNUC__) && (defined __AVR32__)
    setbuf(stdin, NULL);
#endif
    setbuf(stdout, NULL);

#if (defined USB_RESYNC_METHOD) && (USB_RESYNC_METHOD == USB_RESYNC_METHOD_EXT_CLOCK_SYNTHESIZER)
    // Initialize the TWI using the internal RCOSC
    init_twi_CS2200(AVR32_PM_RCOSC_FREQUENCY);

    // Initialize the CS2200 and produce a default 11.2896 MHz frequency
    cs2200_setup(11289600, FOSC0);
#endif

    // Initializes the MCU system clocks
    init_sys_clocks();

    // Initialize the TWI
    init_twi(FPBA_HZ);

    audio_mixer_enable_dacs(DEFAULT_DACS);
    audio_mixer_dacs_start(DEFAULT_DAC_SAMPLE_RATE_HZ,
                           DEFAULT_DAC_NUM_CHANNELS,
                           DEFAULT_DAC_BITS_PER_SAMPLE,
                           DEFAULT_DAC_SWAP_CHANNELS);

    // Initialize the display
    et024006_Init(  FCPU_HZ, FHSB_HZ);

    // Set Backlight
    gpio_set_gpio_pin(ET024006DHU_BL_PIN);

    // Clear the display
    et024006_DrawFilledRect(0, 0, ET024006_WIDTH, ET024006_HEIGHT, WHITE );

    // Display a logo.
    et024006_PutPixmap(avr32_logo, AVR32_LOGO_WIDTH, 0, 0
                       ,(ET024006_WIDTH - AVR32_LOGO_WIDTH)/2
                       ,(ET024006_HEIGHT - AVR32_LOGO_HEIGHT)/2, AVR32_LOGO_WIDTH, AVR32_LOGO_HEIGHT);

    et024006_PrintString(AUDIO_DEMO_STRING, (const unsigned char *)&FONT8x16, 30, 5, BLACK, -1);
    et024006_PrintString("Please plug the USB.", (const unsigned char *)&FONT8x8, 30, 30, BLACK, -1);

    // Initialize USB task
    usb_task_init();

    // Initialize Controller
    controller_init(FCPU_HZ, FHSB_HZ, FPBB_HZ, FPBA_HZ);

#if USB_DEVICE_FEATURE == true
    // Initialize device audio USB task
    device_audio_task_init();

    // Initialize the HID USB task
    device_hid_task_init();
#endif
#if USB_HOST_FEATURE == true
    // Initialize host audio USB task
    host_audio_task_init();
#endif

#ifdef FREERTOS_USED
    // Start OS scheduler
    vTaskStartScheduler();
    portDBG_TRACE("FreeRTOS returned.");
    return 42;
#else
    // No OS here. Need to call each task in round-robin mode.
    while (true)
    {
        usb_task();
#if USB_DEVICE_FEATURE == true
        device_audio_task();
        device_hid_task();
#endif
#if USB_HOST_FEATURE == true
        host_audio_task();
#endif
    }
#endif  // FREERTOS_USED
}
예제 #5
0
파일: board_init.c 프로젝트: 00alis/Arduino
static void init_spi(void)
{
#if defined(WL_SPI)
        int i;
#endif
        

#if defined(AT45DBX_SPI)
        static const gpio_map_t AT45DBX_SPI_GPIO_MAP = {
                { AT45DBX_SPI_SCK_PIN, AT45DBX_SPI_SCK_FUNCTION },
                { AT45DBX_SPI_MISO_PIN, AT45DBX_SPI_MISO_FUNCTION },
                { AT45DBX_SPI_MOSI_PIN, AT45DBX_SPI_MOSI_FUNCTION },
                { AT45DBX_SPI_NPCS2_PIN, AT45DBX_SPI_NPCS2_FUNCTION },
        };
#endif

        
#if defined(WL_SPI) 
	const gpio_map_t WL_SPI_GPIO_MAP = {
#if defined(WL_SPI_NPCS0)
            WL_SPI_NPCS0,
#endif
            WL_SPI_NPCS, WL_SPI_MISO, WL_SPI_MOSI, WL_SPI_SCK
        };
#endif

#if defined(WL_SPI) || defined(AT45DBX_SPI)
        spi_options_t spiOptions = {
                .modfdis = 1 /* only param used by spi_initMaster() */
        };
#endif

#if defined(AT45DBX_SPI)
        gpio_enable_module(AT45DBX_SPI_GPIO_MAP,
                           sizeof(AT45DBX_SPI_GPIO_MAP) /
                           sizeof(AT45DBX_SPI_GPIO_MAP[0]));
        spi_initMaster(AT45DBX_SPI, &spiOptions);
        spi_selectionMode(AT45DBX_SPI, 0, 0, 0);
#endif

#if defined(WL_SPI)
        /* same pins might be initialized twice here */
        gpio_enable_module(WL_SPI_GPIO_MAP,
                           sizeof(WL_SPI_GPIO_MAP) /
                           sizeof(WL_SPI_GPIO_MAP[0]));
        for (i = 0; i < sizeof(WL_SPI_GPIO_MAP)/sizeof(WL_SPI_GPIO_MAP[0]); i++)
                gpio_enable_pin_pull_up(WL_SPI_GPIO_MAP[i].pin);

        /* same SPI controller might be initialized again */
        spi_initMaster(&WL_SPI, &spiOptions);
        spi_selectionMode(&WL_SPI, 0, 0, 0);
#endif

#if defined(AT45DBX_SPI)
        spi_enable(AT45DBX_SPI);

        /* put up flash reset pin */
        gpio_set_gpio_pin(AT45DBX_CHIP_RESET);
#endif

#if defined(WL_SPI)
        spi_enable(&WL_SPI);
#endif
}


static void init_rs232(void)
{
#ifndef NO_SERIAL
#if defined(BOARD_RS232_0)
        const gpio_map_t BOARD_RS232_0_GPIO_MAP = {
                BOARD_RS232_0_TX,
                BOARD_RS232_0_RX,
#if defined(BOARD_RS232_0_RTS) && defined (BOARD_RS232_0_CTS)
                BOARD_RS232_0_RTS,
                BOARD_RS232_0_CTS
#endif
                
        };
#endif

#if defined(BOARD_RS232_1)
        const gpio_map_t BOARD_RS232_1_GPIO_MAP = {
                BOARD_RS232_1_TX,
                BOARD_RS232_1_RX
#if defined(BOARD_RS232_1_RTS) && defined (BOARD_RS232_1_CTS)
                BOARD_RS232_1_RTS,
                BOARD_RS232_1_CTS
#endif
        };
#endif

#if defined(BOARD_RS232_0)
	gpio_enable_module(BOARD_RS232_0_GPIO_MAP,
                           sizeof(BOARD_RS232_0_GPIO_MAP) / 
                           sizeof(BOARD_RS232_0_GPIO_MAP[0]));
#endif

#if defined(BOARD_RS232_1)
	gpio_enable_module(BOARD_RS232_1_GPIO_MAP,
                           sizeof(BOARD_RS232_1_GPIO_MAP) / 
                           sizeof(BOARD_RS232_1_GPIO_MAP[0]));
#endif
#endif /* NO_SERIAL */
}

static void init_printk(void)
{
#ifndef NO_SERIAL
#if defined(CONFIG_CONSOLE_PORT)
	const usart_options_t usart_options = {
		.baudrate = 57600,
		.charlength = 8,
		.paritytype = USART_NO_PARITY,
		.stopbits = USART_1_STOPBIT,
		.channelmode = USART_NORMAL_CHMODE
	};
	usart_init_rs232(&CONFIG_CONSOLE_PORT, &usart_options, FPBA_HZ);
#endif
#endif /* NO_SERIAL */
}

void board_init(void)
{
        
    init_exceptions();
    init_hmatrix();
    init_sys_clocks();
    init_interrupts();

    init_rs232();
    init_printk();
        
#ifdef WITH_SDRAM
    sdramc_init(FHSB_HZ);
#endif
    init_spi();
}
예제 #6
0
/**
 ** PDCA Init.
 **/
void init_pdca(void)
{
  // PDCA channel 0/1 options
  static const pdca_channel_options_t PDCA_CH_OPTIONS =
  {
    .addr = (void *)aDataTransfered,          // memory address
    .pid = AVR32_PDCA_PID_USART2_TX,          // select peripheral - data are transmit on USART TX line.
    .size = 0,                                // transfer counter
    .r_addr = (void *)aDataTransfered,        // next memory address
    .r_size = sizeof(aDataTransfered),        // next transfer counter
    .transfer_size = PDCA_TRANSFER_SIZE_BYTE, // select size of one data packet
    .etrig = true                          // Trigger transfer on event.
  };

  Disable_global_interrupt();

  // Initialize interrupt vectors.
  INTC_init_interrupts();

  // Register the PDCA interrupt handler to the interrupt controller.
  INTC_register_interrupt(&pdca_int_handler, PDCA_CHANNEL_IRQ, AVR32_INTC_INT0);

  Enable_global_interrupt();

  // Init PDCA channel with the pdca_options.
  pdca_init_channel(PDCA_CHANNEL_USART, &PDCA_CH_OPTIONS);
  pdca_channel = pdca_get_handler(PDCA_CHANNEL_USART); // For use in the pdca interrupt handler.

  // Enable pdca transfer error interrupt & transfer complete interrupt.
  pdca_enable_interrupt_transfer_error(PDCA_CHANNEL_USART);
  pdca_enable_interrupt_transfer_complete(PDCA_CHANNEL_USART);

  // Enable the PEVC channel "PDCA CHANNEL 0/1 ONE-ITEM-TRANSFER"
  PEVC_CHANNELS_ENABLE(ppevc, 1<<PEVC_PDCA_SOT_USER);

  // Enable the PDCA.
  pdca_enable(PDCA_CHANNEL_USART);
}

/**
 ** AST Init.
 **/
void init_ast(void)
{

  avr32_ast_pir0_t pir = {
    .insel = 14 // Set a event every second
  };

  ast_calendar_t ast_calendar;
  ast_calendar.FIELD.sec  = 30;
  ast_calendar.FIELD.min  = 45;
  ast_calendar.FIELD.hour = 12;
  ast_calendar.FIELD.day  = 7;
  ast_calendar.FIELD.month= 10;
  ast_calendar.FIELD.year = 9;

  scif_osc32_opt_t opt;
  opt.mode = SCIF_OSC_MODE_2PIN_CRYSTAL;
  opt.startup = AVR32_SCIF_OSCCTRL32_STARTUP_0_RCOSC;

  // Start OSC_32KHZ
  scif_start_osc32(&opt,true);

  // Initialize the AST
  if (!ast_init_calendar(&AVR32_AST, AST_OSC_32KHZ, AST_PSEL_32KHZ_1HZ, ast_calendar))
  {
    print_dbg("Error initializing the AST\r\n");
    while(1);
  }

  ast_set_periodic0_value(&AVR32_AST,pir);

  ast_enable_periodic0(&AVR32_AST);

  // Clear All Interrupt
  AVR32_AST.scr=0xFFFFFFFF;

  // Enable the AST
  ast_enable(&AVR32_AST);
}

/*! \brief Initializes the MCU system clocks.
*/
static void init_sys_clocks(void)
{

  /*! \name System Clock Frequencies
   */
  //! @{
  static pcl_freq_param_t pcl_freq_param =
  {
    .cpu_f        = FCPU_HZ,
    .pba_f        = FPBA_HZ,
    .osc0_f       = FOSC0,
    .osc0_startup = OSC0_STARTUP
  };
  //! @}

  // Configure system clocks.
  if (pcl_configure_clocks(&pcl_freq_param) != PASS) {
    while(1);
  }
}

/*! \brief This example show a DMA transfer to USART controlled by the AST
    periodic alarm using the PEVC.
 */
int main(void)
{
  int i;

  // Init the string with a simple recognizable pattern.
  for(i=0;i<sizeof(aDataTransfered);i++)
    aDataTransfered[i] = '0' + (i%36);

  init_sys_clocks();

  init_usart();

  gpio_clr_gpio_pin(LED0_GPIO);

  init_pevc();

  init_ast();

  init_pdca();

  while(1)
  {
    gpio_tgl_gpio_pin(LED1_GPIO);
    delay_ms(500); //Wait 500ms
  }
}
예제 #7
0
/*! main function */
int main(void)
{
  init_sys_clocks();

  // Initialize RS232 debug text output.
  init_dbg_rs232(FOSC0);

  print_dbg(MSG_WELCOME);

  // Enable LED0 and LED1
  gpio_enable_gpio_pin(LED0_GPIO);
  gpio_enable_gpio_pin(LED1_GPIO);

  // Configure TWI as master
  twi_init();

  // Initialize TPA6130
  tpa6130_init();

  // Initialize DAC that send audio to TPA6130
  tpa6130_dac_start(DEFAULT_DAC_SAMPLE_RATE_HZ,
                    DEFAULT_DAC_NUM_CHANNELS,
                    DEFAULT_DAC_BITS_PER_SAMPLE,
                    DEFAULT_DAC_SWAP_CHANNELS,
                    master_callback,
                      AUDIO_DAC_OUT_OF_SAMPLE_CB
                    | AUDIO_DAC_RELOAD_CB,
                    FOSC0);

  tpa6130_set_volume(0x2F);
  tpa6130_get_volume();

  int count = 0;
  int i=0;

  while(true)
  {
    count = 0;

    // Store sample from the sound_table array
    while(count < (SOUND_SAMPLES)){
      samples[count++] = ((uint8_t)sound_table[i]+0x80) << 8;
      samples[count++] = ((uint8_t)sound_table[i]+0x80) << 8;
      i++;
      if (i >= sizeof(sound_table)) i = 0;
    }

    gpio_set_gpio_pin(LED0_GPIO);
    gpio_clr_gpio_pin(LED1_GPIO);

    // Play buffer
    tpa6130_dac_output((void *) samples,SOUND_SAMPLES/2);

    gpio_clr_gpio_pin(LED0_GPIO);
    gpio_set_gpio_pin(LED1_GPIO);

    /* Wait until the reload register is empty.
     * This means that one transmission is still ongoing
     * but we are already able to set up the next transmission
     */
     while(!tpa6130_dac_output(NULL, 0));
  }
}
예제 #8
0
// main function
int main(void) {
	t_cpu_time timeout;
	t_cpu_time timeout_mpu;
	float deltat_2;
	float roll_first, pitch_first;
	
	board_init();
	hal.init(0,NULL);
	hal.analogin->init();
	
	sysclk_init();
	init_sys_clocks();
	float initials[3];
	int16_t  magnetic[3];
	float yaw_first;
	float soft[3],hard[3];
	float desti[2];
	float kp = 4.8;
	float kpp = 0.7;
	float kd = 0;
  	mpu9150.initMPU9150(FCPU_HZ);
	mpu9150.initHMC58();
	mpu9150.calibrate_mpu9150(initials);

	int16_t myMagData[3];
	hal.uartB->println("NEE ZAFERINDEN BAHSEDIYORSUUN");
	
	
	float percent = 40;
	uint8_t c, last_c;
	uint16_t count = 0;
	cpu_set_timeout(cpu_ms_2_cy(10, FOSC0), &timeout_mpu);
	cpu_set_timeout(cpu_ms_2_cy(1000, FOSC0), &timeout);

	hal.uartB->println("VER COSKUYU");
	c = hal.uartB->read();
	motor.motors_init();

while(1){	 
	  
	if (usart_test_hit(&AVR32_USART4)) {
		hal.uartB->println("I am hit");
		last_c = c;

		c = hal.uartB->read();

		if(c == '9') {
			motor.kill_motors();
			hal.uartB->println("KIRDIN BENI GOD DAMNIT");
			while(1);
		}
		if (c == '8') {
			percent += 1;
			hal.uartB->print("Percent Increased to: ");
			hal.uartB->println(percent);
		}
		if (c == '2') {
			percent -= 1;
			hal.uartB->print("Percent Decreased to: ");
			hal.uartB->println(percent);
		}
		if (c == 'u') {
			kpp = kpp + 0.1;
			hal.uartB->print("Kpp is: ");
			hal.uartB->println(kpp);
		}
		if (c == 'j') {
			kpp = kpp - 0.1;
			hal.uartB->print("Kpp is: ");
			hal.uartB->println(kpp);
		}
		if (c == 't') {
			kd = kd + 0.001;
			hal.uartB->print("Kd is: ");
			hal.uartB->println(kd);
		}
		if (c == 'g') {
			kd = kd - 0.001;
			hal.uartB->print("Kd is: ");
			hal.uartB->println(kd);
		}		
		
		if (c == 'y') {
			kp = kp + 0.1;
			hal.uartB->print("Kp is: ");
			hal.uartB->println(kp);
		}
		if (c == 'h') {
			kp = kp - 0.1;
			hal.uartB->print("Kp is: ");
			hal.uartB->println(kp);
		}
		c = last_c;
	}

	if (c == '5') {		
// 		
		if(cpu_is_timeout(&timeout_mpu)) {
			
			cpu_stop_timeout(&timeout_mpu);
			mpu9150.update();
			PID_Pitch = Pitch_Controller(pitch,initials[1],kp,kpp,0,kd,0.01f);
			motor.motor1_update(percent,PID_Pitch,0,0);
			motor.motor3_update(percent,PID_Pitch,0,0);
			cpu_set_timeout(cpu_ms_2_cy(10, FOSC0), &timeout_mpu);
		}

// 		if(cpu_is_timeout(&timeout)) {
// 			cpu_stop_timeout(&timeout);
// 			hal.uartB->println(PID_Pitch);
// 			
// 			cpu_set_timeout(cpu_ms_2_cy(1000, FOSC0), &timeout);
// 		}

// 		float PID_Pitch = Pitch_Controller(pitch,initials[1],kp,kd,0,0,deltat);
// 		motor.motor1_update(percent,PID_Pitch,0,0);
		
// 		deltat =(float) cpu_cy_2_ms((Get_sys_count()),FOSC0)/1000;
//  		cpu_set_timeout( cpu_ms_2_cy(10000, FOSC0), &timeout);
//  		Set_sys_count(0);
		}
	}
}