/** * @brief Starts audio recording. * @param pbuf: Main buffer pointer for the recorded data storing * @param size: size of the recorded buffer in number of elements (typically number of half-words) * Be careful that it is not the same unit than BSP_AUDIO_OUT_Play function * @retval AUDIO_OK if correct communication, else wrong communication */ uint8_t BSP_AUDIO_IN_Record(uint16_t* pbuf, uint32_t size) { uint32_t ret = AUDIO_ERROR; /* Start the process receive DMA */ HAL_SAI_Receive_DMA(&haudio_in_sai, (uint8_t*)pbuf, size); /* Return AUDIO_OK when all operations are correctly done */ ret = AUDIO_OK; return ret; }
int record_to_flash(void) { int ret = 0; int pos_buff = 0; uint32_t pos_flash = 0; uint32_t part_len = DATA_BUFF_LEN / 2; uint32_t part_bytes = part_len * SAI_DATA_BYTES; uint32_t total_size = get_audio_part_len(); if (!aos_mutex_is_valid(&sai_mutex)) { KIDS_A10_PRT("aos_mutex_is_valid return false.\n"); return -1; } ret = aos_mutex_lock(&sai_mutex, SAI_WAIT_TIMEOUT); if (ret != 0) { KIDS_A10_PRT("SAI is very busy now.\n"); return -1; } if (!aos_sem_is_valid(&audio_sem)) { KIDS_A10_PRT("aos_sem_is_valid return false.\n"); ret = -1; goto REC_EXIT; } ret = reinit_sai_and_dma(SAI_dir_rx_p2m); if (ret != 0) { ret = -1; goto REC_EXIT; } printf("Record time is %f seconds!\n", get_run_time()); ret = HAL_SAI_Receive_DMA(&hsai_BlockA1, (uint8_t *)data_buff, DATA_BUFF_LEN); if (ret != 0) { KIDS_A10_PRT("HAL_SAI_Receive_DMA return failed.\n"); ret = -1; goto REC_EXIT; } #ifdef FLASH_MONO_DATA while (1) { /* Wait a callback event */ while (UpdatePointer == -1) { ret = aos_sem_wait(&audio_sem, DMA_WAIT_TIMEOUT); if (ret != 0) KIDS_A10_PRT("DMA timeout.\n"); } pos_buff = UpdatePointer; UpdatePointer = -1; /* Upate the first or the second part of the buffer */ ready_to_save(&data_buff[pos_buff], part_len); ret = hal_flash_write(PART_FOR_AUDIO, &pos_flash, &data_buff[pos_buff], part_bytes / 2); if (ret != 0) { ret = -1; break; } /* check the end of the file */ if ((pos_flash + part_bytes / 2) > total_size) { ret = HAL_SAI_DMAStop(&hsai_BlockA1); if (ret != 0) { KIDS_A10_PRT("HAL_SAI_DMAStop return failed.\n"); ret = -1; } break; } if (UpdatePointer != -1) { /* Buffer update time is too long compare to the data transfer time */ KIDS_A10_PRT("UpdatePointer error.\n"); ret = -1; break; } } #else while (1) { /* Wait a callback event */ while (UpdatePointer == -1) { aos_sem_wait(&audio_sem, DMA_WAIT_TIMEOUT); if (ret != 0) KIDS_A10_PRT("DMA timeout.\n"); } pos_buff = UpdatePointer; UpdatePointer = -1; /* Upate the first or the second part of the buffer */ ret = hal_flash_write(PART_FOR_AUDIO, &pos_flash, &data_buff[pos_buff], part_bytes); if (ret != 0) { ret = -1; break; } /* check the end of the file */ if ((pos_flash + part_bytes) > total_size) { ret = HAL_SAI_DMAStop(&hsai_BlockA1); if (ret != 0) { KIDS_A10_PRT("HAL_SAI_DMAStop return failed.\n"); ret = -1; } break; } if (UpdatePointer != -1) { /* Buffer update time is too long compare to the data transfer time */ KIDS_A10_PRT("UpdatePointer error.\n"); ret = -1; break; } } #endif REC_EXIT: ret = aos_mutex_unlock(&sai_mutex); if (ret != 0) { KIDS_A10_PRT("SAI release failed.\n"); } return ret; }
bool Putz01SaiBStart (void) { puts ("Putz01SaiBStart() Enter\r"); HAL_StatusTypeDef sts = HAL_SAI_Receive_DMA(&hsai_BlockB1, (uint8_t *)&SaiBBuf, sizeof(SaiBBuf)/sizeof(SaiBBuf[0])); PUTZ_ASSERT(sts==HAL_OK); return true; }