-
Notifications
You must be signed in to change notification settings - Fork 1
/
protectedlcd.c
executable file
·62 lines (54 loc) · 1.41 KB
/
protectedlcd.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
/** \file protectedled.c
*
* @brief Reentrant LCD driver.
*
* @par
* COPYRIGHT NOTICE: (c) 2011 Netrino, LLC.
* All rights reserved.
*/
#include <assert.h>
#include <stdint.h>
#include "includes.h"
#include "protectedlcd.h"
#include "lcd.h"
static OS_MUTEX lcd_mutex;
/*!
* @brief Initialize the reentrant LCD driver.
*/
void protected_lcd_init(void)
{
OS_ERR err;
OSMutexCreate(&lcd_mutex, "LCD Mutex", &err);
assert(OS_ERR_NONE == err);
OSMutexPend(&lcd_mutex, 0, OS_OPT_PEND_BLOCKING, 0, &err);
assert(OS_ERR_NONE == err);
InitialiseLCD();
OSMutexPost(&lcd_mutex, OS_OPT_POST_NONE, &err);
assert(OS_ERR_NONE == err);
}
/*!
* @brief Display data on the LCD, safely.
* @param[in] Position and data.
*/
void protected_lcd_display(uint8_t position, const uint8_t *data)
{
OS_ERR err;
OSMutexPend(&lcd_mutex, 0, OS_OPT_PEND_BLOCKING, 0, &err);
assert(OS_ERR_NONE == err);
DisplayLCD(position, data);
OSMutexPost(&lcd_mutex, OS_OPT_POST_NONE, &err);
assert(OS_ERR_NONE == err);
}
/*!
* @brief Display data on the LCD, safely.
* @param[in] Position and data.
*/
void protected_lcd_clear(void)
{
OS_ERR err;
OSMutexPend(&lcd_mutex, 0, OS_OPT_PEND_BLOCKING, 0, &err);
assert(OS_ERR_NONE == err);
ClearLCD();
OSMutexPost(&lcd_mutex, OS_OPT_POST_NONE, &err);
assert(OS_ERR_NONE == err);
}