Mercurial > lcfOS
view python/c3/wishes/coro.c3 @ 293:6aa721e7b10b
Try to improve build sequence
author | Windel Bouwman |
---|---|
date | Thu, 28 Nov 2013 20:39:37 +0100 |
parents | e64bae57cda8 |
children |
line wrap: on
line source
module coro; /* Some co-routines doing some work. This example demonstrates how to write co-operating routines in a nice way. */ int regbank[10]; function i2c_write(int address, int d) { regbank[2] = address; regbank[0] |= 0x1; // Issue go command while (regbank[1] != 0) { yield; } // Wait while busy: while (regbank[1] != 11) { yield; } } function int i2c_read(int address) { regbank[2] = address; regbank[0] |= 0x1; // Issue go command while (regbank[1] != 0) { yield; } // Wait while busy: while (regbank[1] != 11) { yield; } } function void eeprom_set(int address, int v) { i2c_write(address, v); i2c_read(address); } function int calcX(int y) { var int x; x = 2; x = x + 2 + 9 * y; return x; } var int counter = 0; task task1() { start task3; var int a = 200; while (a > 0) { yield; } } task task2() { while(true) { yield; } } task task3() { eeprom_set(99, 1); yield; } task main() { start task1; start task2; await task1; await task2; }