ctrl_access.h File Reference


Detailed Description

Abstraction layer for memory interfaces.

This module contains the interfaces:

This module may be configured and expanded to support the following features:

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file ctrl_access.h.

#include "compiler.h"
#include "conf_access.h"
#include <LUN_0_INCLUDE>
#include <LUN_1_INCLUDE>
#include <LUN_2_INCLUDE>
#include <LUN_3_INCLUDE>
#include <LUN_4_INCLUDE>
#include <LUN_5_INCLUDE>
#include <LUN_6_INCLUDE>
#include <LUN_7_INCLUDE>
#include <LUN_USB_INCLUDE>

Go to the source code of this file.

Streaming MEM <-> MEM Interface

#define ID_STREAM_ERR   0xFF
 Erroneous streaming data transfer ID.
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.

Defines

LUN IDs
#define LUN_ID_0   (0)
 First static LUN.
#define LUN_ID_1   (LUN_ID_0 + LUN_0)
 First static LUN.
#define LUN_ID_2   (LUN_ID_1 + LUN_1)
 First static LUN.
#define LUN_ID_3   (LUN_ID_2 + LUN_2)
 First static LUN.
#define LUN_ID_4   (LUN_ID_3 + LUN_3)
 First static LUN.
#define LUN_ID_5   (LUN_ID_4 + LUN_4)
 First static LUN.
#define LUN_ID_6   (LUN_ID_5 + LUN_5)
 First static LUN.
#define LUN_ID_7   (LUN_ID_6 + LUN_6)
 First static LUN.
#define LUN_ID_USB   (MAX_LUN)
 First dynamic LUN (USB host mass storage).
#define MAX_LUN   (LUN_ID_7 + LUN_7)
 Number of static LUNs.

Enumerations

enum  Ctrl_status { CTRL_GOOD = PASS, CTRL_FAIL = FAIL, CTRL_NO_PRESENT = FAIL + 1, CTRL_BUSY = FAIL + 2 }
 Status returned by CTRL_ACCESS interfaces. More...

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.

Variables

Bool g_wr_protect
 Write protect.


Define Documentation

#define ID_STREAM_ERR   0xFF

Erroneous streaming data transfer ID.

Definition at line 325 of file ctrl_access.h.

#define LUN_ID_0   (0)

First static LUN.

Definition at line 108 of file ctrl_access.h.

Referenced by get_cur_lun().

#define LUN_ID_1   (LUN_ID_0 + LUN_0)

First static LUN.

Definition at line 109 of file ctrl_access.h.

#define LUN_ID_2   (LUN_ID_1 + LUN_1)

First static LUN.

Definition at line 110 of file ctrl_access.h.

#define LUN_ID_3   (LUN_ID_2 + LUN_2)

First static LUN.

Definition at line 111 of file ctrl_access.h.

#define LUN_ID_4   (LUN_ID_3 + LUN_3)

First static LUN.

Definition at line 112 of file ctrl_access.h.

#define LUN_ID_5   (LUN_ID_4 + LUN_4)

First static LUN.

Definition at line 113 of file ctrl_access.h.

#define LUN_ID_6   (LUN_ID_5 + LUN_5)

First static LUN.

Definition at line 114 of file ctrl_access.h.

#define LUN_ID_7   (LUN_ID_6 + LUN_6)

First static LUN.

Definition at line 115 of file ctrl_access.h.

#define LUN_ID_USB   (MAX_LUN)

First dynamic LUN (USB host mass storage).

Definition at line 117 of file ctrl_access.h.

Referenced by mem_read_capacity(), mem_sector_size(), mem_test_unit_ready(), and mem_wr_protect().

#define MAX_LUN   (LUN_ID_7 + LUN_7)


Enumeration Type Documentation

Status returned by CTRL_ACCESS interfaces.

Enumerator:
CTRL_GOOD  Success, memory ready.
CTRL_FAIL  An error occurred.
CTRL_NO_PRESENT  Memory unplugged.
CTRL_BUSY  Memory not initialized or changed.

Definition at line 65 of file ctrl_access.h.

00066 {
00067   CTRL_GOOD       = PASS,     
00068   CTRL_FAIL       = FAIL,     
00069   CTRL_NO_PRESENT = FAIL + 1, 
00070   CTRL_BUSY       = FAIL + 2  
00071 } Ctrl_status;


Function Documentation

U8 get_cur_lun ( void   ) 

Returns the current LUN.

Returns:
Current LUN.
Todo:
Implement.

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.

Returns:
Number of LUNs in the system.

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.

Parameters:
lun Logical Unit Number.
Returns:
Pointer to the LUN name string.

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.

Parameters:
lun Logical Unit Number.
u32_nb_sector Pointer to the address of the last valid sector.
Returns:
Status.

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.

Parameters:
lun Logical Unit Number.
Returns:
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.

Parameters:
lun Logical Unit Number.
Returns:
Sector size (unit: 512 bytes).

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.

Parameters:
lun Logical Unit Number.
Returns:
Status.

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.

Parameters:
lun Logical Unit Number.
Returns:
TRUE if the memory is write-protected, else FALSE.
Note:
Only used by removable memories with hardware-specific write protection.

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.

Parameters:
lun Logical Unit Number.
addr Address of first memory sector to read.
ram Pointer to RAM buffer to write.
Returns:
Status.

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.

Parameters:
lun Logical Unit Number.
addr Address of first memory sector to read.
nb_sector Number of sectors to transfer.
Returns:
Status.

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.

Parameters:
lun Logical Unit Number.
addr Address of first memory sector to write.
ram Pointer to RAM buffer to read.
Returns:
Status.

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.

Parameters:
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.
Returns:
Status.

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.

Parameters:
id Transfer ID.
Returns:
Status.
Todo:
Implement.

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.

Parameters:
id Transfer ID.
Returns:
Number of remaining sectors.
Todo:
Implement.

Definition at line 561 of file ctrl_access.c.

00562 {
00563   return 0;
00564 }

Ctrl_status usb_2_memory ( U8  lun,
U32  addr,
U16  nb_sector 
)

Tranfers data from USB to the memory.

Parameters:
lun Logical Unit Number.
addr Address of first memory sector to write.
nb_sector Number of sectors to transfer.
Returns:
Status.

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 }


Variable Documentation

Write protect.

Definition at line 214 of file ctrl_access.c.


Generated on Thu Dec 17 19:57:41 2009 for AVR32 - AT45DBX Data Flash Driver by  doxygen 1.5.5