Skip to content

Commit

Permalink
updated examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajmund Szymanski committed Jan 15, 2017
1 parent 5b4d8d1 commit 434e0f9
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 34 deletions.
2 changes: 0 additions & 2 deletions examples/main.c (barrier)
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ bar_t bar = BAR_INIT(2);
void slave()
{
bar_wait(&bar);

LED_Tick();
}

void master()
{
tsk_delay(SEC);

bar_wait(&bar);
}

Expand Down
10 changes: 5 additions & 5 deletions examples/main.c (demo) → examples/main.c (demo 1)
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ int main()
LED_Config();
GRN_Config();

tsk_start(TSK_CREATE(proc));
tsk_start(TSK_CREATE(proc));
tsk_start(TSK_CREATE(proc));
tsk_start(TSK_CREATE(proc));
tsk_start(TSK_CREATE(proc));
tsk_start((tsk_id)TSK_CREATE(proc));
tsk_start((tsk_id)TSK_CREATE(proc));
tsk_start((tsk_id)TSK_CREATE(proc));
tsk_start((tsk_id)TSK_CREATE(proc));
tsk_start((tsk_id)TSK_CREATE(proc));
tsk_stop();
}
30 changes: 30 additions & 0 deletions examples/main.c (demo 2)
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <stm32f4_discovery.h>
#include <os.h>

void proc(volatile unsigned *led, unsigned timePoint)
{
for (;;)
{
tsk_sleepUntil(timePoint += SEC/2);
(*led)++;
}
}

OS_DEF(t1) { proc(&LED[0], SEC/8*0); }
OS_DEF(t2) { proc(&LED[1], SEC/8*1); }
OS_DEF(t3) { proc(&LED[2], SEC/8*2); }
OS_DEF(t4) { proc(&LED[3], SEC/8*3); }
OS_DEF(t5) { proc(&GRN, SEC/8*4); }

int main()
{
LED_Config();
GRN_Config();

tsk_start(t1);
tsk_start(t2);
tsk_start(t3);
tsk_start(t4);
tsk_start(t5);
tsk_stop();
}
4 changes: 0 additions & 4 deletions examples/main.c (flag)
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ flg_t flg = FLG_INIT();
void slave()
{
flg_wait(&flg, 3, flgAll);

LED_Tick();
}

void master()
{
tsk_delay(SEC/2);

flg_give(&flg, 1);

tsk_delay(SEC/2);

flg_give(&flg, 2);
}

Expand Down
1 change: 0 additions & 1 deletion examples/main.c (infinite loop)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ int main()
for (;;)
{
tsk_delay(SEC);

LED_Tick();
}
}
3 changes: 0 additions & 3 deletions examples/main.c (mailbox queue)
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ void slave()
for (;;)
{
box_wait(&box, &x);

LEDs = x;
}
}
Expand All @@ -22,9 +21,7 @@ void master()
for (;;)
{
tsk_delay(SEC);

x++;

box_give(&box, &x);
}
}
Expand Down
2 changes: 0 additions & 2 deletions examples/main.c (message queue)
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ void slave()
for (;;)
{
msg_wait(&msg, &x);

LEDs = x;
}
}
Expand All @@ -22,7 +21,6 @@ void master()
for (;;)
{
tsk_delay(SEC);

msg_give(&msg, ++x);
}
}
Expand Down
4 changes: 0 additions & 4 deletions examples/main.c (mutex)
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ mtx_t mtx = MTX_INIT();
void slave()
{
mtx_wait(&mtx);

LED_Tick();

mtx_give(&mtx);
}

void master()
{
mtx_wait(&mtx);

tsk_delay(SEC);

mtx_give(&mtx);
}

Expand Down
2 changes: 0 additions & 2 deletions examples/main.c (semaphore)
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ sem_t sem = SEM_INIT(0);
void slave()
{
sem_wait(&sem);

LED_Tick();
}

void master()
{
tsk_delay(SEC);

sem_give(&sem);
}

Expand Down
2 changes: 0 additions & 2 deletions examples/main.c (signal 1)
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ sig_t sig = SIG_INIT(sigClear);
void slave()
{
sig_wait(&sig);

LED_Tick();
}

void master()
{
tsk_delay(SEC);

sig_give(&sig);
}

Expand Down
6 changes: 2 additions & 4 deletions examples/main.c (signal 2)
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,20 @@ sig_id sig = SIG_CREATE(sigClear);
void slave()
{
sig_wait(sig);

LED_Tick();
}

void master()
{
tsk_delay(SEC);

sig_give(sig);
}

int main()
{
LED_Config();

tsk_start(TSK_CREATE(slave));
tsk_start(TSK_CREATE(master));
tsk_start((tsk_id)TSK_CREATE(slave));
tsk_start((tsk_id)TSK_CREATE(master));
tsk_sleep();
}
1 change: 0 additions & 1 deletion examples/main.c (timer 1)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ tmr_t tmr = TMR_INIT();
void slave()
{
sem_wait(&sem);

LED_Tick();
}

Expand Down
2 changes: 0 additions & 2 deletions examples/main.c (tsk_flip)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ void master(void);
void slave()
{
LED_Tick();

tsk_flip(master);
}

Expand All @@ -16,7 +15,6 @@ void master()
static unsigned time = 0;

tsk_sleepUntil(time += SEC);

tsk_flip(slave);
}

Expand Down
2 changes: 0 additions & 2 deletions examples/main.c (tsk_startFrom)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ tsk_t tsk = TSK_INIT(0);
void slave()
{
LED_Tick();

tsk_stop();
}

Expand All @@ -17,7 +16,6 @@ void master()
for (;;)
{
tsk_sleepUntil(time += SEC);

tsk_startFrom(&tsk, slave);
}
}
Expand Down

0 comments on commit 434e0f9

Please sign in to comment.