📄 msgq.lst
字号:
C51 COMPILER V6.12 MSGQ 12/07/2004 17:58:46 PAGE 1
C51 COMPILER V6.12, COMPILATION OF MODULE MSGQ
OBJECT MODULE PLACED IN .\msgq.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ..\..\..\ipc\msgq.c INCDIR(d:\rs1.12b\) DEBUG OBJECTEXTEND PRINT(.\msgq.lst
-) OBJECT(.\msgq.obj)
stmt level source
1 /*
2 ===============================================================================
3 | Copyright (C) 2004 RuanHaiShen, All rights reserved.
4 | SUMMARY:
5 | Message queue implementation
6 |
7 | DESCRIPTION:
8 | See http://www.01s.org for documentation, latest information, license
9 | and contact details.
10 | email:ruanhaishen@01s.org
11 =============================================================================*/
12 /*===========================================================================*/
13 #include "arch/arch.h"
14 #include "inc/queue.h"
15 #include "inc/kernel.h"
16 #include "inc/memory.h"
17 #include "inc/ipc.h"
18 #include "inc/kapi.h"
19
20
21 #if CFG_MSGQ_EN > 0
#define __msgq_take_head(msgq, buf) \
do { \
__memcpy(buf, msgq->phead, msgq->msgsz); \
msgq->phead += msgq->msgsz; \
if (msgq->phead == msgq->pend) { \
msgq->phead = msgq->pstart; \
} \
} while (0)
#define __msgq_take_tail(msgq, buf) \
do { \
if (msgq->ptail == msgq->pstart) { \
msgq->ptail = msgq->pend; \
} \
msgq->ptail -= msgq->msgsz; \
__memcpy(buf, msgq->ptail, msgq->msgsz); \
} while (0)
err_t msgq_init(msgq_t __p_* msgq, mmsz_t size, mmsz_t entries, u8 opt)
{
__ASSERT(msgq != NULL);
__ASSERT(size > 0);
__ASSERT(entries > 0);
msgq->pstart = kmalloc(size * entries);
if (msgq->pstart == NULL) {
return ENULL;
}
msgq->phead =
msgq->ptail = msgq->pstart;
msgq->pend = msgq->pstart + size * entries;
msgq->msgsz = size;
C51 COMPILER V6.12 MSGQ 12/07/2004 17:58:46 PAGE 2
msgq->entries = entries;
msgq->opt = opt;
msgq->avail = 0;
__queue_init(msgq->waits);
return EOK;
}
err_t msgq_send(msgq_t __p_* msgq, const void __p_* buf)
{
__ASSERT(msgq != NULL);
__ASSERT(buf != NULL);
CRITICAL_ENTER;
if (msgq->avail < msgq->entries) {
__memcpy(msgq->ptail, buf, msgq->msgsz);
msgq->ptail += msgq->msgsz;
if (msgq->ptail == msgq->pend) {
msgq->ptail = msgq->pstart;
}
if (msgq->avail++ == 0) {
__ipc_resume(&msgq->waits);
CRITICAL_EXIT;
__schedule();
} else {
CRITICAL_EXIT;
}
return EOK;
} else {
CRITICAL_EXIT;
return EFULL;
}
}
err_t msgq_receive(msgq_t __p_* msgq, void __p_* buf)
{
__ASSERT(msgq != NULL);
__ASSERT(buf != NULL);
#if CFG_ARG_CHK > 0
if (_sched_lock > 0) {
return ELOCK;
}
#else
__ASSERT(_sched_lock == 0);
#endif
while (true) {
CRITICAL_ENTER;
if (msgq->avail > 0) {
msgq->avail--;
if (msgq->opt == MSG_FIFO) {
__msgq_take_head(msgq, buf);
} else {
__msgq_take_tail(msgq, buf);
}
CRITICAL_EXIT;
return EOK;
}
__ipc_block(&msgq->waits, 0);
C51 COMPILER V6.12 MSGQ 12/07/2004 17:58:46 PAGE 3
CRITICAL_EXIT;
__schedule();
}
}
#if CFG_IPC_TIMEOUT_EN > 0
err_t msgq_timereceive(msgq_t __p_* msgq, void __p_* buf, tick_t ticks)
{
register u8 current;
__ASSERT(msgq != NULL);
__ASSERT(buf != NULL);
#if CFG_ARG_CHK > 0
if (_sched_lock > 0) {
return ELOCK;
}
#else
__ASSERT(_sched_lock == 0);
#endif
while (true) {
CRITICAL_ENTER;
if (msgq->avail > 0) {
msgq->avail--;
if (msgq->opt == MSG_FIFO) {
__msgq_take_head(msgq, buf);
} else {
__msgq_take_tail(msgq, buf);
}
CRITICAL_EXIT;
return EOK;
}
__ipc_block(&msgq->waits, ticks);
CRITICAL_EXIT;
__schedule();
CRITICAL_ENTER;
current = _current_prio;
if (_tasks[current].state & STATE_BLOCKED) {
__ipc_timeout(&msgq->waits);
CRITICAL_EXIT;
return ETIMEOUT;
}
__adjust_delay(current, ticks);
CRITICAL_EXIT;
}
}
#endif
err_t msgq_flush(msgq_t __p_* msgq)
{
__ASSERT(msgq != NULL);
CRITICAL_ENTER;
msgq->phead =
msgq->ptail = msgq->pstart;
msgq->avail = 0;
C51 COMPILER V6.12 MSGQ 12/07/2004 17:58:46 PAGE 4
CRITICAL_EXIT;
return EOK;
}
err_t msgq_destroy(msgq_t __p_* msgq)
{
__ASSERT(msgq != NULL);
CRITICAL_ENTER;
if (__ipc_resume(&msgq->waits) != NULL_PRIO) {
CRITICAL_EXIT;
return EEXIST;
}
CRITICAL_EXIT;
CRITICAL_ENTER;
if (msgq->pstart != NULL) {
kfree(msgq->pstart);
msgq->pstart = NULL;
}
CRITICAL_EXIT;
return EOK;
}
#endif
206
207
208 /*===========================================================================*/
209
210
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = ---- ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -