*watch: chronos watch application initial checkin

dev/timer
Kaspar Schleiser 13 years ago
parent b416fef56b
commit 9e58c8bcb7

@ -33,11 +33,16 @@ and the mailinglist (subscription via web site)
//static volatile time_t epoch;
static struct tm time_to_set;
static int set_time = 0;
int rtc_second_pid = 0;
/*---------------------------------------------------------------------------*/
void rtc_init(void) {
/* Set to calendar mode */
RTCCTL1 |= RTCMODE_H;
/* enable ready interrupt (every second) */
RTCCTL0 |= RTCRDYIE;
}
/*---------------------------------------------------------------------------*/
@ -59,7 +64,8 @@ void rtc_set_localtime(struct tm* localt) {
/* copy time to be set */
memcpy(&time_to_set, localt, sizeof(struct tm));
/* set interrupt to set this time after the next transition */
RTCCTL0 |= RTCRDYIE;
// RTCCTL0 |= RTCRDYIE;
set_time = 1;
}
/*---------------------------------------------------------------------------
@ -166,16 +172,25 @@ interrupt(RTC_VECTOR) __attribute__ ((naked)) rtc_isr(void) {
/* RTC is save to write for up to one second now */
if (RTCIV == RTC_RTCRDYIFG) {
/* disable interrupt */
RTCCTL0 &= ~RTCRDYIE;
//RTCCTL0 &= ~RTCRDYIE;
if (set_time) {
set_time = 0;
/* set previous set time and reset it */
RTCSEC = time_to_set.tm_sec;
RTCMIN = time_to_set.tm_min;
RTCHOUR = time_to_set.tm_hour;
RTCDAY = time_to_set.tm_mday;
RTCDOW = time_to_set.tm_wday;
RTCMON = time_to_set.tm_mon + 1;
RTCYEARL = (time_to_set.tm_year + 1900) & 0xFF;
RTCYEARH = (time_to_set.tm_year + 1900) >> 0x08;
RTCSEC = time_to_set.tm_sec;
RTCMIN = time_to_set.tm_min;
RTCHOUR = time_to_set.tm_hour;
RTCDAY = time_to_set.tm_mday;
RTCDOW = time_to_set.tm_wday;
RTCMON = time_to_set.tm_mon + 1;
RTCYEARL = (time_to_set.tm_year + 1900) & 0xFF;
RTCYEARH = (time_to_set.tm_year + 1900) >> 0x08;
}
if (rtc_second_pid) {
msg m;
m.type = RTC_SECOND;
msg_send_int(&m, rtc_second_pid);
}
}
/* RTC alarm */
else if (RTCIV == RTC_RTCAIFG) {

@ -27,6 +27,8 @@ and the mailinglist (subscription via web site)
#ifndef RTC_H
#define RTC_H
#define RTC_SECOND 10001U
#include <time.h>
/**
@ -56,4 +58,6 @@ void rtc_set_localtime(struct tm* localt);
*/
void rtc_get_localtime(struct tm* localt);
extern int rtc_second_pid;
#endif

@ -0,0 +1,5 @@
SubDir TOP projects watch ;
Module watch : main.c clock_app.c alarm_app.c : uart0 posix_io rtc display_putchar gpioint hwtimer board_buzzer auto_init ;
UseModule watch ;

@ -0,0 +1,62 @@
#include <stdio.h>
#include <time.h>
#include <thread.h>
#include <msg.h>
#include <rtc.h>
#include <display.h>
#include "alarm_app.h"
#include "clock_app.h"
#include "watch.h"
static char alarm_stack[KERNEL_CONF_STACKSIZE_DEFAULT];
static void alarm_thread(void) {
msg m;
struct tm time;
time.tm_sec = 1;
time.tm_min = 2;
time.tm_hour = 3;
int active = 0;
while(1) {
msg_receive(&m);
switch (m.type) {
case MSG_ACTIVATE:
{
time_print(&time);
if (active) {
} else {
}
break;
}
case MSG_DEACTIVATE:
{
break;
}
case MSG_BUTTON_HASH:
{
if (active) {
active = 0;
display_symbol(LCD_ICON_ALARM, SEG_OFF);
} else {
active = 1;
display_symbol(LCD_ICON_ALARM, SEG_ON);
}
break;
}
default:
{
printf("def alarm\n");
}
}
}
}
int alarm_app_init() {
return thread_create(alarm_stack, sizeof(alarm_stack), PRIORITY_MAIN-1, CREATE_STACKTEST, alarm_thread, "alarm");
}

@ -0,0 +1,6 @@
#ifndef __ALARM_APP_H
#define __ALARM_APP_H
int alarm_app_init();
#endif /* __ALARM_APP_H */

@ -0,0 +1,58 @@
#include <stdio.h>
#include <time.h>
#include <thread.h>
#include <msg.h>
#include <rtc.h>
#include "clock_app.h"
#include "watch.h"
void time_print(struct tm *time) {
printf("%02i %02i%02i\n", time->tm_sec, time->tm_hour, time->tm_min);
}
static char clock_stack[KERNEL_CONF_STACKSIZE_DEFAULT];
static void clock_thread(void) {
msg m;
int active = 0;
rtc_second_pid = thread_getpid();
while(1) {
msg_receive(&m);
switch (m.type) {
case RTC_SECOND:
{
if (! active) break;
}
case MSG_ACTIVATE:
{
active = 1;
struct tm now;
rtc_get_localtime(&now);
time_print(&now);
break;
}
case MSG_DEACTIVATE:
{
active = 0;
break;
}
case MSG_BUTTON_HASH:
{
printf("hashclock\n");
break;
}
default:
{
printf("def clock\n");
}
}
}
}
int clock_app_init() {
return thread_create(clock_stack, sizeof(clock_stack), PRIORITY_MAIN-1, CREATE_STACKTEST, clock_thread, "clock");
}

@ -0,0 +1,7 @@
#ifndef __CLOCK_APP_H
#define __CLOCK_APP_H
int clock_app_init();
void time_print(struct tm *time);
#endif /* __CLOCK_APP_H */

@ -0,0 +1,83 @@
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <thread.h>
#include <msg.h>
#include <gpioint.h>
#include <buttons.h>
#include <buzzer.h>
#include <posix_io.h>
#include <board_uart0.h>
#include "watch.h"
#include "alarm_app.h"
#include "clock_app.h"
#define NUM_APPS 2
int napps = NUM_APPS;
int apps[NUM_APPS];
int button_thread = 0;
void button_star(void) {
msg m;
if (button_thread) {
m.type = MSG_BUTTON_STAR;
msg_send(&m, button_thread, false);
}
}
int main(void)
{
memset(apps, '\0', sizeof(apps));
apps[0] = clock_app_init();
apps[1] = alarm_app_init();
gpioint_set(2, BUTTON_STAR_PIN, (GPIOINT_RISING_EDGE | GPIOINT_DEBOUNCE), button_star);
button_thread = thread_getpid();
int active_app = 0;
msg m;
//buzzer_beep(15, 5000);
printf("ukleos\n");
m.type = MSG_ACTIVATE;
msg_send(&m, apps[active_app], true);
while(1) {
msg_receive(&m);
switch (m.type) {
case MSG_BUTTON_STAR: {
m.type = MSG_DEACTIVATE;
msg_send(&m, apps[active_app], true);
active_app++;
if (active_app == (NUM_APPS)) active_app = 0;
m.type = MSG_ACTIVATE;
msg_send(&m, apps[active_app], true);
// buzzer_beep(15, 5000);
break;
}
case MSG_BUTTON_HASH:
{
m.type = MSG_BUTTON_HASH;
msg_send(&m, apps[active_app], true);
break;
}
default:
{
printf("msg\n");
}
}
}
}

@ -0,0 +1,13 @@
#!/usr/bin/expect
set timeout 5
spawn pseudoterm $env(PORT)
expect {
"Hello World!" {}
timeout { exit 1 }
}
puts "\nTest successful!\n"

@ -0,0 +1,9 @@
#ifndef __WATCH_H
#define __WATCH_H
#define MSG_ACTIVATE 0
#define MSG_DEACTIVATE 1
#define MSG_BUTTON_STAR 2
#define MSG_BUTTON_HASH 3
#endif /* __WATCH_H */
Loading…
Cancel
Save