Mercurial > ecos
comparison packages/devs/flash/synth/current/src/synth.c @ 202:353a011b23b8
Merge from eCos master repository on 2002-01-11-06:43:03-GMT
| author | jlarmour |
|---|---|
| date | Fri, 11 Jan 2002 16:53:46 +0000 |
| parents | |
| children | e0c0827131d1 |
comparison
equal
deleted
inserted
replaced
| 201:dd81b18e45fb | 202:353a011b23b8 |
|---|---|
| 1 //========================================================================== | |
| 2 // | |
| 3 // synth.c | |
| 4 // | |
| 5 // Flash programming | |
| 6 // | |
| 7 //========================================================================== | |
| 8 //####COPYRIGHTBEGIN#### | |
| 9 // | |
| 10 // ------------------------------------------- | |
| 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. | |
| 27 // All Rights Reserved. | |
| 28 // ------------------------------------------- | |
| 29 // | |
| 30 //####COPYRIGHTEND#### | |
| 31 //========================================================================== | |
| 32 //#####DESCRIPTIONBEGIN#### | |
| 33 // | |
| 34 // Author(s): andrew.lunn@ascom.ch | |
| 35 // Contributors: jlarmour | |
| 36 // Date: 2001-10-30 | |
| 37 // Purpose: | |
| 38 // Description: | |
| 39 // | |
| 40 //####DESCRIPTIONEND#### | |
| 41 // | |
| 42 //========================================================================== | |
| 43 | |
| 44 #include <pkgconf/devs_flash_synth.h> | |
| 45 | |
| 46 #include <cyg/hal/hal_io.h> | |
| 47 #include <cyg/infra/cyg_ass.h> | |
| 48 | |
| 49 #define _FLASH_PRIVATE_ | |
| 50 #include <cyg/io/flash.h> | |
| 51 | |
| 52 #include "synth.h" | |
| 53 | |
| 54 /* Holds the fd for the flash file */ | |
| 55 int cyg_dev_flash_synth_flashfd; | |
| 56 | |
| 57 /* Holds the base address of the mmap'd region */ | |
| 58 flash_t *cyg_dev_flash_synth_base; | |
| 59 | |
| 60 /* Helper function. The Linux system call cannot pass 6 parameters. Instead | |
| 61 a structure is filled in and passed as one parameter */ | |
| 62 static int | |
| 63 cyg_hal_sys_do_mmap(void *addr, unsigned long length, unsigned long prot, | |
| 64 unsigned long flags, unsigned long fd, unsigned long off) | |
| 65 { | |
| 66 | |
| 67 struct cyg_hal_sys_mmap_args args; | |
| 68 | |
| 69 args.addr = (unsigned long) addr; | |
| 70 args.len = length; | |
| 71 args.prot = prot = prot; | |
| 72 args.flags = flags; | |
| 73 args.fd = fd; | |
| 74 args.offset = off; | |
| 75 | |
| 76 return (cyg_hal_sys_mmap(&args)); | |
| 77 } | |
| 78 | |
| 79 int | |
| 80 flash_hwr_init(void) | |
| 81 { | |
| 82 flash_info.block_size = CYGNUM_FLASH_SYNTH_BLOCKSIZE; | |
| 83 flash_info.buffer_size = 0; | |
| 84 flash_info.blocks = CYGNUM_FLASH_SYNTH_NUMBLOCKS; | |
| 85 | |
| 86 cyg_dev_flash_synth_flashfd = cyg_hal_sys_open(CYGDAT_FLASH_SYNTH_FILENAME, | |
| 87 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); | |
| 89 CYG_ASSERT( cyg_dev_flash_synth_flashfd >= 0, | |
| 90 "Opening of the file for the synth flash failed!"); | |
| 91 if ( cyg_dev_flash_synth_flashfd <= 0 ) { | |
| 92 return FLASH_ERR_HWR; | |
| 93 } | |
| 94 cyg_dev_flash_synth_base = cyg_hal_sys_do_mmap( NULL, | |
| 95 (CYGNUM_FLASH_SYNTH_BLOCKSIZE * CYGNUM_FLASH_SYNTH_NUMBLOCKS), | |
| 96 CYG_HAL_SYS_PROT_READ, CYG_HAL_SYS_MAP_PRIVATE, | |
| 97 cyg_dev_flash_synth_flashfd, | |
| 98 0 ); | |
| 99 CYG_ASSERT( cyg_dev_flash_synth_base > 0, "mmap of flash file failed!" ); | |
| 100 | |
| 101 if (cyg_dev_flash_synth_base <= 0) { | |
| 102 return FLASH_ERR_HWR; | |
| 103 } | |
| 104 flash_info.start = cyg_dev_flash_synth_base; | |
| 105 flash_info.end = (void *)(((char *)cyg_dev_flash_synth_base) + | |
| 106 (CYGNUM_FLASH_SYNTH_BLOCKSIZE * CYGNUM_FLASH_SYNTH_NUMBLOCKS)); | |
| 107 | |
| 108 return FLASH_ERR_OK; | |
| 109 } | |
| 110 | |
| 111 // Map a hardware status to a package error | |
| 112 int | |
| 113 flash_hwr_map_error(int err) | |
| 114 { | |
| 115 return err; | |
| 116 } | |
| 117 | |
| 118 // See if a range of FLASH addresses overlaps currently running code | |
| 119 bool | |
| 120 flash_code_overlaps(void *start, void *end) | |
| 121 { | |
| 122 extern char _stext[], _etext[]; | |
| 123 | |
| 124 return ((((unsigned long)&_stext >= (unsigned long)start) && | |
| 125 ((unsigned long)&_stext < (unsigned long)end)) || | |
| 126 (((unsigned long)&_etext >= (unsigned long)start) && | |
| 127 ((unsigned long)&_etext < (unsigned long)end))); | |
| 128 } | |
| 129 | |
| 130 // EOF synth.c |
