Contiki 2.5
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 /** @} */