From 6f9be6d790a4e8b5bab37f2dda8d37cb835ad90f Mon Sep 17 00:00:00 2001 From: chunyexixiaoyu <834670833@qq.com> Date: Mon, 16 Aug 2021 15:59:26 +0800 Subject: [PATCH] APP_Framework/lib/:add queue lib --- APP_Framework/lib/Kconfig | 1 + APP_Framework/lib/queue/Kconfig | 3 ++ APP_Framework/lib/queue/SConscript | 10 +++++ APP_Framework/lib/queue/queue.c | 59 ++++++++++++++++++++++++++++++ APP_Framework/lib/queue/queue.h | 26 +++++++++++++ 5 files changed, 99 insertions(+) create mode 100644 APP_Framework/lib/queue/Kconfig create mode 100644 APP_Framework/lib/queue/SConscript create mode 100644 APP_Framework/lib/queue/queue.c create mode 100644 APP_Framework/lib/queue/queue.h diff --git a/APP_Framework/lib/Kconfig b/APP_Framework/lib/Kconfig index d5064ee3..f92cf7cf 100755 --- a/APP_Framework/lib/Kconfig +++ b/APP_Framework/lib/Kconfig @@ -11,4 +11,5 @@ menu "lib" bool "app select other lib" endchoice source "$APP_DIR/lib/cJSON/Kconfig" + source "$APP_DIR/lib/queue/Kconfig" endmenu diff --git a/APP_Framework/lib/queue/Kconfig b/APP_Framework/lib/queue/Kconfig new file mode 100644 index 00000000..6e5e210b --- /dev/null +++ b/APP_Framework/lib/queue/Kconfig @@ -0,0 +1,3 @@ +menuconfig LIB_USING_QUEUE + bool "USING QUEUE" + default n diff --git a/APP_Framework/lib/queue/SConscript b/APP_Framework/lib/queue/SConscript new file mode 100644 index 00000000..852c0822 --- /dev/null +++ b/APP_Framework/lib/queue/SConscript @@ -0,0 +1,10 @@ +from building import * +import os + +cwd = GetCurrentDir() + +src = Glob('*.c') + +group = DefineGroup('queue', src, depend = ['LIB_USING_QUEUE'], CPPPATH = [cwd]) + +Return('group') \ No newline at end of file diff --git a/APP_Framework/lib/queue/queue.c b/APP_Framework/lib/queue/queue.c new file mode 100644 index 00000000..03949890 --- /dev/null +++ b/APP_Framework/lib/queue/queue.c @@ -0,0 +1,59 @@ +#include +Status InitQueue(SqQueue *Q) +{ + Q->front=0; + Q->rear=0; + return OK; +} + + +Status ClearQueue(SqQueue *Q) +{ + Q->front=Q->rear=0; + return OK; +} + + +Status QueueEmpty(SqQueue *Q) +{ + if(Q->front==Q->rear) + return TRUE; + else + return FALSE; +} + + +int QueueLength(SqQueue *Q) +{ + return (Q->rear-Q->front+MAXSIZE)%MAXSIZE; +} + + +Status GetHead(SqQueue *Q,QElemType *e) +{ + if(Q->front==Q->rear) + return ERROR; + *e=Q->data[Q->front]; + return OK; +} + + +Status EnQueue(SqQueue *Q,QElemType e) +{ + if ((Q->rear+1)%MAXSIZE == Q->front) + return ERROR; + Q->data[Q->rear]=e; + Q->rear=(Q->rear+1)%MAXSIZE; + return OK; +} + + +Status DeQueue(SqQueue *Q,QElemType *e) +{ + if (Q->front == Q->rear) + return ERROR; + *e=Q->data[Q->front]; + Q->front=(Q->front+1)%MAXSIZE; + return OK; +} + diff --git a/APP_Framework/lib/queue/queue.h b/APP_Framework/lib/queue/queue.h new file mode 100644 index 00000000..56541cc9 --- /dev/null +++ b/APP_Framework/lib/queue/queue.h @@ -0,0 +1,26 @@ +#ifndef __QUEUE_H__ +#define __QUEUE_H__ +#include +#define OK 1 +#define ERROR 0 +#define TRUE 1 +#define FALSE 0 +#define MAXSIZE 1024 + +typedef int Status; +typedef int QElemType; +typedef struct +{ + int data[MAXSIZE]; + int front; + int rear; +}SqQueue; + +Status InitQueue(SqQueue *Q); +Status ClearQueue(SqQueue *Q); +Status QueueEmpty(SqQueue *Q); +Status GetHead(SqQueue *Q,QElemType *e); +Status EnQueue(SqQueue *Q,QElemType e); +Status DeQueue(SqQueue *Q,QElemType *e); +int QueueLength(SqQueue *Q); +#endif \ No newline at end of file