mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
* 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
This commit is contained in:
parent
ba03f610c4
commit
3b218ec24a
@ -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
|
||||
|
@ -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 ) {
|
||||
|
@ -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
|
||||
|
@ -40,6 +40,7 @@ and the mailinglist (subscription via web site)
|
||||
*
|
||||
* @note $Id: sht11.h 667 2009-02-19 15:06:38Z baar $
|
||||
*/
|
||||
#include <stdint.h>
|
||||
|
||||
#define SHT11_NO_ACK (0)
|
||||
#define SHT11_ACK (1)
|
||||
|
@ -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 ;
|
||||
|
@ -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!");
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <board_uart0.h>
|
||||
#include <lpc2387-rtc.h>
|
||||
#include <auto_init.h>
|
||||
|
||||
#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();
|
||||
|
@ -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 ;
|
||||
|
||||
|
40
sys/shell/rtc.c
Normal file
40
sys/shell/rtc.c
Normal file
@ -0,0 +1,40 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <lpc2387-rtc.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -2,12 +2,32 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#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}
|
||||
};
|
||||
|
41
sys/shell/sht11.c
Normal file
41
sys/shell/sht11.c
Normal file
@ -0,0 +1,41 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <sht11.h>
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user