Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ============================================================================
- Name : xc1-flashing-led.xc
- Description : Flashing LED program for the XC-1 board
- ============================================================================
- */
- #include <platform.h>
- #define FLASH_PERIOD 20000000
- out port cled0 = PORT_CLOCKLED_0;
- out port cled1 = PORT_CLOCKLED_1;
- out port cled2 = PORT_CLOCKLED_2;
- out port cled3 = PORT_CLOCKLED_3;
- out port cledG = PORT_CLOCKLED_SELG;
- out port cledR = PORT_CLOCKLED_SELR;
- void flash_led(chanend, out port, int);
- void master_thread(chanend, chanend, chanend, int, out port);
- void delay(const unsigned int);
- int main(void) {
- chan c1, c2, c3;
- par {
- on stdcore[0]: master_thread(c1, c2, c3, FLASH_PERIOD, cled0);
- on stdcore[1]: flash_led(c1, cled1, FLASH_PERIOD);
- on stdcore[2]: flash_led(c2, cled2, FLASH_PERIOD);
- on stdcore[3]: flash_led(c3, cled3, FLASH_PERIOD);
- }
- return 0;
- }
- void delay(const unsigned int period) {
- unsigned t; timer tmr;
- tmr :> t;
- tmr when timerafter(t+period) :> void;
- }
- void master_thread(chanend c1, chanend c2, chanend c3,
- int period, out port master_led) {
- unsigned int i = 0;
- int led_addresses[3] = { 0x10, 0x20, 0x40 }; // LED 1, LED 2, LED 3 address
- while (1) {
- for (int kore = 0; kore < 4; kore++) {
- for (int led = 0; led <= 2; led++) {
- if (++i % 2 == 0) {
- par { cledG <: 0; cledR <: 1; }
- }
- else {
- par { cledG <: 1; cledR <: 0; }
- }
- switch (kore) {
- case 0:
- master_led <: led_addresses[led];
- delay(period);
- if (led == 2)
- master_led <: 0x00;
- break;
- case 1:
- c1 <: led_addresses[led];
- delay(period);
- if (led == 2)
- c1 <: 0x00;
- break;
- case 2:
- c2 <: led_addresses[led];
- delay(period);
- if (led == 2)
- c2 <: 0x00;
- break;
- case 3:
- c3 <: led_addresses[led];
- delay(period);
- if (led == 2)
- c3 <: 0x00;
- break;
- }
- }
- }
- }
- }
- void flash_led(chanend c, out port led, int period) {
- int token_value;
- while (1) {
- c :> token_value;
- led <: token_value;
- delay(period);
- led <: 0x00;
- }
- }
Add Comment
Please, Sign In to add comment