main.c 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. #if defined BSP_SDCARD_ESDHC_CHANNEL
  21. #if ! BSPCFG_ENABLE_ESDHC
  22. #error This application requires BSPCFG_ENABLE_ESDHC defined \
  23. non-zero in user_config.h. Please recompile libraries with \
  24. this option.
  25. #endif
  26. #elif defined BSP_SDCARD_SDHC_CHANNEL
  27. #if ! BSPCFG_ENABLE_SDHC
  28. #error This application requires BSPCFG_ENABLE_SDHC defined \
  29. non-zero in user_config.h. Please recompile libraries with \
  30. this option.
  31. #endif
  32. #endif
  33. #if defined (BSP_SDCARD_SPI_CHANNEL)
  34. #define SDCARD_COM_CHANNEL BSP_SDCARD_SPI_CHANNEL
  35. #elif defined (BSP_SDCARD_ESDHC_CHANNEL)
  36. #define SDCARD_COM_CHANNEL BSP_SDCARD_ESDHC_CHANNEL
  37. #elif defined (BSP_SDCARD_SDHC_CHANNEL)
  38. #define SDCARD_COM_CHANNEL BSP_SDCARD_SDHC_CHANNEL
  39. #else
  40. #error "SDCARD low level communication device not defined!"
  41. #endif
  42. /* func_args from test.h */
  43. typedef struct func_args {
  44. int argc;
  45. char** argv;
  46. int return_code;
  47. } func_args;
  48. /*TASK*-----------------------------------------------------------------
  49. * Function Name : Main_task
  50. * Comments :
  51. * This task opens the SD card device and runs the
  52. * wolfCrypt test functions located in test.c.
  53. *END------------------------------------------------------------------*/
  54. void Main_task(uint32_t initial_data)
  55. {
  56. int ret = 0;
  57. func_args args;
  58. char filesystem_name[] = "a:";
  59. char partman_name[] = "pm:";
  60. MQX_FILE_PTR com_handle, sdcard_handle, filesystem_handle, partman_handle;
  61. ret = sdcard_open(&com_handle, &sdcard_handle, &partman_handle,
  62. &filesystem_handle, partman_name, filesystem_name);
  63. if (ret != 0) {
  64. printf("error: sdcard_open(), ret = %d\n", ret);
  65. _mqx_exit(1);
  66. }
  67. printf("SD card installed to %s\n", filesystem_name);
  68. wolfcrypt_test(&args);
  69. ret = sdcard_close(&sdcard_handle, &partman_handle,
  70. &filesystem_handle, partman_name, filesystem_name);
  71. if (ret != 0) {
  72. printf("error: sdcard_close(), ret = %d\n", ret);
  73. _mqx_exit(1);
  74. }
  75. printf("SD card uninstalled.\n");
  76. _mqx_exit(0);
  77. }