/*---------------------------------------------------------------------------- * Copyright (c) Fenda Technologies Co., Ltd. 2021. All rights reserved. * * Description: ppg_api.c * * Author: shey.tanxiaoyu * * Create: 2022-04-20 *--------------------------------------------------------------------------*/ #include "ppg_api.h" #include "FreeRTOS.h" #include "semphr.h" static SemaphoreHandle_t g_ppg_mutex_handle = NULL; static ppg_event_handler_ptr g_ppg_event_cb = NULL; void ppg_api_creat_mutex(void) { if (g_ppg_mutex_handle == NULL) { g_ppg_mutex_handle = xSemaphoreCreateRecursiveMutex(); } } void ppg_api_mutex_lock(void) { if (g_ppg_mutex_handle) { xSemaphoreTakeRecursive(g_ppg_mutex_handle, pdMS_TO_TICKS(10 * 1000)); } } void ppg_api_mutex_unlock(void) { if (g_ppg_mutex_handle) { xSemaphoreGiveRecursive(g_ppg_mutex_handle); } } void ppg_api_irq_handler(void) { if (g_ppg_event_cb) { g_ppg_event_cb(PPG_EVENT_IRQ); } } void ppg_api_queue_irq_handler(void) { if (g_ppg_event_cb) { g_ppg_event_cb(PPG_EVENT_QUEUQ_IRQ); } } int32_t ppg_api_init(void) { int8_t ret; ppg_api_creat_mutex(); ppg_api_mutex_lock(); ret = drv_gh3011_init(); ppg_api_mutex_unlock(); return ret; } int32_t ppg_api_get_chip_id(uint16_t *chip_id) { return drv_gh3011_get_chip_id(chip_id); } int32_t ppg_api_get_run_mode(uint8_t *run_mode) { return drv_gh3011_get_run_mode(run_mode); } int32_t ppg_api_open(GH3011_RUN_MODE run_mode, ppg_event_handler_ptr event_cb) { int8_t ret; ppg_api_mutex_lock(); ret = drv_gh3011_open(run_mode, ppg_api_irq_handler); g_ppg_event_cb = event_cb; ppg_api_mutex_unlock(); return ret; } void ppg_api_close(void) { ppg_api_mutex_lock(); drv_gh3011_close(); ppg_api_mutex_unlock(); } void ppg_api_read(int32_t read_buf[][2], uint16_t *read_len) { ppg_api_mutex_lock(); drv_gh3011_read(read_buf, read_len); ppg_api_mutex_unlock(); } void ppg_api_current_set(uint16_t cur0, uint16_t cur1, uint16_t cur2) { ppg_api_mutex_lock(); drv_gh3011_current_set(cur0, cur1, cur2); ppg_api_mutex_unlock(); } void ppg_api_current_get(uint16_t *cur0, uint16_t *cur1, uint16_t *cur2) { ppg_api_mutex_lock(); drv_gh3011_current_get(cur0, cur1, cur2); ppg_api_mutex_unlock(); }