From 61b0cfe9df810db4fbca78e5f880d61c5063f324 Mon Sep 17 00:00:00 2001 From: Leo C Date: Sat, 23 Aug 2014 19:34:22 +0200 Subject: Add date rtc i2c --- include/cmd_mem.h | 2 -- include/common.h | 10 +++------ include/config.h | 6 ++++++ include/crc.h | 4 +++- include/debug.h | 4 ++++ include/i2c.h | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/rtc.h | 49 +++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 128 insertions(+), 10 deletions(-) create mode 100644 include/i2c.h create mode 100644 include/rtc.h (limited to 'include') diff --git a/include/cmd_mem.h b/include/cmd_mem.h index cf379ce..1802338 100644 --- a/include/cmd_mem.h +++ b/include/cmd_mem.h @@ -1,8 +1,6 @@ #ifndef CMD_MEM_H #define CMD_MEM_H -//#include "common.h" - #include "command.h" #include "cmd_mem.h" diff --git a/include/common.h b/include/common.h index a92f62c..e8879a6 100644 --- a/include/common.h +++ b/include/common.h @@ -43,19 +43,15 @@ void my_puts(const char *s) fputs(s, stdout); } -#ifdef __AVR__ static inline void my_puts_P(const char *s) { +#ifdef __AVR__ fputs_P(s, stdout); -} - #else -static inline -void my_puts_P(const char *s) -{ fputs(s, stdout); -} #endif /* __AVR__ */ +} + #endif /* COMMON_H */ diff --git a/include/config.h b/include/config.h index 08d97bd..91b1fae 100644 --- a/include/config.h +++ b/include/config.h @@ -12,6 +12,12 @@ //#define CONFIG_CMD_MEMTEST //#define CONFIG_MX_CYCLIC +#define CONFIG_CMD_DATE 1 + +#define CONFIG_SYS_I2C_RTC_ADDR 0x50 +#define CONFIG_SYS_I2C_BUFSIZE 64 +#define CONFIG_SYS_I2C_CLOCK 100000L /* 100kHz */ + #define CONFIG_SYS_CBSIZE 250 #define CONFIG_SYS_ENV_NAMELEN 16 #define CONFIG_SYS_MAXARGS 8 diff --git a/include/crc.h b/include/crc.h index c38bae4..927b5ff 100644 --- a/include/crc.h +++ b/include/crc.h @@ -1,12 +1,14 @@ #ifndef CRC_H #define CRC_H +#ifdef __AVR__ #include - static inline uint16_t crc16(uint16_t crc, uint8_t data) { return _crc_ccitt_update(crc, data); } +#else /* !__AVR__ */ +#endif /* __AVR__ */ #endif /* CRC_H */ diff --git a/include/debug.h b/include/debug.h index 7c19e40..8fdc830 100644 --- a/include/debug.h +++ b/include/debug.h @@ -3,7 +3,9 @@ #define DEBUG_H_ #include "common.h" +#ifdef __AVR__ #include +#endif #ifdef DEBUG #define _DEBUG 1 @@ -31,6 +33,8 @@ #endif /* 0 */ +void dump_eep(const uint8_t *addr, unsigned int len, char *title); +void dump_ram(const uint8_t *addr, unsigned int len, char *title); void printfreelist(const char * title); diff --git a/include/i2c.h b/include/i2c.h new file mode 100644 index 0000000..50b1fd0 --- /dev/null +++ b/include/i2c.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2009 Sergey Kubushyn + * Copyright (C) 2009 - 2013 Heiko Schocher + * Changes for multibus/multiadapter I2C support. + * + * (C) Copyright 2001 + * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com. + * + * SPDX-License-Identifier: GPL-2.0+ + * + * The original I2C interface was + * (C) 2000 by Paolo Scaffardi (arsenio@tin.it) + * AIRVENT SAM s.p.a - RIMINI(ITALY) + * but has been changed substantially. + */ + +#ifndef _I2C_H_ +#define _I2C_H_ + +/* + * Configuration items. + */ +/* TODO: config.h? */ +#define I2C_RXTX_LEN 128 /* maximum tx/rx buffer length */ + + +/* + * Initialization, must be called once on start up, may be called + * repeatedly to change the speed. + */ +void i2c_init(uint32_t speed); + +/* + * Probe the given I2C chip address. Returns 0 if a chip responded, + * not 0 on failure. + */ +int i2c_probe(uint8_t chip); + +/* + * Read/Write interface: + * chip: I2C chip address, range 0..127 + * addr: Memory (register) address within the chip + * alen: Number of bytes to use for addr (typically 1, 2 for larger + * memories, 0 for register type devices with only one + * register) + * buffer: Where to read/write the data + * len: How many bytes to read/write + * + * Returns: 0 on success, not 0 on failure + */ +int i2c_read(uint8_t chip, unsigned int addr, uint_fast8_t alen, + uint8_t *buffer, uint_fast8_t len); +int i2c_write(uint8_t chip, unsigned int addr, uint_fast8_t alen, + uint8_t *buffer, uint_fast8_t len); + +/* + * Utility routines to read/write registers. + */ +uint8_t i2c_reg_read(uint8_t addr, uint8_t reg); + +void i2c_reg_write(uint8_t addr, uint8_t reg, uint8_t val); + +#endif /* _I2C_H_*/ diff --git a/include/rtc.h b/include/rtc.h new file mode 100644 index 0000000..15215a9 --- /dev/null +++ b/include/rtc.h @@ -0,0 +1,49 @@ +/* + * (C) Copyright 2001 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +/* + * Generic RTC interface. + */ +#ifndef _RTC_H_ +#define _RTC_H_ + + +/* + * The struct used to pass data from the generic interface code to + * the hardware dependend low-level code ande vice versa. Identical + * to struct rtc_time used by the Linux kernel. + * + * Note that there are small but significant differences to the + * common "struct time": + * + * struct time: struct rtc_time: + * tm_mon 0 ... 11 1 ... 12 + * tm_year years since 1900 years since 0 + */ + +struct rtc_time { + int tm_sec; + int tm_min; + int tm_hour; + int tm_mday; + int tm_mon; + int tm_year; + int tm_wday; + int tm_yday; + int tm_isdst; +}; + +int rtc_get (struct rtc_time *); +int rtc_set (struct rtc_time *); +void rtc_reset (void); + +void GregorianDay (struct rtc_time *); +void to_tm (unsigned long, struct rtc_time *); +unsigned long mktime (unsigned int, unsigned int, unsigned int, + unsigned int, unsigned int, unsigned int); + +#endif /* _RTC_H_ */ -- cgit v1.2.3