Advertisement
ddeexxiikk

Untitled

Nov 5th, 2024
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.85 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <system.h>
  3. #include "includes.h"
  4. #include <io.h>
  5.  
  6. typedef enum POZIOM_TEMP{
  7. POZIOM_0 = 0,
  8. POZIOM_1 = 2,
  9. POZIOM_2 = 4,
  10. POZIOM_3 = 8,
  11. POZIOM_4 = 16,
  12. POZIOM_5 = 32,
  13. POZIOM_6 = 64,
  14. POZIOM_7 = 128,
  15. POZIOM_8 = 256,
  16. POZIOM_9 = 512,
  17. POZIOM_10 = 1024,
  18.  
  19. }TEMP;
  20.  
  21. #define SW0 0x00000001
  22. #define SW1 0x00000002
  23. #define SW2 0x00000004
  24. #define SW3 0x00000008
  25. #define SW4 0x00000010
  26. #define SW5 0x00000020
  27. #define SW6 0x00000040
  28. #define SW7 0x00000080
  29. #define SW8 0x00000100
  30. #define SW9 0x00000200
  31.  
  32. #define LED0 0x00000001
  33. #define LED1 0x00000002
  34. #define LED2 0x00000004
  35. #define LED3 0x00000008
  36. #define LED4 0x00000010
  37. #define LED5 0x00000020
  38. #define LED9 0x00000200
  39.  
  40. // Array of LED masks corresponding to cnt
  41. const int led_masks[5] = {LED1, LED2, LED3, LED4, LED5};
  42.  
  43. // Tablica kodów dla wyświetlaczy 7-segmentowych (dla cyfr 0-9)
  44. const alt_u8 hex_digits[16] = {
  45. 0x3F, // 0
  46. 0x06, // 1
  47. 0x5B, // 2
  48. 0x4F, // 3
  49. 0x66, // 4
  50. 0x6D, // 5
  51. 0x7D, // 6
  52. 0x07, // 7
  53. 0x7F, // 8
  54. 0x6F, // 9
  55. 0x77, // A
  56. 0x7C, // B
  57. 0x39, // C
  58. 0x5E, // D
  59. 0x79, // E
  60. 0x71 // F
  61. };
  62.  
  63. const alt_u8 error_code[5] = {
  64. 0x79, // E
  65. 0x50, // r
  66. 0x50, // r
  67. 0x5C, // o
  68. 0x50 // r
  69. };
  70.  
  71.  
  72. /* Definition of Task Stacks */
  73. #define TASK_STACKSIZE 2048
  74. OS_STK task1_stk[TASK_STACKSIZE];
  75. OS_STK task2_stk[TASK_STACKSIZE];
  76. OS_STK task3_stk[TASK_STACKSIZE];
  77. OS_STK task4_stk[TASK_STACKSIZE];
  78. OS_STK task5_stk[TASK_STACKSIZE];
  79. OS_STK task6_stk[TASK_STACKSIZE];
  80. OS_STK task7_stk[TASK_STACKSIZE];
  81.  
  82.  
  83. OS_EVENT *SWBox1;
  84.  
  85. /* Definition of Task Priorities */
  86.  
  87. #define TASK1_PRIORITY 1
  88. #define TASK2_PRIORITY 2
  89. #define TASK3_PRIORITY 3
  90. #define TASK4_PRIORITY 4
  91. #define TASK5_PRIORITY 5
  92. #define TASK6_PRIORITY 6
  93. #define TASK7_PRIORITY 7
  94.  
  95.  
  96. /* Prints "Hello World" and sleeps for three seconds */
  97. void task1(void* pdata)
  98. {
  99. INT8U err;
  100. int people=0;
  101. int *msg;
  102. while (1)
  103. {
  104. msg = OSMboxPend(SWBox1, 0, &err);
  105. if(msg==1)
  106. {
  107. IOWR(LEDS_BASE, 0, 1);
  108. }
  109. OSTimeDlyHMSM(0, 0, 1, 0);
  110. }
  111. }
  112. /* Prints "Hello World" and sleeps for three seconds */
  113. void task2(void* pdata)
  114. {
  115. INT8U err;
  116. int people=0;
  117. int *msg;
  118. while (1)
  119. {
  120. msg = OSMboxPend(SWBox1, 0, &err);
  121. if(msg==2)
  122. {
  123. IOWR(LEDS_BASE, 0, 2);
  124. }
  125. OSTimeDlyHMSM(0, 0, 3, 0);
  126. }
  127. }
  128.  
  129. void task3(void* pdata)
  130. {
  131. INT8U err;
  132. int people=0;
  133. int *msg;
  134. while (1)
  135. {
  136. msg = OSMboxPend(SWBox1, 0, &err);
  137. if(msg==3)
  138. {
  139. IOWR(LEDS_BASE, 0, 4);
  140. }
  141. OSTimeDlyHMSM(0, 0, 5, 0);
  142. }
  143. }
  144.  
  145. void task4(void* pdata)
  146. {
  147. INT8U err;
  148. int people=0;
  149. int *msg;
  150. while (1)
  151. {
  152. msg = OSMboxPend(SWBox1, 0, &err);
  153. if(msg==4)
  154. {
  155. IOWR(LEDS_BASE, 0, 8);
  156. }
  157. OSTimeDlyHMSM(0, 0, 7, 0);
  158. }
  159. }
  160.  
  161. void task5(void* pdata)
  162. {
  163. INT8U err;
  164. int people=0;
  165. int *msg;
  166. while (1)
  167. {
  168. msg = OSMboxPend(SWBox1, 0, &err);
  169. if(msg==5)
  170. {
  171. IOWR(LEDS_BASE, 0, 16);
  172. }
  173. OSTimeDlyHMSM(0, 0, 9, 0);
  174. }
  175. }
  176.  
  177. void task6(void* pdata)
  178. {
  179. int prev_switches = 0;
  180. int in_room=0;
  181. while (1)
  182. {
  183. int switches = IORD_ALTERA_AVALON_PIO_DATA(SW_SLIDERS_BASE);
  184. int changed = prev_switches ^ switches;
  185. int * msg;
  186.  
  187. if (changed & SW0)
  188. {
  189. if (switches & SW0)
  190. in_room = 1; // SW0 turned on
  191. else
  192. in_room = 0; // SW0 turned off
  193. }
  194. for (int i = 1; i <= 9; i++)
  195. {
  196. int mask = 1 << i;
  197. int sw_changed = changed & mask;
  198. int sw_on = switches & mask;
  199. if (sw_changed && sw_on)
  200. {
  201. if (in_room)
  202. {
  203. switch (i)
  204. {
  205. //do gory i w prawo
  206. case 1:
  207. OSMboxPostOpt(SWBox1, &(int){1}, OS_POST_OPT_BROADCAST);
  208. OSMboxPostOpt(SWBox1, &(int){4}, OS_POST_OPT_BROADCAST);
  209. break;
  210. case 2:
  211. cnt[0] += 1;
  212. break;
  213. case 3:
  214. cnt[0] += 1;
  215. break;
  216. case 4:
  217. cnt[4] += 1;
  218. break;
  219. case 5:
  220. cnt[3] -= 1;
  221. break;
  222. case 6:
  223. cnt[0] -= 1;
  224. cnt[3] += 1;
  225. break;
  226. case 7:
  227. cnt[3] += 1;
  228. break;
  229. case 8:
  230. //cd9 bo pomijamy cd8
  231. cnt[2] += 1;
  232. cnt[1] -= 1;
  233. break;
  234. }
  235. }
  236. else
  237. {
  238. //w dol i lewo
  239. switch (i)
  240. {
  241. case 1:
  242. cnt[4] -= 1;
  243. cnt[0] += 1;
  244. break;
  245. case 2:
  246. cnt[0] -= 1;
  247. break;
  248. case 3:
  249. cnt[0] -= 1;
  250. break;
  251. case 4:
  252. cnt[4] -= 1;
  253. break;
  254. case 5:
  255. cnt[4] += 1;
  256. break;
  257. case 6:
  258. cnt[0] += 1;
  259. cnt[3] -= 1;
  260. break;
  261. case 7:
  262. cnt[3] -= 1;
  263. break;
  264. case 8:
  265. //cd9 bo pomijamy cd8
  266. cnt[2] -= 1;
  267. cnt[1] += 1;
  268. break;
  269. }
  270. }
  271. }
  272. }
  273. }
  274. }
  275.  
  276. void task7(void* pdata)
  277. {
  278. while (1)
  279. {
  280. INT8U err;
  281. printf("Hello from task2\n");
  282. int *num;
  283.  
  284. num = OSMboxPend(SWBox1, 0, &err);
  285.  
  286.  
  287. printf("T=%d\n", *num);
  288.  
  289. IOWR(LEDS_BASE, 0, *num);
  290. OSTimeDlyHMSM(0, 0, 1, 0);
  291. }
  292. }
  293.  
  294. /*
  295. *
  296. * while (1)
  297. {
  298. printf("Hello from task1\n");
  299. int sw;
  300. int * msg;
  301. sw = IORD(SW_SLIDERS_BASE, 0);
  302.  
  303. printf("Slider = %d\n", sw);
  304. OSMboxPostOpt(SWBox1, &sw, OS_POST_OPT_BROADCAST);
  305.  
  306. OSTimeDlyHMSM(0, 0, 1, 0);
  307. }
  308. */
  309.  
  310. /* The main function creates two task and starts multi-tasking */
  311. int main(void)
  312. {
  313. SWBox1 =OSMboxCreate((void*)0);
  314.  
  315.  
  316. OSTaskCreateExt(task1,
  317. NULL,
  318. (void *)&task1_stk[TASK_STACKSIZE-1],
  319. TASK1_PRIORITY,
  320. TASK1_PRIORITY,
  321. task1_stk,
  322. TASK_STACKSIZE,
  323. NULL,
  324. 0);
  325.  
  326.  
  327. OSTaskCreateExt(task2,
  328. NULL,
  329. (void *)&task2_stk[TASK_STACKSIZE-1],
  330. TASK2_PRIORITY,
  331. TASK2_PRIORITY,
  332. task2_stk,
  333. TASK_STACKSIZE,
  334. NULL,
  335. 0);
  336.  
  337. OSTaskCreateExt(task3,
  338. NULL,
  339. (void *)&task3_stk[TASK_STACKSIZE-1],
  340. TASK3_PRIORITY,
  341. TASK3_PRIORITY,
  342. task3_stk,
  343. TASK_STACKSIZE,
  344. NULL,
  345. 0);
  346.  
  347. OSTaskCreateExt(task4,
  348. NULL,
  349. (void *)&task4_stk[TASK_STACKSIZE-1],
  350. TASK4_PRIORITY,
  351. TASK4_PRIORITY,
  352. task4_stk,
  353. TASK_STACKSIZE,
  354. NULL,
  355. 0);
  356.  
  357. OSTaskCreateExt(task5,
  358. NULL,
  359. (void *)&task5_stk[TASK_STACKSIZE-1],
  360. TASK5_PRIORITY,
  361. TASK5_PRIORITY,
  362. task5_stk,
  363. TASK_STACKSIZE,
  364. NULL,
  365. 0);
  366.  
  367. OSStart();
  368. return 0;
  369. }
  370.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement