40 #define BIT(n) (1 << (n))
43 #define clock() (0xffff - TCR[CLOCK_CHANNEL])
48 #if (CLOCK_CHANNEL <= 7)
51 TPS0 = (TPS0 & 0xfff0) | CLOCK_SCALER;
52 TMR[CLOCK_CHANNEL] = 0x0000;
54 #if (CLOCK_CHANNEL == 0)
56 #elif (CLOCK_CHANNEL == 1)
58 #elif (CLOCK_CHANNEL == 2)
60 #elif (CLOCK_CHANNEL == 3)
62 #elif (CLOCK_CHANNEL == 4)
64 #elif (CLOCK_CHANNEL == 5)
66 #elif (CLOCK_CHANNEL == 6)
68 #elif (CLOCK_CHANNEL == 7)
71 #error Invalid CLOCK_CHANNEL
74 TE0 |=
BIT(CLOCK_CHANNEL);
75 TS0 |=
BIT(CLOCK_CHANNEL);
79 TPS1 = (TPS1 & 0xfff0) | CLOCK_SCALER;
80 TMR[CLOCK_CHANNEL] = 0x0000;
82 #if (CLOCK_CHANNEL == 8)
84 #elif (CLOCK_CHANNEL == 9)
86 #elif (CLOCK_CHANNEL == 10)
88 #elif (CLOCK_CHANNEL == 11)
90 #elif (CLOCK_CHANNEL == 12)
92 #elif (CLOCK_CHANNEL == 13)
94 #elif (CLOCK_CHANNEL == 14)
96 #elif (CLOCK_CHANNEL == 15)
99 #error Invalid CLOCK_CHANNEL
102 TE1 |=
BIT(CLOCK_CHANNEL);
103 TS1 |=
BIT(CLOCK_CHANNEL);
116 return clock() / CLOCK_CONF_SECOND;
125 while(clock() - t0 < t) ;
void clock_init(void)
Initialize the clock library.
#define BIT(x)
Useful to reference a single bit of a byte.
CCIF clock_time_t clock_time(void)
Get the current clock time.
CCIF unsigned long clock_seconds(void)
Get the current value of the platform seconds.
void clock_wait(clock_time_t t)
Wait for a given number of ticks.