Guest User

Untitled

a guest
May 24th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. /*
  2. ============================================================================
  3. Name : xc1-flashing-led.xc
  4. Description : Flashing LED program for the XC-1 board
  5. ============================================================================
  6. */
  7.  
  8. #include <platform.h>
  9. #define FLASH_PERIOD 20000000
  10.  
  11. out port cled0 = PORT_CLOCKLED_0;
  12. out port cled1 = PORT_CLOCKLED_1;
  13. out port cled2 = PORT_CLOCKLED_2;
  14. out port cled3 = PORT_CLOCKLED_3;
  15. out port cledG = PORT_CLOCKLED_SELG;
  16. out port cledR = PORT_CLOCKLED_SELR;
  17.  
  18. void flash_led(chanend, out port, int);
  19. void master_thread(chanend, chanend, chanend, int, out port);
  20. void delay(const unsigned int);
  21.  
  22.  
  23. int main(void) {
  24. chan c1, c2, c3;
  25. par {
  26. on stdcore[0]: master_thread(c1, c2, c3, FLASH_PERIOD, cled0);
  27. on stdcore[1]: flash_led(c1, cled1, FLASH_PERIOD);
  28. on stdcore[2]: flash_led(c2, cled2, FLASH_PERIOD);
  29. on stdcore[3]: flash_led(c3, cled3, FLASH_PERIOD);
  30. }
  31. return 0;
  32. }
  33.  
  34. void delay(const unsigned int period) {
  35. unsigned t; timer tmr;
  36. tmr :> t;
  37. tmr when timerafter(t+period) :> void;
  38. }
  39.  
  40. void master_thread(chanend c1, chanend c2, chanend c3,
  41. int period, out port master_led) {
  42.  
  43. unsigned int i = 0;
  44. int led_addresses[3] = { 0x10, 0x20, 0x40 }; // LED 1, LED 2, LED 3 address
  45. while (1) {
  46. for (int kore = 0; kore < 4; kore++) {
  47. for (int led = 0; led <= 2; led++) {
  48.  
  49. if (++i % 2 == 0) {
  50. par { cledG <: 0; cledR <: 1; }
  51. }
  52. else {
  53. par { cledG <: 1; cledR <: 0; }
  54. }
  55.  
  56. switch (kore) {
  57. case 0:
  58. master_led <: led_addresses[led];
  59. delay(period);
  60. if (led == 2)
  61. master_led <: 0x00;
  62. break;
  63. case 1:
  64. c1 <: led_addresses[led];
  65. delay(period);
  66. if (led == 2)
  67. c1 <: 0x00;
  68. break;
  69. case 2:
  70. c2 <: led_addresses[led];
  71. delay(period);
  72. if (led == 2)
  73. c2 <: 0x00;
  74. break;
  75. case 3:
  76. c3 <: led_addresses[led];
  77. delay(period);
  78. if (led == 2)
  79. c3 <: 0x00;
  80. break;
  81. }
  82. }
  83. }
  84. }
  85. }
  86.  
  87. void flash_led(chanend c, out port led, int period) {
  88. int token_value;
  89. while (1) {
  90. c :> token_value;
  91. led <: token_value;
  92. delay(period);
  93. led <: 0x00;
  94. }
  95. }
Add Comment
Please, Sign In to add comment