comparison packages/devs/flash/synth/current/src/synth.c @ 208:e0c0827131d1 ecos

Merge from eCos master repository on 2002-05-20-20:11:54-BST
author jlarmour
date Mon, 20 May 2002 22:19:26 +0000
parents 353a011b23b8
children d2c90368aeef
comparison
equal deleted inserted replaced
207:74c807ddde34 208:e0c0827131d1
3 // synth.c 3 // synth.c
4 // 4 //
5 // Flash programming 5 // Flash programming
6 // 6 //
7 //========================================================================== 7 //==========================================================================
8 //####COPYRIGHTBEGIN#### 8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // 9 // -------------------------------------------
10 // ------------------------------------------- 10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // The contents of this file are subject to the Red Hat eCos Public License
12 // Version 1.1 (the "License"); you may not use this file except in
13 // compliance with the License. You may obtain a copy of the License at
14 // http://www.redhat.com/
15 //
16 // Software distributed under the License is distributed on an "AS IS"
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
18 // License for the specific language governing rights and limitations under
19 // the License.
20 //
21 // The Original Code is eCos - Embedded Configurable Operating System,
22 // released September 30, 1998.
23 //
24 // The Initial Developer of the Original Code is Red Hat.
25 // Portions created by Red Hat are
26 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. 11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
27 // All Rights Reserved. 12 //
28 // ------------------------------------------- 13 // eCos is free software; you can redistribute it and/or modify it under
29 // 14 // the terms of the GNU General Public License as published by the Free
30 //####COPYRIGHTEND#### 15 // Software Foundation; either version 2 or (at your option) any later version.
16 //
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 // for more details.
21 //
22 // You should have received a copy of the GNU General Public License along
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25 //
26 // As a special exception, if other files instantiate templates or use macros
27 // or inline functions from this file, or you compile this file and link it
28 // with other works to produce a work based on this file, this file does not
29 // by itself cause the resulting work to be covered by the GNU General Public
30 // License. However the source code for this file must still be made available
31 // in accordance with section (3) of the GNU General Public License.
32 //
33 // This exception does not invalidate any other reasons why a work based on
34 // this file might be covered by the GNU General Public License.
35 //
36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37 // at http://sources.redhat.com/ecos/ecos-license
38 // -------------------------------------------
39 //####ECOSGPLCOPYRIGHTEND####
31 //========================================================================== 40 //==========================================================================
32 //#####DESCRIPTIONBEGIN#### 41 //#####DESCRIPTIONBEGIN####
33 // 42 //
34 // Author(s): andrew.lunn@ascom.ch 43 // Author(s): andrew.lunn@ascom.ch
35 // Contributors: jlarmour 44 // Contributors: jlarmour
43 52
44 #include <pkgconf/devs_flash_synth.h> 53 #include <pkgconf/devs_flash_synth.h>
45 54
46 #include <cyg/hal/hal_io.h> 55 #include <cyg/hal/hal_io.h>
47 #include <cyg/infra/cyg_ass.h> 56 #include <cyg/infra/cyg_ass.h>
57 #include <errno.h>
58 #include <string.h>
48 59
49 #define _FLASH_PRIVATE_ 60 #define _FLASH_PRIVATE_
50 #include <cyg/io/flash.h> 61 #include <cyg/io/flash.h>
51 62
52 #include "synth.h" 63 #include "synth.h"
82 flash_info.block_size = CYGNUM_FLASH_SYNTH_BLOCKSIZE; 93 flash_info.block_size = CYGNUM_FLASH_SYNTH_BLOCKSIZE;
83 flash_info.buffer_size = 0; 94 flash_info.buffer_size = 0;
84 flash_info.blocks = CYGNUM_FLASH_SYNTH_NUMBLOCKS; 95 flash_info.blocks = CYGNUM_FLASH_SYNTH_NUMBLOCKS;
85 96
86 cyg_dev_flash_synth_flashfd = cyg_hal_sys_open(CYGDAT_FLASH_SYNTH_FILENAME, 97 cyg_dev_flash_synth_flashfd = cyg_hal_sys_open(CYGDAT_FLASH_SYNTH_FILENAME,
98 CYG_HAL_SYS_O_RDWR,
99 CYG_HAL_SYS_S_IRWXU|CYG_HAL_SYS_S_IRWXG|CYG_HAL_SYS_S_IRWXO);
100 if (cyg_dev_flash_synth_flashfd == -ENOENT) {
101 long w, bytesleft;
102 char buf[128];
103
104 cyg_dev_flash_synth_flashfd = cyg_hal_sys_open(
105 CYGDAT_FLASH_SYNTH_FILENAME,
87 CYG_HAL_SYS_O_RDWR|CYG_HAL_SYS_O_CREAT, 106 CYG_HAL_SYS_O_RDWR|CYG_HAL_SYS_O_CREAT,
88 CYG_HAL_SYS_S_IRWXU|CYG_HAL_SYS_S_IRWXG|CYG_HAL_SYS_S_IRWXO); 107 CYG_HAL_SYS_S_IRWXU|CYG_HAL_SYS_S_IRWXG|CYG_HAL_SYS_S_IRWXO);
108 CYG_ASSERT( cyg_dev_flash_synth_flashfd >= 0,
109 "Opening of the file for the synth flash failed!");
110 // fill with 0xff
111 memset( buf, 0xff, sizeof(buf) );
112 bytesleft = CYGNUM_FLASH_SYNTH_BLOCKSIZE * CYGNUM_FLASH_SYNTH_NUMBLOCKS;
113 while (bytesleft > 0)
114 {
115 int bytesneeded;
116 bytesneeded = bytesleft < sizeof(buf) ? bytesleft : sizeof(buf);
117
118 w = cyg_hal_sys_write( cyg_dev_flash_synth_flashfd, buf,
119 bytesneeded );
120 CYG_ASSERT(w == bytesneeded, "initialization of flash file failed");
121 bytesleft -= bytesneeded;
122 } // while
123 }
89 CYG_ASSERT( cyg_dev_flash_synth_flashfd >= 0, 124 CYG_ASSERT( cyg_dev_flash_synth_flashfd >= 0,
90 "Opening of the file for the synth flash failed!"); 125 "Opening of the file for the synth flash failed!");
91 if ( cyg_dev_flash_synth_flashfd <= 0 ) { 126 if ( cyg_dev_flash_synth_flashfd <= 0 ) {
92 return FLASH_ERR_HWR; 127 return FLASH_ERR_HWR;
93 } 128 }
94 cyg_dev_flash_synth_base = cyg_hal_sys_do_mmap( NULL, 129 cyg_dev_flash_synth_base = (flash_t *)cyg_hal_sys_do_mmap(
130 #ifdef CYGMEM_FLASH_SYNTH_BASE
131 CYGMEM_FLASH_SYNTH_BASE,
132 #else
133 NULL,
134 #endif
95 (CYGNUM_FLASH_SYNTH_BLOCKSIZE * CYGNUM_FLASH_SYNTH_NUMBLOCKS), 135 (CYGNUM_FLASH_SYNTH_BLOCKSIZE * CYGNUM_FLASH_SYNTH_NUMBLOCKS),
96 CYG_HAL_SYS_PROT_READ, CYG_HAL_SYS_MAP_PRIVATE, 136 CYG_HAL_SYS_PROT_READ,
97 cyg_dev_flash_synth_flashfd, 137 #ifdef CYGSEM_FLASH_SYNTH_FILE_WRITEBACK
98 0 ); 138 CYG_HAL_SYS_MAP_SHARED
139 #else
140 CYG_HAL_SYS_MAP_PRIVATE
141 #endif
142 #ifdef CYGMEM_FLASH_SYNTH_BASE
143 |CYG_HAL_SYS_MAP_FIXED
144 #endif
145 , cyg_dev_flash_synth_flashfd, 0 );
99 CYG_ASSERT( cyg_dev_flash_synth_base > 0, "mmap of flash file failed!" ); 146 CYG_ASSERT( cyg_dev_flash_synth_base > 0, "mmap of flash file failed!" );
100 147
101 if (cyg_dev_flash_synth_base <= 0) { 148 if (cyg_dev_flash_synth_base <= 0) {
102 return FLASH_ERR_HWR; 149 return FLASH_ERR_HWR;
103 } 150 }