rusefi-hardware/SENT-box/firmware/sent_hw_pal.cpp

58 lines
1.3 KiB
C++
Raw Normal View History

/*
* sent.cpp
*
* Created on: 16 May 2022
* Author: alexv
*/
#include "ch.h"
#include "hal.h"
#include "sent.h"
#include "sent_hw_pal.h"
2022-08-06 16:50:45 -07:00
#if SENT_MODE_PAL
uint32_t cyccnt_ch_prev[SENT_CH_MAX] = {0};
#pragma GCC push_options
#pragma GCC optimize ("O2")
static void palperiodcb_in(void *arg)
{
uint32_t cyccnt_ch;
uint16_t cyccnt_ch_period;
int ch = (int)arg;
cyccnt_ch = port_rt_get_counter_value();
if(cyccnt_ch > cyccnt_ch_prev[ch])
{
cyccnt_ch_period = (uint16_t)((cyccnt_ch - cyccnt_ch_prev[ch]));
}
else
{
cyccnt_ch_period = (uint16_t)((0xFFFFFFFF - cyccnt_ch_prev[ch] + cyccnt_ch));
}
cyccnt_ch_prev[ch] = cyccnt_ch;
SENT_ISR_Handler(ch, cyccnt_ch_period);
}
#pragma GCC pop_options
2022-08-05 18:11:58 -07:00
void InitSent()
{
palSetLineMode(HAL_SENT_CH1_LINE, PAL_MODE_INPUT_PULLUP);
palEnableLineEvent(HAL_SENT_CH1_LINE, PAL_EVENT_MODE_FALLING_EDGE);
palSetLineCallback(HAL_SENT_CH1_LINE, (palcallback_t)palperiodcb_in, (void *)SENT_CH1);
palSetLineMode(HAL_SENT_CH2_LINE, PAL_MODE_INPUT_PULLUP);
palEnableLineEvent(HAL_SENT_CH2_LINE, PAL_EVENT_MODE_FALLING_EDGE);
palSetLineCallback(HAL_SENT_CH2_LINE, (palcallback_t)palperiodcb_in, (void *)SENT_CH1);
2022-08-11 15:16:41 -07:00
/* Start decoder thread */
SentDecoder_Init();
}
2022-08-06 16:50:45 -07:00
#endif // SENT_MODE_PAL