Funpack11期于10月31日截止后,到现在已审核完毕,相信审核通过的小伙伴都已经收到祝贺邮件了,那就静等返款吧。
本期的任务也是很有用意思,四选一,难度中等。这款来自NXP的强大的LPC55S69-EVK在群友们和各种开源资料的帮助下被大家玩的非常深入,轻松完成这期的几个任务。
下面就来看看vic网友如何使用本期板卡实现音频播放器的吧。以下项目已开源在电子森林:https://www.eetree.cn/project/detail/626,大家感兴趣的可以来一起学习。
int main(void)
{
int ret;
/* set BOD VBAT level to 1.65V */
POWER_SetBodVbatLevel(kPOWER_BodVbatLevel1650mv, kPOWER_BodHystLevel50mv, false);
CLOCK_EnableClock(kCLOCK_InputMux);
CLOCK_EnableClock(kCLOCK_Iocon);
CLOCK_EnableClock(kCLOCK_Gpio0);
CLOCK_EnableClock(kCLOCK_Gpio1);
/* USART0 clock */
CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);
/* I2C clock */
CLOCK_AttachClk(kFRO12M_to_FLEXCOMM4);
PMC->PDRUNCFGCLR0 |= PMC_PDRUNCFG0_PDEN_XTAL32M_MASK; /*!< Ensure XTAL16M is on */
PMC->PDRUNCFGCLR0 |= PMC_PDRUNCFG0_PDEN_LDOXO32M_MASK; /*!< Ensure XTAL16M is on */
SYSCON->CLOCK_CTRL |= SYSCON_CLOCK_CTRL_CLKIN_ENA_MASK; /*!< Ensure CLK_IN is on */
ANACTRL->XO32M_CTRL |= ANACTRL_XO32M_CTRL_ENABLE_SYSTEM_CLK_OUT_MASK;
/*!< Switch PLL0 clock source selector to XTAL16M */
CLOCK_AttachClk(kEXT_CLK_to_PLL0);
const pll_setup_t pll0Setup = {
.pllctrl = SYSCON_PLL0CTRL_CLKEN_MASK | SYSCON_PLL0CTRL_SELI(2U) | SYSCON_PLL0CTRL_SELP(31U),
.pllndec = SYSCON_PLL0NDEC_NDIV(125U),
.pllpdec = SYSCON_PLL0PDEC_PDIV(8U),
.pllsscg = {0x0U, (SYSCON_PLL0SSCG1_MDIV_EXT(3072U) | SYSCON_PLL0SSCG1_SEL_EXT_MASK)},
.pllRate = 24576000U,
.flags = PLL_SETUPFLAG_WAITLOCK};
/*!< Configure PLL to the desired values */
CLOCK_SetPLL0Freq(&pll0Setup);
CLOCK_SetClkDiv(kCLOCK_DivPll0Clk, 0U, true);
CLOCK_SetClkDiv(kCLOCK_DivPll0Clk, 1U, false);
/* I2S clocks */
CLOCK_AttachClk(kPLL0_DIV_to_FLEXCOMM6);
CLOCK_AttachClk(kPLL0_DIV_to_FLEXCOMM7);
/* Attach PLL clock to MCLK for I2S, no divider */
CLOCK_AttachClk(kPLL0_to_MCLK);
SYSCON->MCLKDIV = SYSCON_MCLKDIV_DIV(0U);
SYSCON->MCLKIO = 1U;
/* reset FLEXCOMM for I2C */
RESET_PeripheralReset(kFC4_RST_SHIFT_RSTn);
/* reset FLEXCOMM for DMA0 */
RESET_PeripheralReset(kDMA0_RST_SHIFT_RSTn);
/* reset FLEXCOMM for I2S */
RESET_PeripheralReset(kFC6_RST_SHIFT_RSTn);
RESET_PeripheralReset(kFC7_RST_SHIFT_RSTn);
/* reset NVIC for FLEXCOMM6 and FLEXCOMM7 */
NVIC_ClearPendingIRQ(FLEXCOMM6_IRQn);
NVIC_ClearPendingIRQ(FLEXCOMM7_IRQn);
/* Enable interrupts for I2S */
EnableIRQ(FLEXCOMM6_IRQn);
EnableIRQ(FLEXCOMM7_IRQn);
/* Initialize the rest */
BOARD_InitPins();
BOARD_BootClockPLL1_150M();
BOARD_InitDebugConsole();
BOARD_InitSysctrl();
PRINTF("\r\n");
PRINTF("**********************************\r\n");
PRINTF("Maestro audio solutions demo start\r\n");
PRINTF("**********************************\r\n");
PRINTF("\r\n");
ret = BOARD_CODEC_Init();
if (ret)
{
PRINTF("CODEC_Init failed\r\n");
return -1;
}
if (xTaskCreate(APP_SDCARD_Task, "SDCard Task", SDCARD_TASK_STACK_SIZE, &app, configMAX_PRIORITIES - 4, NULL) !=
pdPASS)
{
PRINTF("\r\nFailed to create application task\r\n");
while (1)
;
}
/* Set shell command task priority = 1 */
if (xTaskCreate(APP_Shell_Task, "Shell Task", SHELL_TASK_STACK_SIZE, &app, configMAX_PRIORITIES - 5,
&app.shell_task_handle) != pdPASS)
{
PRINTF("\r\nFailed to create application task\r\n");
while (1)
;
}
/* Run RTOS */
vTaskStartScheduler();
/* Should not reach this statement */
return 0;
}
void APP_SDCARD_Task(void *param)
{
const TCHAR driverNumberBuffer[3U] = {SDDISK + '0', ':', '/'};
FRESULT error;
app_handle_t *app = (app_handle_t *)param;
app->sdcardSem = xSemaphoreCreateBinary();
BOARD_SD_Config(&g_sd, APP_SDCARD_DetectCallBack, BOARD_SDMMC_SD_HOST_IRQ_PRIORITY, app);
PRINTF("[APP_SDCARD_Task] start\r\n");
/* SD host init function */
if (SD_HostInit(&g_sd) != kStatus_Success)
{
PRINTF("[APP_SDCARD_Task] SD host init failed.\r\n");
vTaskSuspend(NULL);
}
/* Small delay for SD card detection logic to process */
vTaskDelay(100 / portTICK_PERIOD_MS);
while (1)
{
/* Block waiting for SDcard detect interrupt */
xSemaphoreTake(app->sdcardSem, portMAX_DELAY);
if (app->sdcardInserted != app->sdcardInsertedPrev)
{
app->sdcardInsertedPrev = app->sdcardInserted;
SD_SetCardPower(&g_sd, false);
if (app->sdcardInserted)
{
/* power on the card */
SD_SetCardPower(&g_sd, true);
if (f_mount(&app->fileSystem, driverNumberBuffer, 0U))
{
PRINTF("[APP_SDCARD_Task] Mount volume failed.\r\n");
continue;
}
#if (FF_FS_RPATH >= 2U)
error = f_chdrive((char const *)&driverNumberBuffer[0U]);
if (error)
{
PRINTF("[APP_SDCARD_Task] Change drive failed.\r\n");
continue;
}
#endif
PRINTF("[APP_SDCARD_Task] SD card drive mounted\r\n");
xSemaphoreGive(app->sdcardSem);
}
}
}
}
uint32_t ulTaskGenericNotifyTake( UBaseType_t uxIndexToWait,
BaseType_t xClearCountOnExit,
TickType_t xTicksToWait )
{
uint32_t ulReturn;
configASSERT( uxIndexToWait < configTASK_NOTIFICATION_ARRAY_ENTRIES );
taskENTER_CRITICAL();
{
/* Only block if the notification count is not already non-zero. */
if( pxCurrentTCB->ulNotifiedValue[ uxIndexToWait ] == 0UL )
{
/* Mark this task as waiting for a notification. */
pxCurrentTCB->ucNotifyState[ uxIndexToWait ] = taskWAITING_NOTIFICATION;
if( xTicksToWait > ( TickType_t ) 0 )
{
prvAddCurrentTaskToDelayedList( xTicksToWait, pdTRUE );
traceTASK_NOTIFY_TAKE_BLOCK( uxIndexToWait );
/* All ports are written to allow a yield in a critical
* section (some will yield immediately, others wait until the
* critical section exits) - but it is not something that
* application code should ever do. */
portYIELD_WITHIN_API();
}
else
{
mtCOVERAGE_TEST_MARKER();
}
}
else
{
mtCOVERAGE_TEST_MARKER();
}
}
taskEXIT_CRITICAL();
taskENTER_CRITICAL();
{
traceTASK_NOTIFY_TAKE( uxIndexToWait );
ulReturn = pxCurrentTCB->ulNotifiedValue[ uxIndexToWait ];
if( ulReturn != 0UL )
{
if( xClearCountOnExit != pdFALSE )
{
pxCurrentTCB->ulNotifiedValue[ uxIndexToWait ] = 0UL;
}
else
{
pxCurrentTCB->ulNotifiedValue[ uxIndexToWait ] = ulReturn - ( uint32_t ) 1;
}
}
else
{
mtCOVERAGE_TEST_MARKER();
}
pxCurrentTCB->ucNotifyState[ uxIndexToWait ] = taskNOT_WAITING_NOTIFICATION;
}
taskEXIT_CRITICAL();
return ulReturn;
}
int BOARD_CODEC_Init(void)
{
CODEC_Init(&codecHandle, &boardCodecConfig);
/* Invert the DAC data in order to output signal with correct polarity - set DACL_DATINV and DACR_DATINV = 1 */
WM8904_WriteRegister((wm8904_handle_t *)codecHandle.codecDevHandle, WM8904_AUDIO_IF_0, 0x1850);
/* Initial volume kept low for hearing safety. */
CODEC_SetVolume(&codecHandle, kCODEC_PlayChannelHeadphoneLeft | kCODEC_PlayChannelHeadphoneRight, 75);
return 0;
}
END
硬禾学堂
硬禾团队一直致力于给电子工程师和相关专业的同学,带来规范的核心技能课程,帮助大家在学习和工作的各个阶段,都能有效地提升自己的职业能力。
硬禾学堂
我们一起在电子领域探索前进
关注硬禾公众号,随时直达课堂
点击阅读原文查看更多