Subversion Repositories freemyipod

Rev

Rev 595 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 595 Rev 597
Line 25... Line 25...
25
#include "timer.h"
25
#include "timer.h"
26
#include "thread.h"
26
#include "thread.h"
27
#include "s5l8701.h"
27
#include "s5l8701.h"
28
 
28
 
29
 
29
 
30
void setup_tick()
30
void timer_init()
31
{
31
{
-
 
32
}
-
 
33
 
-
 
34
void timer_schedule_wakeup(uint32_t usecs)
-
 
35
{
32
    int cycles = SYSTEM_TICK / 100;
36
    if (usecs > 11184640)
-
 
37
    {
-
 
38
        TBPRE = 511;
-
 
39
        TBDATA1 = 65535;
33
    
40
    }
34
    /* configure timer for 10 kHz */
41
    else if (usecs > 21845)
-
 
42
    {
-
 
43
        TBPRE = 511;
35
    TBCMD = (1 << 1);   /* TB_CLR */
44
        TBDATA1 = (usecs * 192) >> 15;
-
 
45
    }
-
 
46
    else
-
 
47
    {
-
 
48
        TBPRE = 0;
36
    TBPRE = 300 - 1;    /* prescaler */
49
        TBDATA1 = (usecs * 192) >> 6;
-
 
50
    }
37
    TBCON = (0 << 13) | /* TB_INT1_EN */
51
    TBCON = (1 << 13) | /* TB_INT1_EN */
38
            (1 << 12) | /* TB_INT0_EN */
52
            (0 << 12) | /* TB_INT0_EN */
39
            (0 << 11) | /* TB_START */
53
            (0 << 11) | /* TB_START */
40
            (2 << 8) |  /* TB_CS = PCLK / 16 */
54
            (2 << 8) |  /* TB_CS = PCLK / 16 */
41
            (0 << 4);   /* TB_MODE_SEL = interval mode */
55
            (2 << 4);   /* TB_MODE_SEL = one-shot mode */
42
    TBDATA0 = cycles;   /* set interval period */
56
    TBCMD = (1 << 1);   /* TB_CLR */
43
    TBCMD = (1 << 0);   /* TB_EN */
57
    TBCMD = (1 << 0);   /* TB_EN */
44
}
58
}
45
 
59
 
-
 
60
void timer_kill_wakeup()
-
 
61
{
-
 
62
    TBCMD = (1 << 1);   /* TB_CLR */
-
 
63
    TBCON = TBCON;
-
 
64
}
-
 
65
 
46
void INT_TIMERB(void)
66
void INT_TIMERB(void)
47
{
67
{
48
    TBCON = TBCON;
68
    TBCON = TBCON;
49
    scheduler_switch(NULL, NULL);
69
    scheduler_switch(NULL, NULL);
50
}
70
}