2007-02-03 13:10:17 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
2009-07-12 09:43:44 +00:00
|
|
|
* $Id$
|
2007-02-03 13:10:17 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2007 by Barry Wardell
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2007-02-03 13:10:17 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2007-10-25 09:03:47 +00:00
|
|
|
#include <stdbool.h>
|
2009-04-12 18:00:53 +00:00
|
|
|
#include "config.h"
|
2007-02-03 13:10:17 +00:00
|
|
|
#include "rtc.h"
|
2007-10-25 09:03:47 +00:00
|
|
|
#include "as3514.h"
|
2008-10-31 00:16:42 +00:00
|
|
|
#include "ascodec.h"
|
2012-03-08 20:21:31 +00:00
|
|
|
#include "time.h"
|
2007-02-03 13:10:17 +00:00
|
|
|
|
2010-02-22 10:25:02 +00:00
|
|
|
/* AMS Sansas start counting from Jan 1st 1970 instead of 1980 (not as3525v2) */
|
2009-04-12 18:00:53 +00:00
|
|
|
#if (CONFIG_CPU==AS3525)
|
2012-04-17 19:24:49 +00:00
|
|
|
#define SECS_ADJUST 0 /* 1970-1-1 00:00:00 */
|
2010-02-22 10:25:02 +00:00
|
|
|
#elif (CONFIG_CPU==AS3525v2)
|
2012-04-17 19:24:49 +00:00
|
|
|
#if defined(SANSA_CLIPZIP)
|
|
|
|
#define SECS_ADJUST 0 /* 1970-1-1 00:00:00 */
|
|
|
|
#else
|
2012-03-08 20:21:31 +00:00
|
|
|
#define SECS_ADJUST ((2*365*24*3600) + 26*(24*3600) - 7*3600 - 25*60)
|
2012-04-17 19:24:49 +00:00
|
|
|
#endif
|
2009-04-12 18:00:53 +00:00
|
|
|
#else
|
2012-04-17 19:24:49 +00:00
|
|
|
#define SECS_ADJUST 315532800 /* 1980-1-1 00:00:00 */
|
2009-04-12 18:00:53 +00:00
|
|
|
#endif
|
|
|
|
|
2010-05-22 00:28:03 +00:00
|
|
|
#ifdef HAVE_RTC_ALARM /* as3543 */
|
2010-07-16 10:41:41 +00:00
|
|
|
static struct {
|
2010-07-16 10:05:48 +00:00
|
|
|
unsigned int seconds; /* total seconds to wakeup */
|
|
|
|
int hour; /* wake-up hour */
|
|
|
|
int min; /* wake-up minute */
|
2010-07-16 10:41:41 +00:00
|
|
|
bool enabled; /* alarm enabled or not */
|
|
|
|
unsigned char flag; /* flag used by the OF */
|
2010-07-16 10:05:48 +00:00
|
|
|
} alarm;
|
2010-05-22 00:28:03 +00:00
|
|
|
|
|
|
|
void rtc_set_alarm(int h, int m)
|
|
|
|
{
|
2010-07-16 10:05:48 +00:00
|
|
|
alarm.hour = h;
|
|
|
|
alarm.min = m;
|
2010-05-22 00:28:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void rtc_get_alarm(int *h, int *m)
|
|
|
|
{
|
2010-07-16 10:05:48 +00:00
|
|
|
*h = alarm.hour;
|
|
|
|
*m = alarm.min;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reads the AS3543 wakeup register */
|
|
|
|
static void alarm_read(void)
|
|
|
|
{
|
|
|
|
unsigned char buf[6];
|
|
|
|
unsigned int i;
|
|
|
|
int oldstatus;
|
|
|
|
|
|
|
|
/* read raw data */
|
|
|
|
oldstatus = disable_irq_save();
|
|
|
|
ascodec_read(0);
|
|
|
|
for (i = 0; i < sizeof(buf); i++) {
|
|
|
|
buf[i] = ascodec_read(AS3543_WAKEUP);
|
|
|
|
}
|
|
|
|
restore_irq(oldstatus);
|
|
|
|
|
|
|
|
/* decode */
|
|
|
|
alarm.seconds = buf[0] | (buf[1] << 8) | ((buf[2] & 0x7F) << 16);
|
|
|
|
alarm.enabled = buf[2] & (1 << 7);
|
|
|
|
alarm.flag = buf[3];
|
|
|
|
alarm.hour = buf[4];
|
|
|
|
alarm.min = buf[5];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Writes the AS3543 wakeup register */
|
|
|
|
static void alarm_write(void)
|
|
|
|
{
|
|
|
|
unsigned char buf[6];
|
|
|
|
unsigned int i;
|
|
|
|
int oldstatus;
|
|
|
|
|
|
|
|
/* encode */
|
|
|
|
buf[0] = alarm.seconds & 0xFF;
|
|
|
|
buf[1] = (alarm.seconds >> 8) & 0xFF;
|
|
|
|
buf[2] = ((alarm.seconds >> 16) & 0x7F) | (alarm.enabled ? (1 << 7) : 0);
|
|
|
|
buf[3] = alarm.flag;
|
|
|
|
buf[4] = alarm.hour;
|
|
|
|
buf[5] = alarm.min;
|
|
|
|
|
|
|
|
/* write raw data */
|
|
|
|
oldstatus = disable_irq_save();
|
|
|
|
ascodec_read(0);
|
|
|
|
for (i = 0; i < sizeof(buf); i++) {
|
|
|
|
ascodec_write(AS3543_WAKEUP, buf[i]);
|
|
|
|
}
|
|
|
|
restore_irq(oldstatus);
|
2010-05-22 00:28:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void rtc_alarm_poweroff(void)
|
|
|
|
{
|
2010-07-16 10:05:48 +00:00
|
|
|
if(!alarm.enabled)
|
2010-05-22 00:28:03 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
struct tm tm;
|
|
|
|
rtc_read_datetime(&tm);
|
2010-07-16 10:05:48 +00:00
|
|
|
int hours = alarm.hour - tm.tm_hour;
|
|
|
|
int mins = alarm.min - tm.tm_min;
|
2010-05-22 00:28:03 +00:00
|
|
|
if(mins < 0)
|
|
|
|
{
|
|
|
|
mins += 60;
|
|
|
|
hours -= 1;
|
|
|
|
}
|
|
|
|
if(hours < 0)
|
|
|
|
hours += 24;
|
|
|
|
|
|
|
|
uint32_t seconds = hours*3600 + mins*60;
|
|
|
|
if(seconds == 0)
|
|
|
|
seconds = 24*3600;
|
|
|
|
|
|
|
|
seconds -= tm.tm_sec;
|
Initial commit of the Samsung YP-R0 port.
This port is a hybrid native/RaaA port. It runs on a embedded linux system,
but is the only application. It therefore can implement lots of stuff that
native targets also implement, while leveraging the underlying linux kernel.
The port is quite advanced. User interface, audio playback, plugins work
mostly fine. Missing is e.g. power mangement and USB (see SamsungYPR0 wiki page).
Included in utils/ypr0tools are scripts and programs required to generate
a patched firmware. The patched firmware has the rootfs modified to load
Rockbox. It includes a early/safe USB mode.
This port needs a new toolchain, one that includes glibc headers and libraries.
rockboxdev.sh can generate it, but e.g. codesourcey and distro packages may
also work.
Most of the initial effort is done by Lorenzo Miori and others (on ABI),
including reverse engineering and patching of the original firmware,
initial drivers, and more. Big thanks to you.
Flyspray: FS#12348
Author: Lorenzo Miori, myself
Merry christmas to ypr0 owners! :)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31415 a1c6a512-1295-4272-9138-f99709370657
2011-12-24 11:56:46 +00:00
|
|
|
#ifndef SAMSUNG_YPR0
|
2010-11-01 18:58:40 +00:00
|
|
|
/* disable MCLK, it is a wakeup source and prevents proper shutdown */
|
|
|
|
CGU_AUDIO = (2 << 0) | (1 << 11);
|
|
|
|
CGU_PLLBSUP = (1 << 2) | (1 << 3);
|
Initial commit of the Samsung YP-R0 port.
This port is a hybrid native/RaaA port. It runs on a embedded linux system,
but is the only application. It therefore can implement lots of stuff that
native targets also implement, while leveraging the underlying linux kernel.
The port is quite advanced. User interface, audio playback, plugins work
mostly fine. Missing is e.g. power mangement and USB (see SamsungYPR0 wiki page).
Included in utils/ypr0tools are scripts and programs required to generate
a patched firmware. The patched firmware has the rootfs modified to load
Rockbox. It includes a early/safe USB mode.
This port needs a new toolchain, one that includes glibc headers and libraries.
rockboxdev.sh can generate it, but e.g. codesourcey and distro packages may
also work.
Most of the initial effort is done by Lorenzo Miori and others (on ABI),
including reverse engineering and patching of the original firmware,
initial drivers, and more. Big thanks to you.
Flyspray: FS#12348
Author: Lorenzo Miori, myself
Merry christmas to ypr0 owners! :)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31415 a1c6a512-1295-4272-9138-f99709370657
2011-12-24 11:56:46 +00:00
|
|
|
#endif
|
2010-07-16 10:05:48 +00:00
|
|
|
/* write wakeup register */
|
|
|
|
alarm.seconds = seconds;
|
|
|
|
alarm.enabled = true;
|
|
|
|
alarm_write();
|
2010-05-22 00:28:03 +00:00
|
|
|
|
2010-07-16 10:05:48 +00:00
|
|
|
/* enable heartbeat watchdog */
|
2010-05-24 10:06:46 +00:00
|
|
|
ascodec_write(AS3514_SYSTEM, (1<<3) | (1<<0));
|
|
|
|
|
2010-07-16 10:05:48 +00:00
|
|
|
/* In_Cntr : disable heartbeat source */
|
2010-05-24 10:06:46 +00:00
|
|
|
ascodec_write_pmu(0x1a, 4, ascodec_read_pmu(0x1a, 4) & ~(3<<2));
|
2010-05-22 00:28:03 +00:00
|
|
|
|
|
|
|
while(1);
|
|
|
|
}
|
|
|
|
|
2010-05-22 00:28:26 +00:00
|
|
|
void rtc_enable_alarm(bool enable)
|
2010-05-22 00:28:03 +00:00
|
|
|
{
|
2010-07-16 10:05:48 +00:00
|
|
|
alarm.enabled = enable;
|
2010-05-22 00:28:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool rtc_check_alarm_started(bool release_alarm)
|
|
|
|
{
|
2010-07-16 10:05:48 +00:00
|
|
|
/* read wakeup register and check if alarm was enabled */
|
|
|
|
alarm_read();
|
|
|
|
if (!alarm.enabled) {
|
2010-06-17 05:28:38 +00:00
|
|
|
return false;
|
2010-07-16 10:05:48 +00:00
|
|
|
}
|
2010-05-22 00:28:03 +00:00
|
|
|
|
2010-07-16 10:05:48 +00:00
|
|
|
alarm.enabled = !release_alarm;
|
|
|
|
alarm_write();
|
2010-05-22 00:28:03 +00:00
|
|
|
|
2010-06-17 05:28:38 +00:00
|
|
|
struct tm tm;
|
|
|
|
rtc_read_datetime(&tm);
|
2010-05-22 00:28:03 +00:00
|
|
|
|
2010-06-17 05:28:38 +00:00
|
|
|
/* were we powered up at the programmed time ? */
|
2010-07-16 10:05:48 +00:00
|
|
|
return alarm.hour == tm.tm_hour && alarm.min == tm.tm_min;
|
2010-05-22 00:28:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool rtc_check_alarm_flag(void)
|
|
|
|
{
|
|
|
|
/* We don't need to do anything special if it has already fired */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif /* HAVE_RTC_ALARM */
|
|
|
|
|
2007-02-03 13:10:17 +00:00
|
|
|
void rtc_init(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-09-26 14:58:32 +00:00
|
|
|
int rtc_read_datetime(struct tm *tm)
|
2007-02-03 13:10:17 +00:00
|
|
|
{
|
|
|
|
char tmp[4];
|
|
|
|
unsigned int seconds;
|
2012-03-08 20:21:31 +00:00
|
|
|
int i;
|
2009-09-26 14:58:32 +00:00
|
|
|
|
2012-03-08 20:21:31 +00:00
|
|
|
/* Get seconds time stamp from RTC */
|
2009-09-26 14:58:32 +00:00
|
|
|
for (i = 0; i < 4; i++){
|
2008-10-31 00:16:42 +00:00
|
|
|
tmp[i] = ascodec_read(AS3514_RTC_0 + i);
|
2007-02-03 13:10:17 +00:00
|
|
|
}
|
|
|
|
seconds = tmp[0] + (tmp[1]<<8) + (tmp[2]<<16) + (tmp[3]<<24);
|
2009-09-26 14:58:32 +00:00
|
|
|
|
2012-03-08 20:21:31 +00:00
|
|
|
/* convert to struct tm */
|
|
|
|
time_t time = seconds + SECS_ADJUST;
|
|
|
|
gmtime_r(&time, tm);
|
2009-09-26 14:58:32 +00:00
|
|
|
|
2012-03-08 20:21:31 +00:00
|
|
|
return 1;
|
2007-02-03 13:10:17 +00:00
|
|
|
}
|
|
|
|
|
2009-09-26 14:58:32 +00:00
|
|
|
int rtc_write_datetime(const struct tm *tm)
|
2007-02-03 13:10:17 +00:00
|
|
|
{
|
2012-03-08 20:21:31 +00:00
|
|
|
time_t time;
|
|
|
|
unsigned int seconds;
|
|
|
|
int i;
|
2007-02-03 13:10:17 +00:00
|
|
|
|
2012-03-08 20:21:31 +00:00
|
|
|
/* convert struct tm to time stamp */
|
|
|
|
time = mktime((struct tm *)tm);
|
|
|
|
seconds = time - SECS_ADJUST;
|
2007-02-03 13:10:17 +00:00
|
|
|
|
|
|
|
/* Send data to RTC */
|
2009-09-26 14:58:32 +00:00
|
|
|
for (i=0; i<4; i++){
|
2008-10-31 00:16:42 +00:00
|
|
|
ascodec_write(AS3514_RTC_0 + i, ((seconds >> (8 * i)) & 0xff));
|
2007-02-03 13:10:17 +00:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|