PropWare
C++ objects and CMake build system for Parallax Propeller
Home
Download
Getting Started
Documentation
Reference
About
Related Links
Namespace List
Class List
File List
Examples
Build System
File List
File Members
propsideworkspace
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
}
main
int main(void)
Definition:
GraphicsTest.c:20
Generated on Sat Aug 27 2016 00:58:03 for PropWare by
1.8.12