в библиотеке заменила некоторые строчки на макросы из wiringLL.h. переименовала обработчик прерываний

This commit is contained in:
klassents 2024-10-14 10:21:04 +07:00
parent 47c01383e6
commit 978661626c
3 changed files with 38 additions and 38 deletions

View File

@ -9,7 +9,7 @@ void __attribute__((weak)) wire_interrupt_handler(void)
{
// dummy function for case when wire library is not in use
}
void __attribute__((weak)) servo_handler_wrapper(void)
void __attribute__((weak)) servo_interrupt_handler(void)
{
// dummy function for case when wire library is not in use
}
@ -27,7 +27,7 @@ void __attribute__((noinline, section(".ram_text"), optimize("O3"))) trap_handle
// servo timer interrupt
if (EPIC_CHECK_TIMER16_2())
servo_handler_wrapper();
servo_interrupt_handler();
// uart0 interrupt
if (EPIC_CHECK_UART_0())

View File

@ -29,6 +29,7 @@
#define TIM16_DISABLE(htim16) (htim16.Instance->CR &= ~TIMER16_CR_ENABLE_M)
#define TIM16_CLEAR_INT_MASK(htim16, intMask) (htim16.Instance->ICR = intMask)
#define TIM16_GET_ARRM_INT_STATUS(htim16) ((bool)((htim16.Instance->ISR & htim16.Instance->IER) & TIMER16_ISR_ARR_MATCH_M))
#define TIM16_DISABLE_INT_BY_MASK(htim16,intMask) (htim16.Instance->IER &= ~(intMask))
// ----------------- EPIC ----------------- //
#define EPIC_LEVEL_CLEAR_BY_MASK(mask) (EPIC->MASK_LEVEL_CLEAR |= mask)

View File

@ -4,6 +4,7 @@
#include "mik32_hal_timer16.h"
#include "mik32_hal_irq.h"
#include "wiring_LL.h"
#include "Servo.h"
@ -19,6 +20,9 @@ uint8_t prescaler = TIMER16_PRESCALER_16;
#define usToTicks(_us) ((clockCyclesPerMicrosecond() * _us) / ( (1 << prescaler) )) // converts microseconds to ticks (TIMERx_PRESCALER_16)
#define ticksToUs(_ticks) (((unsigned) _ticks * ( (1 << prescaler) )) / clockCyclesPerMicrosecond()) // converts from ticks back to microseconds
#define SERVO_MIN() (MIN_PULSE_WIDTH - this->min * 4) // minimum value in us for this servo
#define SERVO_MAX() (MAX_PULSE_WIDTH - this->max * 4) // maximum value in us for this servo
#define TRIM_DURATION 5 // compensation ticks to trim adjust for digitalWrite delays
// convenience macros
@ -27,9 +31,6 @@ uint8_t prescaler = TIMER16_PRESCALER_16;
#define SERVO_INDEX(_timer,_channel) ((_timer*SERVOS_PER_TIMER) + _channel) // macro to access servo index by timer and channel
#define SERVO(_timer,_channel) (servos[SERVO_INDEX(_timer,_channel)]) // macro to access servo class by timer and channel
#define SERVO_MIN() (MIN_PULSE_WIDTH - this->min * 4) // minimum value in us for this servo
#define SERVO_MAX() (MAX_PULSE_WIDTH - this->max * 4) // maximum value in us for this servo
// timer handler
Timer16_HandleTypeDef htimer16;
@ -58,9 +59,9 @@ void Timer16_2_Init()
/************ static functions common to all instances ***********************/
// irq handler
extern "C" void servo_handler_wrapper(void)
extern "C" void __attribute__((optimize("O3"))) servo_interrupt_handler(void)
{
if ((htimer16.Instance->ISR & htimer16.Instance->IER) & TIMER16_ISR_ARR_MATCH_M)
if (TIM16_GET_ARRM_INT_STATUS(htimer16))
{
timer16_Sequence_t timer = _timer1;
@ -89,7 +90,7 @@ extern "C" void servo_handler_wrapper(void)
}
// reset timer interrupt flags
htimer16.Instance->ICR = 0xFFFFFFFF;
TIM16_CLEAR_INT_MASK(htimer16, 0xFFFFFFFF);
}
// init isr
@ -108,11 +109,9 @@ static void finISR(timer16_Sequence_t timer)
{
if (timer == _timer1)
{
HAL_Timer16_Disable(&htimer16);
htimer16.Instance->IER &= ~(TIMER16_IER_ARROKIE_M | TIMER16_IER_CMPOKIE_M
| TIMER16_IER_ARRMIE_M | TIMER16_IER_CMPMIE_M);
htimer16.Instance->CR &= ~TIMER16_CR_ENABLE_M; // disable timer
HAL_EPIC_MaskLevelClear(HAL_EPIC_TIMER16_1_MASK);
TIM16_DISABLE(htimer16);
TIM16_DISABLE_INT_BY_MASK(htimer16, TIMER16_IER_ARROKIE_M | TIMER16_IER_CMPOKIE_M | TIMER16_IER_ARRMIE_M | TIMER16_IER_CMPMIE_M);
EPIC_LEVEL_CLEAR_BY_MASK(HAL_EPIC_TIMER16_1_MASK);
}
}