2011-11-06 22:44:25 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id: timer-s5l8700.c 23103 2009-10-11 11:35:14Z theseven $
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Bertrik Sikken
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "inttypes.h"
|
|
|
|
#include "s5l8702.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "timer.h"
|
|
|
|
|
2014-11-10 01:39:16 +00:00
|
|
|
void INT_TIMERF(void)
|
2011-11-06 22:44:25 +00:00
|
|
|
{
|
|
|
|
/* clear interrupt */
|
2014-11-10 01:39:16 +00:00
|
|
|
TSTAT = (0x07 << 16);
|
|
|
|
|
2011-11-06 22:44:25 +00:00
|
|
|
if (pfn_timer != NULL) {
|
|
|
|
pfn_timer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool timer_set(long cycles, bool start)
|
|
|
|
{
|
2014-12-01 01:33:41 +00:00
|
|
|
int tf_en = TFCMD & (1 << 0); /* save TF_EN status */
|
|
|
|
|
2014-11-10 01:39:16 +00:00
|
|
|
/* stop timer */
|
2014-12-01 01:33:41 +00:00
|
|
|
TFCMD = (0 << 0); /* TF_EN = disable */
|
2011-11-06 22:44:25 +00:00
|
|
|
|
|
|
|
/* optionally unregister any previously registered timer user */
|
|
|
|
if (start) {
|
|
|
|
if (pfn_unregister != NULL) {
|
|
|
|
pfn_unregister();
|
|
|
|
pfn_unregister = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* configure timer */
|
2014-11-10 01:39:16 +00:00
|
|
|
TFCON = (1 << 12) | /* TF_INT0_EN */
|
2014-12-01 01:33:41 +00:00
|
|
|
(4 << 8) | /* TF_CS = ECLK / 1 */
|
|
|
|
(1 << 6) | /* select ECLK (12 MHz) */
|
|
|
|
(0 << 4); /* TF_MODE_SEL = interval mode */
|
2014-11-10 01:39:16 +00:00
|
|
|
TFPRE = 0; /* no prescaler */
|
2014-12-01 01:33:41 +00:00
|
|
|
TFDATA0 = cycles; /* set interval period */
|
2014-11-10 01:39:16 +00:00
|
|
|
|
2014-12-01 01:33:41 +00:00
|
|
|
/* After the configuration, we must write '1' in TF_CLR to
|
|
|
|
* initialize the timer (s5l8700 DS):
|
|
|
|
* - Clear the counter register.
|
|
|
|
* - The value of TF_START is set to TF_OUT.
|
|
|
|
* - TF_DATA0 and TF_DATA1 are updated to the internal buffers.
|
|
|
|
* - Initialize the state of the previously captured signal.
|
|
|
|
*/
|
|
|
|
TFCMD = (1 << 1) | /* TF_CLR = initialize timer */
|
|
|
|
(tf_en << 0); /* TF_EN = restore previous status */
|
2014-11-10 01:39:16 +00:00
|
|
|
|
2011-11-06 22:44:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool timer_start(void)
|
|
|
|
{
|
2014-12-01 01:33:41 +00:00
|
|
|
TFCMD = (1 << 0); /* TF_EN = enable */
|
2011-11-06 22:44:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void timer_stop(void)
|
|
|
|
{
|
2014-12-01 01:33:41 +00:00
|
|
|
TFCMD = (0 << 0); /* TF_EN = disable */
|
2011-11-06 22:44:25 +00:00
|
|
|
}
|