перенесла работу с регистрами в LL файл

This commit is contained in:
klassents committed 2024-09-25 11:39:22 +07:00
1 parent 04f2e12ecc
commit 562c29dbe1
3 files changed
+41 -36

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
#ifndef _WIRING_LL_H_
#define _WIRING_LL_H_
#include "mik32_hal_irq.h"
#include "mik32_hal_gpio.h"
#include "mik32_hal_scr1_timer.h"
// ----------------- Systick ----------------- //
// get ticks from systick
#define SYSTICK_GET_TICKS() ((uint64_t)(SCR1_TIMER->MTIMEH)<<32 | SCR1_TIMER->MTIME)
// ----------------- IRQ ----------------- //
#define GLOBAL_IRQ_DISABLE() (clear_csr(mie, MIE_MEIE))
#define GLOBAL_IRQ_ENABLE() set_csr(mstatus, MSTATUS_MIE); \
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)
// ----------------- GPIO IRQ ----------------- //
#define GPIO_IRQ_LINE_ENABLE(lineMask) ( GPIO_IRQ->ENABLE_SET = (1 << (lineMask >> GPIO_IRQ_LINE_S)) )
#define GPIO_IRQ_LINE_DISABLE(lineMask) ( GPIO_IRQ->ENABLE_CLEAR = (1 << (lineMask >> GPIO_IRQ_LINE_S)) )
#define GPIO_IRQ_CLEAR_ALL() (GPIO_IRQ->CLEAR = 0b11111111)
#endif /* _WIRING_LL_H_ */
+12 -34
View File
@@ -19,30 +19,11 @@ http://arduiniana.org.
#include <Arduino.h> #include <Arduino.h>
#include <SoftwareSerial.h> #include <SoftwareSerial.h>
#include "mik32_hal_irq.h" #include "wiring_LL.h"
#include "mik32_hal_gpio.h"
#include "mik32_hal_scr1_timer.h"
#define MAX_SOFT_SERIAL_SPEED 115200 #define MAX_SOFT_SERIAL_SPEED 115200
#define MIN_SOFT_SERIAL_SPEED 300 #define MIN_SOFT_SERIAL_SPEED 300
// --------- TO LL ---------
// get ticks from systick
#define SYSTICK_GET_TICKS() ((uint64_t)(SCR1_TIMER->MTIMEH)<<32 | SCR1_TIMER->MTIME)
#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_IRQ_LINE_ENABLE(lineMask) ( GPIO_IRQ->ENABLE_SET = (1 << (lineMask >> GPIO_IRQ_LINE_S)) )
#define GPIO_IRQ_LINE_DISABLE(lineMask) ( GPIO_IRQ->ENABLE_CLEAR = (1 << (lineMask >> GPIO_IRQ_LINE_S)) )
#define GPIO_IRQ_CLEAR_ALL() (GPIO_IRQ->CLEAR = 0b11111111)
#define GLOBAL_IRQ_DISABLE() (clear_csr(mie, MIE_MEIE))
#define GLOBAL_IRQ_ENABLE() set_csr(mstatus, MSTATUS_MIE); \
set_csr(mie, MIE_MEIE)
// --------- TO LL ---------
// Statics // Statics
// static variable is common to all class instances // static variable is common to all class instances
SoftwareSerial *SoftwareSerial::active_object = 0; SoftwareSerial *SoftwareSerial::active_object = 0;
@@ -279,14 +260,13 @@ void SoftwareSerial::begin(long speed)
_rx_delay_stopbit+=30; _rx_delay_stopbit+=30;
} }
// Save start bit polarity - low to high if _inverse_logic // Save gpio_line for turning on/off interrupts
_int_mode = _inverse_logic ? (uint8_t)GPIO_INT_MODE_RISING : (uint8_t)GPIO_INT_MODE_FALLING; _int_maskLine = digitalPinToGpioIntLine(_receivePin);
// Save gpio_mux and gpio_line for on/off interrupts // Init interrupt line
_int_maskMux = digitalPinToGpioIntMux(_receivePin); // gpio mux value HAL_GPIO_InitInterruptLine((HAL_GPIO_Line_Config)digitalPinToGpioIntMux(_receivePin),
_int_maskLine = digitalPinToGpioIntLine(_receivePin); // gpio irq line value _inverse_logic ? GPIO_INT_MODE_RISING : GPIO_INT_MODE_FALLING);
HAL_GPIO_InitInterruptLine((HAL_GPIO_Line_Config) _int_maskMux, (HAL_GPIO_InterruptMode)_int_mode); GPIO_IRQ_LINE_DISABLE(_int_maskLine); // turn off int line (it turning on while line init)
GPIO_IRQ_LINE_DISABLE(_int_maskLine); // turn off int HAL_EPIC_MaskEdgeSet(HAL_EPIC_GPIO_IRQ_MASK); // turn on the mask in EPIC
HAL_EPIC_MaskEdgeSet(HAL_EPIC_GPIO_IRQ_MASK); // turn on the mask in EPIC
} }
else else
ErrorMsgHandler("SoftwareSerial.begin(): Rx pin does not support interrupts, use different pin"); ErrorMsgHandler("SoftwareSerial.begin(): Rx pin does not support interrupts, use different pin");
@@ -302,12 +282,10 @@ void SoftwareSerial::begin(long speed)
void SoftwareSerial::setRxIntMsk(bool enable) void SoftwareSerial::setRxIntMsk(bool enable)
{ {
if (enable) if (enable)
// enable interrupt line GPIO_IRQ_LINE_ENABLE(_int_maskLine);
GPIO_IRQ_LINE_ENABLE(_int_maskLine); else
else GPIO_IRQ_LINE_DISABLE(_int_maskLine);
// disable interrupt line
GPIO_IRQ_LINE_DISABLE(_int_maskLine);
} }
void SoftwareSerial::end() void SoftwareSerial::end()
@@ -46,9 +46,7 @@ private:
uint8_t _transmitPin; uint8_t _transmitPin;
uint16_t _transmitBitMask; uint16_t _transmitBitMask;
uint32_t _transmitPortRegister; uint32_t _transmitPortRegister;
uint8_t _int_maskMux;
uint8_t _int_maskLine; uint8_t _int_maskLine;
uint8_t _int_mode;
// must never be 0! // must never be 0!
uint32_t _rx_delay_centering; uint32_t _rx_delay_centering;