Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Queue.cpp
00001 /* 00002 00003 -------------------------------------------- 00004 | | 00005 | .... | 00006 | 7OO$?I78. | 00007 | .?8++++7+II?D. | 00008 | .?O++=I++II+?= | 00009 | .IO++?7==I??$. | 00010 | .8++=$===?+I$ | 00011 | ?+++===+===+ | 00012 | ???=+I++==+? | 00013 | .??++====+==++ | 00014 | ?+++==========~ | 00015 | $+++==========+= | 00016 | =?+===+==+I======== | 00017 | ..++======~~~~========? | 00018 | .$?I??+=~~===~~~===~===++. | 00019 | .+==.+=~~~=~==~~~~==~~=~==+? | 00020 | ?===I+====~~=~~~=~~=====~~~=?. | 00021 | .=~~~+==~==..~~~~~~= ~~~~=7= | 00022 | +=~~?+~~=. ==~~~~=. ~~~~=?. | 00023 | =~~~=~~~ ?===~~+. ~~~~+ | 00024 | +~~:+~~= =~~==. =~~+. | 00025 | ~:~ =~~= =~~~= ~=== | 00026 | I=~~ ,=~~= ,. | 00027 | ~~. ,==== | 00028 | ==== | 00029 | =~~. | 00030 | | 00031 |------------------------------------------| 00032 | Internet Of Thing | 00033 | Eli Hughes | 00034 | Freescale / Hack-a-day Make-It-Challenge | 00035 | FTF 2014 - Dallas, Tx | 00036 |------------------------------------------| 00037 00038 */ 00039 #include "stdint.h" 00040 #include "Queue.h" 00041 #include <string.h> 00042 00043 static char StringBuffer[256]; 00044 00045 void InitByteQueue(ByteQueue *BQ,uint16_t Size,uint8_t * Storage) { 00046 uint16_t i; 00047 00048 BQ->QueueSize = Size; 00049 BQ->ReadPtr=0; 00050 BQ->WritePtr=0; 00051 BQ->QueueStorage = Storage; 00052 00053 for (i=0;i<BQ->QueueSize;i++) { 00054 BQ->QueueStorage[i] = 0; 00055 } 00056 } 00057 00058 uint16_t BytesInQueue(ByteQueue *BQ) { 00059 if (BQ->ReadPtr > BQ->WritePtr) { 00060 return (BQ->QueueSize - BQ->ReadPtr + BQ->WritePtr); 00061 } else if (BQ->WritePtr > BQ->ReadPtr) { 00062 return (BQ->WritePtr - BQ->ReadPtr); 00063 } else { 00064 return 0; 00065 } 00066 } 00067 00068 int16_t ByteEnqueue(ByteQueue *BQ,uint8_t Val) { 00069 if (BytesInQueue(BQ) == BQ->QueueSize - 1) { 00070 return QUEUE_FULL; 00071 } else { 00072 BQ->QueueStorage[BQ->WritePtr] = Val; 00073 BQ->WritePtr++; 00074 00075 if (BQ->WritePtr >= BQ->QueueSize) { 00076 BQ->WritePtr = 0; 00077 } 00078 return QUEUE_OK; 00079 } 00080 } 00081 00082 int16_t ByteArrayEnqueue(ByteQueue *BQ,uint8_t *Buf,uint16_t Len) { 00083 uint16_t i; 00084 for (i=0;i<Len;i++) { 00085 ByteEnqueue(BQ,Buf[i]); 00086 } 00087 return QUEUE_OK; 00088 } 00089 00090 00091 int16_t Qprintf(ByteQueue *BQ, const char *FormatString,...) 00092 { 00093 00094 va_list argptr; 00095 va_start(argptr,FormatString); 00096 vsprintf((char *)StringBuffer,FormatString,argptr); 00097 va_end(argptr); 00098 00099 return ByteArrayEnqueue(BQ,(uint8_t *)StringBuffer,strlen(StringBuffer)); 00100 } 00101 00102 00103 int16_t ByteDequeue(ByteQueue *BQ,uint8_t *Val) { 00104 00105 if (BytesInQueue(BQ) == 0) { 00106 return QUEUE_EMPTY; 00107 } else { 00108 *Val = BQ->QueueStorage[BQ->ReadPtr]; 00109 00110 BQ->ReadPtr++; 00111 00112 if (BQ->ReadPtr >= BQ->QueueSize) { 00113 BQ->ReadPtr = 0; 00114 } 00115 return QUEUE_OK; 00116 } 00117 } 00118 00119 uint8_t ForcedByteDequeue(ByteQueue *BQ) 00120 { 00121 uint8_t RetVal; 00122 00123 if (BytesInQueue(BQ) == 0) { 00124 return 0; 00125 } else { 00126 RetVal = BQ->QueueStorage[BQ->ReadPtr]; 00127 00128 BQ->ReadPtr++; 00129 00130 if (BQ->ReadPtr >= BQ->QueueSize) { 00131 BQ->ReadPtr = 0; 00132 } 00133 return RetVal; 00134 } 00135 }
Generated on Tue Jul 19 2022 00:46:05 by
1.7.2