app_shm.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*********************************************************************
  2. * _ _ _
  3. * _ __ | |_ _ | | __ _ | |__ ___
  4. * | '__|| __|(_)| | / _` || '_ \ / __|
  5. * | | | |_ _ | || (_| || |_) |\__ \
  6. * |_| \__|(_)|_| \__,_||_.__/ |___/
  7. *
  8. * www.rt-labs.com
  9. * Copyright 2021 rt-labs AB, Sweden.
  10. *
  11. * This software is dual-licensed under GPLv3 and a commercial
  12. * license. See the file LICENSE.md distributed with this software for
  13. * full license information.
  14. ********************************************************************/
  15. #ifndef APP_SHM_H
  16. #define APP_SHM_H
  17. #include <stddef.h>
  18. #include <stdint.h>
  19. #include <stdbool.h>
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. typedef struct app_shm_t app_shm_t;
  24. /**
  25. * Create a shared memory area used as input.
  26. *
  27. * Shared memory is read by this application.
  28. * Intended for submodule input data.
  29. * The slot and and subslot info is used to
  30. * generate the name of the shared memory area.
  31. *
  32. * @param name In: Submodule id
  33. * @param slot In: Slot number
  34. * @param subslot In: Subslot number
  35. * @param size In: Size of area
  36. * @return Handle to created shared memory area. NULL on error.
  37. */
  38. app_shm_t * app_shm_create_input (
  39. const char * name,
  40. int slot,
  41. int subslot,
  42. int size);
  43. /**
  44. * Create a shared memory area used as output.
  45. *
  46. * Shared memory is written by this application.
  47. * Intended for submodule output data.
  48. * The slot and and subslot info is used to
  49. * generate the name of the shared memory area.
  50. *
  51. * @param name In: Submodule id
  52. * @param slot In: Slot number
  53. * @param subslot In: Subslot number
  54. * @param size In: Size of area
  55. * @return Handle to created shared memory area. NULL on error.
  56. */
  57. app_shm_t * app_shm_create_output (
  58. const char * name,
  59. int slot,
  60. int subslot,
  61. int size);
  62. /**
  63. * Free the resources of a shared memory area
  64. *
  65. * @param handle In: Shared memory object handle
  66. */
  67. void app_shm_destroy (app_shm_t * handle);
  68. /**
  69. * Read shared memory area into a buffer
  70. *
  71. * @param handle In: Shared memory object handle
  72. * @param data In: Start of buffer
  73. * @param size In: Number of bytes to read
  74. * @return 0 on success, -1 on error
  75. */
  76. int app_shm_read (app_shm_t * handle, void * data, size_t size);
  77. /**
  78. * Write to shared memory
  79. *
  80. * @param handle In: Shared memory object handle
  81. * @param data In: Start of buffer
  82. * @param size In: Number of bytes to write
  83. * @return 0 on success, -1 on error
  84. */
  85. int app_shm_write (app_shm_t * handle, void * data, size_t size);
  86. /**
  87. * Set shared memory to zero
  88. *
  89. * @param handle In: Shared memory object handle
  90. * @return 0 on success, -1 on error
  91. */
  92. int app_shm_reset (app_shm_t * handle);
  93. #endif /* APP_SHM_H */