[54] | 1 | |
---|
| 2 | /* USER CODE BEGIN Header */ |
---|
| 3 | /** |
---|
| 4 | ****************************************************************************** |
---|
| 5 | * @file app_filex.c |
---|
| 6 | * @author MCD Application Team |
---|
| 7 | * @brief FileX applicative file |
---|
| 8 | ****************************************************************************** |
---|
| 9 | * @attention |
---|
| 10 | * |
---|
| 11 | * Copyright (c) 2020-2021 STMicroelectronics. |
---|
| 12 | * All rights reserved. |
---|
| 13 | * |
---|
| 14 | * This software is licensed under terms that can be found in the LICENSE file |
---|
| 15 | * in the root directory of this software component. |
---|
| 16 | * If no LICENSE file comes with this software, it is provided AS-IS. |
---|
| 17 | * |
---|
| 18 | ****************************************************************************** |
---|
| 19 | */ |
---|
| 20 | /* USER CODE END Header */ |
---|
| 21 | |
---|
| 22 | /* Includes ------------------------------------------------------------------*/ |
---|
| 23 | #include "app_filex.h" |
---|
| 24 | |
---|
| 25 | /* Private includes ----------------------------------------------------------*/ |
---|
| 26 | /* USER CODE BEGIN Includes */ |
---|
| 27 | |
---|
[57] | 28 | #include "stdio.h" |
---|
| 29 | #include "main_thread.h" |
---|
| 30 | |
---|
[54] | 31 | /* USER CODE END Includes */ |
---|
| 32 | |
---|
| 33 | /* Private typedef -----------------------------------------------------------*/ |
---|
| 34 | /* USER CODE BEGIN PTD */ |
---|
| 35 | |
---|
| 36 | /* USER CODE END PTD */ |
---|
| 37 | |
---|
| 38 | /* Private define ------------------------------------------------------------*/ |
---|
| 39 | /* Main thread stack size */ |
---|
| 40 | #define FX_APP_THREAD_STACK_SIZE 1024 |
---|
| 41 | /* Main thread priority */ |
---|
| 42 | #define FX_APP_THREAD_PRIO 10 |
---|
| 43 | |
---|
| 44 | /* USER CODE BEGIN PD */ |
---|
| 45 | |
---|
| 46 | /* USER CODE END PD */ |
---|
| 47 | |
---|
| 48 | /* Private macro -------------------------------------------------------------*/ |
---|
| 49 | /* USER CODE BEGIN PM */ |
---|
| 50 | |
---|
| 51 | /* USER CODE END PM */ |
---|
| 52 | |
---|
| 53 | /* Private variables ---------------------------------------------------------*/ |
---|
| 54 | /* Main thread global data structures. */ |
---|
| 55 | TX_THREAD fx_app_thread; |
---|
| 56 | |
---|
| 57 | /* Buffer for FileX FX_MEDIA sector cache. */ |
---|
| 58 | ALIGN_32BYTES (uint32_t fx_sd_media_memory[FX_STM32_SD_DEFAULT_SECTOR_SIZE / sizeof(uint32_t)]); |
---|
| 59 | /* Define FileX global data structures. */ |
---|
| 60 | FX_MEDIA sdio_disk; |
---|
| 61 | |
---|
| 62 | /* USER CODE BEGIN PV */ |
---|
| 63 | |
---|
| 64 | /* USER CODE END PV */ |
---|
| 65 | |
---|
| 66 | /* Private function prototypes -----------------------------------------------*/ |
---|
| 67 | /* Main thread entry function. */ |
---|
| 68 | void fx_app_thread_entry(ULONG thread_input); |
---|
| 69 | |
---|
| 70 | /* USER CODE BEGIN PFP */ |
---|
| 71 | |
---|
| 72 | /* USER CODE END PFP */ |
---|
| 73 | |
---|
| 74 | /** |
---|
| 75 | * @brief Application FileX Initialization. |
---|
| 76 | * @param memory_ptr: memory pointer |
---|
| 77 | * @retval int |
---|
| 78 | */ |
---|
| 79 | UINT MX_FileX_Init(VOID *memory_ptr) |
---|
| 80 | { |
---|
| 81 | UINT ret = FX_SUCCESS; |
---|
| 82 | |
---|
| 83 | TX_BYTE_POOL *byte_pool = (TX_BYTE_POOL*)memory_ptr; |
---|
| 84 | VOID *pointer; |
---|
| 85 | |
---|
| 86 | /* USER CODE BEGIN MX_FileX_MEM_POOL */ |
---|
| 87 | |
---|
| 88 | /* USER CODE END MX_FileX_MEM_POOL */ |
---|
| 89 | |
---|
| 90 | /* USER CODE BEGIN 0 */ |
---|
| 91 | |
---|
| 92 | /* USER CODE END 0 */ |
---|
| 93 | |
---|
| 94 | /*Allocate memory for the main thread's stack*/ |
---|
| 95 | ret = tx_byte_allocate(byte_pool, &pointer, FX_APP_THREAD_STACK_SIZE, TX_NO_WAIT); |
---|
| 96 | |
---|
| 97 | /* Check FX_APP_THREAD_STACK_SIZE allocation*/ |
---|
| 98 | if (ret != FX_SUCCESS) |
---|
| 99 | { |
---|
| 100 | return TX_POOL_ERROR; |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | /* Create the main thread. */ |
---|
| 104 | ret = tx_thread_create(&fx_app_thread, FX_APP_THREAD_NAME, fx_app_thread_entry, 0, pointer, FX_APP_THREAD_STACK_SIZE, |
---|
| 105 | FX_APP_THREAD_PRIO, FX_APP_PREEMPTION_THRESHOLD, FX_APP_THREAD_TIME_SLICE, FX_APP_THREAD_AUTO_START); |
---|
| 106 | |
---|
| 107 | /* Check main thread creation */ |
---|
| 108 | if (ret != TX_SUCCESS) |
---|
| 109 | { |
---|
| 110 | return TX_THREAD_ERROR; |
---|
| 111 | } |
---|
| 112 | /* USER CODE BEGIN MX_FileX_Init */ |
---|
| 113 | |
---|
| 114 | /* USER CODE END MX_FileX_Init */ |
---|
| 115 | |
---|
| 116 | /* Initialize FileX. */ |
---|
| 117 | fx_system_initialize(); |
---|
| 118 | |
---|
| 119 | /* USER CODE BEGIN MX_FileX_Init 1*/ |
---|
| 120 | |
---|
| 121 | /* USER CODE END MX_FileX_Init 1*/ |
---|
| 122 | |
---|
| 123 | return ret; |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | /** |
---|
| 127 | * @brief Main thread entry. |
---|
| 128 | * @param thread_input: ULONG user argument used by the thread entry |
---|
| 129 | * @retval none |
---|
| 130 | */ |
---|
| 131 | void fx_app_thread_entry(ULONG thread_input) |
---|
| 132 | { |
---|
| 133 | UINT sd_status = FX_SUCCESS; |
---|
| 134 | /* USER CODE BEGIN fx_app_thread_entry 0 */ |
---|
| 135 | |
---|
| 136 | /* USER CODE END fx_app_thread_entry 0 */ |
---|
| 137 | |
---|
| 138 | /* Open the SD disk driver */ |
---|
| 139 | sd_status = fx_media_open(&sdio_disk, FX_SD_VOLUME_NAME, fx_stm32_sd_driver, (VOID *)FX_NULL, (VOID *) fx_sd_media_memory, sizeof(fx_sd_media_memory)); |
---|
| 140 | |
---|
| 141 | /* Check the media open sd_status */ |
---|
| 142 | if (sd_status != FX_SUCCESS) |
---|
| 143 | { |
---|
| 144 | /* USER CODE BEGIN SD open error */ |
---|
[60] | 145 | printf("Cannot mount SD card!\n"); |
---|
| 146 | //while(1); |
---|
[54] | 147 | /* USER CODE END SD open error */ |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | /* USER CODE BEGIN fx_app_thread_entry 1 */ |
---|
| 151 | |
---|
[57] | 152 | startMainThread(&sdio_disk); |
---|
| 153 | |
---|
[54] | 154 | /* USER CODE END fx_app_thread_entry 1 */ |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | /* USER CODE BEGIN 1 */ |
---|
| 158 | |
---|
| 159 | /* USER CODE END 1 */ |
---|