Загрузка данных
void PowerModeSwitchTask(void *pvParameters)
{
lptmr_config_t lptmrConfig;
lpm_power_mode_t targetPowerMode;
uint32_t freq = 0U;
uint8_t ch;
int32_t status = SCMI_ERR_SUCCESS;
/* Setup LPTMR. */
LPTMR_GetDefaultConfig(&lptmrConfig);
lptmrConfig.prescalerClockSource = kLPTMR_PrescalerClock_2; /* Use RTC 32KHz as clock source. */
lptmrConfig.bypassPrescaler = true;
lptmrConfig.value = kLPTMR_Prescale_Glitch_0; /* Divide clock source by 2. */
LPTMR_Init(LPTMR2, &lptmrConfig);
NVIC_SetPriority(LPTMR2_IRQn, APP_LPTMR2_IRQ_PRIO);
EnableIRQ(LPTMR2_IRQn);
/* Setup LPUART. */
NVIC_SetPriority(LPUART3_IRQn, APP_LPUART3_IRQ_PRIO);
EnableIRQ(LPUART3_IRQn);
for (;;)
{
freq = HAL_ClockGetIpFreq(hal_clock_m7);
PRINTF("\r\n#################### Power Mode Switch Task ####################\n\r\n");
PRINTF(" Build Time: %s--%s \r\n", __DATE__, __TIME__);
PRINTF(" Core Clock: %dHz \r\n", freq);
PRINTF("\r\nSelect the desired operation \n\r\n");
PRINTF("Press %c to enter: Normal RUN mode\r\n", kAPP_PowerModeRun);
PRINTF("Press %c to enter: WAIT mode\r\n", kAPP_PowerModeWait);
PRINTF("Press %c to enter: STOP mode\r\n", kAPP_PowerModeStop);
PRINTF("Press %c to enter: SUSPEND mode\r\n", kAPP_PowerModeSuspend);
PRINTF("Press P to suspend A55 core\r\n");
PRINTF("Press W to wakeup A55 core\r\n");
PRINTF("Press S to scan LPI2C3\r\n");
PRINTF("Press E to camera ON\r\n");
PRINTF("Press F to camera OFF\r\n");
PRINTF("\r\nWaiting for power mode select..\r\n\r\n");
/* Wait for user response */
do
{
ch = GETCHAR();
} while ((ch == '\r') || (ch == '\n'));
if ((ch >= 'a') && (ch <= 'z'))
{
ch -= 'a' - 'A';
}
if ('S' == ch)
{
lpi2c_scan_bus(3);
continue;
}
else if('E' == ch)
{
APP_SRTM_CameraSendCommandSync(SRTM_SERVICE_CAMERA_ID, 0, SRTM_CMD_CAMERA_ON, 50);
continue;
}
else if('F' == ch)
{
APP_SRTM_CameraSendCommandSync(SRTM_SERVICE_CAMERA_ID, 0, SRTM_CMD_CAMERA_OFF, 50);
continue;
}
int modeIndex = ch - 'A';
if ((ch != 'P') && (ch != 'W') && ((modeIndex < 0) || (modeIndex >= LPM_PowerModeCount)))
{
PRINTF("Invalid power mode input: %c\r\n", ch);
continue;
}
targetPowerMode = (lpm_power_mode_t)modeIndex;
if (targetPowerMode < LPM_PowerModeCount)
{
if (targetPowerMode == s_curMode)
{
/* Same mode, skip it */
continue;
}
if (targetPowerMode == LPM_PowerModeSuspend)
{
PRINTF("Application get in Suspend mode\r\n");
}
if (!LPM_SetPowerMode(targetPowerMode))
{
PRINTF("Some task doesn't allow to enter mode %s\r\n", s_modeNames[targetPowerMode]);
}
else /* Idle task will handle the low power state. */
{
APP_GetWakeupConfig();
APP_SetWakeupConfig(targetPowerMode);
PRINTF("Target powermode get in %s\r\n", s_modeNames[targetPowerMode]);
xSemaphoreTake(s_wakeupSig, portMAX_DELAY);
}
}
else if ('P' == ch)
{
/* skip this command if A55 already in suspend mode. */
uint32_t runMode, velow, vehigh;
uint32_t sleepMode = CPU_SLEEP_MODE_RUN;
int32_t status = SCMI_ERR_SUCCESS;
status = SCMI_CpuInfoGet(SCMI_A2P, AP_DOMAIN_LD, &runMode, &sleepMode, &velow, &vehigh);
if (status != SCMI_ERR_SUCCESS)
{
PRINTF("Get AP info fail\r\n");
}
if (sleepMode == CPU_SLEEP_MODE_SUSPEND)
{
PRINTF("AP already in suspend mode, skip this command\r\n");
continue;
}
else
{
status = SCMI_LmmSuspend(SCMI_A2P, AP_DOMAIN_LD);
if (status != SCMI_ERR_SUCCESS)
{
PRINTF("SCMI_LmmSuspend A55 fail\r\n");
}
}
}
else if ('W' == ch)
{
status = SCMI_LmmWake(SCMI_A2P, AP_DOMAIN_LD);
if (status != SCMI_ERR_SUCCESS)
{
PRINTF("SCMI_LmmWake A55 fail\r\n");
}
}
else
{
PRINTF("Invalid command %c[0x%x]\r\n", ch, ch);
}
/* update Mode state */
s_curMode = LPM_PowerModeRun;
PRINTF("\r\nNext loop\r\n");
}
}