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