ctrl_access.h
Go to the documentation of this file.
1 /*****************************************************************************
2  *
3  * \file
4  *
5  * \brief Abstraction layer for memory interfaces.
6  *
7  * This module contains the interfaces:
8  * - MEM <-> USB;
9  * - MEM <-> RAM;
10  * - MEM <-> MEM.
11  *
12  * This module may be configured and expanded to support the following features:
13  * - write-protected globals;
14  * - password-protected data;
15  * - specific features;
16  * - etc.
17  *
18  * Copyright (c) 2009-2018 Microchip Technology Inc. and its subsidiaries.
19  *
20  * \asf_license_start
21  *
22  * \page License
23  *
24  * Subject to your compliance with these terms, you may use Microchip
25  * software and any derivatives exclusively with Microchip products.
26  * It is your responsibility to comply with third party license terms applicable
27  * to your use of third party software (including open source software) that
28  * may accompany Microchip software.
29  *
30  * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
31  * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
32  * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
33  * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
34  * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
35  * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
36  * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
37  * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
38  * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
39  * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
40  * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
41  *
42  * \asf_license_stop
43  *
44  ******************************************************************************/
45 /*
46  * Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
47  */
48 
49 
50 #ifndef _CTRL_ACCESS_H_
51 #define _CTRL_ACCESS_H_
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
66 #include "compiler.h"
67 #include "conf_access.h"
68 
69 #ifndef SECTOR_SIZE
70 #define SECTOR_SIZE 512
71 #endif
72 
74 typedef enum
75 {
79  CTRL_BUSY = FAIL + 2
80 } Ctrl_status;
81 
82 
83 // FYI: Each Logical Unit Number (LUN) corresponds to a memory.
84 
85 // Check LUN defines.
86 #ifndef LUN_0
87  #error LUN_0 must be defined as ENABLE or DISABLE in conf_access.h
88 #endif
89 #ifndef LUN_1
90  #error LUN_1 must be defined as ENABLE or DISABLE in conf_access.h
91 #endif
92 #ifndef LUN_2
93  #error LUN_2 must be defined as ENABLE or DISABLE in conf_access.h
94 #endif
95 #ifndef LUN_3
96  #error LUN_3 must be defined as ENABLE or DISABLE in conf_access.h
97 #endif
98 #ifndef LUN_4
99  #error LUN_4 must be defined as ENABLE or DISABLE in conf_access.h
100 #endif
101 #ifndef LUN_5
102  #error LUN_5 must be defined as ENABLE or DISABLE in conf_access.h
103 #endif
104 #ifndef LUN_6
105  #error LUN_6 must be defined as ENABLE or DISABLE in conf_access.h
106 #endif
107 #ifndef LUN_7
108  #error LUN_7 must be defined as ENABLE or DISABLE in conf_access.h
109 #endif
110 #ifndef LUN_USB
111  #error LUN_USB must be defined as ENABLE or DISABLE in conf_access.h
112 #endif
113 
116 #define LUN_ID_0 (0)
118 #define LUN_ID_1 (LUN_ID_0 + LUN_0)
119 #define LUN_ID_2 (LUN_ID_1 + LUN_1)
120 #define LUN_ID_3 (LUN_ID_2 + LUN_2)
121 #define LUN_ID_4 (LUN_ID_3 + LUN_3)
122 #define LUN_ID_5 (LUN_ID_4 + LUN_4)
123 #define LUN_ID_6 (LUN_ID_5 + LUN_5)
124 #define LUN_ID_7 (LUN_ID_6 + LUN_6)
125 #define MAX_LUN (LUN_ID_7 + LUN_7)
126 #define LUN_ID_USB (MAX_LUN)
127 
129 
130 // Include LUN header files.
131 #if LUN_0 == ENABLE
132  #include LUN_0_INCLUDE
133 #endif
134 #if LUN_1 == ENABLE
135  #include LUN_1_INCLUDE
136 #endif
137 #if LUN_2 == ENABLE
138  #include LUN_2_INCLUDE
139 #endif
140 #if LUN_3 == ENABLE
141  #include LUN_3_INCLUDE
142 #endif
143 #if LUN_4 == ENABLE
144  #include LUN_4_INCLUDE
145 #endif
146 #if LUN_5 == ENABLE
147  #include LUN_5_INCLUDE
148 #endif
149 #if LUN_6 == ENABLE
150  #include LUN_6_INCLUDE
151 #endif
152 #if LUN_7 == ENABLE
153  #include LUN_7_INCLUDE
154 #endif
155 #if LUN_USB == ENABLE
156  #include LUN_USB_INCLUDE
157 #endif
158 
159 
160 // Check the configuration of write protection in conf_access.h.
161 #ifndef GLOBAL_WR_PROTECT
162  #error GLOBAL_WR_PROTECT must be defined as true or false in conf_access.h
163 #endif
164 
165 
166 #if GLOBAL_WR_PROTECT == true
167 
169 extern bool g_wr_protect;
170 
171 #endif
172 
173 
176 
178 #ifdef FREERTOS_USED
179 
184 extern bool ctrl_access_init(void);
185 
186 #endif // FREERTOS_USED
187 
192 extern U8 get_nb_lun(void);
193 
200 extern U8 get_cur_lun(void);
201 
214 extern Ctrl_status mem_test_unit_ready(U8 lun);
215 
224 extern Ctrl_status mem_read_capacity(U8 lun, U32 *u32_nb_sector);
225 
232 extern U8 mem_sector_size(U8 lun);
233 
241 extern bool mem_unload(U8 lun, bool unload);
242 
252 extern bool mem_wr_protect(U8 lun);
253 
260 extern bool mem_removal(U8 lun);
261 
268 extern const char *mem_name(U8 lun);
269 
271 
272 
273 #if ACCESS_USB == true
274 
277 
287 extern Ctrl_status memory_2_usb(U8 lun, U32 addr, U16 nb_sector);
288 
297 extern Ctrl_status usb_2_memory(U8 lun, U32 addr, U16 nb_sector);
298 
300 
301 #endif // ACCESS_USB == true
302 
303 
304 #if ACCESS_MEM_TO_RAM == true
305 
308 
318 extern Ctrl_status memory_2_ram(U8 lun, U32 addr, void *ram);
319 
328 extern Ctrl_status ram_2_memory(U8 lun, U32 addr, const void *ram);
329 
331 
332 #endif // ACCESS_MEM_TO_RAM == true
333 
334 
335 #if ACCESS_STREAM == true
336 
339 
342 #define ID_STREAM_ERR 0xFF
343 
344  #if ACCESS_MEM_TO_MEM == true
345 
356 extern Ctrl_status stream_mem_to_mem(U8 src_lun, U32 src_addr, U8 dest_lun, U32 dest_addr, U16 nb_sector);
357 
358  #endif // ACCESS_MEM_TO_MEM == true
359 
368 extern Ctrl_status stream_state(U8 id);
369 
378 extern U16 stream_stop(U8 id);
379 
381 
382 #endif // ACCESS_STREAM == true
383 
388 #ifdef __cplusplus
389 }
390 #endif
391 
392 #endif // _CTRL_ACCESS_H_
U8 get_cur_lun(void)
Returns the current LUN.
Definition: ctrl_access.c:302
#define FAIL
Definition: compiler.h:429
Memory not initialized or changed.
Definition: ctrl_access.h:79
Ctrl_status ram_2_memory(U8 lun, U32 addr, const void *ram)
Copies 1 data sector from RAM to the memory.
Definition: ctrl_access.c:557
Ctrl_status mem_test_unit_ready(U8 lun)
Tests the memory state and initializes the memory if required.
Definition: ctrl_access.c:308
Ctrl_status usb_2_memory(U8 lun, U32 addr, U16 nb_sector)
Transfers data from USB to the memory.
Definition: ctrl_access.c:498
An error occurred.
Definition: ctrl_access.h:77
U8 mem_sector_size(U8 lun)
Returns the size of the physical sector.
Definition: ctrl_access.c:352
U8 get_nb_lun(void)
Returns the number of LUNs.
Definition: ctrl_access.c:281
Commonly used includes, types and macros.
Ctrl_status memory_2_ram(U8 lun, U32 addr, void *ram)
Copies 1 data sector from the memory to RAM.
Definition: ctrl_access.c:530
Ctrl_status memory_2_usb(U8 lun, U32 addr, U16 nb_sector)
Transfers data from the memory to USB.
Definition: ctrl_access.c:478
#define PASS
Definition: compiler.h:428
Ctrl_status
Status returned by CTRL_ACCESS interfaces.
Definition: ctrl_access.h:74
Success, memory ready.
Definition: ctrl_access.h:76
unsigned short U16
bool mem_wr_protect(U8 lun)
Returns the write-protection state of the memory.
Definition: ctrl_access.c:404
Memory unplugged.
Definition: ctrl_access.h:78
bool mem_unload(U8 lun, bool unload)
Unload/load the medium.
Definition: ctrl_access.c:374
uint8_t U8
8-bit unsigned integer.
Definition: compiler.h:247
bool g_wr_protect
Write protect.
Definition: ctrl_access.c:236
Ctrl_status stream_state(U8 id)
Returns the state of a streaming data transfer.
Definition: ctrl_access.c:618
bool mem_removal(U8 lun)
Tells whether the memory is removable.
Definition: ctrl_access.c:426
unsigned int U32
Ctrl_status stream_mem_to_mem(U8 src_lun, U32 src_addr, U8 dest_lun, U32 dest_addr, U16 nb_sector)
Copies data from one memory to another.
Definition: ctrl_access.c:600
const char * mem_name(U8 lun)
Returns a pointer to the LUN name.
Definition: ctrl_access.c:451
U16 stream_stop(U8 id)
Stops a streaming data transfer.
Definition: ctrl_access.c:625
Ctrl_status mem_read_capacity(U8 lun, U32 *u32_nb_sector)
Returns the address of the last valid sector (512 bytes) in the memory.
Definition: ctrl_access.c:330


inertial_sense_ros
Author(s):
autogenerated on Sun Feb 28 2021 03:17:57