-
Notifications
You must be signed in to change notification settings - Fork 1
/
timer.c
53 lines (41 loc) · 991 Bytes
/
timer.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* ************************************************************************** */
/** timer
@Company
ShimaneJohoshoriCenter.inc
@File Name
timer.c
@Summary
mruby/c firmware for Rboard.
@Description
tick timer.
*/
/* ************************************************************************** */
#include <xc.h>
#include <sys/attribs.h>
#include "pic32mx.h"
#include "mrubyc.h"
/*
Tick timer functions.
using Timer1
16bit mode.
1kHz (1ms/cycle)
see DS60001105G
14.3.4.2 16-BIT SYNCHRONOUS COUNTER INITIALIZATION STEPS
*/
void tick_timer_init( void )
{
T1CON = 0; // count PBCLK 1:1
TMR1 = 0;
PR1 = PBCLK / 1000;
IFS0CLR = (1 << _IFS0_T1IF_POSITION);
IPC1bits.T1IP = 1; // Interrupt priority.
IPC1bits.T1IS = 0;
IEC0bits.T1IE = 1; // Enable interrupt
T1CONbits.ON = 1;
}
// Timer1 interrupt handler.
void __ISR(_TIMER_1_VECTOR, IPL1AUTO) timer1_isr( void )
{
mrbc_tick();
IFS0CLR = (1 << _IFS0_T1IF_POSITION);
}