Contiki 3.x
avr_flash.h
Go to the documentation of this file.
1 /* This file has been prepared for Doxygen automatic documentation generation.*/
2 /*! \file avr_flash.h *********************************************************
3  *
4  * \brief
5  * This file writes/reads to/from flash memory internal to the AVR.
6  *
7  * \addtogroup usbstick
8  *
9  * \author
10  * Colin O'Flynn <coflynn@newae.com>
11  ******************************************************************************/
12 /*
13  Copyright (c) 2008 Colin O'Flynn
14  All rights reserved.
15 
16  Redistribution and use in source and binary forms, with or without
17  modification, are permitted provided that the following conditions are met:
18 
19  * Redistributions of source code must retain the above copyright
20  notice, this list of conditions and the following disclaimer.
21  * Redistributions in binary form must reproduce the above copyright
22  notice, this list of conditions and the following disclaimer in
23  the documentation and/or other materials provided with the
24  distribution.
25  * Neither the name of the copyright holders nor the names of
26  contributors may be used to endorse or promote products derived
27  from this software without specific prior written permission.
28 
29  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
30  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
33  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
36  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
37  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39  POSSIBILITY OF SUCH DAMAGE.
40 */
41 
42 /**
43  \addtogroup usbstorage
44  @{
45 */
46 
47 #ifndef DFMEM_H_
48 #define DFMEM_H_
49 
50 #include "conf_access.h"
51 #include "ctrl_status.h"
52 
53 
54 
55 
56 //_____ D E F I N I T I O N S ______________________________________________
57 
58 //! FAT specification
59 #define ENTRY_SIZE 32 // size of entrie in byte
60 
61 
62 
63 // First sector of the disk virtual (this disk isn't partitioned, only one partion)
64 #define PBR_SECTOR (0)
65 #define FAT_SECTOR (PBR_SECTOR + VMEM_RESERVED_SIZE)
66 #define ROOT_SECTOR (FAT_SECTOR + (VMEM_SIZE_FAT*VMEM_NB_FATS))
67 #define FILE_SECTOR (ROOT_SECTOR + ((ENTRY_SIZE*VMEM_NB_ROOT_ENTRY) / VMEM_SECTOR_SIZE)) // 1(sector) = size root dir
68 
69 
70 /* FAT Format Structure */
71 typedef struct
72 {
73  Uint16 nb_cylinder;
74  Byte nb_head;
75  Byte nb_sector;
76  Byte nb_hidden_sector;
77  Byte nb_sector_per_cluster;
78 } s_format;
79 
80 #define MEM_BSY 0
81 #define MEM_OK 1
82 #define MEM_KO 2
83 
84 
85 
86 
87 //---- CONTROL FONCTIONS ----
88 
89 // those fonctions are declared in df_mem.h
90 void avrf_mem_init(void);
92 Ctrl_status avrf_read_capacity( U32 _MEM_TYPE_SLOW_ *u32_nb_sector );
93 Bool avrf_wr_protect(void);
94 Bool avrf_removal(void);
95 
96 //---- AVR FLASH LOW-LEVEL----
97 
98 
99 bit avrf_init (void);
100 bit avrf_mem_check(void);
101 bit avrf_read_open (Uint32);
102 void avrf_read_close (void);
103 bit avrf_write_open (Uint32);
104 void avrf_write_close (void);
105 
106 //! Funtions to link USB DEVICE flow with data flash
107 bit avrf_write_sector (Uint16);
108 bit avrf_read_sector (Uint16);
109 
110 
111 s_format * avrf_format (void);
112 
113 
114 
115 //---- ACCESS DATA FONCTIONS ----
116 
117 // Standard functions for open in read/write mode the device
118 Ctrl_status avrf_read_10( U32 addr , U16 nb_sector );
119 Ctrl_status avrf_write_10( U32 addr , U16 nb_sector );
120 
121 
122 //** If your device transfer have a specific transfer for USB (Particularity of Chejudo product, or bootloader)
123 #ifdef DF_VALIDATION
124 #include "virtual_usb.h"
125 #else
126 #include "usb_drv.h" // In this case the driver must be known for the USB access
127 #endif
128 //Ctrl_status avr_usb_read( void );
129 //Ctrl_status avr_usb_write( void );
130 Ctrl_status avrf_usb_read( void );
132 
133 
134 
135 #endif //DFMEM_H_
136 
137 /** @} */
void avrf_read_close(void)
This function unselects the current DF memory.
Definition: avr_flash.c:239
void avrf_write_close(void)
This function fills the end of the logical sector (512B) and launch page programming.
Definition: avr_flash.c:329
Ctrl_status avrf_usb_write(void)
This fonction transfer the usb data (programed in scsi_write_10) directly to the memory data...
Definition: avr_flash.c:510
Ctrl_status
Define control status.
Definition: ctrl_status.h:61
bit avrf_read_sector(Uint16 nb_sector)
This function is optimized and writes nb-sector * 512 Bytes from DataFlash memory to USB controller...
Definition: avr_flash.c:269
This file contains the USB driver routines.
bit avrf_write_open(Uint32 pos)
This function opens a DF memory in write mode at a given sector address.
Definition: avr_flash.c:313
Ctrl_status avrf_read_10(U32 addr, U16 nb_sector)
This function performs a read operation of n sectors from a given address on.
Definition: avr_flash.c:178
void avrf_mem_init(void)
This function initializes the hw/sw ressources required to drive the AVR Flash.
Definition: avr_flash.c:91
Bool avrf_wr_protect(void)
This function returns the write protected status of the memory.
Definition: avr_flash.c:140
Ctrl_status avrf_usb_read()
This fonction transfer the memory data (programed in scsi_read_10) directly to the usb interface...
Definition: avr_flash.c:499
Ctrl_status avrf_read_capacity(U32 *u32_nb_sector)
This function gives the address of the last valid sector.
Definition: avr_flash.c:122
Ctrl_status avrf_test_unit_ready(void)
This function tests the state of the AVR Flash.
Definition: avr_flash.c:106
bit avrf_read_open(Uint32 pos)
This function opens a DF memory in read mode at a given sector address.
Definition: avr_flash.c:224
This file contains the interface :
Ctrl_status avrf_write_10(U32 addr, U16 nb_sector)
This fonction initialise the memory for a write operation.
Definition: avr_flash.c:200
This file contains the possible external configuration of the control access.
Bool avrf_removal(void)
This function tells if the memory has been removed or not.
Definition: avr_flash.c:153
bit avrf_write_sector(Uint16 nb_sector)
This function is optimized and writes nb-sector * 512 Bytes from USB controller to DataFlash memory...
Definition: avr_flash.c:400