Skip to content

Commit cd79edf

Browse files
committed
#9 support for earlephilhower pico core.
1 parent f3e6649 commit cd79edf

3 files changed

Lines changed: 27 additions & 7 deletions

File tree

examples/circularBuffer/circularBuffer.ino

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <Arduino.h>
1212
#include <SimpleCollections.h>
1313
#include <SCCircularBuffer.h>
14+
#include <IoLogging.h>
1415

1516
#define INTERRUPT_PIN 1
1617

@@ -26,9 +27,9 @@ void interruptHasOccurred() {
2627

2728
void setup() {
2829
// start up the serial port
29-
Serial.begin(115200);
30-
while(!Serial);
31-
Serial.println("Starting circular buffer example");
30+
Serial1.begin(115200);
31+
// while(!Serial);
32+
serdebugF("Starting circular buffer example");
3233

3334
// enable interrupts on a pin so we can "put" items in the buffer
3435
pinMode(INTERRUPT_PIN, INPUT_PULLUP);
@@ -39,8 +40,7 @@ void loop() {
3940
// whenever data is available we read it, otherwise we wait a bit in our example, in a real system this would
4041
// be within task manager, or within a busy loop.
4142
if(buffer.available()) {
42-
Serial.print("Buffer read ");
43-
Serial.println(buffer.get());
43+
serdebugF2("Buffer read ", buffer.get());
4444
}
4545

4646
delay(1);

src/SCCircularBuffer.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ namespace tccollection {
3939

4040
public:
4141
explicit GenericCircularBuffer(uint16_t size, BufferType asMemPool = CIRCULAR_BUFFER) : readerPosition(0), writerPosition(0),
42-
bufferSize(size), buffer(new T[size]), actingAsMemoryPool(asMemPool) {}
42+
bufferSize(size), buffer(new T[size]), actingAsMemoryPool(asMemPool) {
43+
atomicInitialisationSupport();
44+
}
4345
~GenericCircularBuffer() { delete[] buffer; }
4446

4547
bool available() const { return actingAsMemoryPool || readerPosition != writerPosition; }

src/SCThreadingSupport.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
#ifndef SIMPLECOLLECTIONS_SCTHREADINGSUPPORT_H
77
#define SIMPLECOLLECTIONS_SCTHREADINGSUPPORT_H
88

9+
// when not on mbed, we need to load Arduino.h to get the right defines for some boards.
10+
#ifndef __MBED__
11+
#include <Arduino.h>
12+
#endif
13+
914
/**
1015
* @file SCThreadingSupport.h
1116
* Contains two definitions that are board specific that allow the circular buffer to be thread safe on a wide range of
@@ -18,16 +23,26 @@
1823
#include <inttypes.h>
1924

2025
// START PROCESSOR/BOARD SELECTION BLOCK
21-
#if defined(__MBED__) || defined(TMIOA_FORCE_ARDUINO_MBED)
26+
#if defined(ARDUINO_PICO_REVISION)
27+
#include <Arduino.h>
28+
typedef volatile uint32_t* position_ptr_t;
29+
typedef volatile uint32_t position_t;
30+
bool casAtomic(position_ptr_t ptr, position_t expected, position_t newVal);
31+
inline position_t readAtomic(position_ptr_t ptr) { return *(ptr); }
32+
void atomicInitialisationSupport();
33+
#define SIMPLECOLLECTIONS_PICO_PHT_SUPPORT
34+
#elif defined(__MBED__) || defined(TMIOA_FORCE_ARDUINO_MBED)
2235
#include <mbed_atomic.h>
2336
typedef volatile uint32_t* position_ptr_t;
2437
typedef volatile uint32_t position_t;
38+
#define atomicInitialisationSupport()
2539
inline bool casAtomic(position_ptr_t ptr, position_t expected, position_t newVal) {
2640
uint32_t exp = expected;
2741
return core_util_atomic_cas_u32(ptr, &exp, newVal);
2842
}
2943
inline position_t readAtomic(position_ptr_t ptr) { return *(ptr); }
3044
#elif (defined(SC_USE_ARM_ASM_CAS) || defined(ARDUINO_ARCH_STM32)) && !defined(SC_NO_ARM_ASM_CAS)
45+
#define atomicInitialisationSupport()
3146
#include <Arduino.h>
3247
#if __CORTEX_M > 0x03U
3348
#define SIMPLE_COLLECTIONS_ARM_SUPPORT
@@ -44,11 +59,13 @@ typedef volatile uint32_t position_t;
4459
#include <Arduino.h>
4560
typedef volatile uint32_t* position_ptr_t;
4661
typedef volatile uint32_t position_t;
62+
#define atomicInitialisationSupport()
4763
#define NEEDS_CAS_EMULATION
4864
#elif defined(ESP32)
4965
#include <Arduino.h>
5066
typedef volatile uint32_t* position_ptr_t;
5167
typedef volatile uint32_t position_t;
68+
#define atomicInitialisationSupport()
5269
inline bool casAtomic(position_ptr_t ptr, position_t expected, position_t newVal) {
5370
uint32_t exp32 = expected;
5471
uint32_t new32 = newVal;
@@ -58,6 +75,7 @@ inline bool casAtomic(position_ptr_t ptr, position_t expected, position_t newVal
5875
inline uint16_t readAtomic(position_ptr_t ptr) { return *(ptr); }
5976
#else
6077
#include <Arduino.h>
78+
#define atomicInitialisationSupport()
6179
typedef volatile uint16_t* position_ptr_t;
6280
typedef volatile uint16_t position_t;
6381
#define NEEDS_CAS_EMULATION

0 commit comments

Comments
 (0)