dev_beta_softSerial #4
No files matched your search
@@ -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_ */
|
||||
@@ -19,30 +19,11 @@ http://arduiniana.org.
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <SoftwareSerial.h>
|
||||
#include "mik32_hal_irq.h"
|
||||
#include "mik32_hal_gpio.h"
|
||||
#include "mik32_hal_scr1_timer.h"
|
||||
#include "wiring_LL.h"
|
||||
|
||||
#define MAX_SOFT_SERIAL_SPEED 115200
|
||||
#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
|
||||
// static variable is common to all class instances
|
||||
SoftwareSerial *SoftwareSerial::active_object = 0;
|
||||
@@ -279,14 +260,13 @@ void SoftwareSerial::begin(long speed)
|
||||
_rx_delay_stopbit+=30;
|
||||
}
|
||||
|
||||
// Save start bit polarity - low to high if _inverse_logic
|
||||
_int_mode = _inverse_logic ? (uint8_t)GPIO_INT_MODE_RISING : (uint8_t)GPIO_INT_MODE_FALLING;
|
||||
// Save gpio_mux and gpio_line for on/off interrupts
|
||||
_int_maskMux = digitalPinToGpioIntMux(_receivePin); // gpio mux value
|
||||
_int_maskLine = digitalPinToGpioIntLine(_receivePin); // gpio irq line value
|
||||
HAL_GPIO_InitInterruptLine((HAL_GPIO_Line_Config) _int_maskMux, (HAL_GPIO_InterruptMode)_int_mode);
|
||||
GPIO_IRQ_LINE_DISABLE(_int_maskLine); // turn off int
|
||||
HAL_EPIC_MaskEdgeSet(HAL_EPIC_GPIO_IRQ_MASK); // turn on the mask in EPIC
|
||||
// Save gpio_line for turning on/off interrupts
|
||||
_int_maskLine = digitalPinToGpioIntLine(_receivePin);
|
||||
// Init interrupt line
|
||||
HAL_GPIO_InitInterruptLine((HAL_GPIO_Line_Config)digitalPinToGpioIntMux(_receivePin),
|
||||
_inverse_logic ? GPIO_INT_MODE_RISING : GPIO_INT_MODE_FALLING);
|
||||
GPIO_IRQ_LINE_DISABLE(_int_maskLine); // turn off int line (it turning on while line init)
|
||||
HAL_EPIC_MaskEdgeSet(HAL_EPIC_GPIO_IRQ_MASK); // turn on the mask in EPIC
|
||||
}
|
||||
else
|
||||
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)
|
||||
{
|
||||
if (enable)
|
||||
// enable interrupt line
|
||||
GPIO_IRQ_LINE_ENABLE(_int_maskLine);
|
||||
else
|
||||
// disable interrupt line
|
||||
GPIO_IRQ_LINE_DISABLE(_int_maskLine);
|
||||
if (enable)
|
||||
GPIO_IRQ_LINE_ENABLE(_int_maskLine);
|
||||
else
|
||||
GPIO_IRQ_LINE_DISABLE(_int_maskLine);
|
||||
}
|
||||
|
||||
void SoftwareSerial::end()
|
||||
|
||||
@@ -46,9 +46,7 @@ private:
|
||||
uint8_t _transmitPin;
|
||||
uint16_t _transmitBitMask;
|
||||
uint32_t _transmitPortRegister;
|
||||
uint8_t _int_maskMux;
|
||||
uint8_t _int_maskLine;
|
||||
uint8_t _int_mode;
|
||||
|
||||
// must never be 0!
|
||||
uint32_t _rx_delay_centering;
|
||||
|
||||
Reference in new issue
Block a user