-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp_task.c
More file actions
109 lines (93 loc) · 3.57 KB
/
app_task.c
File metadata and controls
109 lines (93 loc) · 3.57 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// based on the ble_peripheral example in RTL8762C-sdk-gcc-v0.0.5.zip
// <https://www.realmcu.com/en/Home/Product/93cc0582-3a3f-4ea8-82ea-76c6504e478a>
// modified by wuwbobo2021 <https://github.com/wuwbobo2021>, <wuwbobo@outlook.com>
/*============================================================================*
* Header Files
*============================================================================*/
#include <os_msg.h>
#include <os_task.h>
#include "trace.h"
#include <gap.h>
#include <gap_le.h>
#include "app_task.h"
#include "peripheral_app.h"
/** @defgroup PERIPH_APP_TASK Peripheral App Task
* @brief This file handles the implementation of application task related functions.
*
* Create App task and handle events & messages
* @{
*/
/*============================================================================*
* Macros
*============================================================================*/
#define APP_TASK_PRIORITY 1 //!< Task priorities
#define APP_TASK_STACK_SIZE 256 * 4 //!< Task stack size
#define MAX_NUMBER_OF_GAP_MESSAGE 0x20 //!< GAP message queue size
#define MAX_NUMBER_OF_IO_MESSAGE 0x20 //!< IO message queue size
#define MAX_NUMBER_OF_EVENT_MESSAGE (MAX_NUMBER_OF_GAP_MESSAGE + MAX_NUMBER_OF_IO_MESSAGE) //!< Event message queue size
/*============================================================================*
* Variables
*============================================================================*/
void *app_task_handle; //!< APP Task handle
void *evt_queue_handle; //!< Event queue handle
void *io_queue_handle; //!< IO queue handle
/*============================================================================*
* Functions
*============================================================================*/
void app_main_task(void *p_param);
/**
* @brief Initialize App task
* @return void
*/
void app_task_init()
{
os_task_create(&app_task_handle, "app", app_main_task, 0, APP_TASK_STACK_SIZE,
APP_TASK_PRIORITY);
}
/**
* @brief App task to handle events & messages
* @param[in] p_param Parameters sending to the task
* @return void
*/
void app_main_task(void *p_param)
{
uint8_t event;
os_msg_queue_create(&io_queue_handle, MAX_NUMBER_OF_IO_MESSAGE, sizeof(T_IO_MSG));
os_msg_queue_create(&evt_queue_handle, MAX_NUMBER_OF_EVENT_MESSAGE, sizeof(uint8_t));
gap_start_bt_stack(evt_queue_handle, io_queue_handle, MAX_NUMBER_OF_GAP_MESSAGE);
driver_init();
while (true)
{
if (os_msg_recv(evt_queue_handle, &event, 0xFFFFFFFF) == true)
{
if (event == EVENT_IO_TO_APP)
{
T_IO_MSG io_msg;
if (os_msg_recv(io_queue_handle, &io_msg, 0) == true)
{
app_handle_io_msg(io_msg);
}
}
else
{
gap_handle_msg(event);
}
}
}
}
bool send_msg_to_app(T_IO_MSG *p_msg)
{
uint8_t event = EVENT_IO_TO_APP;
if (os_msg_send(io_queue_handle, p_msg, 0) == false)
{
APP_PRINT_ERROR0("app_task.c: send_msg_to_app() failed: io_queue_handle");
return false;
}
else if (os_msg_send(evt_queue_handle, &event, 0) == false)
{
APP_PRINT_ERROR0("app_task.c: send_msg_to_app() failed: evt_queue_handle");
return false;
}
return true;
}
/** @} */ /* End of group PERIPH_APP_TASK */