/** * \brief Interrupt handler for UART interrupt. */ static void pdca_tranfer_done(enum pdca_channel_status status) { /* Get PDCA channel status and check if PDCA transfer complete */ if (status == PDCA_CH_TRANSFER_COMPLETED) { /* Configure PDCA for data transfer */ if (bool_anim == 1){ pdca_channel_write_reload(PDCA_TX_CHANNEL, (void *)ascii_anim2, sizeof( ascii_anim2 )); bool_anim = 2; } else { pdca_channel_write_reload(PDCA_TX_CHANNEL, (void *)ascii_anim1, sizeof( ascii_anim1 )); bool_anim = 1; } } }
/** * \brief Interrupt handler for TC00. Record the number of bytes received, * and then restart a read transfer on the USART if the transfer was stopped. */ void TC00_Handler(void) { uint32_t ul_status; uint32_t ul_byte_total = 0; /* Read TC0 Status. */ ul_status = tc_get_status(TC0, 0); /* RC compare. */ if ((ul_status & TC_SR_CPCS) == TC_SR_CPCS) { /* Flush PDC buffer. */ ul_byte_total = BUFFER_SIZE - pdca_channel_read_load_size(PDCA_RX_CHANNEL); if ((ul_byte_total != 0) && (ul_byte_total != BUFFER_SIZE)) { /* Log current size. */ g_uc_transend_flag = 1; if (pdca_channel_read_reload_size(PDCA_RX_CHANNEL) == 0) { gs_ul_size_buffer = BUFFER_SIZE; gs_ul_size_nextbuffer = ul_byte_total; } else { gs_ul_size_buffer = ul_byte_total; gs_ul_size_nextbuffer = 0; } /* Trigger USART Receive Buffer Full Interrupt. */ /* Restart read on buffer. */ pdca_channel_write_reload(PDCA_RX_CHANNEL, (void *)gs_puc_nextbuffer[gs_uc_buf_num], 0); pdca_channel_write_load(PDCA_RX_CHANNEL, (void *)gs_puc_buffer[gs_uc_buf_num], 0); } } }
/** * PDCA transfer interrupt callback. */ static void pdca_tranfer_done(enum pdca_channel_status status) { /* Get PDCA channel status and check if PDCA transfer is completed */ if (status == PDCA_CH_TRANSFER_COMPLETED) { /* Reload PDCA data transfer */ pdca_channel_write_reload(PEVC_ID_USER_PDCA_0, (void *)event_string, sizeof( event_string)); printf("\r\n"); } }
/** * \brief Interrupt handler for USART. Echo the bytes received and start the * next receive. */ void USART_Handler(void) { uint32_t ul_status; /* Read USART Status. */ ul_status = usart_get_status(BOARD_USART); /* Receive buffer is full. */ if (ul_status & US_CSR_RXBUFF) { /* Disable timer. */ tc_stop(TC0, 0); /* Echo back buffer. */ pdca_channel_write_load(PDCA_TX_CHANNEL, (void *)gs_puc_buffer[gs_uc_buf_num], gs_ul_size_buffer); pdca_channel_write_reload(PDCA_TX_CHANNEL, (void *)gs_puc_nextbuffer[gs_uc_buf_num], gs_ul_size_nextbuffer); if (g_uc_transend_flag) { gs_ul_size_buffer = BUFFER_SIZE; gs_ul_size_nextbuffer = BUFFER_SIZE; g_uc_transend_flag = 0; } gs_uc_buf_num = MAX_BUF_NUM - gs_uc_buf_num; /* Restart read on buffer. */ pdca_channel_write_load(PDCA_RX_CHANNEL, (void *)gs_puc_buffer[gs_uc_buf_num], BUFFER_SIZE); pdca_channel_write_reload(PDCA_RX_CHANNEL, (void *)gs_puc_nextbuffer[gs_uc_buf_num], BUFFER_SIZE); /* Restart timer. */ tc_start(TC0, 0); } }
/** * \brief Application entry point for ABDAC example. * * \return Unused (ANSI-C compatibility). */ int main(void) { uint8_t key; uint32_t i, count; status_code_t status; /* Initialize the SAM system. */ sysclk_init(); board_init(); /* Initialize the UART console. */ configure_console(); /* Output example information */ printf("-- ABDAC Example --\r\n"); printf("-- %s\r\n", BOARD_NAME); printf("-- Compiled: %s %s --\r\n", __DATE__, __TIME__); /* Config the push button. */ config_buttons(); /* Config the ABDAC. */ abdac_get_config_defaults(&g_abdac_cfg); g_abdac_cfg.sample_rate_hz = ABDAC_SAMPLE_RATE_11025; g_abdac_cfg.data_word_format = ABDAC_DATE_16BIT; g_abdac_cfg.mono = false; g_abdac_cfg.cmoc = false; status = abdac_init(&g_abdac_inst, ABDACB, &g_abdac_cfg); if (status != STATUS_OK) { printf("-- Initialization fails! --\r\n"); while (1) { } } abdac_enable(&g_abdac_inst); abdac_clear_interrupt_flag(&g_abdac_inst, ABDAC_INTERRUPT_TXRDY); abdac_clear_interrupt_flag(&g_abdac_inst, ABDAC_INTERRUPT_TXUR); /* Config PDCA module */ pdca_enable(PDCA); pdca_channel_set_config(PDCA_ABDAC_CHANNEL0, &pdca_abdac_config0); pdca_channel_enable(PDCA_ABDAC_CHANNEL0); pdca_channel_set_config(PDCA_ABDAC_CHANNEL1, &pdca_abdac_config1); pdca_channel_enable(PDCA_ABDAC_CHANNEL1); /* Display menu. */ display_menu(); while (1) { scanf("%c", (char *)&key); switch (key) { case 'h': display_menu(); break; case 's': printf("--Looped output audio, use push button to exit--\r\n"); abdac_set_volume0(&g_abdac_inst, false, 0x7FFF); abdac_set_volume1(&g_abdac_inst, false, 0x7FFF); i = 0; /* output sample from the sound_table array */ while(!exit_flag) { count = 0; // Store sample from the sound_table array while(count < (SOUND_SAMPLES)){ samples_left[count] = ((uint8_t)sound_table[i]) << 8; samples_right[count] = ((uint8_t)sound_table[i]) << 8; i++; count++; if (i >= sizeof(sound_table)) i = 0; } pdca_channel_write_reload(PDCA_ABDAC_CHANNEL0, (void *)samples_left, SOUND_SAMPLES); pdca_channel_write_reload(PDCA_ABDAC_CHANNEL1, (void *)samples_right, SOUND_SAMPLES); /** * 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(!(pdca_get_channel_status(PDCA_ABDAC_CHANNEL1) == PDCA_CH_COUNTER_RELOAD_IS_ZERO)); } exit_flag = false; printf("--Exit the audio output--\r\n\r\n"); /* Mute the volume */ abdac_set_volume0(&g_abdac_inst, true, 0x7FFF); abdac_set_volume1(&g_abdac_inst, true, 0x7FFF); break; default: break; } } }