2022-05-19 17:31:57 -07:00
|
|
|
/*
|
|
|
|
* sent.cpp
|
|
|
|
*
|
|
|
|
* Created on: 16 May 2022
|
|
|
|
* Author: alexv
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ch.h"
|
|
|
|
#include "hal.h"
|
|
|
|
|
|
|
|
#include "sent.h"
|
|
|
|
#include "sent_hw_icu.h"
|
|
|
|
|
2022-08-06 16:50:45 -07:00
|
|
|
#if SENT_MODE_ICU
|
|
|
|
|
2022-05-19 17:31:57 -07:00
|
|
|
static void icuperiodcb_in1(ICUDriver *icup);
|
|
|
|
static void icuperiodcb_in2(ICUDriver *icup);
|
2022-07-31 12:14:02 -07:00
|
|
|
#if SENT_DEV == SENT_SILABS_SENS
|
2022-05-19 17:31:57 -07:00
|
|
|
static void icuperiodcb_in3(ICUDriver *icup);
|
|
|
|
static void icuperiodcb_in4(ICUDriver *icup);
|
2022-07-31 12:14:02 -07:00
|
|
|
#endif
|
2022-05-19 17:31:57 -07:00
|
|
|
|
|
|
|
static ICUConfig icucfg_in1 =
|
|
|
|
{
|
2022-08-14 17:37:54 -07:00
|
|
|
.mode = ICU_INPUT_ACTIVE_LOW,
|
|
|
|
.frequency = SENT_ICU_FREQ,
|
|
|
|
.width_cb = NULL,
|
|
|
|
.period_cb = icuperiodcb_in1,
|
|
|
|
.overflow_cb = NULL,
|
|
|
|
.channel = SENT_ICUD_CH1_CH,
|
|
|
|
.dier = 0U,
|
|
|
|
.arr = 0xFFFFFFFFU,
|
2022-05-19 17:31:57 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static ICUConfig icucfg_in2 =
|
|
|
|
{
|
|
|
|
ICU_INPUT_ACTIVE_HIGH,
|
2022-07-31 12:14:02 -07:00
|
|
|
SENT_ICU_FREQ,
|
2022-05-19 17:31:57 -07:00
|
|
|
NULL,
|
|
|
|
icuperiodcb_in2,
|
|
|
|
NULL,
|
2022-08-06 16:55:19 -07:00
|
|
|
SENT_ICUD_CH2_CH,
|
2022-05-19 17:31:57 -07:00
|
|
|
0U,
|
|
|
|
0xFFFFFFFFU
|
|
|
|
};
|
|
|
|
|
2022-07-31 12:14:02 -07:00
|
|
|
#if SENT_DEV == SENT_SILABS_SENS
|
2022-05-19 17:31:57 -07:00
|
|
|
static ICUConfig icucfg_in3 =
|
|
|
|
{
|
|
|
|
ICU_INPUT_ACTIVE_HIGH,
|
2022-07-31 12:14:02 -07:00
|
|
|
SENT_ICU_FREQ,
|
2022-05-19 17:31:57 -07:00
|
|
|
NULL,
|
|
|
|
icuperiodcb_in3,
|
|
|
|
NULL,
|
2022-08-06 16:55:19 -07:00
|
|
|
SENT_ICUD_CH3_CH,
|
2022-05-19 17:31:57 -07:00
|
|
|
0U,
|
|
|
|
0xFFFFFFFFU
|
|
|
|
};
|
|
|
|
|
|
|
|
static ICUConfig icucfg_in4 =
|
|
|
|
{
|
|
|
|
ICU_INPUT_ACTIVE_HIGH,
|
2022-07-31 12:14:02 -07:00
|
|
|
SENT_ICU_FREQ,
|
2022-05-19 17:31:57 -07:00
|
|
|
NULL,
|
|
|
|
icuperiodcb_in4,
|
|
|
|
NULL,
|
2022-08-06 16:55:19 -07:00
|
|
|
SENT_ICUD_CH4_CH,
|
2022-05-19 17:31:57 -07:00
|
|
|
0U,
|
|
|
|
0xFFFFFFFFU
|
|
|
|
};
|
2022-08-06 16:50:45 -07:00
|
|
|
#endif // SENT_DEV
|
2022-05-19 17:31:57 -07:00
|
|
|
|
|
|
|
static void icuperiodcb_in1(ICUDriver *icup)
|
|
|
|
{
|
|
|
|
SENT_ISR_Handler(SENT_CH1, icuGetPeriodX(icup));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void icuperiodcb_in2(ICUDriver *icup)
|
|
|
|
{
|
|
|
|
SENT_ISR_Handler(SENT_CH2, icuGetPeriodX(icup));
|
|
|
|
}
|
|
|
|
|
2022-07-31 12:14:02 -07:00
|
|
|
#if SENT_DEV == SENT_SILABS_SENS
|
2022-05-19 17:31:57 -07:00
|
|
|
static void icuperiodcb_in3(ICUDriver *icup)
|
|
|
|
{
|
2022-07-31 12:14:02 -07:00
|
|
|
SENT_ISR_Handler(SENT_CH3, icuGetPeriodX(icup) >> 1);
|
2022-05-19 17:31:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void icuperiodcb_in4(ICUDriver *icup)
|
|
|
|
{
|
2022-07-31 12:14:02 -07:00
|
|
|
SENT_ISR_Handler(SENT_CH4, icuGetPeriodX(icup) >> 1);
|
2022-05-19 17:31:57 -07:00
|
|
|
}
|
2022-07-31 12:14:02 -07:00
|
|
|
#endif
|
2022-05-19 17:31:57 -07:00
|
|
|
|
2022-08-05 18:11:58 -07:00
|
|
|
void InitSent()
|
2022-05-19 17:31:57 -07:00
|
|
|
{
|
|
|
|
|
2022-08-14 17:37:54 -07:00
|
|
|
//palSetLineMode(HAL_SENT_CH1_LINE, PAL_MODE_INPUT_PULLUP);
|
|
|
|
//palSetLineMode(HAL_SENT_CH2_LINE, PAL_MODE_INPUT_PULLUP);
|
|
|
|
|
2022-08-06 16:55:19 -07:00
|
|
|
icuStart(&SENT_ICUD_CH1_D, &icucfg_in1);
|
|
|
|
icuStartCapture(&SENT_ICUD_CH1_D);
|
|
|
|
icuEnableNotifications(&SENT_ICUD_CH1_D);
|
2022-05-19 17:31:57 -07:00
|
|
|
|
2022-08-14 17:37:54 -07:00
|
|
|
#if 0
|
2022-08-06 16:55:19 -07:00
|
|
|
icuStart(&SENT_ICUD_CH2_D, &icucfg_in2);
|
|
|
|
icuStartCapture(&SENT_ICUD_CH2_D);
|
|
|
|
icuEnableNotifications(&SENT_ICUD_CH2_D);
|
2022-08-14 17:37:54 -07:00
|
|
|
#endif
|
2022-05-19 17:31:57 -07:00
|
|
|
|
2022-07-31 12:14:02 -07:00
|
|
|
#if SENT_DEV == SENT_SILABS_SENS
|
2022-08-06 16:55:19 -07:00
|
|
|
icuStart(&SENT_ICUD_CH3_D, &icucfg_in3);
|
|
|
|
icuStartCapture(&SENT_ICUD_CH3_D);
|
|
|
|
icuEnableNotifications(&SENT_ICUD_CH3_D);
|
2022-05-19 17:31:57 -07:00
|
|
|
|
2022-08-06 16:55:19 -07:00
|
|
|
icuStart(&SENT_ICUD_CH4_D, &icucfg_in4);
|
|
|
|
icuStartCapture(&SENT_ICUD_CH4_D);
|
|
|
|
icuEnableNotifications(&SENT_ICUD_CH4_D);
|
2022-07-31 12:14:02 -07:00
|
|
|
#endif
|
2022-08-14 17:37:54 -07:00
|
|
|
|
|
|
|
/* Start decoder thread */
|
|
|
|
SentDecoder_Init();
|
2022-05-19 17:31:57 -07:00
|
|
|
}
|
|
|
|
|
2022-08-06 16:50:45 -07:00
|
|
|
#endif // SENT_MODE_ICU
|