Advertisement
Sothian

OSTATNIE dzialajace

Oct 28th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.72 KB | None | 0 0
  1. /*
  2. * "Hello World" example.
  3. *
  4. * This example prints 'Hello from Nios II' to the STDOUT stream. It runs on
  5. * the Nios II 'standard', 'full_featured', 'fast', and 'low_cost' example
  6. * designs. It runs with or without the MicroC/OS-II RTOS and requires a STDOUT
  7. * device in your system's hardware.
  8. * The memory footprint of this hosted application is ~69 kbytes by default
  9. * using the standard reference design.
  10. *
  11. * For a reduced footprint version of this template, and an explanation of how
  12. * to reduce the memory footprint for a given application, see the
  13. * "small_hello_world" template.
  14. *
  15. */
  16. #include <stdio.h>
  17. #include <io.h>
  18. #include <system.h>
  19. //#include "alt_types.h"
  20. #include "sys/alt_irq.h"
  21. #include <unistd.h>
  22. #include "sys/alt_alarm.h"
  23.  
  24. struct interrupt_data {
  25. volatile int* leds_addr;
  26. volatile int* sliders_addr;
  27. volatile int* hex_addr;
  28. };
  29. /* Przełączniki */
  30. #define SW0 0x00000001
  31. #define SW1 0x00000002
  32. #define SW2 0x00000004
  33. #define SW3 0x00000008
  34. #define SW4 0x00000010
  35. #define SW5 0x00000020
  36. #define SW6 0x00000040
  37. #define SW7 0x00000080
  38. #define SW8 0x00000100
  39. #define SW9 0x00000200
  40. #define SW10 0x00000400
  41. #define SW11 0x00000800
  42. #define SW12 0x00001000
  43. #define SW13 0x00002000
  44. #define SW14 0x00004000
  45. #define SW15 0x00008000
  46. #define SW16 0x00010000
  47. #define SW17 0x00020000
  48.  
  49. /* PushButtony */
  50. #define KEY1 0x00000002
  51. #define KEY2 0x00000004
  52. #define KEY3 0x00000008
  53.  
  54. /* Ledy */
  55. #define LED0 0x00000001
  56. #define LED1 0x00000002
  57. #define LED2 0x00000004
  58. #define LED3 0x00000008
  59. #define LED4 0x00000010
  60. #define LED5 0x00000020
  61. #define LED6 0x00000040
  62. #define LED7 0x00000080
  63. #define LED8 0x00000100
  64. #define LED9 0x00000200
  65. #define LED10 0x00000400
  66. #define LED11 0x00000800
  67. #define LED12 0x00001000
  68. #define LED13 0x00002000
  69. #define LED14 0x00004000
  70. #define LED15 0x00008000
  71. #define LED16 0x00010000
  72. #define LED17 0x00020000
  73.  
  74. /* Segmenty HEX */
  75. #define SEGA 1
  76. #define SEGB 2
  77. #define SEGC 4
  78. #define SEGD 8
  79. #define SEGE 16
  80. #define SEGF 32
  81. #define SEGG 64
  82.  
  83. /* Litery i cyfry z hex 7 segmentowych */
  84. #define HEX0 (SEGA|SEGB|SEGC|SEGD|SEGE|SEGF)
  85. #define HEX1 (SEGB|SEGC)
  86. #define HEX2 (SEGA|SEGB|SEGG|SEGE|SEGD)
  87. #define HEX3 (SEGA|SEGB|SEGC|SEGD|SEGG)
  88. #define HEX4 (SEGF|SEGG|SEGB|SEGC)
  89. #define HEX5 (SEGA|SEGF|SEGG|SEGC|SEGD)
  90. #define HEX6 (SEGA|SEGF|SEGG|SEGC|SEGD|SEGE)
  91. #define HEX7 (SEGA|SEGB|SEGC)
  92. #define HEX8 (SEGA|SEGB|SEGC|SEGD|SEGE|SEGF|SEGG)
  93. #define HEX9 (SEGA|SEGB|SEGC|SEGD|SEGF|SEGG)
  94. #define HEXE (SEGA|SEGF|SEGG|SEGE|SEGD)
  95. #define HEXr (SEGE|SEGG)
  96. #define HEXA (SEGA|SEGB|SEGC|SEGE|SEGF|SEGG)
  97. #define HEXF (SEGA|SEGE|SEGF|SEGG)
  98. #define HEXC (SEGA|SEGE|SEGF|SEGD)
  99. #define HEXD (SEGB|SEGC|SEGD|SEGE|SEGG)
  100.  
  101.  
  102. int main() {
  103. volatile int *leds = (int *) LEDS_RED_BASE;
  104. volatile int *sliders = (int *) SW_SLIDERS_BASE;;
  105.  
  106. IOWR(LEDS_RED_BASE, 0, 0x00);
  107.  
  108. struct interrupt_data data;
  109.  
  110. data.leds_addr = leds;
  111. data.sliders_addr = sliders;
  112.  
  113. int SW1on, SW1off, SW2on, SW2off, SW3on, SW3off, SW4on, SW4off, SW5on,
  114. SW5off = 0;
  115. int SWon, lastCase;
  116.  
  117. while (1) {
  118.  
  119. volatile int sw_state = IORD(data.sliders_addr, 0);
  120.  
  121. switch (sw_state) {
  122. case (0):
  123. if ((alt_nticks() - SWon >= 2 * alt_ticks_per_second())
  124. && lastCase != 6) {
  125. IOWR(LEDS_RED_BASE, 0, 0x00);
  126. } else if ((alt_nticks() - SWon >= 3 * alt_ticks_per_second())
  127. && lastCase == 6) {
  128. IOWR(LEDS_RED_BASE, 0, 0x00);
  129.  
  130. }
  131. SW1off = alt_nticks();
  132. SW5off = alt_nticks();
  133. SW2off = alt_nticks();
  134. SW3off = alt_nticks();
  135. SW4off = alt_nticks();
  136. lastCase = 0;
  137. break;
  138. case (1):
  139. if (alt_nticks() - SW1off >= 1 * alt_ticks_per_second()) {
  140. IOWR(data.leds_addr, 0, LED0);
  141. }
  142. SWon = alt_nticks();
  143. lastCase = 1;
  144. break;
  145. case (2):
  146. if (alt_nticks() - SW2off >= 1 * alt_ticks_per_second()) {
  147. IOWR(data.leds_addr, 0, LED1);
  148. }
  149. SWon = alt_nticks();
  150. lastCase = 2;
  151. break;
  152. case (4):
  153. if (alt_nticks() - SW3off >= 1 * alt_ticks_per_second()) {
  154. IOWR(data.leds_addr, 0, LED2);
  155. }
  156. SWon = alt_nticks();
  157. lastCase = 3;
  158. break;
  159. case (8):
  160. if (alt_nticks() - SW4off >= 1 * alt_ticks_per_second()) {
  161. IOWR(data.leds_addr, 0, LED3);
  162. }
  163. SWon = alt_nticks();
  164. lastCase = 4;
  165. break;
  166. case (16):
  167. if (alt_nticks() - SW5off >= 1 * alt_ticks_per_second()) {
  168. IOWR(data.leds_addr, 0, LED4);
  169. }
  170. SWon = alt_nticks();
  171.  
  172. lastCase = 5;
  173. break;
  174. case (32):
  175. IOWR(data.leds_addr, 0, LED17);
  176. break;
  177. default:
  178. if (alt_nticks() - SWon >= 1 * alt_ticks_per_second()) {
  179. IOWR(data.leds_addr, 0, LED17);
  180. }
  181. if (alt_nticks() - SWon >= 3 * alt_ticks_per_second()) {
  182. lastCase = 6;
  183. }
  184. break;
  185. }
  186. }
  187.  
  188. return 0;
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement