Advertisement
Sothian

podstawadziala

Oct 28th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.56 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. /* Przełączniki */
  25. #define SW0 0x00000001
  26. #define SW1 0x00000002
  27. #define SW2 0x00000004
  28. #define SW3 0x00000008
  29. #define SW4 0x00000010
  30. #define SW5 0x00000020
  31. #define SW6 0x00000040
  32. #define SW7 0x00000080
  33. #define SW8 0x00000100
  34. #define SW9 0x00000200
  35. #define SW10 0x00000400
  36. #define SW11 0x00000800
  37. #define SW12 0x00001000
  38. #define SW13 0x00002000
  39. #define SW14 0x00004000
  40. #define SW15 0x00008000
  41. #define SW16 0x00010000
  42. #define SW17 0x00020000
  43.  
  44. /* PushButtony */
  45. #define KEY1 0x00000002
  46. #define KEY2 0x00000004
  47. #define KEY3 0x00000008
  48.  
  49. /* Ledy */
  50. #define LED0 0x00000001
  51. #define LED1 0x00000002
  52. #define LED2 0x00000004
  53. #define LED3 0x00000008
  54. #define LED4 0x00000010
  55. #define LED5 0x00000020
  56. #define LED6 0x00000040
  57. #define LED7 0x00000080
  58. #define LED8 0x00000100
  59. #define LED9 0x00000200
  60. #define LED10 0x00000400
  61. #define LED11 0x00000800
  62. #define LED12 0x00001000
  63. #define LED13 0x00002000
  64. #define LED14 0x00004000
  65. #define LED15 0x00008000
  66. #define LED16 0x00010000
  67. #define LED17 0x00020000
  68.  
  69. /* Segmenty HEX */
  70. #define SEGA 1
  71. #define SEGB 2
  72. #define SEGC 4
  73. #define SEGD 8
  74. #define SEGE 16
  75. #define SEGF 32
  76. #define SEGG 64
  77.  
  78. /* Litery i cyfry z hex 7 segmentowych */
  79. #define HEX0 (SEGA|SEGB|SEGC|SEGD|SEGE|SEGF)
  80. #define HEX1 (SEGB|SEGC)
  81. #define HEX2 (SEGA|SEGB|SEGG|SEGE|SEGD)
  82. #define HEX3 (SEGA|SEGB|SEGC|SEGD|SEGG)
  83. #define HEX4 (SEGF|SEGG|SEGB|SEGC)
  84. #define HEX5 (SEGA|SEGF|SEGG|SEGC|SEGD)
  85. #define HEX6 (SEGA|SEGF|SEGG|SEGC|SEGD|SEGE)
  86. #define HEX7 (SEGA|SEGB|SEGC)
  87. #define HEX8 (SEGA|SEGB|SEGC|SEGD|SEGE|SEGF|SEGG)
  88. #define HEX9 (SEGA|SEGB|SEGC|SEGD|SEGF|SEGG)
  89. #define HEXE (SEGA|SEGF|SEGG|SEGE|SEGD)
  90. #define HEXr (SEGE|SEGG)
  91. #define HEXA (SEGA|SEGB|SEGC|SEGE|SEGF|SEGG)
  92. #define HEXF (SEGA|SEGE|SEGF|SEGG)
  93. #define HEXC (SEGA|SEGE|SEGF|SEGD)
  94. #define HEXD (SEGB|SEGC|SEGD|SEGE|SEGG)
  95.  
  96. struct interrupt_data {
  97. volatile int* leds_addr;
  98. volatile int* sliders_addr;
  99. volatile int* hex_addr;
  100. };
  101.  
  102. /*static void handle_sliders_interrupt(struct interrupt_data *data)
  103. {
  104. }*/
  105.  
  106. int main() {
  107. volatile int *leds = (int *) LEDS_RED_BASE;
  108. volatile int *sliders = (int *) SW_SLIDERS_BASE;
  109. //volatile int *hex = (int *)HEX_0_BASE;
  110.  
  111. IOWR(LEDS_RED_BASE, 0, 0x00);
  112. //IOWR(HEX_0_BASE, 0, 0x00);
  113.  
  114. struct interrupt_data data;
  115.  
  116. data.leds_addr = leds;
  117. data.sliders_addr = sliders;
  118. //data.hex_addr = hex;
  119. int SW1on, SW1off, SW2on, SW2off, SW3on, SW3off, SW4on, SW4off, SW5on,
  120. SW5off;
  121.  
  122. SW1on = SW1off = SW2on = SW2off = SW3on = SW3off = SW4on = SW4off = SW5on =
  123. SW5off = 0;
  124.  
  125. int SWon, lastCase;
  126.  
  127. // IOWR_ALTERA_AVALON_PIO_IRQ_MASK(SW_SLIDERS_BASE, 0xff);
  128.  
  129. // alt_ic_isr_register(SW_SLIDERS_IRQ_INTERRUPT_CONTROLLER_ID, SW_SLIDERS_IRQ, handle_sliders_interrupt, &data, 0x0);
  130.  
  131. // alt_ic_irq_enable(SW_SLIDERS_IRQ_INTERRUPT_CONTROLLER_ID, SW_SLIDERS_IRQ);
  132.  
  133. while (1) {
  134.  
  135. volatile int sw_state = IORD(data.sliders_addr, 0);
  136.  
  137. switch (sw_state) {
  138. case (0):
  139. if ((alt_nticks() - SWon >= 2 * alt_ticks_per_second())
  140. && lastCase != 6) {
  141. IOWR(LEDS_RED_BASE, 0, 0x00);
  142. } else if ((alt_nticks() - SWon >= 3 * alt_ticks_per_second())
  143. && lastCase == 6) {
  144. IOWR(LEDS_RED_BASE, 0, 0x00);
  145.  
  146. }
  147. if (alt_nticks() - SWon >= 1 * alt_ticks_per_second()) {
  148. IOWR(data.hex_addr, 0, 0x00);
  149. }
  150. SW1off = alt_nticks();
  151. SW5off = alt_nticks();
  152. SW2off = alt_nticks();
  153. SW3off = alt_nticks();
  154. SW4off = alt_nticks();
  155. IOWR(data.hex_addr, 1, 0x00);
  156. IOWR(data.hex_addr, 2, 0x00);
  157. IOWR(data.hex_addr, 3, 0x00);
  158. lastCase = 0;
  159. break;
  160. case (1):
  161. if (alt_nticks() - SW1off >= 1 * alt_ticks_per_second()) {
  162. IOWR(data.leds_addr, 0, 0x01);
  163. }
  164. if (alt_nticks() - SW1off >= 2 * alt_ticks_per_second()) {
  165. IOWR(data.hex_addr, 0, 0x06);
  166.  
  167. }
  168. SWon = alt_nticks();
  169. IOWR(data.hex_addr, 1, 0x00);
  170. IOWR(data.hex_addr, 2, 0x00);
  171. IOWR(data.hex_addr, 3, 0x00);
  172. lastCase = 1;
  173. break;
  174. case (2):
  175. if (alt_nticks() - SW2off >= 1 * alt_ticks_per_second()) {
  176. IOWR(data.leds_addr, 0, 0x02);
  177. }
  178. if (alt_nticks() - SW2off >= 2 * alt_ticks_per_second()) {
  179. //IOWR(data.hex_addr, 0, TWO);
  180. }
  181. SWon = alt_nticks();
  182. IOWR(data.hex_addr, 1, 0x00);
  183. IOWR(data.hex_addr, 2, 0x00);
  184. IOWR(data.hex_addr, 3, 0x00);
  185. lastCase = 2;
  186. break;
  187. case (4):
  188. if (alt_nticks() - SW3off >= 1 * alt_ticks_per_second()) {
  189. IOWR(data.leds_addr, 0, 0x04);
  190. }
  191. if (alt_nticks() - SW3off >= 2 * alt_ticks_per_second()) {
  192. //IOWR(data.hex_addr, 0, THREE);
  193. }
  194. SWon = alt_nticks();
  195. IOWR(data.hex_addr, 1, 0x00);
  196. IOWR(data.hex_addr, 2, 0x00);
  197. IOWR(data.hex_addr, 3, 0x00);
  198. lastCase = 3;
  199. break;
  200. case (8):
  201. if (alt_nticks() - SW4off >= 1 * alt_ticks_per_second()) {
  202. IOWR(data.leds_addr, 0, 0x08);
  203. }
  204. if (alt_nticks() - SW4off >= 2 * alt_ticks_per_second()) {
  205. //IOWR(data.hex_addr, 0, FOUR);
  206. }
  207. SWon = alt_nticks();
  208. IOWR(data.hex_addr, 1, 0x00);
  209. IOWR(data.hex_addr, 2, 0x00);
  210. IOWR(data.hex_addr, 3, 0x00);
  211. lastCase = 4;
  212. break;
  213. case (16):
  214. if (alt_nticks() - SW5off >= 1 * alt_ticks_per_second()) {
  215. IOWR(data.leds_addr, 0, 0x10);
  216. }
  217. if (alt_nticks() - SW5off >= 2 * alt_ticks_per_second()) {
  218. //IOWR(data.hex_addr, 0, FIVE);
  219. }
  220. SWon = alt_nticks();
  221. IOWR(data.hex_addr, 1, 0x00);
  222. IOWR(data.hex_addr, 2, 0x00);
  223. IOWR(data.hex_addr, 3, 0x00);
  224. lastCase = 5;
  225. break;
  226. case (32):
  227. IOWR(data.leds_addr, 0, 0x20);
  228. break;
  229. default:
  230. if (alt_nticks() - SWon >= 1 * alt_ticks_per_second()) {
  231. IOWR(data.leds_addr, 0, 0x20);
  232. }
  233. if (alt_nticks() - SWon >= 3 * alt_ticks_per_second()) {
  234. //IOWR(data.hex_addr, 0, R);
  235. //IOWR(data.hex_addr, 1, R);
  236. //IOWR(data.hex_addr, 2, E);
  237. lastCase = 6;
  238. }
  239. break;
  240. }
  241. }
  242.  
  243. return 0;
  244. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement