ReactOS 0.4.15-dev-5669-g09dde2c
circularbuffer.c File Reference
#include "serial.h"
#include <debug.h>
Include dependency graph for circularbuffer.c:

Go to the source code of this file.

Functions

NTSTATUS InitializeCircularBuffer (IN PCIRCULAR_BUFFER pBuffer, IN ULONG BufferSize)
 
NTSTATUS FreeCircularBuffer (IN PCIRCULAR_BUFFER pBuffer)
 
BOOLEAN IsCircularBufferEmpty (IN PCIRCULAR_BUFFER pBuffer)
 
ULONG GetNumberOfElementsInCircularBuffer (IN PCIRCULAR_BUFFER pBuffer)
 
NTSTATUS PushCircularBufferEntry (IN PCIRCULAR_BUFFER pBuffer, IN UCHAR Entry)
 
NTSTATUS PopCircularBufferEntry (IN PCIRCULAR_BUFFER pBuffer, OUT PUCHAR Entry)
 
NTSTATUS IncreaseCircularBufferSize (IN PCIRCULAR_BUFFER pBuffer, IN ULONG NewBufferSize)
 

Function Documentation

◆ FreeCircularBuffer()

NTSTATUS FreeCircularBuffer ( IN PCIRCULAR_BUFFER  pBuffer)

Definition at line 30 of file circularbuffer.c.

32{
33 TRACE_(SERIAL, "FreeCircularBuffer(pBuffer %p)\n", pBuffer);
35 if (pBuffer->Buffer != NULL)
37 return STATUS_SUCCESS;
38}
#define NULL
Definition: types.h:112
#define TRACE_(x)
Definition: compat.h:76
#define SERIAL_TAG
Definition: serial.h:100
#define ASSERT(a)
Definition: mode.c:44
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
PVOID pBuffer
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by SerialAddDeviceInternal().

◆ GetNumberOfElementsInCircularBuffer()

ULONG GetNumberOfElementsInCircularBuffer ( IN PCIRCULAR_BUFFER  pBuffer)

Definition at line 50 of file circularbuffer.c.

52{
53 TRACE_(SERIAL, "GetNumberOfElementsInCircularBuffer(pBuffer %p)\n", pBuffer);
55 return (pBuffer->WritePosition + pBuffer->Length - pBuffer->ReadPosition) % pBuffer->Length;
56}

Referenced by SerialInterruptService().

◆ IncreaseCircularBufferSize()

NTSTATUS IncreaseCircularBufferSize ( IN PCIRCULAR_BUFFER  pBuffer,
IN ULONG  NewBufferSize 
)

Definition at line 91 of file circularbuffer.c.

94{
95 PUCHAR NewBuffer;
96
97 TRACE_(SERIAL, "IncreaseCircularBufferSize(pBuffer %p, NewBufferSize %lu)\n", pBuffer, NewBufferSize);
99 ASSERT(pBuffer->Length);
100 if (pBuffer->Length > NewBufferSize)
102 else if (pBuffer->Length == NewBufferSize)
103 return STATUS_SUCCESS;
104
105 NewBuffer = (PUCHAR)ExAllocatePoolWithTag(NonPagedPool, NewBufferSize * sizeof(UCHAR), SERIAL_TAG);
106 if (!NewBuffer)
108 RtlCopyMemory(NewBuffer, pBuffer->Buffer, pBuffer->Length * sizeof(UCHAR));
110 pBuffer->Buffer = NewBuffer;
111 pBuffer->Length = NewBufferSize;
112 return STATUS_SUCCESS;
113}
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define NonPagedPool
Definition: env_spec_w32.h:307
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
unsigned char * PUCHAR
Definition: typedefs.h:53
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by SerialDeviceControl().

◆ InitializeCircularBuffer()

NTSTATUS InitializeCircularBuffer ( IN PCIRCULAR_BUFFER  pBuffer,
IN ULONG  BufferSize 
)

Definition at line 15 of file circularbuffer.c.

18{
19 TRACE_(SERIAL, "InitializeCircularBuffer(pBuffer %p, BufferSize %lu)\n", pBuffer, BufferSize);
22 if (!pBuffer->Buffer)
24 pBuffer->Length = BufferSize;
25 pBuffer->ReadPosition = pBuffer->WritePosition = 0;
26 return STATUS_SUCCESS;
27}
#define BufferSize
Definition: mmc.h:75
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254

Referenced by SerialAddDeviceInternal().

◆ IsCircularBufferEmpty()

BOOLEAN IsCircularBufferEmpty ( IN PCIRCULAR_BUFFER  pBuffer)

Definition at line 41 of file circularbuffer.c.

43{
44 TRACE_(SERIAL, "IsCircularBufferEmpty(pBuffer %p)\n", pBuffer);
46 return (pBuffer->ReadPosition == pBuffer->WritePosition);
47}

Referenced by PopCircularBufferEntry(), ReadBytes(), and SerialSendByte().

◆ PopCircularBufferEntry()

NTSTATUS PopCircularBufferEntry ( IN PCIRCULAR_BUFFER  pBuffer,
OUT PUCHAR  Entry 
)

Definition at line 76 of file circularbuffer.c.

79{
80 TRACE_(SERIAL, "PopCircularBufferEntry(pBuffer %p)\n", pBuffer);
82 ASSERT(pBuffer->Length);
85 *Entry = pBuffer->Buffer[pBuffer->ReadPosition];
86 pBuffer->ReadPosition = (pBuffer->ReadPosition + 1) % pBuffer->Length;
87 return STATUS_SUCCESS;
88}
BOOLEAN IsCircularBufferEmpty(IN PCIRCULAR_BUFFER pBuffer)
#define STATUS_ARRAY_BOUNDS_EXCEEDED
Definition: ntstatus.h:376
base of all file and directory entries
Definition: entries.h:83

Referenced by ReadBytes(), and SerialSendByte().

◆ PushCircularBufferEntry()

NTSTATUS PushCircularBufferEntry ( IN PCIRCULAR_BUFFER  pBuffer,
IN UCHAR  Entry 
)

Definition at line 59 of file circularbuffer.c.

62{
63 ULONG NextPosition;
64 TRACE_(SERIAL, "PushCircularBufferEntry(pBuffer %p, Entry 0x%x)\n", pBuffer, Entry);
66 ASSERT(pBuffer->Length);
67 NextPosition = (pBuffer->WritePosition + 1) % pBuffer->Length;
68 if (NextPosition == pBuffer->ReadPosition)
70 pBuffer->Buffer[pBuffer->WritePosition] = Entry;
71 pBuffer->WritePosition = NextPosition;
72 return STATUS_SUCCESS;
73}
if(dx< 0)
Definition: linetemp.h:194
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
uint32_t ULONG
Definition: typedefs.h:59

Referenced by SerialReceiveByte(), and SerialWrite().