1 /***************************************************************************
2  * Copyright (c) 2024 Microsoft Corporation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the MIT License which is available at
6  * https://opensource.org/licenses/MIT.
7  *
8  * SPDX-License-Identifier: MIT
9  **************************************************************************/
10 
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /** FileX Component                                                       */
16 /**                                                                       */
17 /**   Port Specific                                                       */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 
23 /**************************************************************************/
24 /*                                                                        */
25 /*  PORT SPECIFIC C INFORMATION                            RELEASE        */
26 /*                                                                        */
27 /*    fx_port.h                                            Generic        */
28 /*                                                           6.3.0        */
29 /*                                                                        */
30 /*  AUTHOR                                                                */
31 /*                                                                        */
32 /*    William E. Lamie, Microsoft Corporation                             */
33 /*                                                                        */
34 /*  DESCRIPTION                                                           */
35 /*                                                                        */
36 /*    This file contains data type definitions that make the FileX FAT    */
37 /*    compatible file system function identically on a variety of         */
38 /*    different processor architectures.  For example, the byte offset of */
39 /*    various entries in the boot record, and directory entries are       */
40 /*    defined in this file.                                               */
41 /*                                                                        */
42 /*  RELEASE HISTORY                                                       */
43 /*                                                                        */
44 /*    DATE              NAME                      DESCRIPTION             */
45 /*                                                                        */
46 /*  11-09-2020     William E. Lamie         Initial Version 6.1.2         */
47 /*  03-02-2021     William E. Lamie         Modified comment(s), and      */
48 /*                                            added standalone support,   */
49 /*                                            resulting in version 6.1.5  */
50 /*  10-31-2023     Xiuwen Cai               Modified comment(s),          */
51 /*                                            added basic types guards,   */
52 /*                                            resulting in version 6.3.0  */
53 /*                                                                        */
54 /**************************************************************************/
55 
56 #ifndef FX_PORT_H
57 #define FX_PORT_H
58 
59 
60 /* Determine if the optional FileX user define file should be used.  */
61 
62 #ifdef FX_INCLUDE_USER_DEFINE_FILE
63 
64 
65 /* Yes, include the user defines in fx_user.h. The defines in this file may
66    alternately be defined on the command line.  */
67 
68 #include "fx_user.h"
69 #endif
70 
71 
72 /* Include the ThreadX api file.  */
73 
74 #ifndef FX_STANDALONE_ENABLE
75 #include "tx_api.h"
76 
77 
78 /* Define ULONG64 typedef, if not already defined.  */
79 
80 #ifndef ULONG64_DEFINED
81 #define ULONG64_DEFINED
82 typedef unsigned long long  ULONG64;
83 #endif
84 
85 #else
86 
87 /* Define compiler library include files.  */
88 
89 #include <stdint.h>
90 #include <stdlib.h>
91 
92 #ifndef VOID
93 #define VOID                                    void
94 typedef char                                    CHAR;
95 typedef char                                    BOOL;
96 typedef unsigned char                           UCHAR;
97 typedef int                                     INT;
98 typedef unsigned int                            UINT;
99 typedef long                                    LONG;
100 typedef unsigned long                           ULONG;
101 typedef short                                   SHORT;
102 typedef unsigned short                          USHORT;
103 #endif
104 
105 #ifndef ULONG64_DEFINED
106 #define ULONG64_DEFINED
107 typedef unsigned long long                      ULONG64;
108 #endif
109 
110 /* Define basic alignment type used in block and byte pool operations. This data type must
111    be at least 32-bits in size and also be large enough to hold a pointer type.  */
112 
113 #ifndef ALIGN_TYPE_DEFINED
114 #define ALIGN_TYPE_DEFINED
115 #define ALIGN_TYPE                              ULONG
116 #endif
117 
118 #endif
119 
120 /* Define FileX internal protection macros.  If FX_SINGLE_THREAD is defined,
121    these protection macros are effectively disabled.  However, for multi-thread
122    uses, the macros are setup to utilize a ThreadX mutex for multiple thread
123    access control into an open media.  */
124 
125 #if defined(FX_SINGLE_THREAD) || defined(FX_STANDALONE_ENABLE)
126 #define FX_PROTECT
127 #define FX_UNPROTECT
128 #else
129 #define FX_PROTECT                      if (media_ptr -> fx_media_id != FX_MEDIA_ID) return(FX_MEDIA_NOT_OPEN); \
130                                         else if (tx_mutex_get(&(media_ptr -> fx_media_protect), TX_WAIT_FOREVER) != TX_SUCCESS) return(FX_MEDIA_NOT_OPEN);
131 #define FX_UNPROTECT                    tx_mutex_put(&(media_ptr -> fx_media_protect));
132 #endif
133 
134 
135 /* Define interrupt lockout constructs to protect the system date/time from being updated
136    while they are being read.  */
137 #ifndef FX_STANDALONE_ENABLE
138 #ifndef FX_INT_SAVE_AREA
139 #define FX_INT_SAVE_AREA                unsigned int  old_interrupt_posture;
140 #endif
141 
142 #ifndef FX_DISABLE_INTS
143 #define FX_DISABLE_INTS                 old_interrupt_posture =  tx_interrupt_control(TX_INT_DISABLE);
144 #endif
145 
146 #ifndef FX_RESTORE_INTS
147 #define FX_RESTORE_INTS                 tx_interrupt_control(old_interrupt_posture);
148 #endif
149 #else
150 /* Disable use of ThreadX protection in standalone mode for FileX */
151 #ifndef FX_LEGACY_INTERRUPT_PROTECTION
152 #define FX_LEGACY_INTERRUPT_PROTECTION
153 #endif
154 #define FX_INT_SAVE_AREA
155 #define FX_DISABLE_INTS
156 #define FX_RESTORE_INTS
157 #endif
158 
159 /* Define the error checking logic to determine if there is a caller error in the FileX API.
160    The default definitions assume ThreadX is being used.  This code can be completely turned
161    off by just defining these macros to white space.  */
162 
163 #ifndef FX_STANDALONE_ENABLE
164 #ifndef TX_TIMER_PROCESS_IN_ISR
165 
166 #define FX_CALLER_CHECKING_EXTERNS      extern  TX_THREAD      *_tx_thread_current_ptr; \
167                                         extern  TX_THREAD       _tx_timer_thread; \
168                                         extern  volatile ULONG  _tx_thread_system_state;
169 
170 #define FX_CALLER_CHECKING_CODE         if ((TX_THREAD_GET_SYSTEM_STATE()) || \
171                                             (_tx_thread_current_ptr == TX_NULL) || \
172                                             (_tx_thread_current_ptr == &_tx_timer_thread)) \
173                                             return(FX_CALLER_ERROR);
174 
175 #else
176 #define FX_CALLER_CHECKING_EXTERNS      extern  TX_THREAD      *_tx_thread_current_ptr; \
177                                         extern  volatile ULONG  _tx_thread_system_state;
178 
179 #define FX_CALLER_CHECKING_CODE         if ((TX_THREAD_GET_SYSTEM_STATE()) || \
180                                             (_tx_thread_current_ptr == TX_NULL)) \
181                                             return(FX_CALLER_ERROR);
182 #endif
183 #else
184 #define FX_CALLER_CHECKING_EXTERNS
185 #define FX_CALLER_CHECKING_CODE
186 #endif
187 
188 
189 /* Define the update rate of the system timer.  These values may also be defined at the command
190    line when compiling the fx_system_initialize.c module in the FileX library build.  Alternatively, they can
191    be modified in this file or fx_user.h. Note: the update rate must be an even number of seconds greater
192    than or equal to 2, which is the minimal update rate for FAT time. */
193 
194 /* Define the number of seconds the timer parameters are updated in FileX.  The default
195    value is 10 seconds.  This value can be overwritten externally. */
196 
197 #ifndef FX_UPDATE_RATE_IN_SECONDS
198 #define FX_UPDATE_RATE_IN_SECONDS 10
199 #endif
200 
201 
202 /* Defines the number of ThreadX timer ticks required to achieve the update rate specified by
203    FX_UPDATE_RATE_IN_SECONDS defined previously. By default, the ThreadX timer tick is 10ms,
204    so the default value for this constant is 1000.  If TX_TIMER_TICKS_PER_SECOND is defined,
205    this value is derived from TX_TIMER_TICKS_PER_SECOND.  */
206 
207 #ifndef FX_UPDATE_RATE_IN_TICKS
208 #if (defined(TX_TIMER_TICKS_PER_SECOND) && (!defined(FX_STANDALONE_ENABLE)))
209 #define FX_UPDATE_RATE_IN_TICKS         (TX_TIMER_TICKS_PER_SECOND * FX_UPDATE_RATE_IN_SECONDS)
210 #else
211 #define FX_UPDATE_RATE_IN_TICKS         1000
212 #endif
213 #endif
214 
215 
216 /* Define the version ID of FileX.  This may be utilized by the application.  */
217 
218 #ifdef FX_SYSTEM_INIT
219 CHAR                            _fx_version_id[] =
220                                     "Copyright (c) 2024 Microsoft Corporation.  *  FileX Generic Version 6.4.1 *";
221 #else
222 extern  CHAR                    _fx_version_id[];
223 #endif
224 
225 #endif
226 
227