sampleapp_common.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*********************************************************************
  2. * _ _ _
  3. * _ __ | |_ _ | | __ _ | |__ ___
  4. * | '__|| __|(_)| | / _` || '_ \ / __|
  5. * | | | |_ _ | || (_| || |_) |\__ \
  6. * |_| \__|(_)|_| \__,_||_.__/ |___/
  7. *
  8. * www.rt-labs.com
  9. * Copyright 2018 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 SAMPLEAPP_COMMON_H
  16. #define SAMPLEAPP_COMMON_H
  17. #include "osal.h"
  18. #include "pnal.h"
  19. #include <pnet_api.h>
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. #define APP_TICK_INTERVAL_US 1000 /* 1 ms */
  24. /* Thread configuration for targets where sample
  25. * event loop is run in a separate thread (not main).
  26. * This applies for linux sample app implementation.
  27. */
  28. #define APP_MAIN_THREAD_PRIORITY 15
  29. #define APP_MAIN_THREAD_STACKSIZE 4096 /* bytes */
  30. #define APP_DATA_LED_ID 1
  31. #define APP_PROFINET_SIGNAL_LED_ID 2
  32. #define APP_TICKS_READ_BUTTONS 10
  33. #define APP_TICKS_UPDATE_DATA 100
  34. /** HW Offload configuration. */
  35. typedef enum
  36. {
  37. MODE_HW_OFFLOAD_NONE = 0,
  38. MODE_HW_OFFLOAD_CPU,
  39. MODE_HW_OFFLOAD_FULL,
  40. } app_mode_t;
  41. /** Command line arguments for sample application */
  42. typedef struct app_args
  43. {
  44. char path_button1[PNET_MAX_FILE_FULLPATH_SIZE]; /** Terminated string */
  45. char path_button2[PNET_MAX_FILE_FULLPATH_SIZE]; /** Terminated string */
  46. char path_storage_directory[PNET_MAX_DIRECTORYPATH_SIZE]; /** Terminated */
  47. char station_name[PNET_STATION_NAME_MAX_SIZE]; /** Terminated string */
  48. char eth_interfaces
  49. [PNET_INTERFACE_NAME_MAX_SIZE * (PNET_MAX_PHYSICAL_PORTS + 1) +
  50. PNET_MAX_PHYSICAL_PORTS]; /** Terminated string */
  51. int verbosity;
  52. int show;
  53. bool factory_reset;
  54. bool remove_files;
  55. app_mode_t mode;
  56. } app_args_t;
  57. typedef enum
  58. {
  59. RUN_IN_SEPARATE_THREAD,
  60. RUN_IN_MAIN_THREAD
  61. } app_run_in_separate_task_t;
  62. typedef struct app_data_t app_data_t;
  63. /**
  64. * AR specific event handler type.
  65. *
  66. * Handles an AR specific event.
  67. *
  68. * @param app InOut: Application handle
  69. * @param arep In: Arep of the AR.
  70. *
  71. * @return 0 to indicate that the arep should be kept
  72. * 1 to indicate that the arep should be forgotten
  73. */
  74. typedef int (*app_ar_event_handler_t) (app_data_t * app, uint32_t arep);
  75. /** Partially initialise config values, and use proper callbacks
  76. *
  77. * @param pnet_cfg Out: Configuration to be updated
  78. */
  79. void app_pnet_cfg_init_default (pnet_cfg_t * pnet_cfg);
  80. /**
  81. * Initialize P-Net stack and application.
  82. *
  83. * The \a pnet_cfg argument shall have been initialized using
  84. * \a app_pnet_cfg_init_default() before this function is
  85. * called.
  86. *
  87. * @param pnet_cfg In: P-Net configuration
  88. * @param app_args In: Application arguments
  89. * @return Application handle, NULL on error
  90. */
  91. app_data_t * app_init (const pnet_cfg_t * pnet_cfg, const app_args_t * app_args);
  92. /**
  93. * Start application main loop
  94. *
  95. * Application must have been initialized using \a app_init() before
  96. * this function is called.
  97. *
  98. * If \a task_config parameters is set to RUN_IN_SEPARATE_THREAD a
  99. * thread execution the \a app_loop_forever() function is started.
  100. * If task_config is set to RUN_IN_MAIN_THREAD no such thread is
  101. * started and the caller must call the \a app_loop_forever() after
  102. * calling this function.
  103. *
  104. * RUN_IN_MAIN_THREAD is intended for rt-kernel targets.
  105. * RUN_IN_SEPARATE_THREAD is intended for linux targets.
  106. *
  107. * @param app In: Application handle
  108. * @param task_config In: Defines if stack and application
  109. * is run in main or separate task.
  110. * @return 0 on success, -1 on error
  111. */
  112. int app_start (app_data_t * app, app_run_in_separate_task_t task_config);
  113. /**
  114. * Application task definition. Handles events in eternal loop.
  115. *
  116. * @param arg In: Application handle
  117. */
  118. void app_loop_forever (void * arg);
  119. /**
  120. * Get P-Net instance from application
  121. *
  122. * @param app In: Application handle
  123. * @return P-Net instance, NULL on failure
  124. */
  125. pnet_t * app_get_pnet_instance (app_data_t * app);
  126. /**
  127. * Set LED state
  128. * Hardware specific. Implemented in sample app main file for
  129. * each supported platform.
  130. *
  131. * @param id In: LED number, starting from 0.
  132. * @param led_state In: LED state. Use true for on and false for off.
  133. */
  134. void app_set_led (uint16_t id, bool led_state);
  135. /**
  136. * Read button state
  137. *
  138. * Hardware specific. Implemented in sample app main file for
  139. * each supported platform.
  140. *
  141. * @param id In: Button number, starting from 0.
  142. * @return true if button is pressed, false if not
  143. */
  144. bool app_get_button (uint16_t id);
  145. #ifdef __cplusplus
  146. }
  147. #endif
  148. #endif /* SAMPLEAPP_COMMON_H */