1 /* main.c */
2 
3 #include "main.h"
4 
5 /* SD card open/close utility functions */
6 #include "util.h"
7 
8 #if !BSPCFG_ENABLE_IO_SUBSYSTEM
9 #error This application requires BSPCFG_ENABLE_IO_SUBSYSTEM defined \
10     non-zero in user_config.h. Please recompile BSP with this option.
11 #endif
12 
13 #ifndef BSP_DEFAULT_IO_CHANNEL_DEFINED
14 #error This application requires BSP_DEFAULT_IO_CHANNEL to be not NULL. \
15     Please set corresponding BSPCFG_ENABLE_TTYx to non-zero in \
16     user_config.h and recompile BSP with this option.
17 #endif
18 
19 TASK_TEMPLATE_STRUCT MQX_template_list[] =
20 {
21     /*  Task number, Entry point, Stack, Pri, String, Auto? */
22     {MAIN_TASK,   Main_task,   30000,  9,   "main", MQX_AUTO_START_TASK},
23     {0,           0,           0,     0,   0,      0,                 }
24 };
25 
26 #if defined BSP_SDCARD_ESDHC_CHANNEL
27     #if ! BSPCFG_ENABLE_ESDHC
28         #error This application requires BSPCFG_ENABLE_ESDHC defined \
29             non-zero in user_config.h. Please recompile libraries with \
30             this option.
31     #endif
32 
33 #elif defined BSP_SDCARD_SDHC_CHANNEL
34     #if ! BSPCFG_ENABLE_SDHC
35         #error This application requires BSPCFG_ENABLE_SDHC defined \
36             non-zero in user_config.h. Please recompile libraries with \
37             this option.
38     #endif
39 #endif
40 
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 
51 /* func_args from test.h */
52 typedef struct func_args {
53     int    argc;
54     char** argv;
55     int    return_code;
56 } func_args;
57 
58 /*TASK*-----------------------------------------------------------------
59  * Function Name  : Main_task
60  * Comments       :
61  *    This task opens the SD card device and runs the
62  *    wolfCrypt benchmark functions located in benchmark.c.
63  *END------------------------------------------------------------------*/
64 
Main_task(uint32_t initial_data)65 void Main_task(uint32_t initial_data)
66 {
67     int          ret = 0;
68     func_args    args;
69     char         filesystem_name[] = "a:";
70     char         partman_name[]    = "pm:";
71     MQX_FILE_PTR com_handle, sdcard_handle, filesystem_handle, partman_handle;
72 
73     ret = sdcard_open(&com_handle, &sdcard_handle, &partman_handle,
74                       &filesystem_handle, partman_name, filesystem_name);
75     if (ret != 0) {
76         printf("error: sdcard_open(), ret = %d\n", ret);
77         _mqx_exit(1);
78     }
79     printf("SD card installed to %s\n", filesystem_name);
80 
81     benchmark_test(&args);
82 
83     ret = sdcard_close(&sdcard_handle, &partman_handle,
84                        &filesystem_handle, partman_name, filesystem_name);
85     if (ret != 0) {
86         printf("error: sdcard_close(), ret = %d\n", ret);
87         _mqx_exit(1);
88     }
89     printf("SD card uninstalled.\n");
90 
91     _mqx_exit(0);
92 
93 }
94 
95