#include "ringbuffer.h" #include "kmalloc.h" // TODO: this is disabled because a kb interrupt can occur anytime // and the kernel will need to access the ringbuffer while we are accessing! // DO WE need a spinlock in general? do not use a global one anyway!!!! //static int sl=9; ringbuffer ringbuffer_init(uint32_t size) { ringbuffer f; f.data=kballoc(size); f.size=size*4096; f.front=f.size-1; f.back=f.size-1; return f; } bool ringbuffer_put(ringbuffer* f,uint8_t c) { // x86_cli(); if((f->back-1+f->size)%f->size==f->front) { // x86_sti(); return false; } f->data[f->back]=c; f->back--; f->back+=f->size; f->back%=f->size; // x86_sti(); return true; } bool ringbuffer_has(ringbuffer* f) { // x86_cli(); bool res=true; if(f->front==f->back) res=false; // x86_sti(); return res; } uint8_t ringbuffer_get(ringbuffer* f) // non blocking . please check first { // x86_cli(); char c; if(f->front==f->back) { // x86_sti(); return ' '; } c=f->data[f->front]; f->front--; f->front+=f->size; f->front%=f->size; // x86_sti(); return c; }