-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmutex.c
80 lines (64 loc) · 1.93 KB
/
mutex.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* SPDX-License-Identifier: GPL-3.0-only
* This file is part of Lazuli.
*/
/**
* @file
* @brief Mutexes demonstration program.
* @copyright 2019-2020, Remi Andruccioli <remi.andruccioli@gmail.com>
*
* Example program to demonstrate the use of mutexes in Lazuli.
*/
#include <stdint.h>
#include <stdio.h>
#include <Lazuli/common.h>
#include <Lazuli/lazuli.h>
#include <Lazuli/mutex.h>
#include <Lazuli/serial.h>
DEPENDENCY_ON_MODULE(SERIAL);
DEPENDENCY_ON_MODULE(MUTEX);
static Lz_Mutex mutex = LZ_MUTEX_INIT;
void
Task(void)
{
Lz_Mutex_Lock(&mutex);
puts(Lz_Task_GetName());
Lz_Mutex_Unlock(&mutex);
}
static void
EnableSerialTransmission(void) {
Lz_SerialConfiguration serialConfiguration;
Lz_Serial_GetConfiguration(&serialConfiguration);
serialConfiguration.enableFlags = LZ_SERIAL_ENABLE_TRANSMIT;
serialConfiguration.speed = LZ_SERIAL_SPEED_19200;
Lz_Serial_SetConfiguration(&serialConfiguration);
}
void
main(void)
{
Lz_TaskConfiguration taskConfiguration;
EnableSerialTransmission();
Lz_TaskConfiguration_Init(&taskConfiguration);
taskConfiguration.name =
"Task 1 says: "
"\"An ounce of prevention is better than a pound of cure.\""
LZ_CONFIG_SERIAL_NEWLINE;
Lz_RegisterTask(Task, &taskConfiguration);
Lz_TaskConfiguration_Init(&taskConfiguration);
taskConfiguration.name =
"Task 2 says: "
"\"Don't count your chickens before they hatch.\"" LZ_CONFIG_SERIAL_NEWLINE;
Lz_RegisterTask(Task, &taskConfiguration);
Lz_TaskConfiguration_Init(&taskConfiguration);
taskConfiguration.name =
"Task 3 says: "
"\"Beauty is in the eye of the beholder.\"" LZ_CONFIG_SERIAL_NEWLINE;
Lz_RegisterTask(Task, &taskConfiguration);
Lz_TaskConfiguration_Init(&taskConfiguration);
taskConfiguration.name =
"Task 4 says: "
"\"Fire is a good servant but a bad master.\"" LZ_CONFIG_SERIAL_NEWLINE;
Lz_RegisterTask(Task, &taskConfiguration);
puts(LZ_CONFIG_SERIAL_NEWLINE);
Lz_Run();
}