Handful of minor improvements
parent
42c00b0890
commit
0d0bf18643
|
@ -18,10 +18,10 @@
|
|||
|
||||
// Convert n*R*C into a number of timer counts
|
||||
#ifdef __GNUC__
|
||||
#define TIMDAC_NRC(n, r, c) ({ \
|
||||
#define TIMDAC_NRC(n, r, c) __extension__(({ \
|
||||
_Static_assert((n) * (r) * (c) * TIMDAC_TIMERFREQ_HZ <= 65535, \
|
||||
"Time constant too high for 16-bit timer"); \
|
||||
(unsigned)(((n) * (r) * (c) * TIMDAC_TIMERFREQ_HZ)); })
|
||||
(unsigned)(((n) * (r) * (c) * TIMDAC_TIMERFREQ_HZ)); }))
|
||||
#else
|
||||
#define TIMDAC_NRC(n, r, c) ((unsigned)((n) * (r) * (c) * TIMDAC_TIMERFREQ_HZ))
|
||||
#endif
|
||||
|
|
|
@ -31,11 +31,8 @@
|
|||
// Output compare channel on TIMDAC_HW_TIMER
|
||||
#define TIMDAC_HW_TIMER_CHANNEL 1
|
||||
|
||||
// Interrupt preemption priority
|
||||
#define TIMDAC_HW_TIMER_IRQPRI 3
|
||||
|
||||
// Interrupt subpriority
|
||||
#define TIMDAC_HW_TIMER_IRQSUBPRI 3
|
||||
// Merged interrupt preemption priority
|
||||
#define TIMDAC_HW_TIMER_IRQPRI ((preempt << 6) | (subpri << 4))
|
||||
|
||||
// Define nonzero to use fast interrupts.
|
||||
#define TIMDAC_HW_USE_FAST_ISR 1
|
||||
|
|
|
@ -9,8 +9,8 @@ dependencies = []
|
|||
defs = []
|
||||
|
||||
if o_hw == 'ch32v103'
|
||||
ch32v103_proj = subproject('ch32v103-meson')
|
||||
ch32v103_dep = ch32v103_proj.get_variable('ch32v103_dep')
|
||||
ch32v103_proj = subproject('ch32v10x')
|
||||
ch32v103_dep = ch32v103_proj.get_variable('ch32v10x_dep')
|
||||
dependencies += ch32v103_dep
|
||||
sources += ['src/timdac_hw_ch32v103.c']
|
||||
endif
|
||||
|
@ -30,7 +30,7 @@ timdac_lib = library(
|
|||
include_directories: ['inc'],
|
||||
)
|
||||
|
||||
libtimdac_dep = declare_dependency(
|
||||
timdac_dep = declare_dependency(
|
||||
compile_args: defs,
|
||||
include_directories: include_directories('inc'),
|
||||
link_with: timdac_lib,
|
||||
|
|
|
@ -25,10 +25,7 @@
|
|||
// Number of the output compare channel, from 1 to 4
|
||||
//
|
||||
// #define TIMDAC_HW_TIMER_IRQPRI
|
||||
// Interrupt preemption priority
|
||||
//
|
||||
// #define TIMDAC_HW_TIMER_IRQSUBPRI
|
||||
// Interrupt subpriority
|
||||
// Merged nterrupt priority
|
||||
//
|
||||
// #define TIMDAC_HW_USE_FAST_ISR 1
|
||||
// Define nonzero to use fast interrupts. The CH32V103 has special interrupt
|
||||
|
@ -131,13 +128,14 @@ void timdac_hw_init(void)
|
|||
#ifdef TIMDAC_HW_GPIO_CHAN_PORT
|
||||
for (size_t i = 0; i < N_CHANSEL; i++)
|
||||
{
|
||||
_init_gpio(
|
||||
TIMDAC_HW_GPIO_CHAN_PORT,
|
||||
_chansel[i],
|
||||
GPIO_Mode_Out_PP,
|
||||
false,
|
||||
false
|
||||
);
|
||||
if (_chansel[i])
|
||||
_init_gpio(
|
||||
TIMDAC_HW_GPIO_CHAN_PORT,
|
||||
_chansel[i],
|
||||
GPIO_Mode_Out_PP,
|
||||
false,
|
||||
false
|
||||
);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -187,13 +185,8 @@ void timdac_hw_init(void)
|
|||
TIM_SelectOnePulseMode(TIM, TIM_OPMode_Single);
|
||||
TIM_CtrlPWMOutputs(TIM, ENABLE);
|
||||
|
||||
NVIC_InitTypeDef tim_it_init = {
|
||||
.NVIC_IRQChannel = TIM_IRQn,
|
||||
.NVIC_IRQChannelPreemptionPriority = TIMDAC_HW_TIMER_IRQPRI,
|
||||
.NVIC_IRQChannelSubPriority = TIMDAC_HW_TIMER_IRQSUBPRI,
|
||||
.NVIC_IRQChannelCmd = ENABLE,
|
||||
};
|
||||
NVIC_Init(&tim_it_init);
|
||||
NVIC_SetPriority(TIM_IRQn, TIMDAC_HW_TIMER_IRQPRI);
|
||||
NVIC_EnableIRQ(TIM_IRQn);
|
||||
TIM_ITConfig(TIM, TIM_IT_Update, ENABLE);
|
||||
}
|
||||
|
||||
|
@ -254,6 +247,8 @@ void timdac_hw_gpio_polarity(bool pos)
|
|||
{
|
||||
#ifdef TIMDAC_HW_GPIO_POLARITY
|
||||
GPIO_WriteBit(TIMDAC_HW_GPIO_POLARITY, !pos ? Bit_SET : Bit_RESET);
|
||||
#else
|
||||
(void) pos;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -270,7 +265,7 @@ void timdac_hw_gpio_select_channel(uint8_t chan)
|
|||
if (chan & 1) chan_bits |= bit;
|
||||
}
|
||||
|
||||
GPIO_ResetBits(TIMDAC_HW_GPIO_CHAN_PORT, chan_mask);
|
||||
GPIO_ResetBits(TIMDAC_HW_GPIO_CHAN_PORT, chan_mask & ~chan_bits);
|
||||
GPIO_SetBits(TIMDAC_HW_GPIO_CHAN_PORT, chan_bits);
|
||||
#else
|
||||
(void) chan;
|
||||
|
@ -283,21 +278,6 @@ bool timdac_hw_gpio_tune_is_high(void)
|
|||
^ !TIMDAC_HW_GPIO_TUNE_POL;
|
||||
}
|
||||
|
||||
__attribute__((used))
|
||||
void _timdac_hw_isr(void)
|
||||
{
|
||||
#ifdef TIMDAC_HW_GPIO_PROFILE
|
||||
GPIO_WriteBit(TIMDAC_HW_GPIO_PROFILE, Bit_SET);
|
||||
#endif
|
||||
|
||||
TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
|
||||
timdac_poll();
|
||||
|
||||
#ifdef TIMDAC_HW_GPIO_PROFILE
|
||||
GPIO_WriteBit(TIMDAC_HW_GPIO_PROFILE, Bit_RESET);
|
||||
#endif
|
||||
}
|
||||
|
||||
static uint16_t _ntim_to_channel(uint16_t ntim)
|
||||
{
|
||||
return (ntim - 1) << 2;
|
||||
|
@ -325,13 +305,28 @@ static void _init_gpio(
|
|||
|
||||
#if TIMDAC_HW_USE_FAST_ISR
|
||||
__attribute__((naked))
|
||||
#else
|
||||
__attribute__((interrupt("machine")))
|
||||
#endif
|
||||
void TIM_IRQHandler(void)
|
||||
{
|
||||
asm volatile ("jal ra, _timdac_hw_isr");
|
||||
#if TIMDAC_HW_USE_FAST_ISR
|
||||
asm volatile ("mret");
|
||||
}
|
||||
|
||||
__attribute__((used))
|
||||
void _timdac_hw_isr(void)
|
||||
#else
|
||||
__attribute__((interrupt("machine")))
|
||||
void TIM_IRQHandler(void)
|
||||
#endif
|
||||
|
||||
{
|
||||
#ifdef TIMDAC_HW_GPIO_PROFILE
|
||||
GPIO_WriteBit(TIMDAC_HW_GPIO_PROFILE, Bit_SET);
|
||||
#endif
|
||||
|
||||
TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
|
||||
timdac_poll();
|
||||
|
||||
#ifdef TIMDAC_HW_GPIO_PROFILE
|
||||
GPIO_WriteBit(TIMDAC_HW_GPIO_PROFILE, Bit_RESET);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -251,7 +251,7 @@ static uint16_t _compare_for_value(uint16_t value)
|
|||
|
||||
static void _select(void)
|
||||
{
|
||||
bool inhibit = false;
|
||||
bool inhibit = true;
|
||||
bool discharge = false;
|
||||
uint16_t period = UINT16_MAX;
|
||||
|
||||
|
|
Loading…
Reference in New Issue