-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessaging.c
More file actions
executable file
·100 lines (69 loc) · 1.68 KB
/
Copy pathmessaging.c
File metadata and controls
executable file
·100 lines (69 loc) · 1.68 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
/******************************************************************************
*
* File: messaging.c
* Language: C
* AUTHOR: S. W. Sheppard
* E-Mail: sheppard.will@gmail.com
* https://github.com/wsheppard/ecd2012
*
*
* Description:
* Wrappers for FreeRTOS queue functions.
*
*
*******************************************************************************/
#include "messaging.h"
int msg_newQueue(xQueueHandle*qhandle){
xQueueHandle tempHandle = NULL;
tempHandle = xQueueCreate(MSG_QUEUE_LENGTH, sizeof(msg_message_s));
/* Sanity */
if (qhandle == NULL){
return ECD_ERROR;
}
if (tempHandle == 0) {
/* Return error as couldn't create queue */
return ECD_ERROR;
}
else {
/* Set handle and return OK */
*qhandle = tempHandle;
return ECD_OK;
}
return ECD_ERROR;
}
int msg_rmQueue(xQueueHandle qHandle){
if (qHandle == 0)
return -1;
vQueueDelete(qHandle);
return ECD_OK;
}
int msg_send(xQueueHandle qHandle, msg_message_s msgMessage){
/* Send it to the back of the queue, don't wait for the queue
if it's full */
if (xQueueSendToBack(qHandle, (void*)&msgMessage, 0) != pdTRUE){
fprintf(stderr,"Sent message failed...\n");
return -1;
}
else{
//fprintf(stderr,"Sent message...\n");
return 0;
}
}
int msg_recv_noblock(xQueueHandle qHandle, msg_message_s*pMessage){
if (qHandle == NULL){
return ECD_ERROR;
}
if(pdTRUE==xQueueReceive( qHandle, pMessage, 0 )){
return ECD_OK;
}
else{
return ECD_NOMSG;
}
}
int msg_recv_block(xQueueHandle qHandle, msg_message_s*pMessage){
if (qHandle == NULL){
return ECD_ERROR;
}
xQueueReceive( qHandle, pMessage, portMAX_DELAY );
return ECD_OK;
}