annotate packages/infra/current/tests/fc_test.c @ 1777:c16341b1bac6 default tip

* Added execute permissions to files missed in conversion from CVS
author alexs
date Mon, 12 Oct 2009 02:26:09 +0100
parents 9bf998a57d30
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1452
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
1 //==========================================================================
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
2 //
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
3 // fc_test.c
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
4 //
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
5 // Test/demonstration of using RedBoot 'fconfig' from eCos
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
6 //
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
7 //==========================================================================
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
8 //####ECOSGPLCOPYRIGHTBEGIN####
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
9 // -------------------------------------------
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
10 // This file is part of eCos, the Embedded Configurable Operating System.
1457
9bf998a57d30 Handle changes in FLASH CFG API
gthomas
parents: 1452
diff changeset
11 // Copyright (C) 2003, 2004 Gary Thomas
1452
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
12 //
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
13 // eCos is free software; you can redistribute it and/or modify it under
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
14 // the terms of the GNU General Public License as published by the Free
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
15 // Software Foundation; either version 2 or (at your option) any later version.
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
16 //
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
19 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
20 // for more details.
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
21 //
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
22 // You should have received a copy of the GNU General Public License along
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
25 //
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
26 // As a special exception, if other files instantiate templates or use macros
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
27 // or inline functions from this file, or you compile this file and link it
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
28 // with other works to produce a work based on this file, this file does not
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
29 // by itself cause the resulting work to be covered by the GNU General Public
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
30 // License. However the source code for this file must still be made available
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
31 // in accordance with section (3) of the GNU General Public License.
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
32 //
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
33 // This exception does not invalidate any other reasons why a work based on
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
34 // this file might be covered by the GNU General Public License.
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
35 //
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
37 // at http://sources.redhat.com/ecos/ecos-license/
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
38 // -------------------------------------------
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
39 //####ECOSGPLCOPYRIGHTEND####
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
40 //==========================================================================
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
41 //#####DESCRIPTIONBEGIN####
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
42 //
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
43 // Author(s): gthomas
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
44 // Contributors: gthomas
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
45 // Date: 2003-12-22
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
46 // Purpose:
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
47 // Description:
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
48 //
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
49 //####DESCRIPTIONEND####
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
50 //
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
51 //==========================================================================
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
52
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
53 //
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
54 // Demonstration of how to use virtual vector interfaces to access/modify
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
55 // persistent data stored by 'fconfig' command in RedBoot.
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
56 //
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
57 // Note: there is currently no support for adding new keys using this
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
58 // mechanism. Only existing key/value pairs may be updated.
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
59 //
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
60 #include <pkgconf/hal.h>
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
61 #include <cyg/hal/hal_if.h>
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
62 #include <cyg/infra/diag.h>
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
63
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
64 void
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
65 main(void)
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
66 {
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
67 struct cyg_fconfig fc;
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
68 char key[64];
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
69 int port;
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
70
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
71 diag_printf("fconfig test started\n");
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
72 fc.offset = 0;
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
73 fc.key = key;
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
74 fc.keylen = sizeof(key);
1457
9bf998a57d30 Handle changes in FLASH CFG API
gthomas
parents: 1452
diff changeset
75 while (CYGACC_CALL_IF_FLASH_CFG_OP2(CYGNUM_CALL_IF_FLASH_CFG_NEXT, &fc)) {
1452
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
76 diag_printf(" Offset: %d, key: '%s', type: %d\n", fc.offset, fc.key, fc.type);
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
77 fc.keylen = sizeof(key);
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
78 }
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
79 // Try and update a data value
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
80 fc.key = "gdb_port";
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
81 fc.val = &port;
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
82 fc.type = CYGNUM_FLASH_CFG_TYPE_CONFIG_INT;
1457
9bf998a57d30 Handle changes in FLASH CFG API
gthomas
parents: 1452
diff changeset
83 if (CYGACC_CALL_IF_FLASH_CFG_OP2(CYGNUM_CALL_IF_FLASH_CFG_GET, &fc)) {
1452
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
84 diag_printf("gdb_port = %d\n", port);
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
85 port++;
1457
9bf998a57d30 Handle changes in FLASH CFG API
gthomas
parents: 1452
diff changeset
86 if (CYGACC_CALL_IF_FLASH_CFG_OP2(CYGNUM_CALL_IF_FLASH_CFG_SET, &fc)) {
9bf998a57d30 Handle changes in FLASH CFG API
gthomas
parents: 1452
diff changeset
87 if (CYGACC_CALL_IF_FLASH_CFG_OP2(CYGNUM_CALL_IF_FLASH_CFG_GET, &fc)) {
1452
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
88 diag_printf("now = %d\n", port);
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
89 } else {
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
90 diag_printf("Can't re-fetch 'gdb_port'\n");
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
91 exit(1);
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
92 }
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
93 port--;
1457
9bf998a57d30 Handle changes in FLASH CFG API
gthomas
parents: 1452
diff changeset
94 if (!CYGACC_CALL_IF_FLASH_CFG_OP2(CYGNUM_CALL_IF_FLASH_CFG_SET, &fc)) {
1452
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
95 diag_printf("Can't update 'gdb_port'\n");
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
96 exit(1);
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
97 }
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
98 } else {
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
99 diag_printf("Can't update 'gdb_port'\n");
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
100 exit(1);
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
101 }
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
102 } else {
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
103 diag_printf("Fetch 'gdb_port' failed\n");
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
104 exit(1);
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
105 }
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
106 diag_printf("... done\n");
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
107 exit(1);
c15fe26f81c7 Expand fconfig access via virtual vectors.
gthomas
parents:
diff changeset
108 }