| | |
| | | * Copyright (C) 2023 Panchip Technology Corp. All rights reserved. |
| | | *****************************************************************************/ |
| | | #include "pan_hal.h" |
| | | #if CONFIG_OS_EN |
| | | #include "freertos.h" |
| | | #include "semphr.h" |
| | | #endif |
| | | |
| | | #if CONFIG_OS_EN |
| | | SemaphoreHandle_t xSemaphore = NULL; |
| | | #endif |
| | | |
| | | void HAL_ADC_Init(ADC_HandleTypeDef *pADC) |
| | | { |
| | | #if CONFIG_OS_EN |
| | | if (xSemaphore == NULL) { |
| | | xSemaphore = xSemaphoreCreateMutex(); |
| | | } else { |
| | | return; |
| | | } |
| | | |
| | | #endif |
| | | /* Setting input range (0 ~ 1.2V) as default |
| | | * Note: if the input voltage over 1.2V, should |
| | | * adopt r1/r1+r2 mothod |
| | |
| | | uint32_t result_code; |
| | | |
| | | if ((pADC->id > ADC_CH_BATTERY) || ((pADC->id > ADC_CH7) && (pADC->id < ADC_CH_TEMP))) { |
| | | return PAN_HAL_IO_ERROR; |
| | | return HAL_IO_ERROR; |
| | | } |
| | | |
| | | |
| | | #if CONFIG_OS_EN |
| | | xSemaphoreTake(xSemaphore, portMAX_DELAY); |
| | | |
| | | #endif |
| | | |
| | | /* Open clock related adc */ |
| | | CLK_APB1PeriphClockCmd(CLK_APB1Periph_ADC, ENABLE); |
| | | |
| | |
| | | |
| | | /* Open clock related adc */ |
| | | CLK_APB1PeriphClockCmd(CLK_APB1Periph_ADC, DISABLE); |
| | | |
| | | #if CONFIG_OS_EN |
| | | xSemaphoreGive(xSemaphore); |
| | | |
| | | return PAN_HAL_SUCCESS; |
| | | #endif |
| | | |
| | | return HAL_SUCCESS; |
| | | } |
| | | |
| | | |