forked from Imagelibrary/rtems
2007-11-20 Till Straumann <strauman@slac.stanford.edu>
* libchip/rtc/ds1375.c, libchip/rtc/ds1375-rtc.h: Avoid using 'stdio' before the system is up and fully initialized.
This commit is contained in:
@@ -1,3 +1,9 @@
|
||||
2007-11-20 Till Straumann <strauman@slac.stanford.edu>
|
||||
|
||||
* libchip/rtc/ds1375.c, libchip/rtc/ds1375-rtc.h:
|
||||
Avoid using 'stdio' before the system is up and fully
|
||||
initialized.
|
||||
|
||||
2007-11-20 Till Straumann <strauman@slac.stanford.edu>
|
||||
|
||||
* libchip/rtc/ds1375.c, libchip/rtc/ds1375-rtc.h,
|
||||
|
||||
@@ -71,6 +71,13 @@ rtc_ds1375_set_register( uint32_t port, uint8_t reg, uint32_t value );
|
||||
* BSP must supply string constant argument 'i2cname' which matches
|
||||
* the registered device name of the raw i2c device (created with mknod).
|
||||
* E.g., "/dev/i2c.ds1375-raw"
|
||||
*
|
||||
* NOTE: The i2c bus driver must already be up and 'i2cname' already
|
||||
* be available when this ENTRY is registered or initialized.
|
||||
*
|
||||
* If you want to allow applications to add the RTC driver to
|
||||
* the configuration table then the i2c subsystem must be
|
||||
* initialized by the BSP from the predriver_hook.
|
||||
*/
|
||||
#define DS1375_RTC_TBL_ENTRY(i2cname) \
|
||||
{ \
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
#include <libchip/ds1375-rtc.h>
|
||||
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/errno.h>
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
@@ -61,6 +62,22 @@
|
||||
#define STATIC static
|
||||
#undef DEBUG
|
||||
|
||||
/* The RTC driver routines are possibly called during
|
||||
* system initialization -- that would be prior to opening
|
||||
* the console. At this point it is not safe to use stdio
|
||||
* (printf, perror etc.).
|
||||
* Our file descriptors may even be 0..2
|
||||
*/
|
||||
#define STDIOSAFE(fmt,args...) \
|
||||
do { \
|
||||
if ( _System_state_Is_up( _System_state_Get() ) ) { \
|
||||
fprintf(stderr,fmt,args); \
|
||||
} else { \
|
||||
printk(fmt,args); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
STATIC uint8_t ds1375_bcd2bin(uint8_t x)
|
||||
{
|
||||
uint8_t h = x & 0xf0;
|
||||
@@ -399,19 +416,19 @@ rtc_ds1375_device_probe( int minor )
|
||||
int fd;
|
||||
|
||||
if ( ( fd = getfd( minor ) ) < 0 ) {
|
||||
perror("ds1375_probe (open)");
|
||||
STDIOSAFE( "ds1375_probe (open): %s\n", strerror( errno ) );
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Try to set file pointer */
|
||||
if ( 0 != wr_bytes( fd, DS1375_SEC_REG, 0, 0 ) ) {
|
||||
perror( "ds1375_probe (wr_bytes)" );
|
||||
STDIOSAFE( "ds1375_probe (wr_bytes): %s\n", strerror( errno ) );
|
||||
close( fd );
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ( close( fd ) ) {
|
||||
perror( "ds1375_probe (close)" );
|
||||
STDIOSAFE( "ds1375_probe (close): %s\n", strerror( errno ) );
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user