1 // Copyright 2021 Espressif Systems (Shanghai) CO LTD 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License 14 15 #pragma once 16 17 #include <stddef.h> 18 #include <sys/types.h> 19 20 #include "esp_err.h" 21 22 #define EFD_SUPPORT_ISR (1 << 4) 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 /** 29 * @brief Eventfd vfs initialization settings 30 */ 31 typedef struct { 32 size_t max_fds; /*!< The maxinum number of eventfds supported */ 33 } esp_vfs_eventfd_config_t; 34 35 #define ESP_VFS_EVENTD_CONFIG_DEFAULT() (esp_vfs_eventfd_config_t) { \ 36 .max_fds = 5, \ 37 }; 38 39 /** 40 * @brief Registers the event vfs. 41 * 42 * @return ESP_OK if successful, ESP_ERR_NO_MEM if too many VFSes are 43 * registered. 44 */ 45 esp_err_t esp_vfs_eventfd_register(const esp_vfs_eventfd_config_t *config); 46 47 /** 48 * @brief Unregisters the event vfs. 49 * 50 * @return ESP_OK if successful, ESP_ERR_INVALID_STATE if VFS for given prefix 51 * hasn't been registered 52 */ 53 esp_err_t esp_vfs_eventfd_unregister(void); 54 55 /* 56 * @brief Creates an event file descirptor. 57 * 58 * The behavior of read, write and select is the same as man(2) eventfd with 59 * EFD_SEMAPHORE **NOT** specified. A new flag EFD_SUPPORT_ISR has been added. 60 * This flag is required to write to event fds in interrupt handlers. Accessing 61 * the control blocks of event fds with EFD_SUPPORT_ISR will cause interrupts to 62 * be temporarily blocked (e.g. during read, write and beginning and ending of 63 * the * select). 64 * 65 * @return The file descriptor if successful, -1 if error happens. 66 */ 67 int eventfd(unsigned int initval, int flags); 68 69 #ifdef __cplusplus 70 } 71 #endif 72