Subversion Repositories freemyipod

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
273 theseven 1
//
2
//
3
//    Copyright 2010 TheSeven
4
//
5
//
427 farthen 6
//    This file is part of emCORE.
273 theseven 7
//
427 farthen 8
//    emCORE is free software: you can redistribute it and/or
273 theseven 9
//    modify it under the terms of the GNU General Public License as
10
//    published by the Free Software Foundation, either version 2 of the
11
//    License, or (at your option) any later version.
12
//
427 farthen 13
//    emCORE is distributed in the hope that it will be useful,
273 theseven 14
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
//    See the GNU General Public License for more details.
17
//
18
//    You should have received a copy of the GNU General Public License along
427 farthen 19
//    with emCORE.  If not, see <http://www.gnu.org/licenses/>.
273 theseven 20
//
21
//
22
 
23
 
24
#include "global.h"
25
#include "timer.h"
26
#include "thread.h"
27
#include "s5l8702.h"
28
 
29
 
597 theseven 30
void timer_init()
273 theseven 31
{
32
    TACMD = (1 << 1);   /* TA_CLR */
33
    TBCMD = (1 << 1);   /* TB_CLR */
34
    TCCMD = (1 << 1);   /* TC_CLR */
35
    TDCMD = (1 << 1);   /* TD_CLR */
36
    TGCMD = (1 << 1);   /* TG_CLR */
37
    THCMD = (1 << 1);   /* TH_CLR */
597 theseven 38
}
273 theseven 39
 
597 theseven 40
void timer_schedule_wakeup(uint32_t usecs)
41
{
638 theseven 42
    if (usecs > 28256363)
597 theseven 43
    {
44
        TBPRE = 511;
45
        TBDATA1 = 65535;
46
    }
638 theseven 47
    else if (usecs > 55188)
597 theseven 48
    {
49
        TBPRE = 511;
638 theseven 50
        TBDATA1 = (usecs * 152) >> 16;
597 theseven 51
    }
52
    else
53
    {
54
        TBPRE = 0;
638 theseven 55
        TBDATA1 = (usecs * 152) >> 7;
597 theseven 56
    }
57
    TBCON = (1 << 13) | /* TB_INT1_EN */
58
            (0 << 12) | /* TB_INT0_EN */
273 theseven 59
            (0 << 11) | /* TB_START */
60
            (3 << 8) |  /* TB_CS = PCLK / 64 */
597 theseven 61
            (2 << 4);   /* TB_MODE_SEL = one-shot mode */
62
    TBCMD = (1 << 1);   /* TB_CLR */
273 theseven 63
    TBCMD = (1 << 0);   /* TB_EN */
64
}
65
 
597 theseven 66
void timer_kill_wakeup()
67
{
68
    TBCMD = (1 << 1);   /* TB_CLR */
69
    TBCON = TBCON;
70
}
71
 
273 theseven 72
void INT_TIMERB(void)
73
{
74
    TBCON = TBCON;
595 theseven 75
    scheduler_switch(NULL, NULL);
273 theseven 76
}