Mercurial > flash_v2
annotate packages/io/flash/current/src/legacy_api.c @ 1765:bfd6d67dba43
V2 flash. Miscellaneous fixes to the legacy API and legacy device
driver support
| author | bartv |
|---|---|
| date | Tue, 22 Feb 2005 23:21:12 +0000 |
| parents | 96ec7e534d98 |
| children | 79275fdb4f20 |
| rev | line source |
|---|---|
| 1706 | 1 //========================================================================== |
| 2 // | |
| 3 // legacy_api.c | |
| 4 // | |
| 5 // Legacy API implementation on top of the new API | |
| 6 // | |
| 7 //========================================================================== | |
| 8 //####ECOSGPLCOPYRIGHTBEGIN#### | |
| 9 // ------------------------------------------- | |
| 10 // This file is part of eCos, the Embedded Configurable Operating System. | |
| 11 // Copyright (C) 2004 Andrew Lunn | |
| 12 // | |
| 13 // eCos is free software; you can redistribute it and/or modify it under | |
| 14 // the terms of the GNU General Public License as published by the Free | |
| 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#### | |
| 40 //========================================================================== | |
| 41 //#####DESCRIPTIONBEGIN#### | |
| 42 // | |
| 43 // Author(s): Andrew Lunn | |
| 44 // Contributors: Andrew Lunn | |
| 45 // Date: 2004-07-02 | |
| 46 // Purpose: | |
| 47 // Description: Implement an interface to the legacy device drivers | |
| 48 // | |
| 49 //####DESCRIPTIONEND#### | |
| 50 // | |
| 51 //========================================================================== | |
| 52 | |
| 53 #include <pkgconf/system.h> | |
| 54 #include <pkgconf/io_flash.h> | |
| 55 | |
| 56 #include <cyg/io/flash.h> | |
| 57 | |
| 58 int | |
| 59 flash_init(_printf *pf) | |
| 60 { | |
| 61 return cyg_flash_init(pf); | |
| 62 } | |
| 63 | |
| 64 int | |
| 65 flash_verify_addr(void *target) | |
| 66 { | |
| 67 return cyg_flash_verify_addr((cyg_flashaddr_t) target); | |
| 68 } | |
| 69 | |
| 70 int | |
| 71 flash_get_limits(void *target, void **start, void **end) | |
| 72 { | |
| 1722 | 73 int err; |
| 74 cyg_flash_info_t info; | |
| 75 | |
| 76 err = cyg_flash_get_info(0, &info); | |
| 77 if (err != CYG_FLASH_ERR_OK) { | |
| 78 return err; | |
| 79 } | |
| 80 | |
| 81 *start = (void *)info.start; | |
| 82 *end = (void *)info.end; | |
| 83 | |
| 84 return CYG_FLASH_ERR_OK; | |
| 1706 | 85 } |
| 86 | |
| 1722 | 87 |
| 1706 | 88 int |
| 89 flash_get_block_info(int *block_size, int *blocks) | |
| 90 { | |
| 1722 | 91 size_t biggest_size=0; |
| 92 cyg_uint32 i; | |
| 93 cyg_flash_info_t info; | |
| 94 int err; | |
| 95 | |
| 96 err = cyg_flash_get_info(0, &info); | |
| 97 if (err != CYG_FLASH_ERR_OK) { | |
| 98 return err; | |
| 99 } | |
| 100 | |
| 101 // Find the biggest size of blocks | |
| 102 for (i=0; i < info.num_block_infos; i++) { | |
| 103 if (info.block_info[i].block_size > biggest_size) { | |
| 104 biggest_size = info.block_info[i].block_size; | |
| 105 } | |
| 106 } | |
| 107 | |
| 108 // Calculate the number of biggest size blocks | |
| 109 *block_size = biggest_size; | |
| 110 *blocks = 0; | |
| 111 for (i=0; i < info.num_block_infos; i++) { | |
| 112 *blocks += (info.block_info[i].block_size * | |
| 113 info.block_info[i].blocks) / | |
| 114 biggest_size; | |
| 115 } | |
| 116 return CYG_FLASH_ERR_OK; | |
| 1706 | 117 } |
| 118 | |
| 119 int | |
| 120 flash_erase(void *addr, int len, void **err_addr) | |
| 121 { | |
| 122 return cyg_flash_erase((cyg_flashaddr_t)addr, len, | |
| 123 (cyg_flashaddr_t *)err_addr); | |
| 124 } | |
| 125 | |
| 126 int flash_program(void *flash_base, void *ram_base, int len, | |
| 127 void **err_address) | |
| 128 { | |
| 129 return cyg_flash_program((cyg_flashaddr_t)flash_base, ram_base, | |
| 130 len, (cyg_flashaddr_t *)err_address); | |
| 131 } | |
| 132 | |
| 133 int flash_read(void *flash_base, void *ram_base, int len, void **err_address) | |
| 134 { | |
| 135 return cyg_flash_read((cyg_flashaddr_t)flash_base, ram_base, | |
| 136 len, (cyg_flashaddr_t *)err_address); | |
| 137 } | |
|
1765
bfd6d67dba43
V2 flash. Miscellaneous fixes to the legacy API and legacy device
bartv
parents:
1764
diff
changeset
|
138 |
|
bfd6d67dba43
V2 flash. Miscellaneous fixes to the legacy API and legacy device
bartv
parents:
1764
diff
changeset
|
139 char *flash_errmsg(int err) |
|
bfd6d67dba43
V2 flash. Miscellaneous fixes to the legacy API and legacy device
bartv
parents:
1764
diff
changeset
|
140 { |
|
bfd6d67dba43
V2 flash. Miscellaneous fixes to the legacy API and legacy device
bartv
parents:
1764
diff
changeset
|
141 return (char *)cyg_flash_errmsg(err); |
|
bfd6d67dba43
V2 flash. Miscellaneous fixes to the legacy API and legacy device
bartv
parents:
1764
diff
changeset
|
142 } |
|
bfd6d67dba43
V2 flash. Miscellaneous fixes to the legacy API and legacy device
bartv
parents:
1764
diff
changeset
|
143 |
|
bfd6d67dba43
V2 flash. Miscellaneous fixes to the legacy API and legacy device
bartv
parents:
1764
diff
changeset
|
144 // EOF legacy_api.c |
