shithub: p9-stm32-example-os

ref: f801657f77f3923ec2388c25bdcb036c8019ba89
dir: /prog/dma2q.c/

View raw version
#include	<u.h>
#include	"dat.h"
#include	"fns.h"
#include	"mem.h"
#include	"libkern/kern.h"

#include	"prog/prog.h"
#include	"prog/progfns.h"

typedef
struct DmaQ
{
	Queue*	din;
	Queue*	dout;
	char*	buf;
} DmaQ;

void
dma2q(void *dmaqptr)
{
	DmaQ *dmaq = dmaqptr;
	int n;

	kprint("dma2q: started");

	while(1) {
		n = dma_read(DMAINCH, dmaq->buf, DMAQ_BUFSIZE);
		if(n > 0) {
			qwrite(dmaq->din, dmaq->buf, n);
		}
		n = qlen(dmaq->dout);
		if(n > DMAQ_BUFSIZE) n = DMAQ_BUFSIZE;
		if(n > 0) {
			n = qread(dmaq->dout, dmaq->buf, n);
			dma_write(DMAOUTCH, dmaq->buf, n);
		}
	}

	kprint("dma2q: queues closed; exit\n");
}

Proc*
prog_dma2q(Queue* dmaiq, Queue* dmaoq)
{
	Proc *dmaproc;

	DmaQ *dmaq = malloc(sizeof(DmaQ));
	dmaq->din = dmaiq;
	dmaq->dout = dmaoq;
	dmaq->buf = malloc(DMAQ_BUFSIZE);

	dmaproc = newprog("dma2q", dma2q, dmaq, 0, 1280);

	return dmaproc;
}