PropWare  3.0.0.229
C++ objects and CMake build system for Parallax Propeller
MultiCogBlinky_Demo.cpp

Use PropGCC's native interface to blink an LED from each of the Propeller's 8 cogs. Each cog will be invoking instructions out of HUB memory, not COG memory. For a simpler and more object-oriented way to start new cogs, check out PropWare::Runnable

cmake_minimum_required(VERSION 3.12)
find_package(PropWare REQUIRED)
project(MultiCogBlinky_Demo)
create_simple_executable(${PROJECT_NAME} MultiCogBlinky_Demo.cpp)
// Note the lack of an include for propeller.h; This is because PropWare.h will
// include propeller.h for you
static void run_cog(void *arg);
static const uint16_t COGS = 8;
static const uint16_t STACK_SIZE = 16;
static uint32_t cog_stack[STACK_SIZE][COGS];
static _thread_state_t thread_data;
static volatile uint32_t wait_time;
static volatile uint32_t startCnt;
static volatile int8_t syncStart;
int main(int argc, char *argv[]) {
int8_t n;
int8_t cog;
Pin pin;
uint32_t nextCnt;
const Pin::Mask pins[] = {
Pin::P16,
Pin::P17,
Pin::P18,
Pin::P19,
Pin::P20,
Pin::P21,
Pin::P22,
Pin::P23
};
wait_time = 50 * MILLISECOND;
syncStart = 0;
for (n = 1; n < COGS; n++) {
cog = (int8_t) _start_cog_thread(cog_stack[n] + STACK_SIZE, run_cog, (void *) &pins[n], &thread_data);
pwOut.printf("Toggle COG %d Started\n", cog);
}
pin.set_mask(pins[0]);
pin.set_dir_out();
startCnt = CNT;
syncStart = 1;
nextCnt = wait_time + startCnt;
while (1) {
pin.set();
nextCnt = waitcnt2(nextCnt, wait_time);
pin.clear();
nextCnt = waitcnt2(nextCnt, wait_time);
}
}
void run_cog(void *arg) {
Pin pin;
uint32_t nextCnt;
pin.set_mask(*(Pin::Mask *) arg);
pin.set_dir_out();
// wait for start signal from main cog
while (syncStart == 0);
nextCnt = wait_time + startCnt;
while (1) {
pin.toggle();
nextCnt = waitcnt2(nextCnt, wait_time);
}
}
printer.h
PropWare::Printer::printf
void printf(const char fmt[], const T first, const Targs... remaining) const
Similar in functionality to the C-standard function printf.
Definition: printer.h:497
PropWare::Pin
Utility class to handle general purpose I/O pins.
Definition: pin.h:36
waitcnt2
#define waitcnt2(a, b)
Wait until system counter reaches a value.
Definition: propeller.h:183
main
int main(void)
Definition: GraphicsTest.c:20
PropWare.h
pwOut
PropWare::Printer pwOut
Most common use of printing in PropWare applications (not thread safe; see PropWare::pwSyncOut for mu...
CNT
#define CNT
The system clock count.
Definition: propeller1.h:151
_thread
Definition: thread.h:61
pin.h
PropWare
Generic definitions and functions for the Parallax Propeller.
Definition: runnable.h:33
run_cog
static void run_cog(void *arg)
Toggle thread function gets started in an LMM COG.
Definition: MultiCogBlinky_Demo.cpp:98