finished state machine

This commit is contained in:
Sem van der Hoeven
2023-10-30 23:45:38 +01:00
parent 892ea7d725
commit ef4ed9b617
6 changed files with 264 additions and 96 deletions

View File

@@ -1,23 +1,32 @@
#include "sam3xa/include/sam3x8e.h"
#include "sam3xa/include/component/component_rtt.h"
// #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);
/* enable the timer: reset the RTT
RTT->RTT_MR = RTT_MR_RTTRST;
/* set the alarm value to 0*/
RTT->RTT_AR = 0;
}
void obd2_timer_enable()
{
/* enable the alarm interrupt*/
RTT->RTT_MR |= RTT_MR_ALMIEN;
/* 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.
*/
/* 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 (reading it clears it)
@@ -30,5 +39,10 @@ void obd2_timer_reset()
RTT->RTT_MR |= RTT_MR_ALMIEN;
/* reset the RTT*/
RTT->RTT_MR |= RTT_MR_RTTRST;
}
void obd2_timer_set_period(__UINT32_TYPE__ period)
{
/* set the prescaler value equal to the clock speed divided by how many milliseconds*/
RTT->RTT_MR |= RTT_MR_RTPRES(CLOCK_FREQ / (1000/period));
}