Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- //#include <system.h>
- #include <io.h>
- //#include "includes.h"
- #include "definition.h"
- //#include <unistd.h>
- //#include <os_cpu.h>
- //#include <sys/alt_alarm.h>
- //#include <ucos_ii.h>
- //#include "alt_types.h"
- //#include "sys/alt_timestamp.h"
- //#include "altera_avalon_pio_regs.h"
- //#include "sys/alt_irq.h"
- #include <altera_avalon_mutex.h>
- void VGA_text(int x, int y, char *text_ptr){
- int offset;
- volatile char *character_buffer = (char*) VGA_CHAR_BUFFER_AVALON_CHAR_BUFFER_SLAVE_BASE;
- offset = (y << 7) + x;
- while(*(text_ptr)){
- *(character_buffer + offset) = *(text_ptr);
- ++text_ptr;
- ++offset;
- }
- }
- void error(){
- IOWR(HEX_BASE,2,(HEXE));
- IOWR(HEX_BASE,1,(HEXr));
- IOWR(HEX_BASE,0,(HEXr));
- }
- void on(){
- IOWR(HEX_BASE,2,0);
- IOWR(HEX_BASE,1,(HEXo));
- IOWR(HEX_BASE,0,(HEXn));
- }
- void off(){
- IOWR(HEX_BASE,2,(HEXo));
- IOWR(HEX_BASE,1,(HEXf));
- IOWR(HEX_BASE,0,(HEXf));
- }
- void all(){
- IOWR(HEX_BASE,2,(HEXA));
- IOWR(HEX_BASE,1,(ONE));
- IOWR(HEX_BASE,0,(ONE));
- }
- #define TASK_STACKSIZE 1024
- OS_STK task1_stk[TASK_STACKSIZE];
- OS_STK task2_stk[TASK_STACKSIZE];
- OS_STK task3_stk[TASK_STACKSIZE];
- OS_STK task4_stk[TASK_STACKSIZE];
- OS_STK task5_stk[TASK_STACKSIZE];
- OS_STK task6_stk[TASK_STACKSIZE];
- OS_STK task7_stk[TASK_STACKSIZE];
- OS_EVENT *SWBox1;
- #define TASK1_PRIORITY 1
- #define TASK2_PRIORITY 2
- #define TASK3_PRIORITY 3
- #define TASK4_PRIORITY 4
- #define TASK5_PRIORITY 5
- #define TASK6_PRIORITY 6
- #define TASK7_PRIORITY 7
- struct msg{
- int *sw;
- int *flaga_bledu;
- };
- void task1(void* pdata){
- char znak;
- struct msg m;
- int sw=0;
- m.sw=&sw;
- int flaga_bledu=0;
- m.flaga_bledu=&flaga_bledu;
- char napis1[40] = " \0";
- char napis2[40] = "Blad, wylacz wszystkie funkcje \0";
- char napis3[40] = "Wszystkie funkcje wylaczone \0";
- alt_mutex_dev* mutex = altera_avalon_mutex_open("/dev/mutex");
- while (1){
- altera_avalon_mutex_lock(mutex, 1);
- sw = IORD(SHARED_MEMORY_BASE,0);
- znak = IORD(SHARED_MEMORY_BASE,sizeof(int));
- altera_avalon_mutex_unlock(mutex);
- if((znak==22)||(znak==30)||(znak==38)||(znak==37)||(znak==46)||(znak==54)){switch(znak){
- case 22: sw=SW0; break;
- case 30: sw=SW1; break;
- case 38: sw=SW2; break;
- case 37: sw=SW3; break;
- case 46: sw=SW4; break;
- case 54: sw=SW5; break;
- }}else{/*sw = IORD(SW_SLIDERS_BASE,0);*/}
- if((sw > 32)){
- flaga_bledu=1;
- }
- if(flaga_bledu){
- VGA_text (10,12,napis1);
- VGA_text (10,14,napis1);
- VGA_text (10,16,napis1);
- VGA_text (10,18,napis1);
- VGA_text (10,20,napis1);
- VGA_text (10,22,napis1);
- VGA_text (10,10,napis2);
- error();
- IOWR(LEDS_BASE,0,LED9);
- IOWR(NEW_COMPONENT22_0_BASE,0,2);
- }
- if(sw==0){
- VGA_text (10,12,napis1);
- VGA_text (10,14,napis1);
- VGA_text (10,16,napis1);
- VGA_text (10,18,napis1);
- VGA_text (10,20,napis1);
- VGA_text (10,22,napis1);
- VGA_text (10,10,napis3);
- flaga_bledu=0;
- off();
- IOWR(LEDS_BASE,0,0);
- IOWR(NEW_COMPONENT22_0_BASE,0,0);
- }
- //if((sw)&&(!flaga_bledu)){VGA_text (10,10,napis1);}
- OSMboxPostOpt(SWBox1,&m,OS_POST_OPT_BROADCAST);
- //printf("task1\n");
- OSTimeDlyHMSM(0, 0, 0, 100);
- }
- }
- void task2(void* pdata){
- volatile int sw=0;
- int flaga_bledu=0;
- struct msg *msg=NULL;
- INT8U err;
- char napis[40] = "Wszystkie funkcje wlaczone \0";
- char napis1[40] = " \0";
- while(1){
- msg = (struct msg*)OSMboxPend(SWBox1,0,&err);
- sw=*(msg->sw);
- flaga_bledu=*(msg->flaga_bledu);
- if((sw & SW5)&&(!flaga_bledu)&&(err==OS_NO_ERR)){
- VGA_text (10,12,napis1);
- VGA_text (10,14,napis1);
- VGA_text (10,16,napis1);
- VGA_text (10,18,napis1);
- VGA_text (10,20,napis1);
- VGA_text (10,22,napis1);
- VGA_text(10,10,napis);
- all();
- IOWR(LEDS_BASE,0, (LED0 | LED1 | LED2 | LED3 | LED4));
- }
- //printf("task2\n");
- OSTimeDlyHMSM(0, 0, 0, 100);
- }
- }
- void task3(void* pdata){
- volatile int sw=0;
- int flaga_bledu=0;
- struct msg *msg=NULL;
- INT8U err;
- char napis[40] = "Palnik 1 wlaczony \0";
- char napis1[40] = "Palnik 1 wylaczony \0";
- while(1){
- msg = (struct msg*)OSMboxPend(SWBox1,0,&err);
- sw=*(msg->sw);
- flaga_bledu=*(msg->flaga_bledu);
- if(((sw & SW0))&&(!flaga_bledu)&&(err==OS_NO_ERR)){
- VGA_text (10,10,napis);
- if(!(sw & (SW1 | SW2 | SW3 | SW4))){on();}
- IOWR(LEDS_BASE,0,sw&~ SW4);
- }
- if(((~sw) & SW0)&&(!flaga_bledu)&&sw&&!(sw & SW5)){
- VGA_text (10,10,napis1);
- }
- // printf("task3\n");
- OSTimeDlyHMSM(0, 0, 0, 100);
- }
- }
- void task4(void* pdata){
- volatile int sw=0;
- int flaga_bledu=0;
- struct msg *msg=NULL;
- INT8U err;
- char napis[40] = "Palnik 2 wlaczony \0";
- char napis1[40] = "Palnik 2 wylaczony \0";
- while(1){
- msg = (struct msg*)OSMboxPend(SWBox1,0,&err);
- sw=*(msg->sw);
- flaga_bledu=*(msg->flaga_bledu);
- if((sw & SW1)&&(!flaga_bledu)&&(err==OS_NO_ERR)){
- VGA_text (10,12,napis);
- if(!(sw & (SW0 | SW2 | SW3 | SW4))){on();}
- IOWR(LEDS_BASE,0,sw&~ SW4);
- }
- if(((~sw) & SW1)&&(!flaga_bledu)&&sw&&!(sw & SW5)){
- VGA_text (10,12,napis1);
- }
- // printf("task4\n");
- OSTimeDlyHMSM(0, 0, 0, 100);
- }
- }
- void task5(void* pdata){
- volatile int sw=0;
- int flaga_bledu=0;
- struct msg *msg=NULL;
- INT8U err;
- char napis[40] = "Palnik 3 wlaczony \0";
- char napis1[40] = "Palnik 3 wylaczony \0";
- while(1){
- msg = (struct msg*)OSMboxPend(SWBox1,0,&err);
- sw=*(msg->sw);
- flaga_bledu=*(msg->flaga_bledu);
- if((sw & SW2)&&(!flaga_bledu)&&(err==OS_NO_ERR)){
- VGA_text (10,14,napis);
- if(!(sw & (SW0 | SW1 | SW3 | SW4))){on();}
- IOWR(LEDS_BASE,0,sw&~ SW4);
- }
- if(((~sw) & SW2)&&(!flaga_bledu)&&sw&&!(sw & SW5)){
- VGA_text (10,14,napis1);
- }
- // printf("task5\n");
- OSTimeDlyHMSM(0, 0, 0, 100);
- }
- }
- void task6(void* pdata){
- volatile int sw=0;
- int flaga_bledu=0;
- struct msg *msg=NULL;
- INT8U err;
- char napis[40] = "Palnik 4 wlaczony \0";
- char napis1[40] = "Palnik 4 wylaczony \0";
- while(1){
- msg = (struct msg*)OSMboxPend(SWBox1,0,&err);
- sw=*(msg->sw);
- flaga_bledu=*(msg->flaga_bledu);
- if((sw & SW3)&&(!flaga_bledu)&&(err==OS_NO_ERR)){
- VGA_text (10,16,napis);
- if(!(sw & (SW0 | SW1 | SW2 | SW4))){on();}
- IOWR(LEDS_BASE,0,sw &~ SW4);
- }
- if(((~sw) & SW3)&&(!flaga_bledu)&&sw&&!(sw & SW5)){
- VGA_text (10,16,napis1);
- }
- // printf("task6\n");
- OSTimeDlyHMSM(0, 0, 0, 100);
- }
- }
- void task7(void* pdata){
- volatile int sw=0;
- int flaga_bledu=0;
- struct msg *msg=NULL;
- INT8U err;
- char napis[40] = "Piekarnik wlaczony \0";
- char napis1[40] = "Piekarnik wylaczony \0";
- while(1){
- msg = (struct msg*)OSMboxPend(SWBox1,0,&err);
- sw=*(msg->sw);
- flaga_bledu=*(msg->flaga_bledu);
- if(((sw & SW4))&&(!flaga_bledu)&&(err==OS_NO_ERR)){
- VGA_text (10,18,napis);
- if(!(sw & (SW0 | SW1 | SW2 | SW3))){on();}
- //IOWR(LEDS_BASE,0,sw);
- IOWR(NEW_COMPONENT22_0_BASE,0,1);
- }
- if(((~sw) & SW4)&&(!flaga_bledu)&&sw&&!(sw & SW5)){
- VGA_text (10,18,napis1);
- }
- // printf("task7\n");
- OSTimeDlyHMSM(0, 0, 0, 100);
- }
- }
- int main(void)
- {
- SWBox1 = OSMboxCreate((void*)0);
- OSTaskCreateExt(task1,NULL,(void *)&task1_stk[TASK_STACKSIZE-1],TASK1_PRIORITY,TASK1_PRIORITY,task1_stk,TASK_STACKSIZE,NULL,0);
- OSTaskCreateExt(task2,NULL,(void *)&task2_stk[TASK_STACKSIZE-1],TASK2_PRIORITY,TASK2_PRIORITY,task2_stk,TASK_STACKSIZE,NULL,0);
- OSTaskCreateExt(task3,NULL,(void *)&task3_stk[TASK_STACKSIZE-1],TASK3_PRIORITY,TASK3_PRIORITY,task3_stk,TASK_STACKSIZE,NULL,0);
- OSTaskCreateExt(task4,NULL,(void *)&task4_stk[TASK_STACKSIZE-1],TASK4_PRIORITY,TASK4_PRIORITY,task4_stk,TASK_STACKSIZE,NULL,0);
- OSTaskCreateExt(task5,NULL,(void *)&task5_stk[TASK_STACKSIZE-1],TASK5_PRIORITY,TASK5_PRIORITY,task5_stk,TASK_STACKSIZE,NULL,0);
- OSTaskCreateExt(task6,NULL,(void *)&task6_stk[TASK_STACKSIZE-1],TASK6_PRIORITY,TASK6_PRIORITY,task6_stk,TASK_STACKSIZE,NULL,0);
- OSTaskCreateExt(task7,NULL,(void *)&task7_stk[TASK_STACKSIZE-1],TASK7_PRIORITY,TASK7_PRIORITY,task7_stk,TASK_STACKSIZE,NULL,0);
- OSStart();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement