PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Simple-Libraries
Learn
Examples
Multicore
Cog Info Exchange.c
1
/*
2
Cog Info Exchange.c
3
4
Example of two cogs exchanging information with a volatile global variable.
5
The main function in cog 0 changes the value; and it affects the blink function's
6
rate running in cog 1.
7
8
http://learn.parallax.com/multicore-approaches/cores-sharing-data
9
*/
10
11
#include "
simpletools.h
"
// Library include
12
13
void
blink();
// Forward declaration
14
int
*cog;
// For storing process ID
15
volatile
int
dt;
// Declare dt for both cogs
16
17
int
main
()
// Main function
18
{
19
dt = 100;
// Set value of dt to 100
20
cog =
cog_run
(blink, 128);
// Run blink in other cog
21
pause
(2000);
// Let run for 2 s
22
23
dt = 50;
// Update value of dt
24
pause
(2000);
// New rate for 2 s
25
cog_end
(cog);
// Stop the cog
26
}
27
28
void
blink()
// Function for other cog
29
{
30
while
(1)
// Endless loop
31
{
32
high
(26);
// LED on
33
pause
(dt);
// ...for dt ms
34
low
(26);
// LED off
35
pause
(dt);
// ...for dt ms
36
}
37
}
pause
void pause(int time)
Delay cog from moving on to the next statement for a certain length of time.
Definition:
libws2812.c:125
low
void low(int pin)
Set an I/O pin to output-low.
Definition:
low.c:19
simpletools.h
This library provides convenient functions for a variety of microcontroller I/O, timing,...
main
int main(void)
Definition:
GraphicsTest.c:20
cog_end
void cog_end(int *coginfo)
End function code running in another cog that was launched with cog_run.
Definition:
cogend.c:15
cog_run
int * cog_run(void(*function)(void *par), int stacksize)
Run a function's code in the next available cog (processor).
Definition:
cogrun.c:15
high
void high(int pin)
Set an I/O pin to output-high.
Definition:
high.c:19
Generated on Fri May 20 2022 16:48:04 for PropWare by
1.8.17