00001 /**************************************************************** 00002 * Fulguro 00003 * Copyright (C) 2004 Christophe Clienti 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public 00016 * License along with this library; if not, write to the 00017 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00018 * Boston, MA 02111-1307, USA. 00019 ***************************************************************/ 00020 00021 #include <stdlib.h> 00022 #include <flgrCoreMalloc.h> 00023 #include <flgrCoreDispatch.h> 00024 #include "flgrDataToolsStaticFifo.h" 00025 00033 00034 00039 00040 FLGR_StaticFifo *flgr_static_fifo_init(int size_y, int size_x) { 00041 FLGR_StaticFifo *fifo=flgr_malloc(sizeof(FLGR_StaticFifo)); 00042 00043 00044 00045 fifo->size=size_y*size_x+1; 00046 fifo->size_x=size_x; 00047 fifo->size_y=size_y; 00048 fifo->row=(int *) flgr_malloc(sizeof(int)*fifo->size); 00049 fifo->col=(int *) flgr_malloc(sizeof(int)*fifo->size); 00050 fifo->rdptr=0; 00051 fifo->wrptr=0; 00052 00053 return fifo; 00054 } 00055 00057 00063 00064 void flgr_static_fifo_write(FLGR_StaticFifo *fifo, int row, int col) { 00065 int wr=(fifo->wrptr); 00066 int isWrite=1; 00067 00068 00069 00070 if((row>=0) && (row<fifo->size_y)) 00071 fifo->row[wr]=row; 00072 else 00073 isWrite=0; 00074 00075 if((col>=0) && (col<fifo->size_x)) 00076 fifo->col[wr]=col; 00077 else 00078 isWrite=0; 00079 00080 if(isWrite==1) fifo->wrptr=(fifo->wrptr+1) % fifo->size; 00081 } 00082 00083 00085 00091 00092 void flgr_static_fifo_read(FLGR_StaticFifo *fifo, int *row, int *col) { 00093 int rd=(fifo->rdptr); 00094 00095 00096 00097 *row=fifo->row[rd]; 00098 *col=fifo->col[rd]; 00099 fifo->rdptr=(fifo->rdptr+1) % fifo->size; 00100 } 00101 00103 00107 00108 int flgr_static_fifo_is_empty(FLGR_StaticFifo *fifo) { 00109 00110 return ((fifo->rdptr==fifo->wrptr)==FLGR_TRUE); 00111 } 00112 00114 00118 00119 int flgr_static_fifo_level(FLGR_StaticFifo *fifo) { 00120 00121 return (fifo->wrptr-fifo->rdptr); 00122 } 00123 00125 00129 00130 void flgr_static_fifo_destroy(FLGR_StaticFifo *fifo) { 00131 00132 free(fifo->row); 00133 free(fifo->col); 00134 free(fifo); 00135 } 00136 00137