This module contains the interfaces:
This module may be configured and expanded to support the following features:
Definition in file ctrl_access.c.
#include "compiler.h"
#include "preprocessor.h"
#include "ctrl_access.h"
#include "fat.h"
Go to the source code of this file.
Defines | |
LUN Access Protection Macros | |
#define | Ctrl_access_lock() TRUE |
Locks accesses to LUNs. | |
#define | Ctrl_access_unlock() |
Unlocks accesses to LUNs. | |
Functions | |
Control Interface | |
U8 | get_cur_lun (void) |
Returns the current LUN. | |
U8 | get_nb_lun (void) |
Returns the number of LUNs. | |
const char * | mem_name (U8 lun) |
Returns a pointer to the LUN name. | |
Ctrl_status | mem_read_capacity (U8 lun, U32 *u32_nb_sector) |
Returns the address of the last valid sector (512 bytes) in the memory. | |
Bool | mem_removal (U8 lun) |
Tells whether the memory is removable. | |
U8 | mem_sector_size (U8 lun) |
Returns the size of the physical sector. | |
Ctrl_status | mem_test_unit_ready (U8 lun) |
Tests the memory state and initializes the memory if required. | |
Bool | mem_wr_protect (U8 lun) |
Returns the write-protection state of the memory. | |
MEM <-> RAM Interface | |
Ctrl_status | memory_2_ram (U8 lun, U32 addr, void *ram) |
Copies 1 data sector from the memory to RAM. | |
Ctrl_status | ram_2_memory (U8 lun, U32 addr, const void *ram) |
Copies 1 data sector from RAM to the memory. | |
MEM <-> USB Interface | |
Ctrl_status | memory_2_usb (U8 lun, U32 addr, U16 nb_sector) |
Tranfers data from the memory to USB. | |
Ctrl_status | usb_2_memory (U8 lun, U32 addr, U16 nb_sector) |
Tranfers data from USB to the memory. | |
Streaming MEM <-> MEM Interface | |
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. | |
Ctrl_status | stream_state (U8 id) |
Returns the state of a streaming data transfer. | |
U16 | stream_stop (U8 id) |
Stops a streaming data transfer. | |
Variables | |
Bool | g_wr_protect |
Write protect. |
#define Ctrl_access_lock | ( | ) | TRUE |
Locks accesses to LUNs.
TRUE
if the access was successfully locked, else FALSE
. Definition at line 101 of file ctrl_access.c.
Referenced by get_nb_lun(), mem_read_capacity(), mem_removal(), mem_sector_size(), mem_test_unit_ready(), mem_wr_protect(), memory_2_ram(), memory_2_usb(), ram_2_memory(), and usb_2_memory().
#define Ctrl_access_unlock | ( | ) |
Unlocks accesses to LUNs.
Definition at line 105 of file ctrl_access.c.
Referenced by get_nb_lun(), mem_read_capacity(), mem_removal(), mem_sector_size(), mem_test_unit_ready(), mem_wr_protect(), memory_2_ram(), memory_2_usb(), ram_2_memory(), and usb_2_memory().
U8 get_cur_lun | ( | void | ) |
Returns the current LUN.
Definition at line 277 of file ctrl_access.c.
References LUN_ID_0.
00278 { 00279 return LUN_ID_0; 00280 }
U8 get_nb_lun | ( | void | ) |
Returns the number of LUNs.
Definition at line 259 of file ctrl_access.c.
References Ctrl_access_lock, Ctrl_access_unlock, and MAX_LUN.
00260 { 00261 #if MEM_USB == ENABLE 00262 U8 nb_lun; 00263 00264 if (!Ctrl_access_lock()) return MAX_LUN; 00265 00266 nb_lun = MAX_LUN + host_get_lun(); 00267 00268 Ctrl_access_unlock(); 00269 00270 return nb_lun; 00271 #else 00272 return MAX_LUN; 00273 #endif 00274 }
const char* mem_name | ( | U8 | lun | ) |
Returns a pointer to the LUN name.
lun | Logical Unit Number. |
Definition at line 393 of file ctrl_access.c.
References LUN_USB, LUN_USB_NAME, and MAX_LUN.
00394 { 00395 return 00396 #if MAX_LUN 00397 (lun < MAX_LUN) ? lun_desc[lun].name : 00398 #endif 00399 #if LUN_USB == ENABLE 00400 LUN_USB_NAME; 00401 #else 00402 NULL; 00403 #endif 00404 }
Ctrl_status mem_read_capacity | ( | U8 | lun, | |
U32 * | u32_nb_sector | |||
) |
Returns the address of the last valid sector (512 bytes) in the memory.
lun | Logical Unit Number. | |
u32_nb_sector | Pointer to the address of the last valid sector. |
Definition at line 305 of file ctrl_access.c.
References Ctrl_access_lock, Ctrl_access_unlock, CTRL_FAIL, LUN_ID_USB, Lun_usb_read_capacity, and MAX_LUN.
00306 { 00307 Ctrl_status status; 00308 00309 if (!Ctrl_access_lock()) return CTRL_FAIL; 00310 00311 status = 00312 #if MAX_LUN 00313 (lun < MAX_LUN) ? lun_desc[lun].read_capacity(u32_nb_sector) : 00314 #endif 00315 #if LUN_USB == ENABLE 00316 Lun_usb_read_capacity(lun - LUN_ID_USB, u32_nb_sector); 00317 #else 00318 CTRL_FAIL; 00319 #endif 00320 00321 Ctrl_access_unlock(); 00322 00323 return status; 00324 }
Bool mem_removal | ( | U8 | lun | ) |
Tells whether the memory is removable.
lun | Logical Unit Number. |
TRUE
if the memory is removable, else FALSE
. Definition at line 371 of file ctrl_access.c.
References Ctrl_access_lock, Ctrl_access_unlock, Lun_usb_removal, and MAX_LUN.
00372 { 00373 Bool removal; 00374 00375 if (!Ctrl_access_lock()) return TRUE; 00376 00377 removal = 00378 #if MAX_LUN 00379 (lun < MAX_LUN) ? lun_desc[lun].removal() : 00380 #endif 00381 #if LUN_USB == ENABLE 00382 Lun_usb_removal(); 00383 #else 00384 TRUE; 00385 #endif 00386 00387 Ctrl_access_unlock(); 00388 00389 return removal; 00390 }
U8 mem_sector_size | ( | U8 | lun | ) |
Returns the size of the physical sector.
lun | Logical Unit Number. |
Definition at line 327 of file ctrl_access.c.
References Ctrl_access_lock, Ctrl_access_unlock, LUN_ID_USB, LUN_USB, Lun_usb_read_sector_size, and MAX_LUN.
00328 { 00329 U8 sector_size; 00330 00331 if (!Ctrl_access_lock()) return 0; 00332 00333 sector_size = 00334 #if MAX_LUN 00335 (lun < MAX_LUN) ? 1 : 00336 #endif 00337 #if LUN_USB == ENABLE 00338 Lun_usb_read_sector_size(lun - LUN_ID_USB); 00339 #else 00340 0; 00341 #endif 00342 00343 Ctrl_access_unlock(); 00344 00345 return sector_size; 00346 }
Ctrl_status mem_test_unit_ready | ( | U8 | lun | ) |
Tests the memory state and initializes the memory if required.
The TEST UNIT READY SCSI primary command allows an application client to poll a LUN until it is ready without having to allocate memory for returned data.
This command may be used to check the media status of LUNs with removable media.
lun | Logical Unit Number. |
Definition at line 283 of file ctrl_access.c.
References Ctrl_access_lock, Ctrl_access_unlock, CTRL_FAIL, LUN_ID_USB, Lun_usb_test_unit_ready, and MAX_LUN.
00284 { 00285 Ctrl_status status; 00286 00287 if (!Ctrl_access_lock()) return CTRL_FAIL; 00288 00289 status = 00290 #if MAX_LUN 00291 (lun < MAX_LUN) ? lun_desc[lun].test_unit_ready() : 00292 #endif 00293 #if LUN_USB == ENABLE 00294 Lun_usb_test_unit_ready(lun - LUN_ID_USB); 00295 #else 00296 CTRL_FAIL; 00297 #endif 00298 00299 Ctrl_access_unlock(); 00300 00301 return status; 00302 }
Bool mem_wr_protect | ( | U8 | lun | ) |
Returns the write-protection state of the memory.
lun | Logical Unit Number. |
TRUE
if the memory is write-protected, else FALSE
.Definition at line 349 of file ctrl_access.c.
References Ctrl_access_lock, Ctrl_access_unlock, LUN_ID_USB, Lun_usb_wr_protect, and MAX_LUN.
00350 { 00351 Bool wr_protect; 00352 00353 if (!Ctrl_access_lock()) return TRUE; 00354 00355 wr_protect = 00356 #if MAX_LUN 00357 (lun < MAX_LUN) ? lun_desc[lun].wr_protect() : 00358 #endif 00359 #if LUN_USB == ENABLE 00360 Lun_usb_wr_protect(lun - LUN_ID_USB); 00361 #else 00362 TRUE; 00363 #endif 00364 00365 Ctrl_access_unlock(); 00366 00367 return wr_protect; 00368 }
Ctrl_status memory_2_ram | ( | U8 | lun, | |
U32 | addr, | |||
void * | ram | |||
) |
Copies 1 data sector from the memory to RAM.
lun | Logical Unit Number. | |
addr | Address of first memory sector to read. | |
ram | Pointer to RAM buffer to write. |
Definition at line 469 of file ctrl_access.c.
References Ctrl_access_lock, Ctrl_access_unlock, CTRL_FAIL, Lun_usb_mem_2_ram, MAX_LUN, memory_start_read_action, and memory_stop_read_action.
Referenced by stream_mem_to_mem().
00470 { 00471 Ctrl_status status; 00472 00473 if (!Ctrl_access_lock()) return CTRL_FAIL; 00474 00475 memory_start_read_action(1); 00476 status = 00477 #if MAX_LUN 00478 (lun < MAX_LUN) ? lun_desc[lun].mem_2_ram(addr, ram) : 00479 #endif 00480 #if LUN_USB == ENABLE 00481 Lun_usb_mem_2_ram(addr, ram); 00482 #else 00483 CTRL_FAIL; 00484 #endif 00485 memory_stop_read_action(); 00486 00487 Ctrl_access_unlock(); 00488 00489 return status; 00490 }
Ctrl_status memory_2_usb | ( | U8 | lun, | |
U32 | addr, | |||
U16 | nb_sector | |||
) |
Tranfers data from the memory to USB.
lun | Logical Unit Number. | |
addr | Address of first memory sector to read. | |
nb_sector | Number of sectors to transfer. |
Definition at line 417 of file ctrl_access.c.
References Ctrl_access_lock, Ctrl_access_unlock, CTRL_FAIL, MAX_LUN, memory_start_read_action, and memory_stop_read_action.
00418 { 00419 Ctrl_status status; 00420 00421 if (!Ctrl_access_lock()) return CTRL_FAIL; 00422 00423 memory_start_read_action(nb_sector); 00424 status = 00425 #if MAX_LUN 00426 (lun < MAX_LUN) ? lun_desc[lun].usb_read_10(addr, nb_sector) : 00427 #endif 00428 CTRL_FAIL; 00429 memory_stop_read_action(); 00430 00431 Ctrl_access_unlock(); 00432 00433 return status; 00434 }
Ctrl_status ram_2_memory | ( | U8 | lun, | |
U32 | addr, | |||
const void * | ram | |||
) |
Copies 1 data sector from RAM to the memory.
lun | Logical Unit Number. | |
addr | Address of first memory sector to write. | |
ram | Pointer to RAM buffer to read. |
Definition at line 493 of file ctrl_access.c.
References Ctrl_access_lock, Ctrl_access_unlock, CTRL_FAIL, Lun_usb_ram_2_mem, MAX_LUN, memory_start_write_action, and memory_stop_write_action.
Referenced by stream_mem_to_mem().
00494 { 00495 Ctrl_status status; 00496 00497 if (!Ctrl_access_lock()) return CTRL_FAIL; 00498 00499 memory_start_write_action(1); 00500 status = 00501 #if MAX_LUN 00502 (lun < MAX_LUN) ? lun_desc[lun].ram_2_mem(addr, ram) : 00503 #endif 00504 #if LUN_USB == ENABLE 00505 Lun_usb_ram_2_mem(addr, ram); 00506 #else 00507 CTRL_FAIL; 00508 #endif 00509 memory_stop_write_action(); 00510 00511 Ctrl_access_unlock(); 00512 00513 return status; 00514 }
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.
src_lun | Source Logical Unit Number. | |
src_addr | Source address of first memory sector to read. | |
dest_lun | Destination Logical Unit Number. | |
dest_addr | Destination address of first memory sector to write. | |
nb_sector | Number of sectors to copy. |
Definition at line 533 of file ctrl_access.c.
References CTRL_GOOD, memory_2_ram(), ram_2_memory(), and sector_buf.
00534 { 00535 #if (defined __GNUC__) && (defined __AVR32__) 00536 __attribute__((__aligned__(4))) 00537 #elif (defined __ICCAVR32__) 00538 #pragma data_alignment = 4 00539 #endif 00540 static U8 sector_buf[FS_512B]; 00541 Ctrl_status status = CTRL_GOOD; 00542 00543 while (nb_sector--) 00544 { 00545 if ((status = memory_2_ram(src_lun, src_addr++, sector_buf)) != CTRL_GOOD) break; 00546 if ((status = ram_2_memory(dest_lun, dest_addr++, sector_buf)) != CTRL_GOOD) break; 00547 } 00548 00549 return status; 00550 }
Ctrl_status stream_state | ( | U8 | id | ) |
Returns the state of a streaming data transfer.
id | Transfer ID. |
Definition at line 555 of file ctrl_access.c.
References CTRL_GOOD.
00556 { 00557 return CTRL_GOOD; 00558 }
U16 stream_stop | ( | U8 | id | ) |
Stops a streaming data transfer.
id | Transfer ID. |
Definition at line 561 of file ctrl_access.c.
Ctrl_status usb_2_memory | ( | U8 | lun, | |
U32 | addr, | |||
U16 | nb_sector | |||
) |
Tranfers data from USB to the memory.
lun | Logical Unit Number. | |
addr | Address of first memory sector to write. | |
nb_sector | Number of sectors to transfer. |
Definition at line 437 of file ctrl_access.c.
References Ctrl_access_lock, Ctrl_access_unlock, CTRL_FAIL, MAX_LUN, memory_start_write_action, and memory_stop_write_action.
00438 { 00439 Ctrl_status status; 00440 00441 if (!Ctrl_access_lock()) return CTRL_FAIL; 00442 00443 memory_start_write_action(nb_sector); 00444 status = 00445 #if MAX_LUN 00446 (lun < MAX_LUN) ? lun_desc[lun].usb_write_10(addr, nb_sector) : 00447 #endif 00448 CTRL_FAIL; 00449 memory_stop_write_action(); 00450 00451 Ctrl_access_unlock(); 00452 00453 return status; 00454 }
Bool g_wr_protect |