Subversion Repositories NaviCtrl

Rev

Rev 380 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
41 ingob 1
#include "fifo.h"
362 holgerb 2
#include "main.h"
378 holgerb 3
#include "uart1.h"
41 ingob 4
 
244 killagreg 5
u8 fifo_init (fifo_t* f, u8* buffer, const u16 size, u16 putvicsource, u16 getvicsource)
41 ingob 6
{
7
        if(f == NULL) return(0);
8
        f->buffer = buffer;
153 killagreg 9
        f->size = size;
244 killagreg 10
        f->putvicsource = putvicsource;
11
        f->getvicsource = getvicsource;
153 killagreg 12
        fifo_purge(f);
41 ingob 13
        return(1);
14
}
15
 
380 holgerb 16
u8 fifo_put(fifo_t *f, const u8 data)
41 ingob 17
{
272 killagreg 18
        if(f->buffer == 0) return(0);
41 ingob 19
        if (f->count >= f->size) return(0);     // return 0 in case of FIFO overflow.
244 killagreg 20
        if(f->putvicsource != NO_ITLine) VIC_ITCmd(f->putvicsource, DISABLE);
21
        *(f->pwrite++) = data;      // copy data byte to buffer
22
        if(f->pwrite >= f->buffer + f->size) f->pwrite = f->buffer; // start at the begining after reaching the end 
41 ingob 23
        f->count++;
244 killagreg 24
        if(f->putvicsource != NO_ITLine) VIC_ITCmd(f->putvicsource, ENABLE);
25
        return(1);
41 ingob 26
}
27
 
28
u8 fifo_get (fifo_t *f, u8 *pdata)
29
{
272 killagreg 30
        if(f->buffer == 0) return(0);
41 ingob 31
        if(!f->count) return(0);
244 killagreg 32
        if(f->getvicsource != NO_ITLine) VIC_ITCmd(f->getvicsource, DISABLE);
33
        *pdata = *(f->pread++);
34
        if(f->pread >= f->buffer + f->size) f->pread = f->buffer; // start at the begining after reaching the end 
41 ingob 35
        f->count--;
244 killagreg 36
        if(f->getvicsource != NO_ITLine) VIC_ITCmd(f->getvicsource, ENABLE);
41 ingob 37
        return(1);
38
}
39
 
40
u8 fifo_get_wait (fifo_t *f, u8 *pdata)
41
{
378 holgerb 42
        while (!f->count);
41 ingob 43
        return fifo_get(f, pdata);
44
}
153 killagreg 45
 
46
void fifo_purge(fifo_t* f)
47
{
48
        if((f == NULL)) return;
49
        f->count = 0;
50
        f->pread = f->buffer;
51
        f->pwrite = f->buffer;
52
        return;
53
}