OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [devs/] [flash/] [synthv2/] [current/] [tests/] [flash1.c] - Blame information for rev 838

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
/* Hey, the copyright is usefull for something! */
2
 
3
static char copyright[] =
4
"//=========================================================================="
5
"//"
6
"//      flash1.c"
7
"//"
8
"//      Test flash operations for the synth target synth flash driver"
9
"//"
10
"//=========================================================================="
11
"// ####ECOSGPLCOPYRIGHTBEGIN####                                          "
12
"// -------------------------------------------                            "
13
"// This file is part of eCos, the Embedded Configurable Operating System. "
14
"// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. "
15
"//                                                                   "
16
"// eCos is free software; you can redistribute it and/or modify it under  "
17
"// the terms of the GNU General Public License as published by the Free   "
18
"// Software Foundation; either version 2 or (at your option) any later    "
19
"// version.                                                               "
20
"//                                                                   "
21
"// eCos is distributed in the hope that it will be useful, but WITHOUT    "
22
"// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or  "
23
"// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License  "
24
"// for more details.                                                      "
25
"//                                                                   "
26
"// You should have received a copy of the GNU General Public License      "
27
"// along with eCos; if not, write to the Free Software Foundation, Inc.,  "
28
"// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.          "
29
"//                                                                   "
30
"// As a special exception, if other files instantiate templates or use    "
31
"// macros or inline functions from this file, or you compile this file    "
32
"// and link it with other works to produce a work based on this file,     "
33
"// this file does not by itself cause the resulting work to be covered by "
34
"// the GNU General Public License. However the source code for this file  "
35
"// must still be made available in accordance with section (3) of the GNU "
36
"// General Public License v2.                                             "
37
"//                                                                   "
38
"// This exception does not invalidate any other reasons why a work based  "
39
"// on this file might be covered by the GNU General Public License.       "
40
"// -------------------------------------------                            "
41
"// ####ECOSGPLCOPYRIGHTEND####                                            "
42
"//=========================================================================="
43
"//#####DESCRIPTIONBEGIN####"
44
"//"
45
"// Author(s):           andrew.lunn@ascom.ch"
46
"// Contributors:        andrew.lunn"
47
"// Date:                2000-10-31"
48
"// Purpose:             Test a flash driver"
49
"// Description:         Try out a number of flash operations and make sure"
50
"//                      what is in the flash is what we expeect."
51
"//                      "
52
"//####DESCRIPTIONEND####"
53
"//"
54
"//=========================================================================="
55
;
56
 
57
#include <cyg/io/flash.h>
58
#include <cyg/infra/testcase.h>
59
#include <cyg/infra/diag.h>
60
 
61
#include <string.h>
62
 
63
#ifndef CYGINT_ISO_STRING_STRFUNCS
64
# define NA_MSG "Need string functions for test"
65
#endif
66
#ifndef CYGSEM_IO_FLASH_LEGACY_API
67
# define NA_MSG "Need legacy IO FLASH API for test"
68
#endif
69
 
70
#ifdef NA_MSG
71
void cyg_user_start(void)
72
{
73
    CYG_TEST_INIT();
74
    CYG_TEST_NA( NA_MSG );
75
}
76
#else
77
 
78
//==========================================================================
79
// main
80
 
81
void cyg_user_start(void)
82
{
83
    int ret;
84
#ifdef CYGHWR_IO_FLASH_DEVICE_LEGACY
85
    char data[1024];
86
#endif
87
    void *flash_start, *flash_end;
88
    int block_size, blocks;
89
    char *prog_start;
90
    unsigned char * ptr;
91
 
92
    CYG_TEST_INIT();
93
 
94
    ret=flash_init((_printf *)diag_printf);
95
 
96
    CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_init");
97
 
98
#ifdef CYGHWR_IO_FLASH_DEVICE_LEGACY
99
    //Strictly speaking, this is a device driver call, not a user API call.
100
    flash_dev_query(data);
101
    CYG_TEST_PASS_FAIL(!strncmp(data,"Linux Synthetic Flash",sizeof(data)),
102
                       "flash_query");
103
#endif
104
    ret = flash_get_limits(NULL,&flash_start,&flash_end);
105
    CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_get_limits");
106
 
107
    ret = flash_get_block_info(&block_size, &blocks);
108
    CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_get_block_info");
109
 
110
    /* Erase the whole flash. Not recommended on real hardware since this
111
     will probably erase the bootloader etc!!! */
112
    ret=flash_erase(flash_start,block_size * blocks,NULL);
113
    CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_erase1");
114
 
115
    /* check that its actually been erased, and test the mmap area */
116
    for (ptr=flash_start,ret=0; ptr < (unsigned char *)flash_end; ptr++) {
117
        if (*ptr != 0xff) {
118
            ret++;
119
        }
120
    }
121
 
122
    CYG_TEST_PASS_FAIL((ret == 0),"flash empty check");
123
 
124
    ret = flash_program(flash_start,&copyright,sizeof(copyright),NULL);
125
    CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_program1");
126
 
127
    /* Check the contents made it into the flash */
128
    CYG_TEST_PASS_FAIL(!strncmp(flash_start,copyright,sizeof(copyright)),
129
                       "flash program contents");
130
 
131
    /* .. and check nothing else changed */
132
    for (ptr=(unsigned char *)flash_start+sizeof(copyright),ret=0;
133
         ptr < (unsigned char *)flash_end; ptr++) {
134
        if (*ptr != 0xff) {
135
            ret++;
136
        }
137
    }
138
 
139
    CYG_TEST_PASS_FAIL((ret == 0),"flash program overrun check");
140
 
141
    /* Program over a block boundary */
142
    prog_start = (char *)flash_start + block_size - sizeof(copyright)/2;
143
    ret = flash_program(prog_start,&copyright,sizeof(copyright),NULL);
144
    CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_program2");
145
 
146
    /* Check the first version is still OK */
147
    CYG_TEST_PASS_FAIL(!strncmp(flash_start,copyright,sizeof(copyright)),
148
                       "Original contents");
149
 
150
    CYG_TEST_PASS_FAIL(!strncmp(prog_start,copyright,sizeof(copyright)),
151
                       "New program contents");
152
 
153
    /* Check the bit in between is still erased */
154
    for (ptr=(unsigned char *)flash_start+sizeof(copyright),ret=0;
155
         ptr < (unsigned char *)prog_start; ptr++) {
156
        if (*ptr != 0xff) {
157
            ret++;
158
        }
159
    }
160
    CYG_TEST_PASS_FAIL((ret == 0),"flash erase check1");
161
 
162
    /* Erase the second block and make sure the first is not erased */
163
    ret=flash_erase((void *)((unsigned)flash_start+block_size),
164
                    block_size,NULL);
165
    CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_erase2");
166
 
167
    /* Check the erase worked */
168
    for (ptr=(unsigned char *)flash_start+block_size,ret=0;
169
         ptr < (unsigned char *)flash_start+block_size*2; ptr++) {
170
        if (*ptr != 0xff) {
171
            ret++;
172
        }
173
    }
174
 
175
    CYG_TEST_PASS_FAIL((ret == 0), "flash erase check2");
176
 
177
    /* Lastly check the first half of the copyright message is still there */
178
    CYG_TEST_PASS_FAIL(!strncmp(prog_start,copyright,sizeof(copyright)/2),
179
                       "Block 1 OK");
180
 
181
#if 0
182
    /* This test it fatal! Its not run by default!
183
     Check the flash is read only, by trying to write to it. We expect
184
     to get an exception */
185
 
186
    *(char *)flash_start = 'a';
187
#endif
188
 
189
    CYG_TEST_PASS_FINISH("flash1");
190
}
191
 
192
#endif /* ifndef NA_MSG */
193
 
194
/* EOF flash1.c */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.