# HG changeset patch # User jlarmour # Date 1235002466 0 # Node ID 422d0a343b4d0c83d7ff848b5ec033930915021a # Parent 3cd309d2d8296fb234b5ccd76a283b916c48ada9 * include/flash.h: Modest API change: cyg_flash_init() no longer takes a printf function argument. Instead two new API functions are available: cyg_flash_set_printf() and cyg_flash_set_global_printf(). * src/flash.c (CHATTER): Don't attempt output if printf function is NULL. (cyg_flash_init): No longer takes printf arg. (cyg_flash_set_printf): New. Set per-device printf function, locking if needed. (cyg_flash_set_global_printf): New. Set printf function for all devices, locking if needed. * src/flashiodev.c (flashiodev_init): cyg_flash_init no longer takes printf arg, and we can leave global printf at default. * src/flashiodevlegacy.c (flashiodev_init): Ditto. * src/legacy_api.c (flash_init): cyg_flash_init no longer takes printf arg. So call cyg_flash_set_global_printf as well. * src/legacy_dev.c (legacy_flash_init): legacy drivers can't handle NULL printf function, so provide a dummy. * doc/flash.sgml: Document removal of printf functionality of cyg_flash_init() and document cyg_flash_set_printf() and cyg_flash_set_global_printf(). diff --git a/packages/io/flash/current/ChangeLog b/packages/io/flash/current/ChangeLog --- a/packages/io/flash/current/ChangeLog +++ b/packages/io/flash/current/ChangeLog @@ -1,3 +1,32 @@ +2009-02-18 Jonathan Larmour + + * include/flash.h: Modest API change: cyg_flash_init() no longer + takes a printf function argument. Instead two new API functions + are available: cyg_flash_set_printf() and + cyg_flash_set_global_printf(). + + * src/flash.c (CHATTER): Don't attempt output if printf function + is NULL. + (cyg_flash_init): No longer takes printf arg. + (cyg_flash_set_printf): New. Set per-device printf function, locking + if needed. + (cyg_flash_set_global_printf): New. Set printf function for all + devices, locking if needed. + + * src/flashiodev.c (flashiodev_init): cyg_flash_init no longer takes + printf arg, and we can leave global printf at default. + * src/flashiodevlegacy.c (flashiodev_init): Ditto. + + * src/legacy_api.c (flash_init): cyg_flash_init no longer takes + printf arg. So call cyg_flash_set_global_printf as well. + + * src/legacy_dev.c (legacy_flash_init): legacy drivers can't handle + NULL printf function, so provide a dummy. + + * doc/flash.sgml: Document removal of printf functionality of + cyg_flash_init() and document cyg_flash_set_printf() and + cyg_flash_set_global_printf(). + 2009-02-13 Bart Veer * doc/flash.sgml: remove incomplete sentence. @@ -642,7 +671,7 @@ 2000-07-29 Gary Thomas - + @@ -118,19 +118,7 @@ operations can be performed. This only n following function will only do the initialization once so it's safe to call multiple times: -__externC int cyg_flash_init(const cyg_flash_printf *pf); -typedef int cyg_flash_printf(const char *fmt, ...); - - -The parameter pf is a pointer to a function -which is to be used for diagnostic output. Typically the function -diag_printf() will be passed. Normally this -function is not used by the higher layer of the library unless -CYGSEM_IO_FLASH_CHATTER is enabled. Passing a -NULL is not recommended, even when -CYGSEM_IO_FLASH_CHATTER is disabled. The lower layers of the library -may unconditionally call this function, especially when errors occur, -probably resulting in a more serious error/crash!. +__externC int cyg_flash_init(void); @@ -281,7 +269,43 @@ blocked. __externC int cyg_flash_mutex_unlock(const cyg_flashaddr_t from, size_t len); - + + +Configuring diagnostic output + + Each FLASH device can have an associated function which is +called to perform diagnostic output. The function to be used can +be configured with the following functions: + +__externC int cyg_flash_set_printf(const cyg_flashaddr_t flash_base, + cyg_flash_printf *pf); +__externC void cyg_flash_set_global_printf(cyg_flash_printf *pf); +typedef int cyg_flash_printf(const char *fmt, ...); + +The parameter pf is a pointer to a function +which is to be used for diagnostic output. Typically the function +diag_printf() will be passed. Normally this +function is not used by the higher layer of the library unless +CYGSEM_IO_FLASH_CHATTER is enabled. Passing a +NULL causes diagnostic output from lower level +drivers to be discarded. + +cyg_flash_set_printf is used to set a +diagnostic output function which will be used specifically when +diagnostic output is attempted from the FLASH device driver associated +with the base address of flash_base. An error +will be returned if no FLASH device is found for this address, or the +FLASH subsystem has not yet been initialised with +cyg_flash_init. + +cyg_flash_set_global_printf sets a +diagnostic output function for all available FLASH devices. Any +previous setting of a diagnostic output function (including with +cyg_flash_set_printf) will be discarded. +This function may be called prior to +cyg_flash_init. + diff --git a/packages/io/flash/current/include/flash.h b/packages/io/flash/current/include/flash.h --- a/packages/io/flash/current/include/flash.h +++ b/packages/io/flash/current/include/flash.h @@ -8,7 +8,7 @@ // ####ECOSGPLCOPYRIGHTBEGIN#### // ------------------------------------------- // This file is part of eCos, the Embedded Configurable Operating System. -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. +// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2009 Free Software Foundation, Inc. // // 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 @@ -80,7 +80,10 @@ typedef struct { } cyg_flash_info_t; typedef int cyg_flash_printf(const char *fmt, ...); -__externC int cyg_flash_init( cyg_flash_printf *pf ); +__externC int cyg_flash_init(void); +__externC int cyg_flash_set_printf(const cyg_flashaddr_t flash_base, + cyg_flash_printf *pf); +__externC void cyg_flash_set_global_printf(cyg_flash_printf *pf); __externC int cyg_flash_get_info(cyg_uint32 devno, cyg_flash_info_t * info); __externC int cyg_flash_get_info_addr(const cyg_flashaddr_t flash_base, diff --git a/packages/io/flash/current/src/flash.c b/packages/io/flash/current/src/flash.c --- a/packages/io/flash/current/src/flash.c +++ b/packages/io/flash/current/src/flash.c @@ -8,7 +8,7 @@ // ####ECOSGPLCOPYRIGHTBEGIN#### // ------------------------------------------- // This file is part of eCos, the Embedded Configurable Operating System. -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. +// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009 Free Software Foundation, Inc. // // 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 @@ -76,7 +76,10 @@ // Optional verbosity. Using a macro here avoids lots of ifdefs in the // rest of the code. #ifdef CYGSEM_IO_FLASH_CHATTER -# define CHATTER(_dev_, _fmt_, ...) (*(_dev_)->pf)((_fmt_), ## __VA_ARGS__) +# define CHATTER(_dev_, _fmt_, ...) CYG_MACRO_START \ + if ((_dev_)->pf) \ + (*(_dev_)->pf)((_fmt_), ## __VA_ARGS__); \ + CYG_MACRO_END #else # define CHATTER(_dev_, _fmt_, ...) CYG_EMPTY_STATEMENT #endif @@ -217,7 +220,7 @@ find_dev(cyg_flashaddr_t addr, int* stat // ascending order of address and put them into a linked list. Lastly // check if we have any overlap of the addresses. __externC int -cyg_flash_init(cyg_flash_printf *pf) +cyg_flash_init(void) { int err; struct cyg_flash_dev * dev; @@ -225,15 +228,10 @@ cyg_flash_init(cyg_flash_printf *pf) CYG_ASSERT(&(cyg_flashdevtab[CYGHWR_IO_FLASH_DEVICE]) == &cyg_flashdevtab_end, "incorrect number of flash devices"); if (init) { - // In case the printf function has changed. - for (dev = &cyg_flashdevtab[0]; dev != &cyg_flashdevtab_end; dev++) { - dev->pf = pf; - } return CYG_FLASH_ERR_OK; } for (dev = &cyg_flashdevtab[0]; dev != &cyg_flashdevtab_end; dev++) { - dev->pf = pf; LOCK_INIT(dev); err = dev->funs->flash_init(dev); @@ -281,6 +279,51 @@ cyg_flash_init(cyg_flash_printf *pf) return CYG_FLASH_ERR_OK; } +// Set a printf function to use for a particular device, +// which is associated with the supplied base address +__externC int +cyg_flash_set_printf(const cyg_flashaddr_t flash_base, + cyg_flash_printf *pf) +{ + struct cyg_flash_dev *dev; + int stat = CYG_FLASH_ERR_OK; + + dev = find_dev(flash_base, &stat); + if (dev) { + // Locking may seem like overkill, but if there's any chance of CHATTER + // mid-change then bad things are theoretically possible. But we only + // lock if this device is usable, i.e. it's been initialised. + if (dev->init) { + LOCK(dev); + } + dev->pf = pf; + if (dev->init) { + UNLOCK(dev); + } + } + return stat; +} + +// Set a printf function to use for all flash devices. +// This overrides any previously set printf function. +__externC void + cyg_flash_set_global_printf(cyg_flash_printf *pf) +{ + struct cyg_flash_dev *dev; + for (dev = &cyg_flashdevtab[0]; dev != &cyg_flashdevtab_end; dev++) { + // Locking may seem like overkill, but if there's any chance of CHATTER + // mid-change then bad things are theoretically possible. But we only + // lock if this device is usable, i.e. it's been initialised. + if (dev->init) { + LOCK(dev); + } + dev->pf = pf; + if (dev->init) { + UNLOCK(dev); + } + } +} + // Is the address within one of the flash drivers? __externC int cyg_flash_verify_addr(const cyg_flashaddr_t address) diff --git a/packages/io/flash/current/src/flashiodev.c b/packages/io/flash/current/src/flashiodev.c --- a/packages/io/flash/current/src/flashiodev.c +++ b/packages/io/flash/current/src/flashiodev.c @@ -8,7 +8,7 @@ // ####ECOSGPLCOPYRIGHTBEGIN#### // ------------------------------------------- // This file is part of eCos, the Embedded Configurable Operating System. -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2007 Free Software Foundation, Inc. +// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2007, 2009 Free Software Foundation, Inc. // // 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 @@ -123,12 +123,10 @@ BLOCK_DEVTAB_ENTRY( cyg_io_flashdev, // FUNCTIONS -static int dummy_printf( const char *fmt, ... ) {return 0;} - static bool flashiodev_init( struct cyg_devtab_entry *tab ) { - int stat = cyg_flash_init( &dummy_printf ); + int stat = cyg_flash_init(); cyg_ucount32 i; if (stat == CYG_FLASH_ERR_OK) diff --git a/packages/io/flash/current/src/flashiodevlegacy.c b/packages/io/flash/current/src/flashiodevlegacy.c --- a/packages/io/flash/current/src/flashiodevlegacy.c +++ b/packages/io/flash/current/src/flashiodevlegacy.c @@ -8,7 +8,7 @@ // ####ECOSGPLCOPYRIGHTBEGIN#### // ------------------------------------------- // This file is part of eCos, the Embedded Configurable Operating System. -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004 Free Software Foundation, Inc. +// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2009 Free Software Foundation, Inc. // // 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 @@ -74,12 +74,10 @@ struct flashiodev_priv_t{ cyg_bool init; }; -static int dummy_printf( const char *fmt, ... ) {return 0;} - static bool flashiodev_init( struct cyg_devtab_entry *tab ) { - int stat = cyg_flash_init( &dummy_printf ); + int stat = cyg_flash_init(); return (stat == CYG_FLASH_ERR_OK); } // flashiodev_init() diff --git a/packages/io/flash/current/src/legacy_api.c b/packages/io/flash/current/src/legacy_api.c --- a/packages/io/flash/current/src/legacy_api.c +++ b/packages/io/flash/current/src/legacy_api.c @@ -8,7 +8,7 @@ // ####ECOSGPLCOPYRIGHTBEGIN#### // ------------------------------------------- // This file is part of eCos, the Embedded Configurable Operating System. -// Copyright (C) 2004 Free Software Foundation, Inc. +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. // // 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 @@ -57,7 +57,8 @@ int flash_init(_printf *pf) { - return cyg_flash_init(pf); + cyg_flash_set_global_printf(pf); + return cyg_flash_init(); } int diff --git a/packages/io/flash/current/src/legacy_dev.c b/packages/io/flash/current/src/legacy_dev.c --- a/packages/io/flash/current/src/legacy_dev.c +++ b/packages/io/flash/current/src/legacy_dev.c @@ -8,7 +8,7 @@ // ####ECOSGPLCOPYRIGHTBEGIN#### // ------------------------------------------- // This file is part of eCos, the Embedded Configurable Operating System. -// Copyright (C) 2004, 2006 Free Software Foundation, Inc. +// Copyright (C) 2004, 2006, 2009 Free Software Foundation, Inc. // // 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 @@ -81,6 +81,8 @@ externC code_fun flash_read_buf; externC code_fun flash_lock_block; externC code_fun flash_unlock_block; +static int dummy_printf( const char *fmt, ... ) {return 0;} + // Initialize the device static int legacy_flash_init (struct cyg_flash_dev *dev) @@ -88,7 +90,11 @@ legacy_flash_init (struct cyg_flash_dev int err; static cyg_flash_block_info_t block_info[1]; - flash_info.pf = dev->pf; + // Legacy device drivers can't handle NULL printf function + if (NULL != dev->pf) + flash_info.pf = dev->pf; + else + flash_info.pf = &dummy_printf; err=flash_hwr_init();