Contiki 2.5
ctrl_access.c
Go to the documentation of this file.
1 /* This file has been prepared for Doxygen automatic documentation generation.*/
2 /*! \file ctrl_access.c *********************************************************************
3  *
4  * \brief
5  * This file contains the interface :
6  * - between USB <-> MEMORY
7  * OR
8  * - between USB <- Access Memory Ctrl -> Memory
9  *
10  * This interface may be controled by a "Access Memory Control" for :
11  * - include a management of write protect global or specific
12  * - include a management of access password
13  *
14  * \addtogroup usbstick
15  *
16  * \author
17  * Atmel Corporation: http://www.atmel.com \n
18  * Support email: avr@atmel.com
19  ******************************************************************************/
20 /*
21  Copyright (c) 2004 ATMEL Corporation
22  All rights reserved.
23 
24  Redistribution and use in source and binary forms, with or without
25  modification, are permitted provided that the following conditions are met:
26 
27  * Redistributions of source code must retain the above copyright
28  notice, this list of conditions and the following disclaimer.
29  * Redistributions in binary form must reproduce the above copyright
30  notice, this list of conditions and the following disclaimer in
31  the documentation and/or other materials provided with the
32  distribution.
33  * Neither the name of the copyright holders nor the names of
34  contributors may be used to endorse or promote products derived
35  from this software without specific prior written permission.
36 
37  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
38  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
40  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
41  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
42  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
43  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
44  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
45  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
47  POSSIBILITY OF SUCH DAMAGE.
48 */
49 
50 /**
51  \addtogroup usbstorage
52  @{
53 */
54 
55 
56 //_____ I N C L U D E S ____________________________________________________
57 
58 #include "config.h"
59 #include "storage/ctrl_access.h"
60 #include "avr_flash.h"
61 
62 
63 //_____ D E F I N I T I O N S ______________________________________________
64 
65 #if (ACCESS_MEM_TO_MEM == ENABLED)
66  #include "modules/file_system/fat.h"
67  U8 buf_sector[FS_SIZE_OF_SECTOR];
68 #endif
69 
70 
71 //! Computed the maximum of static lun (don't add the lun of Mass Storage in mode USB Host)
72 // FYC: Memory = Logical Unit
73 
74 
75 
76  // CHECK FOR LUN DEFINE
77 #ifndef LUN_0
78  # error LUN_0 must be defined with ENABLE or DISABLE in conf_access.h
79 #endif
80 #ifndef LUN_1
81  # error LUN_1 must be defined with ENABLE or DISABLE in conf_access.h
82 #endif
83 #ifndef LUN_2
84  # error LUN_2 must be defined with ENABLE or DISABLE in conf_access.h
85 #endif
86 #ifndef LUN_3
87  # error LUN_3 must be defined with ENABLE or DISABLE in conf_access.h
88 #endif
89 #ifndef LUN_4
90  # error LUN_4 must be defined with ENABLE or DISABLE in conf_access.h
91 #endif
92 #ifndef LUN_5
93  # error LUN_5 must be defined with ENABLE or DISABLE in conf_access.h
94 #endif
95 #ifndef LUN_6
96  # error LUN_6 must be defined with ENABLE or DISABLE in conf_access.h
97 #endif
98 #ifndef LUN_7
99  # error LUN_7 must be defined with ENABLE or DISABLE in conf_access.h
100 #endif
101 #ifndef LUN_USB
102  # error LUN_USB must be defined with ENABLE or DISABLE in conf_access.h
103 #endif
104 
105 
106 
107 #if (LUN_0 == ENABLE)
108  #define LUN_0_EN 1
109  U8 FLASH lun0_name[]=LUN_0_NAME;
110  #else
111  #define LUN_0_EN 0
112 #endif
113 #if (LUN_1 == ENABLE)
114  #define LUN_1_EN 1
115  U8 FLASH lun1_name[]=LUN_1_NAME;
116  #else
117  #define LUN_1_EN 0
118 #endif
119 #if (LUN_2 == ENABLE)
120  #define LUN_2_EN 1
121  U8 FLASH lun2_name[]=LUN_2_NAME;
122  #else
123  #define LUN_2_EN 0
124 #endif
125 #if (LUN_3 == ENABLE)
126  #define LUN_3_EN 1
127  U8 FLASH lun3_name[]=LUN_3_NAME;
128  #else
129  #define LUN_3_EN 0
130 #endif
131 #if (LUN_4 == ENABLE)
132  #define LUN_4_EN 1
133  U8 FLASH lun4_name[]=LUN_4_NAME;
134  #else
135  #define LUN_4_EN 0
136 #endif
137 #if (LUN_5 == ENABLE)
138  #define LUN_5_EN 1
139  U8 FLASH lun5_name[]=LUN_5_NAME;
140  #else
141  #define LUN_5_EN 0
142 #endif
143 #if (LUN_6 == ENABLE)
144  #define LUN_6_EN 1
145  U8 FLASH lun6_name[]=LUN_6_NAME;
146  #else
147  #define LUN_6_EN 0
148 #endif
149 #if (LUN_7 == ENABLE)
150  #define LUN_7_EN 1
151  U8 FLASH lun7_name[]=LUN_7_NAME;
152  #else
153  #define LUN_7_EN 0
154 #endif
155 #if (LUN_USB == ENABLE)
156  #define LUN_USB_EN 1
157  U8 FLASH lunusb_name[]=LUN_USB_NAME;
158  #else
159  #define LUN_USB_EN 0
160 #endif
161 
162 
163 #define LUN_ID_0 (0)
164 #define LUN_ID_1 (LUN_0_EN)
165 #define LUN_ID_2 (LUN_0_EN+LUN_1_EN)
166 #define LUN_ID_3 (LUN_0_EN+LUN_1_EN+LUN_2_EN)
167 #define LUN_ID_4 (LUN_0_EN+LUN_1_EN+LUN_2_EN+LUN_3_EN)
168 #define LUN_ID_5 (LUN_0_EN+LUN_1_EN+LUN_2_EN+LUN_3_EN+LUN_4_EN)
169 #define LUN_ID_6 (LUN_0_EN+LUN_1_EN+LUN_2_EN+LUN_3_EN+LUN_4_EN+LUN_5_EN)
170 #define LUN_ID_7 (LUN_0_EN+LUN_1_EN+LUN_2_EN+LUN_3_EN+LUN_4_EN+LUN_5_EN+LUN_6_EN)
171 #define MAX_LUN (LUN_0_EN+LUN_1_EN+LUN_2_EN+LUN_3_EN+LUN_4_EN+LUN_5_EN+LUN_6_EN+LUN_7_EN)
172 #define LUN_ID_USB (MAX_LUN)
173 
174 // Check configuration
175 #if (MAX_LUN == 0)
176  #error No memory is active in conf_access.h
177 #endif
178 
179 // Write protect variable
180 #if (GLOBAL_WR_PROTECT == ENABLED)
181  static U8 g_u8_wr_protect;
182 #endif
183 
184 
185 //_____ D E F I N I T I O N S __ F O N C T I O N S _________________________
186 
187 
188 //! This fonction return the number of logical unit
189 //!
190 //! @return U8 number of logical unit in the system
191 //!
193 {
194 #if (MEM_USB == ENABLED)
195  return (MAX_LUN + Host_getlun());
196 #else
197  return MAX_LUN;
198 #endif
199 }
200 
201 
202 //! This fonction return the current logical unit
203 //!
204 //! @return U8 number of logical unit in the system
205 //!
207 {
208  return 0; //TODO
209 }
210 
211 
212 //! This fonction test the state of memory, and start the initialisation of the memory
213 //!
214 //! MORE (see SPC-3 §5.2.4) : The TEST UNIT READY command allows an application client
215 //! to poll a logical unit until it is ready without the need to allocate space for returned data.
216 //! The TEST UNIT READY command may be used to check the media status of logical units with removable media.
217 //!
218 //! @param lun Logical unit number
219 //!
220 //! @return Ctrl_status
221 //! It is ready -> CTRL_GOOD
222 //! Memory unplug -> CTRL_NO_PRESENT
223 //! Not initialize -> CTRL_BUSY
224 //!
226 {
227  switch( lun )
228  {
229 # if (LUN_0 == ENABLE)
230  case LUN_ID_0:
231  return Lun_0_test_unit_ready();
232  break;
233 # endif
234 # if (LUN_1 == ENABLE)
235  case LUN_ID_1:
236  return Lun_1_test_unit_ready();
237  break;
238 # endif
239 # if (LUN_2 == ENABLE)
240  case LUN_ID_2:
241  return Lun_2_test_unit_ready();
242  break;
243 # endif
244 # if (LUN_3 == ENABLE)
245  case LUN_ID_3:
246  return Lun_3_test_unit_ready();
247  break;
248 # endif
249 # if (LUN_4 == ENABLE)
250  case LUN_ID_4:
251  return Lun_4_test_unit_ready();
252  break;
253 # endif
254 # if (LUN_5 == ENABLE)
255  case LUN_ID_5:
256  return Lun_5_test_unit_ready();
257  break;
258 # endif
259 # if (LUN_6 == ENABLE)
260  case LUN_ID_6:
261  return Lun_6_test_unit_ready();
262  break;
263 # endif
264 # if (LUN_7 == ENABLE)
265  case LUN_ID_7:
266  return Lun_7_test_unit_ready();
267  break;
268 # endif
269 # if (LUN_USB == ENABLE)
270  default:
271  return Lun_usb_test_unit_ready(lun - LUN_ID_USB);
272  break;
273 # endif
274  }
275  return CTRL_FAIL;
276 }
277 
278 //! This fonction return the capacity of the memory
279 //!
280 //! @param lun Logical unit number
281 //! @param u32_nb_sector The sector to query
282 //!
283 //! @return *u16_nb_sector number of sector (sector = 512B)
284 //! @return Ctrl_status
285 //! It is ready -> CTRL_GOOD
286 //! Memory unplug -> CTRL_NO_PRESENT
287 //!
288 Ctrl_status mem_read_capacity( U8 lun , U32 _MEM_TYPE_SLOW_ *u32_nb_sector )
289 {
290  switch( lun )
291  {
292 # if (LUN_0 == ENABLE)
293  case LUN_ID_0:
294  return Lun_0_read_capacity( u32_nb_sector );
295  break;
296 # endif
297 # if (LUN_1 == ENABLE)
298  case LUN_ID_1:
299  return Lun_1_read_capacity( u32_nb_sector );
300  break;
301 # endif
302 # if (LUN_2 == ENABLE)
303  case LUN_ID_2:
304  return Lun_2_read_capacity( u32_nb_sector );
305  break;
306 # endif
307 # if (LUN_3 == ENABLE)
308  case LUN_ID_3:
309  return Lun_3_read_capacity( u32_nb_sector );
310  break;
311 # endif
312 # if (LUN_4 == ENABLE)
313  case LUN_ID_4:
314  return Lun_4_read_capacity( u32_nb_sector );
315  break;
316 # endif
317 # if (LUN_5 == ENABLE)
318  case LUN_ID_5:
319  return Lun_5_read_capacity( u32_nb_sector );
320  break;
321 # endif
322 # if (LUN_6 == ENABLE)
323  case LUN_ID_6:
324  return Lun_6_read_capacity( u32_nb_sector );
325  break;
326 # endif
327 # if (LUN_7 == ENABLE)
328  case LUN_ID_7:
329  return Lun_7_read_capacity( u32_nb_sector );
330  break;
331 # endif
332 # if (LUN_USB == ENABLE)
333  default:
334  return Lun_usb_read_capacity( lun - LUN_ID_USB,u32_nb_sector );
335  break;
336 # endif
337  }
338  return CTRL_FAIL;
339 }
340 
341 //! This fonction return is the write protected mode
342 //!
343 //! @param lun Logical unit number
344 //!
345 //! Only used by memory removal with a HARDWARE SPECIFIC write protected detection
346 //! !!! The customer must be unplug the card for change this write protected mode.
347 //!
348 //! @return TRUE -> the memory is protected
349 //!
350 Bool mem_wr_protect( U8 lun )
351 {
352  switch( lun )
353  {
354 # if (LUN_0 == ENABLE)
355  case LUN_ID_0:
356  return Lun_0_wr_protect();
357  break;
358 # endif
359 # if (LUN_1 == ENABLE)
360  case LUN_ID_1:
361  return Lun_1_wr_protect();
362  break;
363 # endif
364 # if (LUN_2 == ENABLE)
365  case LUN_ID_2:
366  return Lun_2_wr_protect();
367  break;
368 # endif
369 # if (LUN_3 == ENABLE)
370  case LUN_ID_3:
371  return Lun_3_wr_protect();
372  break;
373 # endif
374 # if (LUN_4 == ENABLE)
375  case LUN_ID_4:
376  return Lun_4_wr_protect();
377  break;
378 # endif
379 # if (LUN_5 == ENABLE)
380  case LUN_ID_5:
381  return Lun_5_wr_protect();
382  break;
383 # endif
384 # if (LUN_6 == ENABLE)
385  case LUN_ID_6:
386  return Lun_6_wr_protect();
387  break;
388 # endif
389 # if (LUN_7 == ENABLE)
390  case LUN_ID_7:
391  return Lun_7_wr_protect();
392  break;
393 # endif
394 # if (LUN_USB == ENABLE)
395  default:
396  return Lun_usb_wr_protect(lun - LUN_ID_USB);
397  break;
398 # endif
399  }
400  return CTRL_FAIL;
401 }
402 
403 
404 //! This fonction inform about the memory type
405 //!
406 //! @param lun Logical unit number
407 //!
408 //! @return TRUE -> The memory is removal
409 //!
410 Bool mem_removal( U8 lun )
411 {
412  switch( lun )
413  {
414 # if (LUN_0 == ENABLE)
415  case LUN_ID_0:
416  return Lun_0_removal();
417  break;
418 # endif
419 # if (LUN_1 == ENABLE)
420  case LUN_ID_1:
421  return Lun_1_removal();
422  break;
423 # endif
424 # if (LUN_2 == ENABLE)
425  case LUN_ID_2:
426  return Lun_2_removal();
427  break;
428 # endif
429 # if (LUN_3 == ENABLE)
430  case LUN_ID_3:
431  return Lun_3_removal();
432  break;
433 # endif
434 # if (LUN_4 == ENABLE)
435  case LUN_ID_4:
436  return Lun_4_removal();
437  break;
438 # endif
439 # if (LUN_5 == ENABLE)
440  case LUN_ID_5:
441  return Lun_5_removal();
442  break;
443 # endif
444 # if (LUN_6 == ENABLE)
445  case LUN_ID_6:
446  return Lun_6_removal();
447  break;
448 # endif
449 # if (LUN_7 == ENABLE)
450  case LUN_ID_7:
451  return Lun_7_removal();
452  break;
453 # endif
454 # if (LUN_USB == ENABLE)
455  default:
456  return Lun_usb_removal();
457  break;
458 # endif
459  }
460  return CTRL_FAIL;
461 }
462 
463 //! This fonction returns a pointer to the LUN name
464 //!
465 //! @param lun Logical unit number
466 //!
467 //! @return pointer to code string
468 //!
469 #if 0 //not used anywhere and the FLASH attribute causes a compilation warning - dak
470 U8 FLASH* mem_name( U8 lun )
471 {
472  switch( lun )
473  {
474 # if (LUN_0 == ENABLE)
475  case LUN_ID_0:
476  return (U8 FLASH*)lun0_name;
477  break;
478 # endif
479 # if (LUN_1 == ENABLE)
480  case LUN_ID_1:
481  return (U8 FLASH*)lun1_name;
482  break;
483 # endif
484 # if (LUN_2 == ENABLE)
485  case LUN_ID_2:
486  return (U8 FLASH*)lun2_name;
487  break;
488 # endif
489 # if (LUN_3 == ENABLE)
490  case LUN_ID_3:
491  return (U8 FLASH*)lun3_name;
492  break;
493 # endif
494 # if (LUN_4 == ENABLE)
495  case LUN_ID_4:
496  return (U8 FLASH*)lun4_name;
497  break;
498 # endif
499 # if (LUN_5 == ENABLE)
500  case LUN_ID_5:
501  return (U8 FLASH*)lun5_name;
502  break;
503 # endif
504 # if (LUN_6 == ENABLE)
505  case LUN_ID_6:
506  return (U8 FLASH*)lun6_name;
507  break;
508 # endif
509 # if (LUN_7 == ENABLE)
510  case LUN_ID_7:
511  return (U8 FLASH*)lun7_name;
512  break;
513 # endif
514 # if (LUN_USB == ENABLE)
515  default:
516  return (U8 FLASH*)lunusb_name;
517  break;
518 # endif
519  }
520  return 0; // Remove compiler warning
521 }
522 #endif /* 0 */
523 
524 //************************************************************************************
525 //!----------- Listing of READ/WRITE interface with MODE ACCESS REGISTER -------------
526 //************************************************************************************
527 
528 
529 //! This fonction tranfer a data from memory to usb
530 //!
531 //! @param lun Logical unit number
532 //! @param addr Sector address to start read (sector = 512B)
533 //! @param nb_sector Number of sectors to transfer
534 //!
535 //! @return Ctrl_status
536 //! It is ready -> CTRL_GOOD
537 //! A error occur -> CTRL_FAIL
538 //! Memory unplug -> CTRL_NO_PRESENT
539 //!
540 Ctrl_status memory_2_usb( U8 lun , U32 addr , U16 nb_sector )
541 {
542  Ctrl_status status=0;
543 
544  switch( lun )
545  {
546 # if (LUN_0 == ENABLE)
547  case LUN_ID_0:
548  status = Lun_0_read_10(addr , nb_sector);
549  if (CTRL_GOOD == status)
550  {
551  status = Lun_0_usb_read();
552  }
553  break;
554 # endif
555 # if (LUN_1 == ENABLE)
556  case LUN_ID_1:
557  status = Lun_1_read_10(addr , nb_sector);
558  if (CTRL_GOOD == status)
559  {
560  status = Lun_1_usb_read();
561  }
562  break;
563 # endif
564 # if (LUN_2 == ENABLE)
565  case LUN_ID_2:
566  status = Lun_2_read_10(addr , nb_sector);
567  if (CTRL_GOOD == status)
568  {
569  status = Lun_2_usb_read();
570  }
571  break;
572 # endif
573 # if (LUN_3 == ENABLE)
574  case LUN_ID_3:
575  status = Lun_3_read_10(addr , nb_sector);
576  if (CTRL_GOOD == status)
577  {
578  status = Lun_3_usb_read();
579  }
580  break;
581 # endif
582 # if (LUN_4 == ENABLE)
583  case LUN_ID_4:
584  status = Lun_4_read_10(addr , nb_sector);
585  if (CTRL_GOOD == status)
586  {
587  status = Lun_4_usb_read();
588  }
589  break;
590 # endif
591 # if (LUN_5 == ENABLE)
592  case LUN_ID_5:
593  status = Lun_5_read_10(addr , nb_sector);
594  if (CTRL_GOOD == status)
595  {
596  status = Lun_5_usb_read();
597  }
598  break;
599 # endif
600 # if (LUN_6 == ENABLE)
601  case LUN_ID_6:
602  status = Lun_6_read_10(addr , nb_sector);
603  if (CTRL_GOOD == status)
604  {
605  status = Lun_6_usb_read();
606  }
607  break;
608 # endif
609 # if (LUN_7 == ENABLE)
610  case LUN_ID_7:
611  status = Lun_7_read_10(addr , nb_sector);
612  if (CTRL_GOOD == status)
613  {
614  status = Lun_7_usb_read();
615  }
616  break;
617 # endif
618  }
619  return status;
620 }
621 
622 //! This fonction trabsfer a data from usb to memory
623 //!
624 //! @param lun Logical unit number
625 //! @param addr Sector address to start write (sector = 512B)
626 //! @param nb_sector Number of sectors to transfer
627 //!
628 //! @return Ctrl_status
629 //! It is ready -> CTRL_GOOD
630 //! A error occur -> CTRL_FAIL
631 //! Memory unplug -> CTRL_NO_PRESENT
632 //!
633 Ctrl_status usb_2_memory( U8 lun , U32 addr , U16 nb_sector )
634 {
635  Ctrl_status status=0;
636 
637  switch( lun )
638  {
639 # if (LUN_0 == ENABLE)
640  case LUN_ID_0:
641  status = Lun_0_write_10(addr , nb_sector);
642  if (CTRL_GOOD == status)
643  {
644  status = Lun_0_usb_write();
645  }
646  break;
647 # endif
648 # if (LUN_1 == ENABLE)
649  case LUN_ID_1:
650  status = Lun_1_write_10(addr , nb_sector);
651  if (CTRL_GOOD == status)
652  {
653  status = Lun_1_usb_write();
654  }
655  break;
656 # endif
657 # if (LUN_2 == ENABLE)
658  case LUN_ID_2:
659  status = Lun_2_write_10(addr , nb_sector);
660  if (CTRL_GOOD == status)
661  {
662  status = Lun_2_usb_write();
663  }
664  break;
665 # endif
666 # if (LUN_3 == ENABLE)
667  case LUN_ID_3:
668  status = Lun_3_write_10(addr , nb_sector);
669  if (CTRL_GOOD == status)
670  {
671  status = Lun_3_usb_write();
672  }
673  break;
674 # endif
675 # if (LUN_4 == ENABLE)
676  case LUN_ID_4:
677  status = Lun_4_write_10(addr , nb_sector);
678  if (CTRL_GOOD == status)
679  {
680  status = Lun_4_usb_write();
681  }
682  break;
683 # endif
684 # if (LUN_5 == ENABLE)
685  case LUN_ID_5:
686  status = Lun_5_write_10(addr , nb_sector);
687  if (CTRL_GOOD == status)
688  {
689  status = Lun_5_usb_write();
690  }
691  break;
692 # endif
693 # if (LUN_6 == ENABLE)
694  case LUN_ID_6:
695  status = Lun_6_write_10(addr , nb_sector);
696  if (CTRL_GOOD == status)
697  {
698  status = Lun_6_usb_write();
699  }
700  break;
701 # endif
702 # if (LUN_7 == ENABLE)
703  case LUN_ID_7:
704  status = Lun_7_write_10(addr , nb_sector);
705  if (CTRL_GOOD == status)
706  {
707  status = Lun_7_usb_write();
708  }
709  break;
710 # endif
711  }
712  return status;
713 }
714 
715 //! Interface for RAM
716 #if (ACCESS_MEM_TO_RAM == ENABLED)
717 
718 //! This fonction tranfer one sector data from memory to ram
719 //!
720 //! @param lun Logical unit number
721 //! @param addr Sector address to start read (sector = 512B)
722 //! @param ram Adresse of ram buffer (only xdata)
723 //!
724 //! @return TRUE -> The memory is removal
725 //!
726 Ctrl_status memory_2_ram( U8 lun , const U32 _MEM_TYPE_SLOW_ *addr , U8 _MEM_TYPE_SLOW_ *ram )
727 {
728 
729  Ctrl_status status;
730 
731  switch( lun )
732  {
733 # if (LUN_0 == ENABLE)
734  case LUN_ID_0:
735  status = Lun_0_mem_2_ram(*addr , ram);
736  if (CTRL_GOOD == status)
737  {
738  status = Lun_0_mem_2_ram_read();
739  }
740  break;
741 # endif
742 # if (LUN_1 == ENABLE)
743  case LUN_ID_1:
744  status = Lun_1_mem_2_ram(*addr , ram);
745  if (CTRL_GOOD == status)
746  {
747  status = Lun_1_mem_2_ram_read();
748  }
749  break;
750 # endif
751 # if (LUN_2 == ENABLE)
752  case LUN_ID_2:
753  status = Lun_2_mem_2_ram(*addr , ram);
754  if (CTRL_GOOD == status)
755  {
756  status = Lun_2_mem_2_ram_read();
757  }
758  break;
759 # endif
760 # if (LUN_3 == ENABLE)
761  case LUN_ID_3:
762  status = Lun_3_mem_2_ram(*addr , ram);
763  if (CTRL_GOOD == status)
764  {
765  status = Lun_3_mem_2_ram_read();
766  }
767  break;
768 # endif
769 # if (LUN_4 == ENABLE)
770  case LUN_ID_4:
771  status = Lun_4_mem_2_ram(*addr , ram);
772  if (CTRL_GOOD == status)
773  {
774  status = Lun_4_mem_2_ram_read();
775  }
776  break;
777 # endif
778 # if (LUN_5 == ENABLE)
779  case LUN_ID_5:
780  status = Lun_5_mem_2_ram(*addr , ram);
781  if (CTRL_GOOD == status)
782  {
783  status = Lun_5_mem_2_ram_read();
784  }
785  break;
786 # endif
787 # if (LUN_6 == ENABLE)
788  case LUN_ID_6:
789  status = Lun_6_mem_2_ram(*addr , ram);
790  if (CTRL_GOOD == status)
791  {
792  status = Lun_6_mem_2_ram_read();
793  }
794  break;
795 # endif
796 # if (LUN_7 == ENABLE)
797  case LUN_ID_7:
798  status = Lun_7_mem_2_ram(*addr , ram);
799  if (CTRL_GOOD == status)
800  {
801  status = Lun_7_mem_2_ram_read();
802  }
803  break;
804 # endif
805 # if (LUN_USB == ENABLE)
806  default:
807  return Lun_usb_mem_2_ram(*addr , ram);
808 # endif
809  }
810  return status;
811 }
812 #endif // ACCESS_MEM_TO_RAM == ENABLED
813 
814 
815 
816 #if (ACCESS_MEM_TO_RAM==ENABLE)
817 
818 //! This fonction trabsfer a data from ram to memory
819 //!
820 //! @param lun Logical unit number
821 //! @param addr Sector address to start write (sector = 512B)
822 //! @param ram Adresse of ram buffer (only xdata)
823 //!
824 //! @return TRUE -> The memory is removal
825 //!
826 Ctrl_status ram_2_memory( U8 lun , const U32 _MEM_TYPE_SLOW_ *addr , U8 _MEM_TYPE_SLOW_ * ram )
827 {
828  Ctrl_status status;
829 
830  switch( lun )
831  {
832 # if (LUN_0 == ENABLE)
833  case LUN_ID_0:
834  status = Lun_0_ram_2_mem(*addr , ram);
835  if (CTRL_GOOD == status)
836  {
837  status = Lun_0_ram_2_mem_write();
838  }
839  break;
840 # endif
841 # if (LUN_1 == ENABLE)
842  case LUN_ID_1:
843  status = Lun_1_ram_2_mem(*addr , ram);
844  if (CTRL_GOOD == status)
845  {
846  status = Lun_1_ram_2_mem_write();
847  }
848  break;
849 # endif
850 # if (LUN_2 == ENABLE)
851  case LUN_ID_2:
852  status = Lun_2_ram_2_mem(*addr , ram);
853  if (CTRL_GOOD == status)
854  {
855  status = Lun_2_ram_2_mem_write();
856  }
857  break;
858 # endif
859 # if (LUN_3 == ENABLE)
860  case LUN_ID_3:
861  status = Lun_3_ram_2_mem(*addr , ram);
862  if (CTRL_GOOD == status)
863  {
864  status = Lun_3_ram_2_mem_write();
865  }
866  break;
867 # endif
868 # if (LUN_4 == ENABLE)
869  case LUN_ID_4:
870  status = Lun_4_ram_2_mem(*addr , ram);
871  if (CTRL_GOOD == status)
872  {
873  status = Lun_4_ram_2_mem_write();
874  }
875  break;
876 # endif
877 # if (LUN_5 == ENABLE)
878  case LUN_ID_5:
879  status = Lun_5_ram_2_mem(*addr , ram);
880  if (CTRL_GOOD == status)
881  {
882  status = Lun_5_ram_2_mem_write();
883  }
884  break;
885 # endif
886 # if (LUN_6 == ENABLE)
887  case LUN_ID_6:
888  status = Lun_6_ram_2_mem(*addr , ram);
889  if (CTRL_GOOD == status)
890  {
891  status = Lun_6_ram_2_mem_write();
892  }
893  break;
894 # endif
895  # if (LUN_7 == ENABLE)
896  case LUN_ID_7:
897  status = Lun_7_ram_2_mem(*addr , ram);
898  if (CTRL_GOOD == status)
899  {
900  status = Lun_7_ram_2_mem_write();
901  }
902  break;
903 # endif
904 # if (LUN_USB == ENABLE)
905  default:
906  return Lun_usb_ram_2_mem(*addr , ram);
907  break;
908 # endif
909  }
910  return status;
911 }
912 #endif // ACCESS_RAM_TO_MEM == ENABLED
913 
914 
915 
916 //! Interface for streaming interface
917 #if (ACCESS_STREAM == ENABLED)
918 
919 
920 
921 // Interface for transfer MEM to MEM
922 # if (ACCESS_MEM_TO_MEM == ENABLED)
923 //! This fonction copy a data from memory to other memory
924 //!
925 //! @param src_lun The LUN of the source
926 //! @param src_addr The address of the source
927 //! @param dest_lun The LUN of the destination
928 //! @param dest_addr The address of the destination
929 //! @param nb_sector Number of sectors to transfer
930 //!
931 U8 stream_mem_to_mem( U8 src_lun , U32 src_addr , U8 dest_lun , U32 dest_addr , U16 nb_sector )
932 {
933  while(nb_sector)
934  {
935  memory_2_ram( src_lun , &src_addr , buf_sector );
936  ram_2_memory( dest_lun , &dest_addr , buf_sector );
937  src_addr++;
938  dest_addr++;
939  nb_sector--;
940  }
941  return CTRL_GOOD;
942 }
943 # endif // ACCESS_MEM_TO_MEM == ENABLED
944 
945 
946 
947 
948 //! Returns the state on a data transfer
949 //!
950 //! @param Id transfer id
951 //!
952 //! @return the state of the transfer
953 //! CTRL_GOOD It is finish
954 //! CTRL_BUSY It is running
955 //! CTRL_FAIL It is fail
956 //!
958 {
959 
960  return CTRL_GOOD;
961 }
962 
963 //! Stop the data transfer
964 //!
965 //! @param Id Transfer id
966 //!
967 //! @return the number of sector remainder
968 //!
969 U16 stream_stop( U8 Id )
970 {
971  return 0;
972 }
973 
974 #endif // ACCESS_STREAM == ENABLED
975 
976 /** @} */