Subversion Repositories Code-Repo

Rev

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

Rev 199 Rev 201
Line 1... Line 1...
1
#include <xc.h>
1
#include <xc.h>
2
#include <plib.h>
2
#include <plib.h>
3
#include "defines.h"
3
#include "defines.h"
4
#include "TIMER5.h"
4
#include "TIMER5.h"
5
 
5
 
6
static void (*callback_function)(void);
6
static TIMER_DATA *timer_data_ptr;
7
 
7
 
8
void TIMER5_Init(void (*callback)(void), unsigned int time_us) {
8
void TIMER5_Init(TIMER_DATA *data, void (*callback)(void), unsigned int time_us) {
-
 
9
    if (data != NULL) // if ptr is null, use existing data
-
 
10
        timer_data_ptr = data;
-
 
11
    
9
    callback_function = callback;
12
    timer_data_ptr->callback_function = callback;
-
 
13
 
-
 
14
    // Note: PR5 is 16-bit wide! (max time_us = 13107)
10
    int time = 5 * time_us;
15
    int time = 5 * time_us;
11
 
16
 
12
    INTDisableInterrupts();
17
    INTDisableInterrupts();
13
    
18
    
14
    T5CON = 0x0040;         // Prescaler at 1:16, clock from peripheral clock
19
    T5CON = 0x0040;         // Prescaler at 1:16, clock from peripheral clock
Line 30... Line 35...
30
    T5CONCLR = 0x8000; // Stop timer
35
    T5CONCLR = 0x8000; // Stop timer
31
}
36
}
32
 
37
 
33
void __ISR(_TIMER_5_VECTOR, ipl4) __TIMER_5_Interrupt_Handler(void) {
38
void __ISR(_TIMER_5_VECTOR, ipl4) __TIMER_5_Interrupt_Handler(void) {
34
    // Call the saved callback function
39
    // Call the saved callback function
35
    (*callback_function)();
40
    (*timer_data_ptr->callback_function)();
36
    
41
    
37
    IFS0CLR = 0x00100000; // Clear the timer interrupt flag
42
    IFS0CLR = 0x00100000; // Clear the timer interrupt flag
38
}
43
}
39
44