Beispiel #1
0
/*! \brief Noise Task:
 *        - Add random noise to buffer input signal
 */
void noise_task(void)
{
	static uint32_t noise_value = NOISE_STARTUP_VALUE;
	int32_t i;
	if (gpio_get_pin_value(GPIO_PUSH_BUTTON_0) == GPIO_PUSH_BUTTON_0_PRESSED) {
		if (noise_value < NOISE_MAX_VALUE - NOISE_STEP)
			noise_value = noise_value + NOISE_STEP;
	}
	if (gpio_get_pin_value(GPIO_PUSH_BUTTON_1) == GPIO_PUSH_BUTTON_1_PRESSED) {
		if (noise_value > NOISE_MIN_VALUE + NOISE_STEP)
			noise_value = noise_value - NOISE_STEP;
	}
	for (i=0;i<GUI_BUFFER_LENGTH;i++) {
		// Generate a Random noise reading the potentiometer Value
		signal_noise_remote[i] = (rand()%(noise_value));
		// Rescale the value on a 16-bits fixed point format
		signal_noise_gui[i] =
			GUI_SCALE_GAIN_VALUE*((int32_t)signal_noise_remote[i]) -
			GUI_SCALE_OFFSET_VALUE;
		// Add noise to the sine wave signal
		signalin_noise_remote[i] = signalin_remote[i] +
			signal_noise_remote[i];
		// Rescale the value on a 16-bits fixed point format
		signalin_noise_gui[i] = GUI_SCALE_GAIN_VALUE *
			((int32_t)signalin_noise_remote[i]) - GUI_SCALE_OFFSET_VALUE;
	}
}
Beispiel #2
0
static void irq_port1_line1(void) {
    // print_dbg("\r\ninterrupt on PB08-PB15.");

    // static event_t e;   
    // e.type = kSwitchEvents[swIdx];
    // e.data = gpio_get_pin_value(kSwitchPins[swIdx]); 
    // event_post(&e);

    // clock norm
    if(gpio_get_pin_interrupt_flag(B09)) {

      static event_t e;
      e.type = kEventClockNormal;
      e.data = !gpio_get_pin_value(B09);
      event_post(&e);

      gpio_clear_pin_interrupt_flag(B09);
    }

    // clock in
    if(gpio_get_pin_interrupt_flag(B08)) {
      // CLOCK BOUNCY WITHOUT THESE PRINTS
      // print_dbg("\rclk: ");
      // print_dbg_ulong(gpio_get_pin_value(B08));
      // (*clock_pulse)(gpio_get_pin_value(B08));
      static event_t e;
      e.type = kEventClockExt;
      e.data = gpio_get_pin_value(B08);
      event_post(&e);
      gpio_clear_pin_interrupt_flag(B08);
    }
}
Beispiel #3
0
static void irq_port1_line1(void) {
    // print_dbg("\r\ninterrupt on PB08-PB15.");

    // clock norm
    // if(gpio_get_pin_interrupt_flag(B10)) {

    //   static event_t e;
    //   e.type = kEventTrNormal;
    //   e.data = !gpio_get_pin_value(B10);
    //   event_post(&e);
    //   gpio_clear_pin_interrupt_flag(B10);
    // }

    // clock in
    if(gpio_get_pin_interrupt_flag(B08)) {
      static event_t e;
      e.type = kEventTr;
      e.data = gpio_get_pin_value(B08);
      event_post(&e);
      gpio_clear_pin_interrupt_flag(B08);
    }

    // tr in
    if(gpio_get_pin_interrupt_flag(B09)) {
      static event_t e;
      e.type = kEventTr;
      e.data = gpio_get_pin_value(B09) + 2;
      event_post(&e);
      gpio_clear_pin_interrupt_flag(B09);
    }

}
Beispiel #4
0
/** \brief Test if a touch is detected.
 *
 * Checks if one of the Y lines is pulled low due to a touch on the surface.
 * The Y lines must be pulled up and the X lines must be GND in order to work.
 *
 * \return \c true if a touch is detected and \c false if no touch is detected.
 */
static bool inline rtouch_is_detect(void)
{
	/* Check if one of the Y lines is pulled low */
	if (!gpio_get_pin_value(rtouch_gpio_ymap[0].pin) ||
			!gpio_get_pin_value(rtouch_gpio_ymap[1].pin)) {
		return true;
	} else {
		return false;
	}
}
Beispiel #5
0
void gnms_button_init() {
	gpio_enable_pin_glitch_filter(PROJECTOR_LEFT);
	gpio_enable_pin_glitch_filter(PROJECTOR_RIGHT);
	gpio_enable_pin_glitch_filter(PROJECTOR_UP);
	gpio_enable_pin_glitch_filter(PROJECTOR_DOWN);
	gpio_enable_pin_glitch_filter(PROJECTOR_MENU);
	gpio_enable_pin_glitch_filter(PROJECTOR_EXIT);
	gpio_enable_pin_glitch_filter(PROJECTOR_ENTER);
	gpio_enable_pin_glitch_filter(VOLUME_UP);
	gpio_enable_pin_glitch_filter(VOLUME_DN);
	
	
	prev_proj_left  = gpio_get_pin_value(PROJECTOR_LEFT);
	prev_proj_right = gpio_get_pin_value(PROJECTOR_RIGHT);
	prev_proj_up    = gpio_get_pin_value(PROJECTOR_UP);
	prev_proj_down  = gpio_get_pin_value(PROJECTOR_DOWN);
	prev_proj_menu  = gpio_get_pin_value(PROJECTOR_MENU);
	prev_proj_enter = gpio_get_pin_value(PROJECTOR_ENTER);
	prev_proj_exit  = gpio_get_pin_value(PROJECTOR_EXIT);
	prev_vol_up		= gpio_get_pin_value(VOLUME_UP);
	prev_vol_dn		= gpio_get_pin_value(VOLUME_DN);
	
	cur_proj_left  = prev_proj_left;
	cur_proj_right = prev_proj_right;
	cur_proj_up    = prev_proj_up;
	cur_proj_down  = prev_proj_down;
	cur_proj_menu  = prev_proj_menu;
	cur_proj_enter = prev_proj_enter;
	cur_proj_exit  = prev_proj_exit;
	cur_vol_up	   = prev_vol_up;
	cur_vol_dn	   = prev_vol_dn;
}
Beispiel #6
0
unsigned char Switch_On(unsigned char switch_flags)
{
	if ((switch_flags & SWITCH2) && !gpio_get_pin_value(GPIO_PUSH_BUTTON_SW2))
	return 1;
	else
	return 0;
}
Beispiel #7
0
__always_inline static int is_pressed(short idx) {
#if BOARD == EVK1104
        return qt60168_is_key_pressed(idx_to_button_map[idx]);
#else
        return (gpio_get_pin_value(button[idx]) == BUTTON_PRESSED);
#endif
}
unsigned int FC_standby(void)
{
	unsigned int fc_state;
	if (gpio_get_pin_value(START))
	{
		fc_state = FC_STATE_STARTUP_FANS;
		gpio_clr_gpio_pin(LED_STOP);
		gpio_set_gpio_pin(LED_START);
	}
	else
	{
		//make sure fuel cell stays off
		//Supply valve closed
		gpio_clr_gpio_pin(H2_VALVE);
		//purge valve closed
		gpio_clr_gpio_pin(PURGE_VALVE);
		//relays open
		gpio_clr_gpio_pin(MOTOR_RELAY);
		gpio_clr_gpio_pin(RES_RELAY);
		gpio_clr_gpio_pin(CAP_RELAY);
		//led's off
		gpio_clr_gpio_pin(LED_RUN);
		gpio_clr_gpio_pin(LED_START);
		gpio_clr_gpio_pin(LED_STOP);
		//fan low
		FANUpdate(0);
		fc_state = FC_STATE_STANDBY;
	}
	return(fc_state);
}
Beispiel #9
0
// wait for ready status (e.g. after module init)
void bfin_wait_ready(void) {
  // use ready pin
  while( !gpio_get_pin_value(BFIN_READY_PIN) ) { 
    ;;    //    print_dbg("\r\n wait bfin_ready ");
  }
  //  print_dbg("... waited");
}
Beispiel #10
0
/*********************************************************************
Functions
*********************************************************************/
int main (void)
{
	int i;
	// initialize
	init();
	

	
	gpio_configure_pin(RESPONSE_A, GPIO_DIR_OUTPUT | GPIO_INIT_LOW);
	gpio_configure_pin(TEST_A, GPIO_DIR_INPUT | GPIO_INIT_LOW);
	
	gpio_configure_pin(RESPONSE_B, GPIO_DIR_OUTPUT | GPIO_INIT_LOW);
	gpio_configure_pin(TEST_B, GPIO_DIR_INPUT | GPIO_INIT_LOW);
	
	gpio_configure_pin(RESPONSE_C, GPIO_DIR_OUTPUT | GPIO_INIT_LOW);
	gpio_configure_pin(TEST_C, GPIO_DIR_INPUT | GPIO_INIT_LOW);
	// start code from here
	gpio_set_pin_high(RESPONSE_A);
	gpio_set_pin_high(RESPONSE_B);
	gpio_set_pin_high(RESPONSE_C);
	
	while(1)
	{
		if(!gpio_get_pin_value(TEST_A)){
			gpio_set_pin_low(RESPONSE_A);
			busy_delay_us(5);
			gpio_set_pin_high(RESPONSE_A);
		}
		
		if(!gpio_get_pin_value(TEST_B)){
			gpio_set_pin_low(RESPONSE_B);
			busy_delay_us(5);
			gpio_set_pin_high(RESPONSE_B);
		}
		
		if(!gpio_get_pin_value(TEST_C)){
			gpio_set_pin_low(RESPONSE_C);
			busy_delay_us(5);
			gpio_set_pin_high(RESPONSE_C);
		}


		//printf("tick\n");
		//gpio_toggle_pin(LED0_GPIO);
		//busy_delay_ms(500);
	}
}
Beispiel #11
0
// generate events from switch interrupts
void process_sw( const U8 swIdx )  {
  static event_t e;   
  e.type = kSwitchEvents[swIdx];
  e.data = gpio_get_pin_value(kSwitchPins[swIdx]); 
  event_post(&e);
  //  print_dbg("\r\n posted switch event ");
  //  print_dbg_ulong(swIdx);
}
Beispiel #12
0
// wait for ready status (e.g. after module init)
void bfin_wait_ready(void) {
#if 1
#else
  // use ready pin
  while( !gpio_get_pin_value(BFIN_READY_PIN) ) { 
    //    print_dbg("\r\n waiting on bfin ready pin... ");
  }
#endif
}
Beispiel #13
0
static void irq_port0_line1(void) {
    if(gpio_get_pin_interrupt_flag(NMI)) {
      gpio_clear_pin_interrupt_flag(NMI);
      // print_dbg("\r\n ### NMI ### ");
      static event_t e;
      e.type = kEventFront;
      e.data = gpio_get_pin_value(NMI);
      event_post(&e);
    }
}
Beispiel #14
0
// wait for busy pin to clear
void bfin_wait(void) {
  //  print_dbg("\r\n hwait: ");
  //  print_dbg_ulong(gpio_get_pin_value(BFIN_HWAIT_PIN));
    while (gpio_get_pin_value(BFIN_HWAIT_PIN) > 0) { 
      ;;
      print_dbg("\r\n HWAIT asserted..."); 
	    //            delay_ms(1);
    }
    delay_us(50);
}
Beispiel #15
0
/*! \brief Wait for NAND flash R/B signal to go ready.
 *
 *  This function will wait for the R/B signal to go to the ready state. It
 *  will do a polled wait with the possibility for a timeout.
 *
 *  \param nfd Pointer to the nand_driver_data struct which
 *             holds all vital data about the NAND GPIO driver.
 *
 *  \return 0 on success, an error number elsewise.
 */
static int32_t nand_gpio_wait_ready(struct nand_driver_data *nfd)
{
	/* Should be done within 3 milliseconds for all commands. */
	volatile uint64_t timeout = 0x200000; //approx. 3secs

	while (timeout > 0) {
		if (gpio_get_pin_value(nfd->gpio_cont_pin, nfd->gpio_rb)) return 0;
		--timeout;
	}

	return -ETIMEDOUT;
}
Beispiel #16
0
static inline void manage_button_isr(int pin, enum joystick_status_t status_pressed, enum joystick_status_t status_released)
{
  if (gpio_get_pin_interrupt_flag(pin))
  {
    // Clear current pin status
    joystick_status &= ~(status_pressed | status_released);
    if (gpio_get_pin_value(pin))
      joystick_status |= status_pressed;
    else
      joystick_status |= status_released;
    gpio_clear_pin_interrupt_flag(pin);
  }
}
uint32_t debounce2( uint32_t GPIO_PIN ){//regresar se presiono el boton o no
	
	
	
	if(gpio_get_pin_value(GPIO_PIN)==1){// se presiono el boton?, sino salir de la funcion
		delay_ms(10);

		if (gpio_get_pin_value(GPIO_PIN)==0){//Si ya se libero, es ruido, salir sin hacer nada
			goto salir;
		}
		espera://espera a que suelte el botón
		while (gpio_get_pin_value(GPIO_PIN)==1){}
		delay_ms(10);
		if (gpio_get_pin_value(GPIO_PIN)==1) {//si ya lo presiono otra vez , es ruido, regresa a esperar
			goto espera;
		}
		
		return 1;//debounce completo regresa 1

	}
	salir:
	return 0;
}
Beispiel #18
0
static void testerA(void *pvParameters){
	const portTickType xDelay = 10 / portTICK_RATE_MS;
	gpio_configure_pin(RESPONSE_A, GPIO_DIR_OUTPUT | GPIO_INIT_LOW);
	gpio_configure_pin(TEST_A, GPIO_DIR_INPUT | GPIO_INIT_LOW);
	
	gpio_set_pin_high(RESPONSE_A);
	while (1){
		if(!gpio_get_pin_value(TEST_A)){
			gpio_set_pin_low(RESPONSE_A);
			vTaskDelay(xDelay);
			gpio_set_pin_high(RESPONSE_A);
		}
	}
}
unsigned int FC_startup_fans(void)
{
	unsigned int fc_state;
	//relays open
	gpio_clr_gpio_pin(START_RELAY);
	gpio_clr_gpio_pin(MOTOR_RELAY);
	gpio_clr_gpio_pin(RES_RELAY);
	gpio_clr_gpio_pin(CAP_RELAY);
	//valves closed
	gpio_clr_gpio_pin(H2_VALVE);
	gpio_clr_gpio_pin(PURGE_VALVE);
	
	//set fans to min
	FANUpdate(0);
	//read fan tachometer to ensure fans are spinning
	//increment if tach is 0 and reads 1
	if(tachometer_test == 0)
	{
		if(gpio_get_pin_value(FAN_TACH)==1)
		{
			tachometer_test = 1;
		}
	}
	fc_state = FC_STATE_STARTUP_FANS; //keep looping in this function
	
	//then wait for it to go low again (then the fan is spinning)
	if(tachometer_test == 1)
	{
		if(gpio_get_pin_value(FAN_TACH) == 0)
		{
			//fan is spinning go to startup
			fc_state = FC_STATE_STARTUP_H2;
		}
	}
	start_delay = millis();
	return(FC_STATE_STARTUP_H2); //don't run this function again it is broken
}
void Lab3(void){
	
	pm_switch_to_osc0(&AVR32_PM,FOSC0,OSC0_STARTUP);
	
	int32_t cuenta =0;
	while(1){
	if (gpio_get_pin_value(QT1081_TOUCH_SENSOR_ENTER))
	{
		while (gpio_get_pin_value(QT1081_TOUCH_SENSOR_DOWN)==0)
		{
			display(cuenta++);
			if (cuenta>9)
			{
				cuenta=0;
			}
			delay_s(100);
		}
		//ya se presiono la tecla down
		
		while (gpio_get_pin_value(QT1081_TOUCH_SENSOR_ENTER)==0)
		{
			
			display(cuenta--);
			if (cuenta<0)
			{
				cuenta=9;
			}
			delay_s(100);
			
		}
		
		
		
	}
	}
}
Beispiel #21
0
/*! \brief This is the main function.
 *
 */
int main(void)
{
  U8 button_status=0;

  // Read Button Status
  button_status=gpio_get_pin_value(GPIO_USB_MODE_BUTTON);

  // If Button is pressed, launch prog2.
  if(button_status==0) {
    jumpAddress(PROGRAM2_START_ADDRESS);
  }
  // else launch prog1.
  else {
    jumpAddress(PROGRAM1_START_ADDRESS);
  }
  while(1); // Never reached
}
Beispiel #22
0
int main(void)
{
	sysclk_init();

	init_dbg_rs232(FMCK_HZ);

	init_gpio();
	assign_main_event_handlers();
	init_events();
	init_tc();
	init_spi();
	init_adc();

	irq_initialize_vectors();
	register_interrupts();
	cpu_irq_enable();

	init_usb_host();
	init_monome();

	if(flash_is_fresh()) {
		// nothing has been stored in the flash memory so far
		// so you need to initialize any variables you store in flash here with appropriate default values
	}
	else {
		// read from flash
		flash_read();
	}

	clock_pulse = &clock;
	clock_external = !gpio_get_pin_value(B09);

	// start timers that track clock, ADCs (including the clock and the param knobs) and the front panel button
	timer_add(&clockTimer,120,&clockTimer_callback, NULL);
	timer_add(&keyTimer,50,&keyTimer_callback, NULL);
	timer_add(&adcTimer,100,&adcTimer_callback, NULL);
	clock_temp = 10000; // out of ADC range to force tempo

	// main loop - you probably don't need to do anything here as everything should be done by handlers
	while (true) {
		check_events();
	}
}
Beispiel #23
0
static void handle_Switch5(s32 data) { 
  /// power switch
  render_boot("");
  render_boot("");
  render_boot("");
  render_boot("");
  render_boot("");
  render_boot("");
  render_boot("powering down");

  // skip flash write if MODE is down
  if(!gpio_get_pin_value(SW_MODE_PIN)) {
    scene_write_default();
  }

  // power down
  delay_ms(100);
  gpio_clr_gpio_pin(POWER_CTL_PIN);
}
Beispiel #24
0
static ai_device_status_t ai_sd_mmc_get_device_status(ai_async_status_t *cmd_ai_status)
{
  *cmd_ai_status = CMD_DONE;

#if defined(SD_MMC_CARD_DETECT_PIN)
  if (gpio_get_pin_value(SD_MMC_CARD_DETECT_PIN))
#endif
#if defined(SUPPORT_SD_MMC_MCI) && SUPPORT_SD_MMC_MCI == true
  if (sd_mmc_mci_mem_check(SD_SLOT))
  {
    volatile uint32_t card_size;
    sd_mmc_mci_read_capacity(SD_SLOT, (uint32_t *) &card_size);
    return AI_DEVICE_STATUS_CONNECTED;
  }
#else
  if (sd_mmc_spi_check_presence() == true)
    return AI_DEVICE_STATUS_CONNECTED;
#endif

  return AI_DEVICE_STATUS_NOT_PRESENT;
}
Beispiel #25
0
static void testerC(void *pvParameters){
	const portTickType xDelay = 5 / portTICK_RATE_MS;
	portTickType xLastWakeTime;
	
	xLastWakeTime = xTaskGetTickCount();
	
	gpio_configure_pin(RESPONSE_C, GPIO_DIR_OUTPUT | GPIO_INIT_LOW);
	gpio_configure_pin(TEST_C, GPIO_DIR_INPUT | GPIO_INIT_LOW);
	
	gpio_set_pin_high(RESPONSE_C);
	while (1){
		vTaskDelayUntil(&xLastWakeTime, xDelay);
		
		if(!gpio_get_pin_value(TEST_C)){
			gpio_set_pin_low(RESPONSE_C);
			
			vTaskDelay(xDelay);
			
			gpio_set_pin_high(RESPONSE_C);
		}
	}
}
Beispiel #26
0
static void vTask_B(void *pvParameters)
{
	/* init counter variable to be used for periodic execution */
	portTickType xLastWakeTime;
	const portTickType xFrequency = TASK_B_PERIOD/portTICK_RATE_MS;
	xLastWakeTime = xTaskGetTickCount();
	
	while (true)
	{
		/* Wait until the period time is up */
		vTaskDelayUntil(&xLastWakeTime, xFrequency);
		
		/* Check for test signal */
		if (!gpio_get_pin_value(TEST_B))
		{
			gpio_set_pin_low(RESPONSE_B);
			vTaskDelay(RESPONSE_DELAY/portTICK_RATE_MS);
			gpio_set_pin_high(RESPONSE_B);
		}
	}
	
}
Beispiel #27
0
/*********************************************************************
Functions
*********************************************************************/
int main (void)
{
	int i;
	// initialize
	init();
	
	// start code from here
	gpio_set_pin_high(RESPONSE_A);
	
	while(1)
	{
		if(!gpio_get_pin_value(TEST_A)){
			gpio_set_pin_low(RESPONSE_A);
			busy_delay_us(5);
			gpio_set_pin_high(RESPONSE_A);
		}
		


		//printf("tick\n");
		//gpio_toggle_pin(LED0_GPIO);
		//busy_delay_ms(500);
	}
}
Beispiel #28
0
void aic23b_dac_start(uint32_t sample_rate_hz,
                      uint8_t num_channels,
                      uint8_t bits_per_sample,
                      bool swap_channels,
                      void (*callback)(uint32_t arg),
                      uint32_t callback_opt,
                      uint32_t pba_hz)
{
#if AIC23B_CTRL_INTERFACE == AIC23B_CTRL_INTERFACE_SPI
  static const spi_options_t AIC23B_SPI_OPTIONS =
  {
    .reg          = AIC23B_SPI_NPCS,
    .baudrate     = AIC23B_SPI_MASTER_SPEED,
    .bits         = AIC23B_CTRL_SIZE,
    .spck_delay   = 0,
    .trans_delay  = 0,
    .stay_act     = 0,
    .spi_mode     = 3,
    .modfdis      = 1
  };
  spi_setupChipReg(AIC23B_SPI, &AIC23B_SPI_OPTIONS, pba_hz);
#endif

  aic23b_dac_stop();

  gpio_enable_module(AIC23B_SSC_DAC_GPIO_MAP,
                     sizeof(AIC23B_SSC_DAC_GPIO_MAP) / sizeof(AIC23B_SSC_DAC_GPIO_MAP[0]));

  aic23b_pdc_t pdc;
  pdc.data  = AIC23B_DEFAULT(AIC23B_PDC);
  pdc.off   = 0;
  pdc.clk   = 0;
  pdc.osc   = 0;
  pdc.out   = 0;
  pdc.dac   = 0;
  pdc.adc   = 1;
  pdc.mic   = 1;
  pdc.line  = 1;
  aic23b_set_power_down_state(pdc);

  aic23b_dac_setup(sample_rate_hz,
                   num_channels,
                   bits_per_sample,
                   swap_channels,
                   callback,
                   callback_opt,
                   pba_hz);

  aic23b_aapc_t aapc;
  aapc.data = AIC23B_DEFAULT(AIC23B_AAPC);
  aapc.ste  = 0;
  aapc.dac  = 1;
  aapc.byp  = 0;
  aapc.micm = 1;
  aapc.micb = 0;
  aic23b_set_analog_audio_path(aapc);

  aic23b_dapc_t dapc;
  dapc.data   = AIC23B_DEFAULT(AIC23B_DAPC);
  dapc.dacm   = 0;
  dapc.deemp  = AIC23B_DAPC_DEEMP_NONE;
  dapc.adchp  = 1;
  aic23b_set_digital_audio_path(dapc);

  // set an acceptable start volume
  aic23b_set_headphone_volume(AIC23B_LEFT_CHANNEL | AIC23B_RIGHT_CHANNEL,
                              -30,
                              true);

  aic23b_activate_dig_audio(true);

  INTC_register_interrupt(&aic23b_ssc_tx_pdca_int_handler,
                          AIC23B_SSC_TX_PDCA_IRQ,
                          AIC23B_SSC_TX_PDCA_INT_LEVEL);
}


void aic23b_dac_setup(uint32_t sample_rate_hz,
                      uint8_t num_channels,
                      uint8_t bits_per_sample,
                      bool swap_channels,
                      void (*callback)(uint32_t arg),
                      uint32_t callback_opt,
                      uint32_t pba_hz)
{
#if defined(AIC23B_DAC_USE_RX_CLOCK) && AIC23B_DAC_USE_RX_CLOCK == true
  #if defined(AIC23B_DAC_RX_CLOCK_SET_CALLBACK)
    AIC23B_DAC_RX_CLOCK_SET_CALLBACK(2 * sample_rate_hz *
                                     ((bits_per_sample <= 16) ? 16 :
                                     (bits_per_sample <= 20) ? 20 :
                                     (bits_per_sample <= 24) ? 24 :
                                     32));
  #endif
  ssc_i2s_init(AIC23B_SSC,
               sample_rate_hz,
               bits_per_sample,
               (bits_per_sample <= 16) ? 16 :
               (bits_per_sample <= 20) ? 20 :
               (bits_per_sample <= 24) ? 24 :
                                         32,
               SSC_I2S_MODE_STEREO_OUT_EXT_CLK,
               pba_hz);
#else
  ssc_i2s_init(AIC23B_SSC,
               sample_rate_hz,
               bits_per_sample,
               (bits_per_sample <= 16) ? 16 :
               (bits_per_sample <= 20) ? 20 :
               (bits_per_sample <= 24) ? 24 :
                                         32,
               SSC_I2S_MODE_STEREO_OUT,
               pba_hz);
#endif

  pdca_channel_options_t aic23b_ssc_pdca_options =
  {
    .addr           = NULL,
    .size           = 0,
    .r_addr         = NULL,
    .r_size         = 0,
    .pid            = AIC23B_SSC_TX_PDCA_PID,
    .transfer_size  = (bits_per_sample <=  8) ? PDCA_TRANSFER_SIZE_BYTE      :
                      (bits_per_sample <= 16) ? PDCA_TRANSFER_SIZE_HALF_WORD :
                                                PDCA_TRANSFER_SIZE_WORD
  };
  pdca_init_channel(AIC23B_SSC_TX_PDCA_CHANNEL, &aic23b_ssc_pdca_options);
  pdca_enable(AIC23B_SSC_TX_PDCA_CHANNEL);

#if !defined(AIC23B_DAC_USE_RX_CLOCK) || AIC23B_DAC_USE_RX_CLOCK == false || \
    !defined(AIC23B_DAC_RX_CLOCK_SET_CALLBACK)
  // Set DAC frequency
  aic23b_configure_freq(AIC23B_MCLK_HZ, sample_rate_hz);
#endif

  aic23b_daif_t daif;
  daif.data   = AIC23B_DEFAULT(AIC23B_DAIF);
  daif.ms     = AIC23B_DAIF_MS_SLAVE;
  daif.lrswap = swap_channels;
  daif.lrp    = 0;
  daif.iwl    = (bits_per_sample <= 16) ? AIC23B_DAIF_IWL_16 :
                (bits_per_sample <= 20) ? AIC23B_DAIF_IWL_20 :
                (bits_per_sample <= 24) ? AIC23B_DAIF_IWL_24 :
                                          AIC23B_DAIF_IWL_32;
  daif.fmt    = AIC23B_DAIF_FMT_I2S;
  aic23b_write_reg(AIC23B_DAIF, daif.data);

  aic23b_output_params.num_channels             = num_channels;
  aic23b_output_params.callback                 = callback;
  aic23b_output_params.callback_opt             = callback_opt;
}
#endif

bool aic23b_dac_output(void *sample_buffer, size_t sample_length)
{
  bool global_interrupt_enabled;

  if (!(pdca_get_transfer_status(AIC23B_SSC_TX_PDCA_CHANNEL) &
        PDCA_TRANSFER_COUNTER_RELOAD_IS_ZERO))
    return false;

  if (sample_length)
  {
    if (aic23b_output_params.num_channels == 1)
    {
      int16_t *s16_sample_buffer = sample_buffer;
      int i;

      for (i = sample_length - 1; i >= 0; i--)
      {
        s16_sample_buffer[2 * i + 1] =
        s16_sample_buffer[2 * i]     = s16_sample_buffer[i];
      }
    }

    // The PDCA is not able to synchronize its start of transfer with the SSC
    // start of period, so this has to be done by polling the TF pin.
    // Not doing so may result in channels being swapped randomly.
    if ((global_interrupt_enabled = Is_global_interrupt_enabled()))
      Disable_global_interrupt();
    if (pdca_get_transfer_status(AIC23B_SSC_TX_PDCA_CHANNEL) &
        PDCA_TRANSFER_COMPLETE)
    {
      while (gpio_get_pin_value(AIC23B_SSC_TX_FRAME_SYNC_PIN));
      while (!gpio_get_pin_value(AIC23B_SSC_TX_FRAME_SYNC_PIN));
    }
    pdca_reload_channel(AIC23B_SSC_TX_PDCA_CHANNEL, sample_buffer, sample_length * 2);
    pdca_get_reload_size(AIC23B_SSC_TX_PDCA_CHANNEL);
    if (global_interrupt_enabled)
      Enable_global_interrupt();

    if (aic23b_output_params.callback_opt & AUDIO_DAC_OUT_OF_SAMPLE_CB)
      pdca_enable_interrupt_transfer_complete(AIC23B_SSC_TX_PDCA_CHANNEL);
    if (aic23b_output_params.callback_opt & AUDIO_DAC_RELOAD_CB)
      pdca_enable_interrupt_reload_counter_zero(AIC23B_SSC_TX_PDCA_CHANNEL);
  }
  return true;
}
Beispiel #29
0
//!
//! @brief Entry point of the AK5394A task management
//!
void AK5394A_task(void *pvParameters)
{
  portTickType xLastWakeTime;
  xLastWakeTime = xTaskGetTickCount();
  int i;

  while (TRUE)
  {
	  // All the hardwork is done by the pdca and the interrupt handler.
	  // Just check whether sampling freq is changed, to do rate change etc.

    vTaskDelayUntil(&xLastWakeTime, configTSK_AK5394A_PERIOD);


    if (freq_changed){


    	if (current_freq.frequency == 96000){
	   	pdca_disable_interrupt_reload_counter_zero(PDCA_CHANNEL_SSC_RX);
	    pdca_disable(PDCA_CHANNEL_SSC_RX);

    		gpio_set_gpio_pin(AK5394_DFS0);		// L H  -> 96khz
    		gpio_clr_gpio_pin(AK5394_DFS1);

    		pm_gc_disable(&AVR32_PM, AVR32_PM_GCLK_GCLK1);
    		pm_gc_setup(&AVR32_PM, AVR32_PM_GCLK_GCLK1, // gc
    						  0,                  // osc_or_pll: use Osc (if 0) or PLL (if 1)
    						  1,                  // pll_osc: select Osc0/PLL0 or Osc1/PLL1
    						  1,                  // diven - enabled
    						  0);                 // divided by 2.  Therefore GCLK1 = 6.144Mhz
    		pm_gc_enable(&AVR32_PM, AVR32_PM_GCLK_GCLK1);

    	   	if (Is_usb_full_speed_mode()) FB_rate = 96 << 14;
    	    	else FB_rate = (96) << 13;

    	}
    	else if (current_freq.frequency == 192000)
    	{
    	pdca_disable_interrupt_reload_counter_zero(PDCA_CHANNEL_SSC_RX);
        pdca_disable(PDCA_CHANNEL_SSC_RX);

				gpio_clr_gpio_pin(AK5394_DFS0);		// H L -> 192khz
        		gpio_set_gpio_pin(AK5394_DFS1);

           		pm_gc_disable(&AVR32_PM, AVR32_PM_GCLK_GCLK1);
            	pm_gc_setup(&AVR32_PM, AVR32_PM_GCLK_GCLK1, // gc
            						  0,                  // osc_or_pll: use Osc (if 0) or PLL (if 1)
            						  1,                  // pll_osc: select Osc0/PLL0 or Osc1/PLL1
            						  0,                  // diven - disabled
            						  0);                 // GCLK1 = 12.288Mhz
            	pm_gc_enable(&AVR32_PM, AVR32_PM_GCLK_GCLK1);

              	if (Is_usb_full_speed_mode()) FB_rate = 192 << 14;
                	else FB_rate = (192) << 13;

    	}
    	else if (current_freq.frequency == 48000) // 48khz
    	{

        	pdca_disable_interrupt_reload_counter_zero(PDCA_CHANNEL_SSC_RX);
            pdca_disable(PDCA_CHANNEL_SSC_RX);

				gpio_clr_gpio_pin(AK5394_DFS0);		// L L  -> 48khz
        		gpio_clr_gpio_pin(AK5394_DFS1);

           		pm_gc_disable(&AVR32_PM, AVR32_PM_GCLK_GCLK1);
            	pm_gc_setup(&AVR32_PM, AVR32_PM_GCLK_GCLK1, // gc
            						  0,                  // osc_or_pll: use Osc (if 0) or PLL (if 1)
            						  1,                  // pll_osc: select Osc0/PLL0 or Osc1/PLL1
            						  1,                  // diven - enabled
            						  1);                 // divided by 4.  Therefore GCLK1 = 3.072Mhz
            	pm_gc_enable(&AVR32_PM, AVR32_PM_GCLK_GCLK1);

            	if (Is_usb_full_speed_mode()) FB_rate = 48 << 14;
                	else FB_rate = (48) << 13;


        }

    	// re-sync SSC to LRCK
        // Wait for the next frame synchronization event
        // to avoid channel inversion.  Start with left channel - FS goes low
    	// However, the channels are reversed at 192khz

    	if (current_freq.frequency == 192000) {
			while (gpio_get_pin_value(AK5394_LRCK));
			while (!gpio_get_pin_value(AK5394_LRCK));	// exit when FS goes high
    	}
    	else {
			while (!gpio_get_pin_value(AK5394_LRCK));
			while (gpio_get_pin_value(AK5394_LRCK));	// exit when FS goes low
    	}
        // Enable now the transfer.
        pdca_enable(PDCA_CHANNEL_SSC_RX);

        // Init PDCA channel with the pdca_options.
        pdca_init_channel(PDCA_CHANNEL_SSC_RX, &PDCA_OPTIONS); // init PDCA channel with options.
        pdca_enable_interrupt_reload_counter_zero(PDCA_CHANNEL_SSC_RX);

        // reset freq_changed flag
        freq_changed = FALSE;
    }
    if (usb_alternate_setting_out_changed){
    	if (usb_alternate_setting_out != 1){
    		for (i = 0; i < SPK_BUFFER_SIZE; i++){
    			spk_buffer_0[i] = 0;
    			spk_buffer_1[i] = 0;
    		}
    	};

    	usb_alternate_setting_out_changed = FALSE;
    }
  }
}
Beispiel #30
0
//!
//! @brief This function initializes the hardware/software resources
//! required for device CDC task.
//!
void AK5394A_task_init(void)
{
	// Set up CS4344
	// Set up GLCK1 to provide master clock for CS4344
	gpio_enable_module_pin(GCLK1, GCLK1_FUNCTION);	// for DA_SCLK
													// LRCK is SCLK / 64 generated by TX_SSC
													// so SCLK of 6.144Mhz ===> 96khz

	pm_gc_setup(&AVR32_PM, AVR32_PM_GCLK_GCLK1, // gc
					  0,                  // osc_or_pll: use Osc (if 0) or PLL (if 1)
					  1,                  // pll_osc: select Osc0/PLL0 or Osc1/PLL1
					  1,                  // diven - enabled
					  0);                 // divided by 2.  Therefore GCLK1 = 6.144Mhz
	pm_gc_enable(&AVR32_PM, AVR32_PM_GCLK_GCLK1);

	pm_enable_osc1_ext_clock(&AVR32_PM);	// OSC1 is clocked by 12.288Mhz Osc
												// from AK5394A Xtal Oscillator
	pm_enable_clk1(&AVR32_PM, OSC1_STARTUP);

	// Set up AK5394A
	gpio_clr_gpio_pin(AK5394_RSTN);		// put AK5394A in reset
	gpio_clr_gpio_pin(AK5394_DFS0);		// L L  -> 48khz
	gpio_clr_gpio_pin(AK5394_DFS1);
	gpio_set_gpio_pin(AK5394_HPFE);		// enable HP filter
	gpio_clr_gpio_pin(AK5394_ZCAL);		// use VCOML and VCOMR to cal
	gpio_set_gpio_pin(AK5394_SMODE1);	// SMODE1 = H for Master i2s
	gpio_set_gpio_pin(AK5394_SMODE2);	// SMODE2 = H for Master/Slave i2s

    gpio_set_gpio_pin(AK5394_RSTN);		// start AK5394A
    while (gpio_get_pin_value(AK5394_CAL)); // wait till CAL goes low

		// Assign GPIO to SSC.
	  gpio_enable_module(SSC_GPIO_MAP, sizeof(SSC_GPIO_MAP) / sizeof(SSC_GPIO_MAP[0]));
	  gpio_enable_pin_glitch_filter(SSC_RX_CLOCK);
	  gpio_enable_pin_glitch_filter(SSC_RX_DATA);
	  gpio_enable_pin_glitch_filter(SSC_RX_FRAME_SYNC);
	  gpio_enable_pin_glitch_filter(SSC_TX_CLOCK);
	  gpio_enable_pin_glitch_filter(SSC_TX_DATA);
	  gpio_enable_pin_glitch_filter(SSC_TX_FRAME_SYNC);

	  current_freq.frequency = 96000;

	  // set up SSC
	  ssc_i2s_init(ssc, 96000, 24, 32, SSC_I2S_MODE_STEREO_OUT_STEREO_IN, FPBA_HZ);

	  // set up PDCA
	  // In order to avoid long slave handling during undefined length bursts (INCR), the Bus Matrix
	  // provides specific logic in order to re-arbitrate before the end of the INCR transfer.
	  //
	  // HSB Bus Matrix: By default the HSB bus matrix mode is in Undefined length burst type (INCR).
	  // Here we have to put in single access (the undefined length burst is treated as a succession of single
	  // accesses, allowing re-arbitration at each beat of the INCR burst.
	  // Refer to the HSB bus matrix section of the datasheet for more details.
	  //
	  // HSB Bus matrix register MCFG1 is associated with the CPU instruction master interface.
	  AVR32_HMATRIX.mcfg[AVR32_HMATRIX_MASTER_CPU_INSN] = 0x1;

	  audio_buffer_in = 0;
	  spk_buffer_out = 0;
	  // Register PDCA IRQ interrupt.
	  pdca_set_irq();

	  // Init PDCA channel with the pdca_options.
	  pdca_init_channel(PDCA_CHANNEL_SSC_RX, &PDCA_OPTIONS); // init PDCA channel with options.
      pdca_enable_interrupt_reload_counter_zero(PDCA_CHANNEL_SSC_RX);
      pdca_init_channel(PDCA_CHANNEL_SSC_TX, &SPK_PDCA_OPTIONS); // init PDCA channel with options.
       pdca_enable_interrupt_reload_counter_zero(PDCA_CHANNEL_SSC_TX);

       //////////////////////////////////////////////
       // Enable now the transfer.
       pdca_enable(PDCA_CHANNEL_SSC_TX);


	  xTaskCreate(AK5394A_task,
              configTSK_AK5394A_NAME,
              configTSK_AK5394A_STACK_SIZE,
              NULL,
              configTSK_AK5394A_PRIORITY,
              NULL);

}