From 3b218ec24adcd2117a07f759cdf836e9b8a054d2 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Thu, 4 Nov 2010 18:16:39 +0100 Subject: [PATCH] * changed API for rtc * added drivers directory to doxygen file * added missing include to sht11 header * added rtc and sht11 support to default project * added rtc to auto_init * added rtc and sht11 support to shell --- cpu/lpc2387/include/lpc2387-rtc.h | 12 ++++++--- cpu/lpc2387/lpc2387-rtc.c | 14 +++++------ doc/doxygen/ukleos.doxyfile | 4 +-- drivers/include/sht11.h | 1 + projects/default/Jamfile | 2 +- projects/default/main.c | 1 - sys/auto_init.c | 6 +++++ sys/shell/Jamfile | 2 +- sys/shell/rtc.c | 40 ++++++++++++++++++++++++++++++ sys/shell/shell.c | 2 +- sys/shell/shell_commands.c | 22 ++++++++++++++++- sys/shell/sht11.c | 41 +++++++++++++++++++++++++++++++ 12 files changed, 130 insertions(+), 17 deletions(-) create mode 100644 sys/shell/rtc.c create mode 100644 sys/shell/sht11.c diff --git a/cpu/lpc2387/include/lpc2387-rtc.h b/cpu/lpc2387/include/lpc2387-rtc.h index 9420fc7c21..c1580329eb 100644 --- a/cpu/lpc2387/include/lpc2387-rtc.h +++ b/cpu/lpc2387/include/lpc2387-rtc.h @@ -81,9 +81,9 @@ enum rtc_alarm_mask { * @internal * During reboots only alarms are reset. */ -void _rtc_init(void); +void rtc_init(void); -void _rtc_reset(void); +void rtc_reset(void); /** * @brief Returns the time of compilation in seconds @@ -91,6 +91,12 @@ void _rtc_reset(void); */ time_t rtc_get_compile_time(void) __attribute__((noinline)); +/** + * @brief Sets the current time in broken down format directly from to RTC + * @param[in] localt Pointer to structure with time to set + */ +void rtc_set_localtime(struct tm* localt); + /** * @brief Returns the current clock time * @param[out] time optional return value @@ -131,7 +137,7 @@ void rtc_get_localtime(struct tm* localt); * * @see ::rtc_alarm_mask */ -void _rtc_set_alarm(struct tm* localt, enum rtc_alarm_mask mask); +void rtc_set_alarm(struct tm* localt, enum rtc_alarm_mask mask); /** * @brief Gets the current alarm setting diff --git a/cpu/lpc2387/lpc2387-rtc.c b/cpu/lpc2387/lpc2387-rtc.c index ca713833a0..4c896c47d2 100644 --- a/cpu/lpc2387/lpc2387-rtc.c +++ b/cpu/lpc2387/lpc2387-rtc.c @@ -68,7 +68,7 @@ static volatile time_t epoch; * @brief Sets the current time in broken down format directly from to RTC * @param[in] localt Pointer to structure with time to set */ -static void +void rtc_set_localtime(struct tm* localt) { if( localt == NULL ) @@ -93,14 +93,14 @@ void rtc_set(time_t time) { } /*---------------------------------------------------------------------------*/ /// set clock to start of unix epoch -void _rtc_reset(void) +void rtc_reset(void) { rtc_set(0); epoch = 0; } /*---------------------------------------------------------------------------*/ void -_rtc_set_alarm(struct tm* localt, enum rtc_alarm_mask mask) +rtc_set_alarm(struct tm* localt, enum rtc_alarm_mask mask) { if( localt != NULL ) { RTC_ALSEC = localt->tm_sec; @@ -120,7 +120,7 @@ _rtc_set_alarm(struct tm* localt, enum rtc_alarm_mask mask) } /*---------------------------------------------------------------------------*/ enum rtc_alarm_mask -_rtc_get_alarm(struct tm* localt) +rtc_get_alarm(struct tm* localt) { if( localt != NULL ) { localt->tm_sec = RTC_ALSEC; @@ -169,7 +169,7 @@ void rtc_enable(void) epoch = now - (now % 3600); } /*---------------------------------------------------------------------------*/ -void _rtc_init(void) +void rtc_init(void) { PCONP |= BIT9; RTC_AMR = 0xff; // disable alarm irq @@ -183,7 +183,7 @@ void _rtc_init(void) /* initialize clock with valid unix compatible values * If RTC_YEAR contains an value larger unix time_t we must reset. */ if( RTC_YEAR > 2037 ) { - _rtc_reset(); + rtc_reset(); } PRINTF("%2lu.%2lu.%4lu %2lu:%2lu:%2lu epoch %lu", @@ -242,7 +242,7 @@ rtc_get_localtime(struct tm* localt) } } /*---------------------------------------------------------------------------*/ -void _gettimeofday_r(struct _reent *r, struct timeval *ptimeval, struct timezone *ptimezone) +void gettimeofday_r(struct _reent *r, struct timeval *ptimeval, struct timezone *ptimezone) { r->_errno = 0; if( ptimeval != NULL ) { diff --git a/doc/doxygen/ukleos.doxyfile b/doc/doxygen/ukleos.doxyfile index bbf20122e9..490fd04f21 100644 --- a/doc/doxygen/ukleos.doxyfile +++ b/doc/doxygen/ukleos.doxyfile @@ -85,7 +85,7 @@ WARN_LOGFILE = #--------------------------------------------------------------------------- # configuration options related to the input files #--------------------------------------------------------------------------- -INPUT = ../../core ../../cpu ../../board ../../sys ../manual +INPUT = ../../core ../../cpu ../../board ../../sys ../manual ../../drivers INPUT_ENCODING = UTF-8 FILE_PATTERNS = *.doc *.c *.h RECURSIVE = YES @@ -125,7 +125,7 @@ HTML_OUTPUT = html HTML_FILE_EXTENSION = .html HTML_HEADER = src/ukleos-header.html HTML_FOOTER = src/ukleos-footer.html -HTML_STYLESHEET = src/ukleos.css +HTML_STYLESHEET = HTML_ALIGN_MEMBERS = YES HTML_DYNAMIC_SECTIONS = YES GENERATE_DOCSET = NO diff --git a/drivers/include/sht11.h b/drivers/include/sht11.h index d929a2ecb5..227569f5e1 100644 --- a/drivers/include/sht11.h +++ b/drivers/include/sht11.h @@ -40,6 +40,7 @@ and the mailinglist (subscription via web site) * * @note $Id: sht11.h 667 2009-02-19 15:06:38Z baar $ */ +#include #define SHT11_NO_ACK (0) #define SHT11_ACK (1) diff --git a/projects/default/Jamfile b/projects/default/Jamfile index 947f72a353..476db1c00c 100644 --- a/projects/default/Jamfile +++ b/projects/default/Jamfile @@ -6,6 +6,6 @@ SubDir TOP projects default ; -Module default_project : main.c : shell posix_io uart0 shell_commands ps ; +Module default_project : main.c : shell posix_io uart0 shell_commands ps rtc sht11 auto_init ; UseModule default_project ; diff --git a/projects/default/main.c b/projects/default/main.c index bc2100f539..5480211801 100644 --- a/projects/default/main.c +++ b/projects/default/main.c @@ -21,7 +21,6 @@ void shell_putchar(int c) { } int main(void) { - board_uart0_init(); posix_open(uart0_handler_pid, 0); puts("Welcome to ukleos!"); diff --git a/sys/auto_init.c b/sys/auto_init.c index 17fdeb34de..c92b2b0176 100644 --- a/sys/auto_init.c +++ b/sys/auto_init.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #define ENABLE_DEBUG @@ -21,6 +22,11 @@ void auto_init(void) { DEBUG("Auto init uart0 module.\n"); board_uart0_init(); #endif +#ifdef MODULE_RTC + DEBUG("Auto init rtc module.\n"); + rtc_init(); + rtc_enable(); +#endif #ifdef MODULE_SHT11 DEBUG("Auto init SHT11 module.\n"); sht11_init(); diff --git a/sys/shell/Jamfile b/sys/shell/Jamfile index 195b04fd8c..a17b4173df 100644 --- a/sys/shell/Jamfile +++ b/sys/shell/Jamfile @@ -28,7 +28,7 @@ SubDir TOP sys shell ; Module shell : shell.c ; -Module shell_commands : shell_commands.c : shell ; +Module shell_commands : shell_commands.c rtc.c sht11.c : shell ; Module ps : ps.c ; diff --git a/sys/shell/rtc.c b/sys/shell/rtc.c new file mode 100644 index 0000000000..86d4add0ec --- /dev/null +++ b/sys/shell/rtc.c @@ -0,0 +1,40 @@ +#include +#include +#include +#include + +void _gettime_handler(char *unused) { + struct tm now; + rtc_get_localtime(&now); + + printf("%s", asctime(&now)); +} + +void _settime_handler(char* c) { + struct tm now; + int res; + uint16_t month, epoch_year; + + res = sscanf(c, "settime %hu-%hu-%i %i:%i:%i", + &epoch_year, + &month, + &(now.tm_mday), + &(now.tm_hour), + &(now.tm_min), + &(now.tm_sec)); + + if (res < 6) { + printf("Usage: settime YYYY-MM-DD hh:mm:ss\n"); + return; + } + else { + printf("OK %s", asctime(&now)); + } + + now.tm_year = epoch_year - 1900; + now.tm_mon = month - 1; + time_t t = mktime(&now); + rtc_set(t); +} + + diff --git a/sys/shell/shell.c b/sys/shell/shell.c index 8c5a665fc2..02f4726cb3 100644 --- a/sys/shell/shell.c +++ b/sys/shell/shell.c @@ -122,7 +122,7 @@ void shell_run(shell_t *shell) { char line_buf[255]; while(1) { - shell->put_char('>'); + shell->put_char('> '); int res = readline(shell, line_buf, sizeof(line_buf)); if (! res ) { char* line_copy = strdup(line_buf); diff --git a/sys/shell/shell_commands.c b/sys/shell/shell_commands.c index e3656ecf8f..f5aa08c650 100644 --- a/sys/shell/shell_commands.c +++ b/sys/shell/shell_commands.c @@ -2,12 +2,32 @@ #include #ifdef MODULE_PS -extern void _ps_handler(char* unnused); +extern void _ps_handler(char* unused); +#endif + +#ifdef MODULE_RTC +extern void _gettime_handler(char* unused); +extern void _settime_handler(char* now); +#endif + +#ifdef MODULE_SHT11 +extern void _get_temperature_handler(char* unused); +extern void _get_humidity_handler(char* unused); +extern void _get_weather_handler(char* unused); #endif const shell_command_t _shell_command_list[] = { #ifdef MODULE_PS {"ps", "Prints information about running threads.", _ps_handler}, +#endif +#ifdef MODULE_RTC + {"gettime", "Prints current date and time.", _gettime_handler}, + {"settime", "Sets current time.", _settime_handler}, +#endif +#ifdef MODULE_SHT11 + {"gettemp", "Prints measured temperature.", _get_temperature_handler}, + {"gethum", "Prints measured humidity.", _get_humidity_handler}, + {"getweather", "Prints measured humidity and temperature.", _get_weather_handler}, #endif {NULL, NULL, NULL} }; diff --git a/sys/shell/sht11.c b/sys/shell/sht11.c new file mode 100644 index 0000000000..b24c8db936 --- /dev/null +++ b/sys/shell/sht11.c @@ -0,0 +1,41 @@ +#include +#include +#include + +void _get_humidity_handler(char* unused) { + uint8_t success; + sht11_val_t sht11_val; + success = sht11_read_sensor(&sht11_val, HUMIDITY|TEMPERATURE); + if (!success) { + printf("Error reading SHT11\n"); + } + else { + printf("Relative humidity: %5.2f%% / Temperature compensated humidity; %5.2f%%\n", + sht11_val.relhum, sht11_val.relhum_temp); + } +} +void _get_temperature_handler(char* unused) { + uint8_t success; + sht11_val_t sht11_val; + success = sht11_read_sensor(&sht11_val, TEMPERATURE); + if (!success) { + printf("Error reading SHT11\n"); + } + else { + printf("Temperature: %-6.2f°C\n", sht11_val.temperature); + } +} +void _get_weather_handler(char* unused) { + uint8_t success; + sht11_val_t sht11_val; + success = sht11_read_sensor(&sht11_val, HUMIDITY|TEMPERATURE); + if (!success) { + printf("Error reading SHT11\n"); + } + else { + printf("Relative humidity: %5.2f%% / Temperature compensated humidity; %5.2f%% ", + sht11_val.relhum, sht11_val.relhum_temp); + printf("Temperature: %-6.2f°C\n", sht11_val.temperature); + } +} +