source: SVN/cambria/redboot/packages/infra/current/tests/fc_test.c @ 1

Last change on this file since 1 was 1, checked in by Tim Harvey, 2 years ago

restored latest version of files from server backup

Signed-off-by: Tim Harvey <tharvey@…>

File size: 4.0 KB
Line 
1//==========================================================================
2//
3//      fc_test.c
4//
5//      Test/demonstration of using RedBoot 'fconfig' from eCos
6//
7//==========================================================================
8//####ECOSGPLCOPYRIGHTBEGIN####
9// -------------------------------------------
10// This file is part of eCos, the Embedded Configurable Operating System.
11// Copyright (C) 2003, 2004 Gary Thomas
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):    gthomas
44// Contributors: gthomas
45// Date:         2003-12-22
46// Purpose:     
47// Description: 
48//             
49//####DESCRIPTIONEND####
50//
51//==========================================================================
52
53//
54// Demonstration of how to use virtual vector interfaces to access/modify
55// persistent data stored by 'fconfig' command in RedBoot.
56//
57// Note: there is currently no support for adding new keys using this
58// mechanism.  Only existing key/value pairs may be updated.
59//
60#include <pkgconf/hal.h>
61#include <cyg/hal/hal_if.h>
62#include <cyg/infra/diag.h>
63
64void
65main(void)
66{
67    struct cyg_fconfig fc;
68    char key[64];
69    int port;
70
71    diag_printf("fconfig test started\n");
72    fc.offset = 0;
73    fc.key = key;
74    fc.keylen = sizeof(key);
75    while (CYGACC_CALL_IF_FLASH_CFG_OP2(CYGNUM_CALL_IF_FLASH_CFG_NEXT, &fc)) {
76        diag_printf("  Offset: %d, key: '%s', type: %d\n", fc.offset, fc.key, fc.type);
77        fc.keylen = sizeof(key);
78    }
79    // Try and update a data value
80    fc.key = "gdb_port";
81    fc.val = &port;
82    fc.type = CYGNUM_FLASH_CFG_TYPE_CONFIG_INT;
83    if (CYGACC_CALL_IF_FLASH_CFG_OP2(CYGNUM_CALL_IF_FLASH_CFG_GET, &fc)) {
84        diag_printf("gdb_port = %d\n", port);
85        port++;
86        if (CYGACC_CALL_IF_FLASH_CFG_OP2(CYGNUM_CALL_IF_FLASH_CFG_SET, &fc)) {
87            if (CYGACC_CALL_IF_FLASH_CFG_OP2(CYGNUM_CALL_IF_FLASH_CFG_GET, &fc)) {
88                diag_printf("now = %d\n", port);
89            } else {
90                diag_printf("Can't re-fetch 'gdb_port'\n");
91                exit(1);
92            }
93            port--;
94            if (!CYGACC_CALL_IF_FLASH_CFG_OP2(CYGNUM_CALL_IF_FLASH_CFG_SET, &fc)) {
95                diag_printf("Can't update 'gdb_port'\n");
96                exit(1);
97            }
98        } else {
99            diag_printf("Can't update 'gdb_port'\n");
100            exit(1);
101        }
102    } else {
103        diag_printf("Fetch 'gdb_port' failed\n");
104        exit(1);
105    }
106    diag_printf("... done\n");
107    exit(1);
108}
Note: See TracBrowser for help on using the repository browser.