Skip to content

Commit a5897b2

Browse files
committed
Rough in of interrupt pointer. Add available() and read() and debug.
1 parent 67151fc commit a5897b2

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

libraries/SoftwareSerial/src/SoftwareSerial.cpp

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,16 @@ uint8_t gSoftwareSerialNumObjs = 0;
4141

4242
SoftwareSerial *ap3_serial_handle = 0;
4343

44+
//Uncomment to enable debug pulses and Serial.prints
45+
#define DEBUG
46+
47+
#ifdef DEBUG
48+
#define SS_DEBUG_PIN 8
49+
ap3_gpio_pad_t debugPad = ap3_gpio_pin2pad(SS_DEBUG_PIN);
50+
#endif
51+
4452
// Software Serial ISR (To attach to pin change interrupts)
45-
void _software_serial_isr(void)
53+
/*void _software_serial_isr(void)
4654
{
4755
uint64_t gpio_int_mask = 0x00;
4856
am_hal_gpio_interrupt_status_get(true, &gpio_int_mask);
@@ -59,6 +67,10 @@ void _software_serial_isr(void)
5967
obj->rxBit();
6068
}
6169
}
70+
}*/
71+
inline void _software_serial_isr(void)
72+
{
73+
ap3_serial_handle->rxBit();
6274
}
6375

6476
//Constructor
@@ -151,6 +163,20 @@ void SoftwareSerial::begin(uint32_t baudRate, HardwareSerial_Config_e SSconfig)
151163
attachInterrupt(digitalPinToInterrupt(_rxPin), _software_serial_isr, CHANGE);
152164
}
153165

166+
int SoftwareSerial::available()
167+
{
168+
return (rxBufferHead + AP3_SS_BUFFER_SIZE - rxBufferTail) % AP3_SS_BUFFER_SIZE;
169+
}
170+
171+
uint8_t SoftwareSerial::read()
172+
{
173+
if (available() == 0) return (-1);
174+
175+
rxBufferTail++;
176+
rxBufferTail %= AP3_SS_BUFFER_SIZE;
177+
return (rxBuffer[rxBufferTail]);
178+
}
179+
154180
ap3_err_t SoftwareSerial::softwareserialSetConfig(HardwareSerial_Config_e SSconfig)
155181
{
156182
ap3_err_t retval = AP3_OK;
@@ -294,7 +320,7 @@ void SoftwareSerial::rxBit(void)
294320
uint32_t bitTime = CTIMER->STTMR; //Capture current system time
295321

296322
#ifdef DEBUG
297-
am_hal_gpio_output_set(triggerPad);
323+
am_hal_gpio_output_set(debugPad);
298324
#endif
299325

300326
if (lastBitTime == 0)
@@ -360,7 +386,7 @@ void SoftwareSerial::rxBit(void)
360386
}
361387

362388
#ifdef DEBUG
363-
am_hal_gpio_output_clear(triggerPad);
389+
am_hal_gpio_output_clear(debugPad);
364390
#endif
365391
}
366392

@@ -415,8 +441,8 @@ void SoftwareSerial::endOfByte()
415441
else
416442
{
417443
#ifdef DEBUG
418-
am_hal_gpio_output_set(triggerPad);
419-
am_hal_gpio_output_clear(triggerPad);
444+
am_hal_gpio_output_set(debugPad);
445+
am_hal_gpio_output_clear(debugPad);
420446
#endif
421447
_rxBufferOverflow = true;
422448
}
@@ -433,7 +459,7 @@ void SoftwareSerial::endOfByte()
433459
extern "C" void am_stimer_cmpr7_isr(void)
434460
{
435461
#ifdef DEBUG
436-
am_hal_gpio_output_set(triggerPad);
462+
am_hal_gpio_output_set(debugPad);
437463
#endif
438464

439465
uint32_t ui32Status = am_hal_stimer_int_status_get(false);
@@ -445,6 +471,6 @@ extern "C" void am_stimer_cmpr7_isr(void)
445471
}
446472

447473
#ifdef DEBUG
448-
am_hal_gpio_output_clear(triggerPad);
474+
am_hal_gpio_output_clear(debugPad);
449475
#endif
450476
}

libraries/SoftwareSerial/src/SoftwareSerial.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,13 @@ class SoftwareSerial
5050
void begin(uint32_t baudRate, HardwareSerial_Config_e SSconfig);
5151

5252
ap3_err_t softwareserialSetConfig(HardwareSerial_Config_e SSconfig);
53+
int available();
54+
uint8_t read();
5355

5456
void rxBit(void);
5557
void endOfByte(void);
5658

57-
uint64_t _rxPadBitMask; // The AM HAL style pad bit mask associated with the RX pad
59+
uint64_t _rxPadBitMask; // The AM HAL style pad bit mask associated with the RX pad
5860

5961
private:
6062
void startRXListening(void);

0 commit comments

Comments
 (0)