PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/mqx/ctaocrypt_test/Sources/main.c

https://github.com/andersmalm/cyassl
C | 103 lines | 71 code | 19 blank | 13 comment | 4 complexity | e8b45a2400ae17d2690724b5070f45ac MD5 | raw file
Possible License(s): GPL-2.0
  1. /* main.c */
  2. #include "main.h"
  3. /* SD card open/close utility functions */
  4. #include "util.h"
  5. #if !BSPCFG_ENABLE_IO_SUBSYSTEM
  6. #error This application requires BSPCFG_ENABLE_IO_SUBSYSTEM defined \
  7. non-zero in user_config.h. Please recompile BSP with this option.
  8. #endif
  9. #ifndef BSP_DEFAULT_IO_CHANNEL_DEFINED
  10. #error This application requires BSP_DEFAULT_IO_CHANNEL to be not NULL. \
  11. Please set corresponding BSPCFG_ENABLE_TTYx to non-zero in \
  12. user_config.h and recompile BSP with this option.
  13. #endif
  14. TASK_TEMPLATE_STRUCT MQX_template_list[] =
  15. {
  16. /* Task number, Entry point, Stack, Pri, String, Auto? */
  17. {MAIN_TASK, Main_task, 20000, 9, "main", MQX_AUTO_START_TASK},
  18. {0, 0, 0, 0, 0, 0, }
  19. };
  20. /*TASK*-----------------------------------------------------
  21. *
  22. * Task Name : Main_task
  23. * Comments :
  24. * This task opens the SD card device and runs the
  25. * CTaoCrypt test functions located in test.c.
  26. *
  27. *END*-----------------------------------------------------*/
  28. #if defined BSP_SDCARD_ESDHC_CHANNEL
  29. #if ! BSPCFG_ENABLE_ESDHC
  30. #error This application requires BSPCFG_ENABLE_ESDHC defined \
  31. non-zero in user_config.h. Please recompile libraries with \
  32. this option.
  33. #endif
  34. #elif defined BSP_SDCARD_SDHC_CHANNEL
  35. #if ! BSPCFG_ENABLE_SDHC
  36. #error This application requires BSPCFG_ENABLE_SDHC defined \
  37. non-zero in user_config.h. Please recompile libraries with \
  38. this option.
  39. #endif
  40. #endif
  41. #if defined (BSP_SDCARD_SPI_CHANNEL)
  42. #define SDCARD_COM_CHANNEL BSP_SDCARD_SPI_CHANNEL
  43. #elif defined (BSP_SDCARD_ESDHC_CHANNEL)
  44. #define SDCARD_COM_CHANNEL BSP_SDCARD_ESDHC_CHANNEL
  45. #elif defined (BSP_SDCARD_SDHC_CHANNEL)
  46. #define SDCARD_COM_CHANNEL BSP_SDCARD_SDHC_CHANNEL
  47. #else
  48. #error "SDCARD low level communication device not defined!"
  49. #endif
  50. /* func_args from test.h */
  51. typedef struct func_args {
  52. int argc;
  53. char** argv;
  54. int return_code;
  55. } func_args;
  56. void Main_task(uint_32 initial_data)
  57. {
  58. int ret = 0;
  59. func_args args;
  60. _mqx_int error_code, bytes;
  61. _mqx_uint sz;
  62. char filesystem_name[] = "a:";
  63. char partman_name[] = "pm:";
  64. MQX_FILE_PTR com_handle, sdcard_handle, filesystem_handle, partman_handle;
  65. MQX_FILE_PTR cert_file = NULL;
  66. const char* fileName = "a:\certs\\client-key.der";
  67. ret = sdcard_open(&com_handle, &sdcard_handle, &partman_handle,
  68. &filesystem_handle, partman_name, filesystem_name);
  69. if (ret != 0) {
  70. printf("error: sdcard_open(), ret = %d\n", ret);
  71. _mqx_exit(1);
  72. }
  73. printf("SD card installed to %s\n", filesystem_name);
  74. ctaocrypt_test(&args);
  75. ret = sdcard_close(&sdcard_handle, &partman_handle,
  76. &filesystem_handle, partman_name, filesystem_name);
  77. if (ret != 0) {
  78. printf("error: sdcard_close(), ret = %d\n", ret);
  79. _mqx_exit(1);
  80. }
  81. printf("SD card uninstalled.\n");
  82. _mqx_exit(0);
  83. }
  84. /* EOF */