PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Simple-Libraries
Learn
Examples
C Intro
Functions
Multicore Example.c
1
/*
2
Multicore Example.c
3
4
Launch a function into another cog (processor) and display what it does
5
to the global n variable over time.
6
7
http://learn.parallax.com/propeller-c-functions/multicore-example
8
*/
9
10
#include "
simpletools.h
"
// Include simpletools
11
12
void
adder(
void
*par);
// Forward declaration
13
14
static
volatile
int
t, n;
// Global vars for cogs to share
15
unsigned
int
stack[44 + 128];
// Stack vars for other cog
16
17
int
main
()
// main function
18
{
19
t = 50;
// Set values of t & n
20
n = 5000;
21
22
// Launch adder function into another cog (processor).
23
cogstart
(adder, NULL, stack,
sizeof
(stack));
24
25
// Watch what the other cog is doing to the value of n.
26
while
(1)
27
{
28
print
(
"n = %d\n"
, n);
// Display result
29
pause
(100);
// Wait 1/10 of a second
30
}
31
}
32
33
// Function that can continue on its
34
// own if launched into another cog.
35
void
adder(
void
*par)
// Adder keeps going on its own
36
{
37
while
(1)
// Endless loop
38
{
39
n = n + 1;
// n + 1 each time loop repeats
40
pause
(t);
// Wait for t ms between updates
41
}
42
}
pause
void pause(int time)
Delay cog from moving on to the next statement for a certain length of time.
Definition:
libws2812.c:125
simpletools.h
This library provides convenient functions for a variety of microcontroller I/O, timing,...
print
int print(const char *format,...) __attribute__((format(printf
Print format "..." args to the default simple terminal device. The output is limited to 256 bytes.
main
int main(void)
Definition:
GraphicsTest.c:20
cogstart
int cogstart(void(*func)(void *), void *par, void *stack, size_t stacksize)
Start a new propeller LMM function/thread in another COG.
Generated on Fri May 20 2022 16:48:04 for PropWare by
1.8.17