FIFO tagged functions

Co-Authored-By: Miran Grča <oubattler@gmail.com>
This commit is contained in:
Jasmine Iwanek
2025-02-08 21:48:57 -05:00
parent d00f80d3ce
commit dd24d0329c
2 changed files with 145 additions and 5 deletions

View File

@@ -10,7 +10,7 @@
*
* Authors: Miran Grca, <mgrca8@gmail.com>
*
* Copyright 2023 Miran Grca.
* Copyright 2023-2025 Miran Grca.
*/
#include <stdarg.h>
#include <stdint.h>
@@ -84,6 +84,31 @@ fifo_write(uint8_t val, void *priv)
}
}
void
fifo_write_tagged(uint8_t tag, uint8_t val, void *priv)
{
fifo_t *fifo = (fifo_t *) priv;
fifo->d_full = fifo->d_empty = 0;
fifo->d_ready = fifo->d_overrun = 0;
if (fifo->full)
fifo->overrun = 1;
else {
fifo->buf[fifo->end] = val;
fifo->tag[fifo->end] = tag;
fifo->end = (fifo->end + 1) % fifo->len;
if (fifo->end == fifo->start)
fifo->full = 1;
fifo->empty = 0;
if (fifo_get_count(fifo) >= fifo->trigger_len)
fifo->ready = 1;
}
}
void
fifo_write_evt(uint8_t val, void *priv)
{
@@ -122,6 +147,45 @@ fifo_write_evt(uint8_t val, void *priv)
}
}
void
fifo_write_evt_tagged(uint8_t tag, uint8_t val, void *priv)
{
fifo_t *fifo = (fifo_t *) priv;
fifo->d_full = fifo->d_empty = 0;
fifo->d_ready = fifo->d_overrun = 0;
if (fifo->full) {
fifo->d_overrun = (fifo->overrun != 1);
fifo->overrun = 1;
if (fifo->d_overrun && (fifo->d_overrun_evt != NULL))
fifo->d_overrun_evt(fifo->priv);
} else {
fifo->buf[fifo->end] = val;
fifo->tag[fifo->end] = tag;
fifo->end = (fifo->end + 1) % fifo->len;
if (fifo->end == fifo->start) {
fifo->d_full = (fifo->full != 1);
fifo->full = 1;
if (fifo->d_full && (fifo->d_full_evt != NULL))
fifo->d_full_evt(fifo->priv);
}
fifo->d_empty = (fifo->empty != 0);
fifo->empty = 0;
if (fifo->d_empty && (fifo->d_empty_evt != NULL))
fifo->d_empty_evt(fifo->priv);
if (fifo_get_count(fifo) >= fifo->trigger_len) {
fifo->d_ready = (fifo->ready != 1);
fifo->ready = 1;
if (fifo->d_ready && (fifo->d_ready_evt != NULL))
fifo->d_ready_evt(fifo->priv);
}
}
}
uint8_t
fifo_read(void *priv)
{
@@ -148,6 +212,35 @@ fifo_read(void *priv)
return ret;
}
uint8_t
fifo_read_tagged(uint8_t *tag, void *priv)
{
fifo_t *fifo = (fifo_t *) priv;
uint8_t ret = 0x00;
int count;
if (!fifo->empty) {
ret = fifo->buf[fifo->start];
*tag = fifo->tag[fifo->start];
fifo->start = (fifo->start + 1) % fifo->len;
fifo->full = 0;
count = fifo_get_count(fifo);
if (count < fifo->trigger_len) {
fifo->ready = 0;
if (count == 0)
fifo->empty = 1;
}
} else
*tag = 0x00;
return ret;
}
uint8_t
fifo_read_evt(void *priv)
{
@@ -187,6 +280,48 @@ fifo_read_evt(void *priv)
return ret;
}
uint8_t
fifo_read_evt_tagged(uint8_t *tag, void *priv)
{
fifo_t *fifo = (fifo_t *) priv;
uint8_t ret = 0x00;
int count;
fifo->d_full = fifo->d_empty = 0;
fifo->d_ready = 0;
if (!fifo->empty) {
ret = fifo->buf[fifo->start];
*tag = fifo->tag[fifo->start];
fifo->start = (fifo->start + 1) % fifo->len;
fifo->d_full = (fifo->full != 0);
fifo->full = 0;
if (fifo->d_full && (fifo->d_full_evt != NULL))
fifo->d_full_evt(fifo->priv);
count = fifo_get_count(fifo);
if (count < fifo->trigger_len) {
fifo->d_ready = (fifo->ready != 0);
fifo->ready = 0;
if (fifo->d_ready && (fifo->d_ready_evt != NULL))
fifo->d_ready_evt(fifo->priv);
if (count == 0) {
fifo->d_empty = (fifo->empty != 1);
fifo->empty = 1;
if (fifo->d_empty && (fifo->d_empty_evt != NULL))
fifo->d_empty_evt(fifo->priv);
}
}
} else
*tag = 0x00;
return ret;
}
void
fifo_clear_overrun(void *priv)
{

View File

@@ -1,6 +1,3 @@
#ifndef FIFO_H
#define FIFO_H
/*
* 86Box A hypervisor and IBM PC system emulator that specializes in
* running old operating systems and software designed for IBM
@@ -13,8 +10,11 @@
*
* Authors: Miran Grca, <mgrca8@gmail.com>
*
* Copyright 2023 Miran Grca.
* Copyright 2023-2025 Miran Grca.
*/
#ifndef FIFO_H
#define FIFO_H
#define FIFO(size) \
typedef struct { \
int start; \
@@ -37,6 +37,7 @@
void (*d_full_evt)(void *); \
void (*d_ready_evt)(void *); \
\
uint8_t tag[64]; \
uint8_t buf[size]; \
} fifo## size ##_t;
@@ -50,9 +51,13 @@ FIFO(64)
extern int fifo_get_count(void *priv);
extern void fifo_write(uint8_t val, void *priv);
extern void fifo_write_tagged(uint8_t tag, uint8_t val, void *priv);
extern void fifo_write_evt(uint8_t val, void *priv);
extern void fifo_write_evt_tagged(uint8_t tag, uint8_t val, void *priv);
extern uint8_t fifo_read(void *priv);
extern uint8_t fifo_read_tagged(uint8_t *tag, void *priv);
extern uint8_t fifo_read_evt(void *priv);
extern uint8_t fifo_read_evt_tagged(uint8_t *tag, void *priv);
extern void fifo_clear_overrun(void *priv);
extern int fifo_get_full(void *priv);
extern int fifo_get_d_full(void *priv);