Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.36 KB | None | 0 0
  1. #include <stdio.h>
  2. //#include <system.h>
  3. #include <io.h>
  4. //#include "includes.h"
  5. #include "definition.h"
  6. //#include <unistd.h>
  7. //#include <os_cpu.h>
  8. //#include <sys/alt_alarm.h>
  9. //#include <ucos_ii.h>
  10. //#include "alt_types.h"
  11. //#include "sys/alt_timestamp.h"
  12. //#include "altera_avalon_pio_regs.h"
  13. //#include "sys/alt_irq.h"
  14. #include <altera_avalon_mutex.h>
  15.  
  16. void VGA_text(int x, int y, char *text_ptr){
  17. int offset;
  18. volatile char *character_buffer = (char*) VGA_CHAR_BUFFER_AVALON_CHAR_BUFFER_SLAVE_BASE;
  19. offset = (y << 7) + x;
  20. while(*(text_ptr)){
  21. *(character_buffer + offset) = *(text_ptr);
  22. ++text_ptr;
  23. ++offset;
  24. }
  25. }
  26.  
  27. void error(){
  28. IOWR(HEX_BASE,2,(HEXE));
  29. IOWR(HEX_BASE,1,(HEXr));
  30. IOWR(HEX_BASE,0,(HEXr));
  31. }
  32. void on(){
  33. IOWR(HEX_BASE,2,0);
  34. IOWR(HEX_BASE,1,(HEXo));
  35. IOWR(HEX_BASE,0,(HEXn));
  36. }
  37. void off(){
  38. IOWR(HEX_BASE,2,(HEXo));
  39. IOWR(HEX_BASE,1,(HEXf));
  40. IOWR(HEX_BASE,0,(HEXf));
  41. }
  42. void all(){
  43. IOWR(HEX_BASE,2,(HEXA));
  44. IOWR(HEX_BASE,1,(ONE));
  45. IOWR(HEX_BASE,0,(ONE));
  46. }
  47.  
  48. #define TASK_STACKSIZE 1024
  49. OS_STK task1_stk[TASK_STACKSIZE];
  50. OS_STK task2_stk[TASK_STACKSIZE];
  51. OS_STK task3_stk[TASK_STACKSIZE];
  52. OS_STK task4_stk[TASK_STACKSIZE];
  53. OS_STK task5_stk[TASK_STACKSIZE];
  54. OS_STK task6_stk[TASK_STACKSIZE];
  55. OS_STK task7_stk[TASK_STACKSIZE];
  56.  
  57. OS_EVENT *SWBox1;
  58.  
  59. #define TASK1_PRIORITY 1
  60. #define TASK2_PRIORITY 2
  61. #define TASK3_PRIORITY 3
  62. #define TASK4_PRIORITY 4
  63. #define TASK5_PRIORITY 5
  64. #define TASK6_PRIORITY 6
  65. #define TASK7_PRIORITY 7
  66.  
  67. struct msg{
  68. int *sw;
  69. int *flaga_bledu;
  70. };
  71.  
  72. void task1(void* pdata){
  73. char znak;
  74. struct msg m;
  75. int sw=0;
  76. m.sw=&sw;
  77. int flaga_bledu=0;
  78. m.flaga_bledu=&flaga_bledu;
  79. char napis1[40] = " \0";
  80. char napis2[40] = "Blad, wylacz wszystkie funkcje \0";
  81. char napis3[40] = "Wszystkie funkcje wylaczone \0";
  82. alt_mutex_dev* mutex = altera_avalon_mutex_open("/dev/mutex");
  83.  
  84. while (1){
  85. altera_avalon_mutex_lock(mutex, 1);
  86. sw = IORD(SHARED_MEMORY_BASE,0);
  87. znak = IORD(SHARED_MEMORY_BASE,sizeof(int));
  88. altera_avalon_mutex_unlock(mutex);
  89.  
  90. if((znak==22)||(znak==30)||(znak==38)||(znak==37)||(znak==46)||(znak==54)){switch(znak){
  91. case 22: sw=SW0; break;
  92. case 30: sw=SW1; break;
  93. case 38: sw=SW2; break;
  94. case 37: sw=SW3; break;
  95. case 46: sw=SW4; break;
  96. case 54: sw=SW5; break;
  97. }}else{/*sw = IORD(SW_SLIDERS_BASE,0);*/}
  98.  
  99. if((sw > 32)){
  100. flaga_bledu=1;
  101. }
  102. if(flaga_bledu){
  103. VGA_text (10,12,napis1);
  104. VGA_text (10,14,napis1);
  105. VGA_text (10,16,napis1);
  106. VGA_text (10,18,napis1);
  107. VGA_text (10,20,napis1);
  108. VGA_text (10,22,napis1);
  109. VGA_text (10,10,napis2);
  110. error();
  111. IOWR(LEDS_BASE,0,LED9);
  112. IOWR(NEW_COMPONENT22_0_BASE,0,2);
  113. }
  114. if(sw==0){
  115. VGA_text (10,12,napis1);
  116. VGA_text (10,14,napis1);
  117. VGA_text (10,16,napis1);
  118. VGA_text (10,18,napis1);
  119. VGA_text (10,20,napis1);
  120. VGA_text (10,22,napis1);
  121. VGA_text (10,10,napis3);
  122. flaga_bledu=0;
  123. off();
  124. IOWR(LEDS_BASE,0,0);
  125. IOWR(NEW_COMPONENT22_0_BASE,0,0);
  126. }
  127. //if((sw)&&(!flaga_bledu)){VGA_text (10,10,napis1);}
  128. OSMboxPostOpt(SWBox1,&m,OS_POST_OPT_BROADCAST);
  129. //printf("task1\n");
  130. OSTimeDlyHMSM(0, 0, 0, 100);
  131. }
  132. }
  133.  
  134. void task2(void* pdata){
  135. volatile int sw=0;
  136. int flaga_bledu=0;
  137. struct msg *msg=NULL;
  138. INT8U err;
  139. char napis[40] = "Wszystkie funkcje wlaczone \0";
  140. char napis1[40] = " \0";
  141.  
  142. while(1){
  143. msg = (struct msg*)OSMboxPend(SWBox1,0,&err);
  144. sw=*(msg->sw);
  145. flaga_bledu=*(msg->flaga_bledu);
  146. if((sw & SW5)&&(!flaga_bledu)&&(err==OS_NO_ERR)){
  147. VGA_text (10,12,napis1);
  148. VGA_text (10,14,napis1);
  149. VGA_text (10,16,napis1);
  150. VGA_text (10,18,napis1);
  151. VGA_text (10,20,napis1);
  152. VGA_text (10,22,napis1);
  153. VGA_text(10,10,napis);
  154. all();
  155. IOWR(LEDS_BASE,0, (LED0 | LED1 | LED2 | LED3 | LED4));
  156. }
  157. //printf("task2\n");
  158. OSTimeDlyHMSM(0, 0, 0, 100);
  159. }
  160. }
  161.  
  162. void task3(void* pdata){
  163. volatile int sw=0;
  164. int flaga_bledu=0;
  165. struct msg *msg=NULL;
  166. INT8U err;
  167. char napis[40] = "Palnik 1 wlaczony \0";
  168. char napis1[40] = "Palnik 1 wylaczony \0";
  169.  
  170. while(1){
  171. msg = (struct msg*)OSMboxPend(SWBox1,0,&err);
  172. sw=*(msg->sw);
  173. flaga_bledu=*(msg->flaga_bledu);
  174. if(((sw & SW0))&&(!flaga_bledu)&&(err==OS_NO_ERR)){
  175. VGA_text (10,10,napis);
  176. if(!(sw & (SW1 | SW2 | SW3 | SW4))){on();}
  177. IOWR(LEDS_BASE,0,sw&~ SW4);
  178. }
  179. if(((~sw) & SW0)&&(!flaga_bledu)&&sw&&!(sw & SW5)){
  180. VGA_text (10,10,napis1);
  181. }
  182. // printf("task3\n");
  183. OSTimeDlyHMSM(0, 0, 0, 100);
  184. }
  185. }
  186.  
  187. void task4(void* pdata){
  188. volatile int sw=0;
  189. int flaga_bledu=0;
  190. struct msg *msg=NULL;
  191. INT8U err;
  192. char napis[40] = "Palnik 2 wlaczony \0";
  193. char napis1[40] = "Palnik 2 wylaczony \0";
  194.  
  195. while(1){
  196. msg = (struct msg*)OSMboxPend(SWBox1,0,&err);
  197. sw=*(msg->sw);
  198. flaga_bledu=*(msg->flaga_bledu);
  199. if((sw & SW1)&&(!flaga_bledu)&&(err==OS_NO_ERR)){
  200. VGA_text (10,12,napis);
  201. if(!(sw & (SW0 | SW2 | SW3 | SW4))){on();}
  202. IOWR(LEDS_BASE,0,sw&~ SW4);
  203. }
  204. if(((~sw) & SW1)&&(!flaga_bledu)&&sw&&!(sw & SW5)){
  205. VGA_text (10,12,napis1);
  206. }
  207. // printf("task4\n");
  208. OSTimeDlyHMSM(0, 0, 0, 100);
  209. }
  210. }
  211.  
  212. void task5(void* pdata){
  213. volatile int sw=0;
  214. int flaga_bledu=0;
  215. struct msg *msg=NULL;
  216. INT8U err;
  217. char napis[40] = "Palnik 3 wlaczony \0";
  218. char napis1[40] = "Palnik 3 wylaczony \0";
  219.  
  220. while(1){
  221. msg = (struct msg*)OSMboxPend(SWBox1,0,&err);
  222. sw=*(msg->sw);
  223. flaga_bledu=*(msg->flaga_bledu);
  224. if((sw & SW2)&&(!flaga_bledu)&&(err==OS_NO_ERR)){
  225. VGA_text (10,14,napis);
  226. if(!(sw & (SW0 | SW1 | SW3 | SW4))){on();}
  227. IOWR(LEDS_BASE,0,sw&~ SW4);
  228. }
  229. if(((~sw) & SW2)&&(!flaga_bledu)&&sw&&!(sw & SW5)){
  230. VGA_text (10,14,napis1);
  231. }
  232. // printf("task5\n");
  233. OSTimeDlyHMSM(0, 0, 0, 100);
  234. }
  235. }
  236.  
  237. void task6(void* pdata){
  238. volatile int sw=0;
  239. int flaga_bledu=0;
  240. struct msg *msg=NULL;
  241. INT8U err;
  242. char napis[40] = "Palnik 4 wlaczony \0";
  243. char napis1[40] = "Palnik 4 wylaczony \0";
  244.  
  245. while(1){
  246. msg = (struct msg*)OSMboxPend(SWBox1,0,&err);
  247. sw=*(msg->sw);
  248. flaga_bledu=*(msg->flaga_bledu);
  249. if((sw & SW3)&&(!flaga_bledu)&&(err==OS_NO_ERR)){
  250. VGA_text (10,16,napis);
  251. if(!(sw & (SW0 | SW1 | SW2 | SW4))){on();}
  252. IOWR(LEDS_BASE,0,sw &~ SW4);
  253. }
  254. if(((~sw) & SW3)&&(!flaga_bledu)&&sw&&!(sw & SW5)){
  255. VGA_text (10,16,napis1);
  256. }
  257. // printf("task6\n");
  258. OSTimeDlyHMSM(0, 0, 0, 100);
  259. }
  260. }
  261.  
  262. void task7(void* pdata){
  263. volatile int sw=0;
  264. int flaga_bledu=0;
  265. struct msg *msg=NULL;
  266. INT8U err;
  267. char napis[40] = "Piekarnik wlaczony \0";
  268. char napis1[40] = "Piekarnik wylaczony \0";
  269.  
  270. while(1){
  271. msg = (struct msg*)OSMboxPend(SWBox1,0,&err);
  272. sw=*(msg->sw);
  273. flaga_bledu=*(msg->flaga_bledu);
  274. if(((sw & SW4))&&(!flaga_bledu)&&(err==OS_NO_ERR)){
  275. VGA_text (10,18,napis);
  276. if(!(sw & (SW0 | SW1 | SW2 | SW3))){on();}
  277. //IOWR(LEDS_BASE,0,sw);
  278. IOWR(NEW_COMPONENT22_0_BASE,0,1);
  279. }
  280. if(((~sw) & SW4)&&(!flaga_bledu)&&sw&&!(sw & SW5)){
  281. VGA_text (10,18,napis1);
  282. }
  283. // printf("task7\n");
  284. OSTimeDlyHMSM(0, 0, 0, 100);
  285. }
  286. }
  287.  
  288.  
  289. int main(void)
  290. {
  291. SWBox1 = OSMboxCreate((void*)0);
  292.  
  293. OSTaskCreateExt(task1,NULL,(void *)&task1_stk[TASK_STACKSIZE-1],TASK1_PRIORITY,TASK1_PRIORITY,task1_stk,TASK_STACKSIZE,NULL,0);
  294. OSTaskCreateExt(task2,NULL,(void *)&task2_stk[TASK_STACKSIZE-1],TASK2_PRIORITY,TASK2_PRIORITY,task2_stk,TASK_STACKSIZE,NULL,0);
  295. OSTaskCreateExt(task3,NULL,(void *)&task3_stk[TASK_STACKSIZE-1],TASK3_PRIORITY,TASK3_PRIORITY,task3_stk,TASK_STACKSIZE,NULL,0);
  296. OSTaskCreateExt(task4,NULL,(void *)&task4_stk[TASK_STACKSIZE-1],TASK4_PRIORITY,TASK4_PRIORITY,task4_stk,TASK_STACKSIZE,NULL,0);
  297. OSTaskCreateExt(task5,NULL,(void *)&task5_stk[TASK_STACKSIZE-1],TASK5_PRIORITY,TASK5_PRIORITY,task5_stk,TASK_STACKSIZE,NULL,0);
  298. OSTaskCreateExt(task6,NULL,(void *)&task6_stk[TASK_STACKSIZE-1],TASK6_PRIORITY,TASK6_PRIORITY,task6_stk,TASK_STACKSIZE,NULL,0);
  299. OSTaskCreateExt(task7,NULL,(void *)&task7_stk[TASK_STACKSIZE-1],TASK7_PRIORITY,TASK7_PRIORITY,task7_stk,TASK_STACKSIZE,NULL,0);
  300.  
  301. OSStart();
  302. return 0;
  303. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement