From f83f5bfa9ff3e58f32a47ad1edfb3ac3e2be87f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=A1=D0=BE=D0=BB?= =?UTF-8?q?=D0=BE=D0=B4=D1=8F=D0=BD=D0=BA=D0=B8=D0=BD?= <stud126791@vyatsu.ru> Date: Fri, 16 Jun 2023 21:39:45 +0000 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B8=D1=82=D1=8C=20'U?= =?UTF-8?q?ART/ring=5Fbuf.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- UART/ring_buf.c | 42 ------------------------------------------ 1 file changed, 42 deletions(-) delete mode 100644 UART/ring_buf.c diff --git a/UART/ring_buf.c b/UART/ring_buf.c deleted file mode 100644 index 3f09963..0000000 --- a/UART/ring_buf.c +++ /dev/null @@ -1,42 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -#define BUFFER_SIZE 10 - -typedef struct { - int buffer[BUFFER_SIZE]; - int BufHead; - int BufTail; -} CircularBuffer; - -void initializeBuffer(CircularBuffer* cb) { - cb->BufHead = 0; - cb->BufTail = 0; -} -// ��������, �������� �� ����� ������ -int BufferEmpty(const CircularBuffer* cb) { - return cb->BufHead == cb->BufTail; -} -// ��������, �������� �� ����� ������ -int BufferFull(const CircularBuffer* cb) { - return (cb->BufTail + 1) % BUFFER_SIZE == cb->BufHead;//��������� ��������� �����, ���� ��� ����� ��������� � �������� ������ �� ����� false, ��� ���������� �������� true -} -// ������ �������� � ����� -void writeBuffer(CircularBuffer* cb, int value) { - if (BufferFull(cb)) { // �������� �� ������������� - return; - } - cb->buffer[cb->BufTail] = value;//���������� �������� value � ������� ������� buffer � ����� - cb->BufTail = (cb->BufTail + 1) % BUFFER_SIZE;//������������� cb->BufTail, �������� ��� �������� �� ��������� ������ � ��������� ������ -} -// ������ �������� �� ������ -int readBuffer(CircularBuffer* cb) { - if (BufferEmpty(cb)) { //��������� ������ �� ������� - return -1;// -1 � �������� ���������� ������ - } - int value = cb->buffer[cb->BufHead]; //������ �������� �� ������� �� ������� ������ - cb->BufHead = (cb->BufHead + 1) % BUFFER_SIZE; //����������� ������ ������ +1 - return value; -} - -