Mercurial > ecos
changeset 1452:c15fe26f81c7
Expand fconfig access via virtual vectors.
| author | gthomas |
|---|---|
| date | Sun, 21 Dec 2003 13:18:02 +0000 |
| parents | 077fd39935a2 |
| children | 0e3378e69a2a |
| files | packages/hal/common/current/ChangeLog packages/hal/common/current/include/hal_if.h packages/hal/common/current/src/hal_if.c packages/infra/current/ChangeLog packages/infra/current/src/tcdiag.cxx packages/infra/current/tests/fc_test.c |
| diffstat | 6 files changed, 175 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/packages/hal/common/current/ChangeLog +++ b/packages/hal/common/current/ChangeLog @@ -1,3 +1,9 @@ +2003-12-21 Gary Thomas <gary@mlbassoc.com> + + * src/hal_if.c (flash_config_op): + * include/hal_if.h: New expanded functions for RedBoot 'fconfig' + database. + 2003-09-04 Patrick Doyle <wpd@dtccom.com> * include/hal_if.h:
--- a/packages/hal/common/current/include/hal_if.h +++ b/packages/hal/common/current/include/hal_if.h @@ -12,7 +12,7 @@ // ------------------------------------------- // This file is part of eCos, the Embedded Configurable Operating System. // Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Red Hat, Inc. -// Copyright (C) 2002 Gary Thomas +// Copyright (C) 2002, 2003 Gary Thomas // // eCos is free software; you can redistribute it and/or modify it under // the terms of the GNU General Public License as published by the Free @@ -423,12 +423,21 @@ typedef void (__call_if_reset_t)(void); typedef int __call_if_console_interrupt_flag_t; typedef void (__call_if_delay_us_t)(cyg_int32 usecs); typedef void (__call_if_install_bpt_fn_t)(void *__epc); -typedef cyg_bool (__call_if_flash_cfg_op_fn_t)(int __oper, char *__key, - void *__val, int __type); typedef char *__call_if_monitor_version_t; typedef void (__call_if_monitor_return_t)(int status); -typedef cyg_bool (__call_if_flash_fis_op_fn_t)(int __oper, char *__name, - void *__val); +typedef cyg_bool (__call_if_flash_fis_op_fn_t)(int __oper, char *__name, void *__val); +// +// This structure is used to pass parameters to/from the fconfig routines. +// This allows a single virtual vector interface, with widely varying functionality +// +struct cyg_fconfig { + char *key; // Datum 'key' + int keylen; // Length of key + void *val; // Pointer to data + int type; // Type of datum + int offset; // Offset within data (used by _NEXT) +}; +typedef cyg_bool (__call_if_flash_cfg_op_fn_t)(int __oper, struct cyg_fconfig *__data); #ifndef CYGACC_CALL_IF_DEFINED @@ -637,12 +646,17 @@ static __inline__ _rt_ #define CYGACC_CALL_IF_INSTALL_BPT_FN_SET(_x_) \ hal_virtual_vector_table[CYGNUM_CALL_IF_INSTALL_BPT_FN]=(CYG_ADDRWORD)(_x_) -#define CYGACC_CALL_IF_FLASH_CFG_OP(_o_,_k_,_d_,_t_) \ - CYGACC_CALL_VV4(__call_if_flash_cfg_op_fn_t*, CYGNUM_CALL_IF_FLASH_CFG_OP, (_o_),(_k_),(_d_),(_t_)) -__call_VV4(CYGNUM_CALL_IF_FLASH_CFG_OP, __call_if_flash_cfg_op_fn_t, cyg_bool, int, char *, void *, int) +// +// Access persistent data store - kept in FLASH or EEPROM by RedBoot +// +#define CYGNUM_CALL_IF_FLASH_CFG_GET (0) // Get a particular fconfig key +#define CYGNUM_CALL_IF_FLASH_CFG_NEXT (1) // Enumerate keys (get the next one) +#define CYGNUM_CALL_IF_FLASH_CFG_SET (2) // Update particular fconfig key +#define CYGACC_CALL_IF_FLASH_CFG_OP(_o_,_d_) \ + CYGACC_CALL_VV2(__call_if_flash_cfg_op_fn_t*, CYGNUM_CALL_IF_FLASH_CFG_OP, (_o_),(_d_)) +__call_VV2(CYGNUM_CALL_IF_FLASH_CFG_OP, __call_if_flash_cfg_op_fn_t, cyg_bool, int, struct cyg_fconfig *) #define CYGACC_CALL_IF_FLASH_CFG_OP_SET(_x_) \ hal_virtual_vector_table[CYGNUM_CALL_IF_FLASH_CFG_OP]=(CYG_ADDRWORD)(_x_) -#define CYGNUM_CALL_IF_FLASH_CFG_GET (0) #define CYGACC_CALL_IF_MONITOR_RETURN(_u_) \ CYGACC_CALL_VV1(__call_if_monitor_return_t*, CYGNUM_CALL_IF_MONITOR_RETURN, (_u_)) @@ -666,13 +680,13 @@ static __inline__ _rt_ // These need to be kept uptodate with the (unadorned) masters // in RedBoot's flash_config.h: -#define CYGNUM_FLASH_CFG_OP_CONFIG_EMPTY 0 -#define CYGNUM_FLASH_CFG_OP_CONFIG_BOOL 1 -#define CYGNUM_FLASH_CFG_OP_CONFIG_INT 2 -#define CYGNUM_FLASH_CFG_OP_CONFIG_STRING 3 -#define CYGNUM_FLASH_CFG_OP_CONFIG_SCRIPT 4 -#define CYGNUM_FLASH_CFG_OP_CONFIG_IP 5 -#define CYGNUM_FLASH_CFG_OP_CONFIG_ESA 6 +#define CYGNUM_FLASH_CFG_TYPE_CONFIG_EMPTY 0 +#define CYGNUM_FLASH_CFG_TYPE_CONFIG_BOOL 1 +#define CYGNUM_FLASH_CFG_TYPE_CONFIG_INT 2 +#define CYGNUM_FLASH_CFG_TYPE_CONFIG_STRING 3 +#define CYGNUM_FLASH_CFG_TYPE_CONFIG_SCRIPT 4 +#define CYGNUM_FLASH_CFG_TYPE_CONFIG_IP 5 +#define CYGNUM_FLASH_CFG_TYPE_CONFIG_ESA 6 #endif // CYGACC_CALL_IF_DEFINED
--- a/packages/hal/common/current/src/hal_if.c +++ b/packages/hal/common/current/src/hal_if.c @@ -9,7 +9,7 @@ // ------------------------------------------- // This file is part of eCos, the Embedded Configurable Operating System. // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. -// Copyright (C) 2002 Gary Thomas +// Copyright (C) 2002, 2003 Gary Thomas // Copyright (C) 2003 Nick Garnett <nickg@calivar.com> // Copyright (C) 2003 Jonathan Larmour <jlarmour@eCosCentric.com> // @@ -96,15 +96,21 @@ externC void init_thread_syscall(void * static __call_if_flash_cfg_op_fn_t flash_config_op; static cyg_bool -flash_config_op( int op, char * key, void *val, int type) +flash_config_op(int op, struct cyg_fconfig *fc) { cyg_bool res = false; CYGARC_HAL_SAVE_GP(); - switch ( op ) { + switch (op) { case CYGNUM_CALL_IF_FLASH_CFG_GET: - res = flash_get_config( key, val, type ); + res = flash_get_config(fc->key, fc->val, fc->type); + break; + case CYGNUM_CALL_IF_FLASH_CFG_NEXT: + res = flash_next_key(fc->key, fc->keylen, &fc->type, &fc->offset); + break; + case CYGNUM_CALL_IF_FLASH_CFG_SET: + res = flash_set_config(fc->key, fc->val, fc->type); break; default: // nothing else supported yet - though it is expected that "set"
--- a/packages/infra/current/ChangeLog +++ b/packages/infra/current/ChangeLog @@ -1,3 +1,10 @@ +2003-12-21 Gary Thomas <gary@mlbassoc.com> + + * tests/fc_test.c: New test/demonstration of 'fconfig' access. + + * src/tcdiag.cxx (cyg_assert_msg): Interface to 'fconfig' data + has changed. + 2003-10-11 Gary Thomas <gary@mlbassoc.com> * src/tcdiag.cxx (cyg_test_exit):
--- a/packages/infra/current/src/tcdiag.cxx +++ b/packages/infra/current/src/tcdiag.cxx @@ -153,16 +153,22 @@ cyg_assert_msg( const char *psz_func, co { int cur_console; int i; + struct cyg_fconfig fc; + cur_console = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT); - if ( CYGACC_CALL_IF_FLASH_CFG_OP( CYGNUM_CALL_IF_FLASH_CFG_GET, - "info_console_force", &i, - CYGNUM_FLASH_CFG_OP_CONFIG_BOOL ) ) - if ( i ) - if ( CYGACC_CALL_IF_FLASH_CFG_OP( CYGNUM_CALL_IF_FLASH_CFG_GET, - "info_console_number", &i, - CYGNUM_FLASH_CFG_OP_CONFIG_INT ) ) + fc.key = "info_console_force"; + fc.type = CYGNUM_FLASH_CFG_TYPE_CONFIG_BOOL; + fc.val = (void *)&i; + if (CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, &fc)) { + if (i) { + fc.key = "info_console_number"; + fc.type = CYGNUM_FLASH_CFG_TYPE_CONFIG_INT; + if (CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, &fc)) { // Then i is the console to force it to: - CYGACC_CALL_IF_SET_CONSOLE_COMM( i ); + CYGACC_CALL_IF_SET_CONSOLE_COMM(i); + } + } + } #endif diag_write_string("ASSERT FAIL: "); write_thread_id();
new file mode 100644 --- /dev/null +++ b/packages/infra/current/tests/fc_test.c @@ -0,0 +1,108 @@ +//========================================================================== +// +// fc_test.c +// +// Test/demonstration of using RedBoot 'fconfig' from eCos +// +//========================================================================== +//####ECOSGPLCOPYRIGHTBEGIN#### +// ------------------------------------------- +// This file is part of eCos, the Embedded Configurable Operating System. +// Copyright (C) 2003 Gary Thomas +// +// eCos is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 2 or (at your option) any later version. +// +// eCos is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with eCos; if not, write to the Free Software Foundation, Inc., +// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +// +// As a special exception, if other files instantiate templates or use macros +// or inline functions from this file, or you compile this file and link it +// with other works to produce a work based on this file, this file does not +// by itself cause the resulting work to be covered by the GNU General Public +// License. However the source code for this file must still be made available +// in accordance with section (3) of the GNU General Public License. +// +// This exception does not invalidate any other reasons why a work based on +// this file might be covered by the GNU General Public License. +// +// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. +// at http://sources.redhat.com/ecos/ecos-license/ +// ------------------------------------------- +//####ECOSGPLCOPYRIGHTEND#### +//========================================================================== +//#####DESCRIPTIONBEGIN#### +// +// Author(s): gthomas +// Contributors: gthomas +// Date: 2003-12-22 +// Purpose: +// Description: +// +//####DESCRIPTIONEND#### +// +//========================================================================== + +// +// Demonstration of how to use virtual vector interfaces to access/modify +// persistent data stored by 'fconfig' command in RedBoot. +// +// Note: there is currently no support for adding new keys using this +// mechanism. Only existing key/value pairs may be updated. +// +#include <pkgconf/hal.h> +#include <cyg/hal/hal_if.h> +#include <cyg/infra/diag.h> + +void +main(void) +{ + struct cyg_fconfig fc; + char key[64]; + int port; + + diag_printf("fconfig test started\n"); + fc.offset = 0; + fc.key = key; + fc.keylen = sizeof(key); + while (CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_NEXT, &fc)) { + diag_printf(" Offset: %d, key: '%s', type: %d\n", fc.offset, fc.key, fc.type); + fc.keylen = sizeof(key); + } + // Try and update a data value + fc.key = "gdb_port"; + fc.val = &port; + fc.type = CYGNUM_FLASH_CFG_TYPE_CONFIG_INT; + if (CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, &fc)) { + diag_printf("gdb_port = %d\n", port); + port++; + if (CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_SET, &fc)) { + if (CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, &fc)) { + diag_printf("now = %d\n", port); + } else { + diag_printf("Can't re-fetch 'gdb_port'\n"); + exit(1); + } + port--; + if (!CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_SET, &fc)) { + diag_printf("Can't update 'gdb_port'\n"); + exit(1); + } + } else { + diag_printf("Can't update 'gdb_port'\n"); + exit(1); + } + } else { + diag_printf("Fetch 'gdb_port' failed\n"); + exit(1); + } + diag_printf("... done\n"); + exit(1); +}
