annotate packages/devs/flash/synthv2/current/src/synth.c @ 1762:9c1d9e5039c2

Move dummy init/query/lock/unlock functions to the generic flash code, and use these in the V2 drivers where appropriate
author bartv
date Mon, 29 Nov 2004 00:43:48 +0000
parents 2f4e31c45a45
children 42c8ea63b78d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
1 //==========================================================================
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
2 //
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
3 // synth.c
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
4 //
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
5 // Flash programming
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
6 //
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
7 //==========================================================================
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
8 //####ECOSGPLCOPYRIGHTBEGIN####
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
9 // -------------------------------------------
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
10 // This file is part of eCos, the Embedded Configurable Operating System.
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
12 //
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
13 // eCos is free software; you can redistribute it and/or modify it under
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
14 // the terms of the GNU General Public License as published by the Free
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
15 // Software Foundation; either version 2 or (at your option) any later version.
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
16 //
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
19 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
20 // for more details.
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
21 //
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
22 // You should have received a copy of the GNU General Public License along
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
25 //
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
26 // As a special exception, if other files instantiate templates or use macros
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
27 // or inline functions from this file, or you compile this file and link it
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
28 // with other works to produce a work based on this file, this file does not
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
29 // by itself cause the resulting work to be covered by the GNU General Public
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
30 // License. However the source code for this file must still be made available
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
31 // in accordance with section (3) of the GNU General Public License.
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
32 //
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
33 // This exception does not invalidate any other reasons why a work based on
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
34 // this file might be covered by the GNU General Public License.
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
35 //
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
37 // at http://sources.redhat.com/ecos/ecos-license/
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
38 // -------------------------------------------
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
39 //####ECOSGPLCOPYRIGHTEND####
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
40 //==========================================================================
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
41 //#####DESCRIPTIONBEGIN####
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
42 //
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
43 // Author(s): andrew.lunn@ascom.ch
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
44 // Contributors: jlarmour
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
45 // Date: 2001-10-30
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
46 // Purpose:
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
47 // Description:
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
48 //
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
49 //####DESCRIPTIONEND####
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
50 //
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
51 //==========================================================================
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
52
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
53 #include <pkgconf/devs_flash_synth_v2.h>
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
54
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
55 #include <cyg/hal/hal_io.h>
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
56 #include <cyg/infra/cyg_ass.h>
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
57 #include <string.h>
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
58
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
59 #define _FLASH_PRIVATE_
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
60 #include <cyg/io/flash.h>
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
61 #include <cyg/flash/synth.h>
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
62
1724
a24dbf2587a3 * src/flash_synth.c: Allow the use of arbitary sized block.
asl
parents: 1702
diff changeset
63 #ifndef MIN
a24dbf2587a3 * src/flash_synth.c: Allow the use of arbitary sized block.
asl
parents: 1702
diff changeset
64 #define MIN(x,y) ((x)<(y) ? (x) : (y))
a24dbf2587a3 * src/flash_synth.c: Allow the use of arbitary sized block.
asl
parents: 1702
diff changeset
65 #endif
a24dbf2587a3 * src/flash_synth.c: Allow the use of arbitary sized block.
asl
parents: 1702
diff changeset
66
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
67 /* Helper function. The Linux system call cannot pass 6 parameters. Instead
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
68 a structure is filled in and passed as one parameter */
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
69 static int
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
70 cyg_hal_sys_do_mmap(void *addr, unsigned long length, unsigned long prot,
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
71 unsigned long flags, unsigned long fd, unsigned long off)
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
72 {
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
73
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
74 struct cyg_hal_sys_mmap_args args;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
75
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
76 args.addr = (unsigned long) addr;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
77 args.len = length;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
78 args.prot = prot = prot;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
79 args.flags = flags;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
80 args.fd = fd;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
81 args.offset = off;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
82
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
83 return (cyg_hal_sys_mmap(&args));
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
84 }
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
85
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
86 static int
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
87 synth_flash_init(struct cyg_flash_dev *dev)
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
88 {
1756
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
89 struct cyg_flash_synth_priv *priv = (struct cyg_flash_synth_priv*)dev->priv;
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
90 cyg_flashaddr_t base;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
91 int flags=CYG_HAL_SYS_MAP_SHARED;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
92
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
93 priv->flashfd =
1756
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
94 cyg_hal_sys_open(priv->filename,
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
95 CYG_HAL_SYS_O_RDWR,
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
96 CYG_HAL_SYS_S_IRWXU|CYG_HAL_SYS_S_IRWXG|
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
97 CYG_HAL_SYS_S_IRWXO);
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
98 if (priv->flashfd == -ENOENT) {
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
99 long w, bytesleft;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
100 char buf[128];
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
101
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
102 priv->flashfd = cyg_hal_sys_open(
1756
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
103 priv->filename,
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
104 CYG_HAL_SYS_O_RDWR|CYG_HAL_SYS_O_CREAT,
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
105 CYG_HAL_SYS_S_IRWXU|CYG_HAL_SYS_S_IRWXG|CYG_HAL_SYS_S_IRWXO);
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
106 CYG_ASSERT( priv->flashfd >= 0,
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
107 "Opening of the file for the synth flash failed!");
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
108 // fill with 0xff
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
109 memset( buf, 0xff, sizeof(buf) );
1756
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
110 bytesleft = priv->block_size * priv->blocks +
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
111 priv->boot_block_size * priv->boot_blocks;
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
112
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
113 while (bytesleft > 0) {
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
114 int bytesneeded;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
115 bytesneeded = bytesleft < sizeof(buf) ?
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
116 bytesleft : sizeof(buf);
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
117
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
118 w = cyg_hal_sys_write( priv->flashfd, buf,
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
119 bytesneeded );
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
120 CYG_ASSERT(w == bytesneeded,
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
121 "initialization of flash file failed");
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
122 bytesleft -= bytesneeded;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
123 } // while
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
124 }
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
125 CYG_ASSERT( priv->flashfd >= 0,
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
126 "Opening of the file for the synth flash failed!");
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
127 if ( priv->flashfd <= 0 ) {
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
128 return CYG_FLASH_ERR_HWR;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
129 }
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
130
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
131 if (dev->start != 0) {
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
132 flags |= CYG_HAL_SYS_MAP_FIXED;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
133 }
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
134 base = (cyg_flashaddr_t)cyg_hal_sys_do_mmap(
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
135 (void *)dev->start,
1756
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
136 priv->blocks * priv->block_size +
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
137 priv->boot_block_size * priv->boot_blocks,
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
138 CYG_HAL_SYS_PROT_READ,
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
139 flags,
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
140 priv->flashfd,
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
141 0l);
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
142 CYG_ASSERT( (int) base > 0, "mmap of flash file failed!" );
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
143 if (base <= 0) {
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
144 return CYG_FLASH_ERR_HWR;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
145 }
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
146 dev->start = base;
1756
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
147 dev->end = base + (priv->blocks * priv->block_size) +
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
148 (priv->boot_blocks * priv->boot_block_size) - 1;
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
149 if (priv->boot_blocks) {
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
150 if (priv->boot_block_bottom) {
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
151 priv->block_info[0].block_size = priv->boot_block_size;
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
152 priv->block_info[0].blocks = priv->boot_blocks;
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
153 priv->block_info[1].block_size = priv->block_size;
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
154 priv->block_info[1].blocks = priv->blocks;
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
155 } else {
1756
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
156 priv->block_info[0].block_size = priv->block_size;
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
157 priv->block_info[0].blocks = priv->blocks;
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
158 priv->block_info[1].block_size = priv->boot_block_size;
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
159 priv->block_info[1].blocks = priv->boot_blocks;
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
160 }
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
161 dev->num_block_infos = 2;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
162 } else {
1756
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
163 priv->block_info[0].block_size = priv->block_size;
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
164 priv->block_info[0].blocks = priv->blocks;
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
165 dev->num_block_infos = 1;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
166 }
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
167 dev->block_info = &priv->block_info[0];
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
168
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
169 return CYG_FLASH_ERR_OK;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
170 }
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
171
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
172 // Map a hardware status to a package error
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
173 static int
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
174 synth_flash_hwr_map_error(struct cyg_flash_dev *dev, int err)
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
175 {
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
176 return err;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
177 }
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
178
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
179 /* This helps speed up the erase. */
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
180 static char empty[4096];
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
181 static cyg_bool empty_inited = false;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
182
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
183 // Return the size of the block which is at the given address.
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
184 // __inline__ so that we know it will be in RAM, not ROM.
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
185 static __inline__ size_t
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
186 flash_block_size(struct cyg_flash_dev *dev, const cyg_flashaddr_t addr)
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
187 {
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
188 int i;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
189 size_t offset;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
190
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
191
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
192 CYG_ASSERT((addr >= dev->start) && (addr <= dev->end), "Not inside device");
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
193
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
194 offset = addr - dev->start;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
195 for (i=0; i < dev->num_block_infos; i++) {
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
196 if (offset < (dev->block_info[i].blocks * dev->block_info[i].block_size))
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
197 return dev->block_info[i].block_size;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
198 offset = offset -
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
199 (dev->block_info[i].blocks * dev->block_info[i].block_size);
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
200 }
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
201 CYG_FAIL("Programming error");
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
202 return 0;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
203 }
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
204
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
205 static int
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
206 synth_flash_erase_block(struct cyg_flash_dev *dev,
1756
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
207 cyg_flashaddr_t block_base)
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
208 {
1756
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
209 const struct cyg_flash_synth_priv *priv = dev->priv;
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
210 int offset = (int)block_base;
1724
a24dbf2587a3 * src/flash_synth.c: Allow the use of arbitary sized block.
asl
parents: 1702
diff changeset
211 size_t remaining;
a24dbf2587a3 * src/flash_synth.c: Allow the use of arbitary sized block.
asl
parents: 1702
diff changeset
212 int write_size;
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
213
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
214 offset -= dev->start;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
215
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
216 cyg_hal_sys_lseek(priv->flashfd, offset,
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
217 CYG_HAL_SYS_SEEK_SET);
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
218
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
219 if (!empty_inited) {
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
220 memset(empty, 0xff, sizeof(empty));
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
221 empty_inited = true;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
222 }
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
223
1724
a24dbf2587a3 * src/flash_synth.c: Allow the use of arbitary sized block.
asl
parents: 1702
diff changeset
224 remaining = flash_block_size(dev, block_base);
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
225
1724
a24dbf2587a3 * src/flash_synth.c: Allow the use of arbitary sized block.
asl
parents: 1702
diff changeset
226 while (remaining) {
a24dbf2587a3 * src/flash_synth.c: Allow the use of arbitary sized block.
asl
parents: 1702
diff changeset
227 write_size = MIN(remaining, sizeof(empty));
a24dbf2587a3 * src/flash_synth.c: Allow the use of arbitary sized block.
asl
parents: 1702
diff changeset
228 cyg_hal_sys_write(priv->flashfd, empty, write_size);
a24dbf2587a3 * src/flash_synth.c: Allow the use of arbitary sized block.
asl
parents: 1702
diff changeset
229 remaining -= write_size;
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
230 }
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
231 return CYG_FLASH_ERR_OK;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
232 }
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
233
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
234 static int
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
235 synth_flash_program (struct cyg_flash_dev *dev,
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
236 cyg_flashaddr_t base,
1756
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
237 const void* data, size_t len)
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
238 {
1756
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
239 const struct cyg_flash_synth_priv *priv = dev->priv;
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
240 int offset = base;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
241 offset -= dev->start;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
242
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
243 cyg_hal_sys_lseek(priv->flashfd, offset, CYG_HAL_SYS_SEEK_SET);
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
244 cyg_hal_sys_write(priv->flashfd, data, len);
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
245
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
246 return CYG_FLASH_ERR_OK;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
247 }
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
248
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
249 #define QUERY "Linux Synthetic Flash"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
250
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
251 static size_t
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
252 synth_flash_query(struct cyg_flash_dev *dev, void * data,
1756
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
253 size_t len)
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
254 {
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
255 memcpy(data,QUERY,sizeof(QUERY));
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
256 return sizeof(QUERY);
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
257 }
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
258
1756
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
259 const CYG_FLASH_FUNS(cyg_flash_synth_funs,
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
260 synth_flash_init,
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
261 synth_flash_query,
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
262 synth_flash_erase_block,
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
263 synth_flash_program,
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
264 NULL, // read
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
265 synth_flash_hwr_map_error,
1762
9c1d9e5039c2 Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents: 1756
diff changeset
266 cyg_flash_devfn_lock_nop,
9c1d9e5039c2 Move dummy init/query/lock/unlock functions to the generic flash code,
bartv
parents: 1756
diff changeset
267 cyg_flash_devfn_unlock_nop);
1756
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
268
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
269 static struct cyg_flash_synth_priv synth_flash_priv = {
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
270 .block_size = CYGNUM_FLASH_SYNTH_V2_BLOCKSIZE,
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
271 .blocks = CYGNUM_FLASH_SYNTH_V2_NUMBLOCKS,
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
272 .boot_block_size = CYGNUM_FLASH_SYNTH_V2_BOOT_BLOCKSIZE,
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
273 .boot_blocks = CYGNUM_FLASH_SYNTH_V2_NUMBOOT_BLOCKS,
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
274 .boot_block_bottom = CYGNUM_FLASH_SYNTH_V2_BOOT_BLOCK_BOTTOM,
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
275 .filename = CYGDAT_FLASH_SYNTH_V2_FILENAME,
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
276 .flashfd = -1
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
277 };
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
278
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
279 CYG_FLASH_DRIVER(cyg_flash_synth_flashdev,
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
280 &cyg_flash_synth_funs,
1756
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
281 0, // flags
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
282 CYGMEM_FLASH_SYNTH_V2_BASE, // Start, if 0 will be updated by init
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
283 0, // end, filled in by init
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
284 0, // number of block_info's, filled in by init
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
285 synth_flash_priv.block_info,
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1728
diff changeset
286 &synth_flash_priv);
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
287
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
288 // EOF synth.c