1 /* ustredni hodiny Spejbla */
5 #include <periph/can.h>
7 #define CANLOAD_ID (*((volatile unsigned long *) 0x40000120))
9 void timer_irq() __attribute__((interrupt
));
11 void timer_init(uint32_t prescale
, uint32_t period
) {
14 T0MCR
= 0x3<<3; /* interrupt and counter reset on match1 */
15 T0EMR
= 0x1<<6 | 0x2; /* set MAT0.1 low on match and high now */
16 T0CCR
= 0x0; /* no capture */
17 T0TCR
|= 0x1; /* go! */
20 void timer_init_irq(unsigned irq_vect
) {
21 /* set interrupt vector */
22 ((uint32_t*)&VICVectAddr0
)[irq_vect
] = (uint32_t)timer_irq
;
23 ((uint32_t*)&VICVectCntl0
)[irq_vect
] = 0x20 | 4;
24 /* enable timer int */
25 VICIntEnable
= 0x00000010;
28 can_msg_t msg
= {.flags
= 0, .dlc
= 1};
32 msg
.data
[0] = seq_num
++;
33 while (can_tx_msg(&msg
));
41 /* peripheral clock = CPU clock (10MHz) */
43 /** map exception handling to RAM **/
45 /* init Vector Interrupt Controller */
46 VICIntEnClr
= 0xFFFFFFFF;
47 VICIntSelect
= 0x00000000;
48 /* 10MHz VPB, 1000kb/s TSEG1=6, TSEG2=3, SJW= */
49 can_init(0x250000, 14, NULL
);
52 timer_init(10, 4000 /*250Hz*/);