Copie RTK

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Program 2 Taskuri

#include <iostream.h> #include <conio.h> #include <stdio.h> #include <dos.h>


#include <stdlib.h> #include "rtkernel.h" #include "rtkeybrd.h"
TaskHandle T1,T2; void Task1()
{ int i=0; while(1) { cout<<i<<" "; RTKDelay(18); i++; } }
void Task2() { while(1) { RTKDelay(18*5); clrscr(); } }
void main() { char c; int prioritate; RTKernelInit(3); RTKeybrdInit();
T1 = RTKCreateTask(Task1,5,1024,"Task1"); T2 = RTKCreateTask(Task2,7,1024,"Task2");
while(1)
{ c = RTGetCh(); if (c == 'E' || c == 'e') exit(0); if (c == 'S' || c =='s') RTKSuspend(T2);
if (c == 'R' || c =='r') RTKResume(T2); if (c == 'P' || c == 'p') {prioritate = RTKGetTaskPrio(T1);
cout<< endl<<" --- Prioritate task1 = "<< prioritate<<endl; } if ( c == 'T' || c == 't') RTKSetPriority(T1,6); } }

Program Semafor

#include <dos.h> #include <conio.h> #include <stdio.h> #include <stdlib.h>


#include "rtkernel.h" #include "rtkeybrd.h"
struct date d; struct time t; TaskHandle Handler_dest; void afordata()
{ getdate(&d); gettime(&t); gotoxy(55,3);
cprintf("%02d-%02d-%4d",d.da_day,d.da_mon,d.da_year)
cprintf(" %02d:%02d:%02d",t.ti_hour,t.ti_min,t.ti_sec); }
void Task_ora()
{for(;;) { RTKDelay(18); afordata();} } void Task_dest() { char j2; for(;;) { RTKReceive(&j2,2); gotoxy
(5,8);
cprintf("Dest a receptionat %c ",j2); } } void main()
{char c; char j1= '0'; int i; RTKernelInit(3); clrscr(); gotoxy(5,8);
cprintf("Orice tasta mai putin E transmite E - Iesire");RTKeybrdInit();
RTKCreateTask(Task_ora,5,1024,"Task-tip_ora");
Handler_dest=RTKCreateTask(Task_dest,7,1024,"Destinatar");
for(;;) { c=RTGetCh(); for(i=1;i<=25;i++)
{ j1++; gotoxy(5,10); cprintf("main transmite %c ",j1);
RTKSend(Handler_dest,&j1); RTKDelay(18); } if(c=='E') exit(0); j1='0';} }

Program Cutie Postala (aceleasi # ca si Semafor)

Mailbox Cut_post_sincr; truct date d; struct time t; void afordata()

{ getdate(&d); gettime(&t); gotoxy(55,3); cprintf("%02d-%02d-%4d",d.da_day,d.da_mon,d.da_year);


cprintf(" %02d:%02d:%02d",t.ti_hour,t.ti_min,t.ti_sec); } void Task_ora()
{ for(;;) { RTKDelay(18); afordata(); }} void Task_sincr() { char i;
for(;;) { gotoxy(5,10); cprintf("Task_sincr asteapta la Cut_post_sincr"); RTKGet(Cut_post_sincr,&i);
RTKDelay(18); gotoxy(7,12); cprintf("Sosit in Cut_post_sincr mesaj %c",i); RTKDelay(18); } }
void main() { char c; RTKernelInit(3); clrscr(); gotoxy(5,8);
cprintf("Orice tasta mai putin E - executie task_sincr E - Iesire"); RTKeybrdInit();
Cut_post_sincr=RTKCreateMailbox(2,1,"CP_sincr");
RTKCreateTask(Task_ora,5,1024,"Task_af_ora"); RTKCreateTask(Task_sincr,7,1024,"Task_sin");
for(;;) { gotoxy(8,9); cprintf("Transmis din main mesajul "); c=RTGetCh(); if(c=='E') exit(0); gotoxy(41,9);
cprintf("%c",c); RTKPut(Cut_post_sincr,&c); } }
//Tipuri de date

struct time <numeStructuraTimp>;//structura pentru timp

struct date <numeStructuraData>;//structura pentru data

TaskHandle <numeTaskHandle>; //handle pentru lucru cu functii

Semaphore <numeSemafor>; //definire semafor

Mailbox <numeCutiePostala>; //definire cutie postala

//Functii RTK

//Laboratorul 2

//initializare functie principala

RTKernelInit(prioritateTaskMain);

//initializare tastatura

RTKeybrdInit();

//creare task now si retinerea lui intr-un handler pentru a putea fi folosit de functii

TaskHandle Handler_Task = RTKCreateTask(void *Cod_Task(void), unsigned int Prioritate_Task, unsigned int


Stiva_task, char *Nume_Task);

//creare task now

RTKCreateTask(void *Cod_Task(void), unsigned int Prioritate_Task, unsigned int Stiva_task, char *Nume_Task);

//Trecerea taskului din starea Current in Suspended

RTKSuspend(TaskHandle Handler_task);

//Trecerea taskului din starea Suspended in starea Ready

RTKResume(TaskHandle Handler_Task);

//Setarea prioritatii unui task retinut in Handler_Task la prioritatea Prioritate_Noua

RTKSetPriority(TaskHandle Handler_Task, unsigned int Prioritate_Noua);

//Returnarea prioritatii intr-o variabila valoarePrioritate dintr-un task retinut in Handler_Task

unsigned int valoarePrioritate = RTKGetTaskPrio(TaskHandle Handler_Task);

//Returnarea dimensiunii stivei intr-o variabila dimensiuneStiva dintr-un task retinut in Handler_Task

unsigned int dimensiuneStiva = RTKGetTaskStack(TaskHandle Handler_Task);

//Returnarea starii unui task intr-o variabila Stare_Task dintr-un task retinut in Handler_Task

TaskState Stare_Task = RTKGetTaskState(TaskHandle Handler_Task);

//Laboratorul 3-4

RTKSetTime(Time Timp_nou);
Time Timp_actual = RTKGetTime();

RTKDelay(Duration Intarziere);

RTKDelayUntil(Time Moment_Impus);

char variabilaCaracter = RTGetCh();

Semaphore Semafor = RTKCreateSemaphore(SemaType Tip_Semafor, unsigned Valoare_Initiala, char


*Nume_Semaf);

unsigned numarEvenimente = RTKSemaValue(Semaphore Semaf);

RTKSignal(Semaphore Semaf);

RTKWait (Semaphore Semaf);

bool executat = RTKWaitCond(Semaphore Semaf);

bool executat = RTKWaitTimed(Semaphore Semaf, Duration Timp_astept);

//Laboratorul 5-6

Mailbox Cutie_Postala = RTKCreateMailbox(unsigned Lungime_Mesaj, unsigned Numar_Mesaje, char


*Nume_Cutie_Postala);

unsigned int Numar_Mesaje = RTKMessages(Mailbox Cutie_Postala);

RTKClearMailbox(Mailbox Cutie_Postala);

RTKPut(Mailbox Cutie_Postala, void *Variabila_depunere);

bool executat = RTKPutCond(Mailbox Cutie_Postala, void *Variabila_Depunere);

bool executat = RTKPutTimed(Mailbox Cutie_Postala, void *Variabila_Depunere, Duration Timp_Așteptare);

RTKGet(Mailbox Cutie_Postala, void *Variabila_Preluare);

bool executat = RTKGetCond(Mailbox Cutie_Postala, void *Variabila_Preluare);

bool executat = RTKGetCond(Mailbox Cutie_Postala, void *Variabila_Preluare, Duration Timp_Așteptare);

//Laboratorul 8-9

RTKSend(TaskHandle Handler_Receptie, void *Variabila_Depunere);

bool executat = RTKSendCond(TaskHandle Handler_Receptie, void *Variabila_Depunere);

bool executat = RTKSendTimed(TaskHandle Handler_Receptie, void *Variabila_Depunere, Duration


Timp_Asteptare);

RTKReceive(void *Variabila_Receptie, unsigned Lungime_Mesaj_Trecere );

bool executat = RTKReceiveCond(void *Variabila_Receptie, unsigned Lungime_Mesaj_Trecere);

bool executat = RTKReceiveTimed(void *Variabila_Receptie, unsigned Lungime_Mesaj_Trecere, Duration


Timp_Asteptare);

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy