mirror of
https://github.com/SemvdH/OBD2-car-display.git
synced 2025-12-16 04:31:04 +00:00
Add test code for using RTT
This commit is contained in:
32
due_obd2/obd2_timer.c
Normal file
32
due_obd2/obd2_timer.c
Normal file
@@ -0,0 +1,32 @@
|
||||
// #include "sam3xa/include/component/component_rtt.h"
|
||||
// #include "sam3xa/include/sam3x8e.h"
|
||||
#include "obd2_timer.h"
|
||||
|
||||
void obd2_timer_init(void)
|
||||
{
|
||||
/* enable the timer: reset the RTT, enable the alarm interrupt, set the prescaler value equal to the processor clock speed*/
|
||||
RTT->RTT_MR = RTT_MR_RTTRST | RTT_MR_ALMIEN | RTT_MR_RTPRES(32768/2);
|
||||
/* set the alarm value to 0*/
|
||||
RTT->RTT_AR = 0;
|
||||
/* enable the interrupt*/
|
||||
NVIC_EnableIRQ(RTT_IRQn);
|
||||
}
|
||||
|
||||
void obd2_timer_reset()
|
||||
{
|
||||
/* To prevent several executions of the interrupt handler,
|
||||
the interrupt must be disabled in the interrupt handler
|
||||
and re-enabled when the status register is cleared.
|
||||
*/
|
||||
/* disable interrupts */
|
||||
RTT->RTT_MR &= ~RTT_MR_ALMIEN;
|
||||
/* clear the status register */
|
||||
RTT->RTT_SR;
|
||||
/* set the alarm value to 0*/
|
||||
RTT->RTT_AR = 0;
|
||||
/* re-enable the interrupt*/
|
||||
RTT->RTT_MR |= RTT_MR_ALMIEN;
|
||||
/* reset the RTT*/
|
||||
RTT->RTT_MR |= RTT_MR_RTTRST;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user