app_gsdml.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. #include "sampleapp_common.h"
  16. #include "app_utils.h"
  17. #include "app_gsdml.h"
  18. #include "app_log.h"
  19. #include "osal.h"
  20. #include "pnal.h"
  21. #include <pnet_api.h>
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. /******************* Supported modules ***************************/
  26. static const app_gsdml_module_t dap_1 = {
  27. .id = PNET_MOD_DAP_IDENT,
  28. .name = "DAP 1",
  29. .submodules = {
  30. PNET_SUBMOD_DAP_IDENT,
  31. PNET_SUBMOD_DAP_INTERFACE_1_PORT_1_IDENT,
  32. PNET_SUBMOD_DAP_INTERFACE_1_PORT_2_IDENT,
  33. PNET_SUBMOD_DAP_INTERFACE_1_PORT_3_IDENT,
  34. PNET_SUBMOD_DAP_INTERFACE_1_PORT_4_IDENT,
  35. 0}};
  36. static const app_gsdml_module_t module_digital_in = {
  37. .id = APP_GSDML_MOD_ID_8_0_DIGITAL_IN,
  38. .name = "DI 8xLogicLevel",
  39. .submodules = {APP_GSDML_SUBMOD_ID_DIGITAL_IN, 0},
  40. };
  41. static const app_gsdml_module_t module_digital_out = {
  42. .id = APP_GSDML_MOD_ID_0_8_DIGITAL_OUT,
  43. .name = "DO 8xLogicLevel",
  44. .submodules = {APP_GSDML_SUBMOD_ID_DIGITAL_OUT, 0}};
  45. static const app_gsdml_module_t module_digital_in_out = {
  46. .id = APP_GSDML_MOD_ID_8_8_DIGITAL_IN_OUT,
  47. .name = "DIO 8xLogicLevel",
  48. .submodules = {APP_GSDML_SUBMOD_ID_DIGITAL_IN_OUT, 0}};
  49. static const app_gsdml_module_t module_echo = {
  50. .id = APP_GSDML_MOD_ID_ECHO,
  51. .name = "Echo module",
  52. .submodules = {APP_GSDML_SUBMOD_ID_ECHO, 0}};
  53. /******************* Supported submodules ************************/
  54. static const app_gsdml_submodule_t dap_indentity_1 = {
  55. .name = "DAP Identity 1",
  56. .api = APP_GSDML_API,
  57. .id = PNET_SUBMOD_DAP_IDENT,
  58. .data_dir = PNET_DIR_NO_IO,
  59. .insize = 0,
  60. .outsize = 0,
  61. .parameters = {0}};
  62. static const app_gsdml_submodule_t dap_interface_1 = {
  63. .name = "DAP Interface 1",
  64. .api = APP_GSDML_API,
  65. .id = PNET_SUBMOD_DAP_INTERFACE_1_IDENT,
  66. .data_dir = PNET_DIR_NO_IO,
  67. .insize = 0,
  68. .outsize = 0,
  69. .parameters = {0}};
  70. static const app_gsdml_submodule_t dap_port_1 = {
  71. .name = "DAP Port 1",
  72. .api = APP_GSDML_API,
  73. .id = PNET_SUBMOD_DAP_INTERFACE_1_PORT_1_IDENT,
  74. .data_dir = PNET_DIR_NO_IO,
  75. .insize = 0,
  76. .outsize = 0,
  77. .parameters = {0}};
  78. static const app_gsdml_submodule_t dap_port_2 = {
  79. .name = "DAP Port 2",
  80. .api = APP_GSDML_API,
  81. .id = PNET_SUBMOD_DAP_INTERFACE_1_PORT_2_IDENT,
  82. .data_dir = PNET_DIR_NO_IO,
  83. .insize = 0,
  84. .outsize = 0,
  85. .parameters = {0}};
  86. static const app_gsdml_submodule_t dap_port_3 = {
  87. .name = "DAP Port 3",
  88. .api = APP_GSDML_API,
  89. .id = PNET_SUBMOD_DAP_INTERFACE_1_PORT_3_IDENT,
  90. .data_dir = PNET_DIR_NO_IO,
  91. .insize = 0,
  92. .outsize = 0,
  93. .parameters = {0}};
  94. static const app_gsdml_submodule_t dap_port_4 = {
  95. .name = "DAP Port 4",
  96. .api = APP_GSDML_API,
  97. .id = PNET_SUBMOD_DAP_INTERFACE_1_PORT_4_IDENT,
  98. .data_dir = PNET_DIR_NO_IO,
  99. .insize = 0,
  100. .outsize = 0,
  101. .parameters = {0}};
  102. static const app_gsdml_submodule_t submod_digital_in = {
  103. .id = APP_GSDML_SUBMOD_ID_DIGITAL_IN,
  104. .name = "Digital Input",
  105. .api = APP_GSDML_API,
  106. .data_dir = PNET_DIR_INPUT,
  107. .insize = APP_GSDML_INPUT_DATA_DIGITAL_SIZE,
  108. .outsize = 0,
  109. .parameters = {0}};
  110. static const app_gsdml_submodule_t submod_digital_out = {
  111. .id = APP_GSDML_SUBMOD_ID_DIGITAL_OUT,
  112. .name = "Digital Output",
  113. .api = APP_GSDML_API,
  114. .data_dir = PNET_DIR_OUTPUT,
  115. .insize = 0,
  116. .outsize = APP_GSDML_OUTPUT_DATA_DIGITAL_SIZE,
  117. .parameters = {0}};
  118. static const app_gsdml_submodule_t submod_digital_inout = {
  119. .id = APP_GSDML_SUBMOD_ID_DIGITAL_IN_OUT,
  120. .name = "Digital Input/Output",
  121. .api = APP_GSDML_API,
  122. .data_dir = PNET_DIR_IO,
  123. .insize = APP_GSDML_INPUT_DATA_DIGITAL_SIZE,
  124. .outsize = APP_GSDML_OUTPUT_DATA_DIGITAL_SIZE,
  125. .parameters = {APP_GSDML_PARAMETER_1_IDX, APP_GSDML_PARAMETER_2_IDX, 0}};
  126. static const app_gsdml_submodule_t submod_echo = {
  127. .id = APP_GSDML_SUBMOD_ID_ECHO,
  128. .name = "Echo submodule",
  129. .api = APP_GSDML_API,
  130. .data_dir = PNET_DIR_IO,
  131. .insize = APP_GSDML_INPUT_DATA_ECHO_SIZE,
  132. .outsize = APP_GSDML_OUTPUT_DATA_ECHO_SIZE,
  133. .parameters = {APP_GSDML_PARAMETER_ECHO_IDX, 0}};
  134. /** List of supported modules */
  135. static const app_gsdml_module_t * app_gsdml_modules[] = {
  136. &dap_1,
  137. &module_digital_in,
  138. &module_digital_out,
  139. &module_digital_in_out,
  140. &module_echo};
  141. /** List of supported submodules */
  142. static const app_gsdml_submodule_t * app_gsdml_submodules[] = {
  143. &dap_indentity_1,
  144. &dap_interface_1,
  145. &dap_port_1,
  146. &dap_port_2,
  147. &dap_port_3,
  148. &dap_port_4,
  149. &submod_digital_in,
  150. &submod_digital_out,
  151. &submod_digital_inout,
  152. &submod_echo,
  153. };
  154. /* List of supported parameters.
  155. * Note that parameters are submodule attributes.
  156. * This list contain all parameters while each
  157. * submodule list its supported parameters using
  158. * their indexes.
  159. */
  160. static app_gsdml_param_t app_gsdml_parameters[] = {
  161. {
  162. .index = APP_GSDML_PARAMETER_1_IDX,
  163. .name = "Demo 1",
  164. .length = APP_GSDML_PARAMETER_LENGTH,
  165. },
  166. {
  167. .index = APP_GSDML_PARAMETER_2_IDX,
  168. .name = "Demo 2",
  169. .length = APP_GSDML_PARAMETER_LENGTH,
  170. },
  171. {
  172. .index = APP_GSDML_PARAMETER_ECHO_IDX,
  173. .name = "Echo gain setting",
  174. .length = APP_GSDML_PARAMETER_LENGTH,
  175. }};
  176. const app_gsdml_module_t * app_gsdml_get_module_cfg (uint32_t id)
  177. {
  178. uint32_t i;
  179. for (i = 0; i < NELEMENTS (app_gsdml_modules); i++)
  180. {
  181. if (app_gsdml_modules[i]->id == id)
  182. {
  183. return app_gsdml_modules[i];
  184. }
  185. }
  186. return NULL;
  187. }
  188. const app_gsdml_submodule_t * app_gsdml_get_submodule_cfg (uint32_t id)
  189. {
  190. uint32_t i;
  191. for (i = 0; i < NELEMENTS (app_gsdml_submodules); i++)
  192. {
  193. if (app_gsdml_submodules[i]->id == id)
  194. {
  195. return app_gsdml_submodules[i];
  196. }
  197. }
  198. return NULL;
  199. }
  200. const app_gsdml_param_t * app_gsdml_get_parameter_cfg (
  201. uint32_t submodule_id,
  202. uint32_t index)
  203. {
  204. uint16_t i;
  205. uint16_t j;
  206. const app_gsdml_submodule_t * submodule_cfg =
  207. app_gsdml_get_submodule_cfg (submodule_id);
  208. if (submodule_cfg == NULL)
  209. {
  210. /* Unsupported submodule id */
  211. return NULL;
  212. }
  213. /* Search for parameter index in submodule configuration */
  214. for (i = 0; submodule_cfg->parameters[i] != 0; i++)
  215. {
  216. if (submodule_cfg->parameters[i] == index)
  217. {
  218. /* Find parameter configuration */
  219. for (j = 0; j < NELEMENTS (app_gsdml_parameters); j++)
  220. {
  221. if (app_gsdml_parameters[j].index == index)
  222. {
  223. return &app_gsdml_parameters[j];
  224. }
  225. }
  226. }
  227. }
  228. return NULL;
  229. }