заменила часть функций на макросы из wiring_LL.h

This commit is contained in:
klassents committed 2024-10-10 19:14:24 +07:00
1 parent d1a5896d2d
commit d7010fba6e
5 files changed
+45 -14

No files matched your search

+2 -2
View File
@@ -19,13 +19,13 @@ static void nothing(void)
// enable global interrupts
void interrupts(void)
{
HAL_IRQ_EnableInterrupts();
GLOBAL_IRQ_ENABLE();
}
// disable global interrupts
void noInterrupts(void)
{
HAL_IRQ_DisableInterrupts();
GLOBAL_IRQ_DISABLE();
}
// we can provide no more than 8 interrupts on gpio at the same time
-2
View File
@@ -27,8 +27,6 @@ void post_init(void)
{
// enable global interrupts by default
interrupts();
((GPIO_0)->SET = (GPIO_PIN_0));
}
// --------------------- other --------------------- //
+2 -1
View File
@@ -1,4 +1,5 @@
#include "mik32_hal_irq.h"
#include "wiring_LL.h"
// isr functions
extern void serial_handler_wrapper(uint8_t uartNumInt);
@@ -33,5 +34,5 @@ void __attribute__((noinline, section(".ram_text"))) trap_handler(void)
wire_handler_wrapper();
// reset all interrupts
HAL_EPIC_Clear(0xFFFFFFFF);
EPIC_CLEAR_ALL();
}
+33 -6
View File
@@ -4,11 +4,31 @@
#include "mik32_hal_irq.h"
#include "mik32_hal_gpio.h"
#include "mik32_hal_scr1_timer.h"
#include "mik32_hal_timer16.h"
// ----------------- Systick ----------------- //
// ----------------- COMMON ----------------- //
// convert pin mask from HAL_PinsTypeDef to pin number
#define PIN_MASK_TO_PIN_NUMBER(mask) \
({ \
uint8_t pos; \
for (pos = 0; pos < 16; pos++) \
if ((mask >> pos) & 1) \
break; \
pos; \
})
// ----------------- SYSTICK ----------------- //
// get ticks from systick
#define SYSTICK_GET_TICKS() ((uint64_t)(SCR1_TIMER->MTIMEH)<<32 | SCR1_TIMER->MTIME)
// ----------------- TIMER16 ----------------- //
#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))
// ----------------- EPIC ----------------- //
#define EPIC_LEVEL_CLEAR_BY_MASK(mask) (EPIC->MASK_LEVEL_CLEAR |= mask)
#define EPIC_CLEAR_ALL() (EPIC->CLEAR = 0xFFFFFFFF)
// ----------------- IRQ ----------------- //
#define GLOBAL_IRQ_DISABLE() (clear_csr(mie, MIE_MEIE))
@@ -16,9 +36,12 @@
set_csr(mie, MIE_MEIE)
// ----------------- GPIO ----------------- //
#define GPIO_SET_PIN(GPIO_x, pin) ((GPIO_x)->SET = (pin))
#define GPIO_CLEAR_PIN(GPIO_x, pin) ((GPIO_x)->CLEAR = (pin))
#define GPIO_READ_PIN(GPIO_x, pin) (((GPIO_x)->SET & (pin)) != (uint32_t)GPIO_PIN_LOW ? GPIO_PIN_HIGH : GPIO_PIN_LOW)
#define GPIO_SET_PIN(GPIO_x, pinMask) ((GPIO_x)->SET = (pinMask))
#define GPIO_CLEAR_PIN(GPIO_x, pinMask) ((GPIO_x)->CLEAR = (pinMask))
#define GPIO_TOGGLE_PIN(GPIO_x, pinMask) ((GPIO_x)->OUTPUT_ ^= pinMask)
#define GPIO_READ_PIN(GPIO_x, pinMask) (((GPIO_x)->SET & (pinMask)) != (uint32_t)GPIO_PIN_LOW ? GPIO_PIN_HIGH : GPIO_PIN_LOW)
// get pin state by it's number
#define GPIO_GET_PIN_STATE(GPIO_x, pinNumber) (((GPIO_x)->OUTPUT_ >> pinNumber) & 0b1)
// ----------------- GPIO IRQ ----------------- //
#define GPIO_IRQ_LINE_ENABLE(lineMask) ( GPIO_IRQ->ENABLE_SET = (1 << (lineMask >> GPIO_IRQ_LINE_S)) )
@@ -27,7 +50,11 @@
#define GPIO_IRQ_CLEAR_ALL() ( GPIO_IRQ->CLEAR = 0b11111111)
// ----------------- PIN CONFIG ----------------- //
// return config of pin with pinShift(0...16) in portReg (config, pupd, ds for ports 0...2)
#define PIN_GET_PAD_CONFIG(portReg, pinShift) ((PAD_CONFIG->portReg >> (pinShift<<1)) & 0b11)
// return config of pin with pinNumber(0...16) in portReg (config, pupd, ds for ports 0...2)
#define PIN_GET_PAD_CONFIG(portReg, pinNumber) ((PAD_CONFIG->portReg >> (pinNumber<<1)) & 0b11)
#define PIN_SET_PAD_CONFIG(portReg, pinNumber, value) (PAD_CONFIG->portReg = (PAD_CONFIG->portReg & (~PAD_CONFIG_PIN_M(pinNumber))) \
| PAD_CONFIG_PIN(pinNumber, value))
#endif /* _WIRING_LL_H_ */
@@ -198,10 +198,15 @@ void SoftwareSerial::setRX(uint8_t rx)
// attach interrupt to rx pin if available
attachInterrupt(digitalPinToInterrupt(_receivePin), softSerial_handler_wrapper, _inverse_logic ? RISING : FALLING);
if (!_inverse_logic)
// turn on pull up for rx if logic is not inverse
HAL_GPIO_PinConfig((GPIO_TypeDef *)_receivePortRegister, (HAL_PinsTypeDef)_receiveBitMask,
HAL_GPIO_MODE_GPIO_INPUT, HAL_GPIO_PULL_UP, HAL_GPIO_DS_2MA);
if (!_inverse_logic)
{
uint8_t pinNumber = PIN_MASK_TO_PIN_NUMBER(_receiveBitMask);
if (((GPIO_TypeDef*)_receivePortRegister) == GPIO_0)
PIN_SET_PAD_CONFIG(PORT_0_PUPD, pinNumber, HAL_GPIO_PULL_UP);
else if (((GPIO_TypeDef*)_receivePortRegister) == GPIO_1)
PIN_SET_PAD_CONFIG(PORT_1_PUPD, pinNumber, HAL_GPIO_PULL_UP);
}
// turn off int line for while (it turning on in attachInterrupt())
GPIO_IRQ_LINE_DISABLE(_int_maskLine);
}