esp_vfs_eventfd.h 2.0 KB

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