- main: no global vars
- changed data types in fifo git-svn-id: http://moon:8086/svn/projects/HendiControl@39 fda53097-d464-4ada-af97-ba876c37ca34
This commit is contained in:
@@ -8,6 +8,26 @@
|
||||
#include <stdint.h>
|
||||
#include "fifo.h"
|
||||
|
||||
static volatile size_t criticalCount = 0;
|
||||
|
||||
void enterCritical()
|
||||
{
|
||||
cli();
|
||||
criticalCount++;
|
||||
}
|
||||
|
||||
void exitCritial()
|
||||
{
|
||||
if (criticalCount)
|
||||
{
|
||||
criticalCount--;
|
||||
if (!criticalCount)
|
||||
{
|
||||
sei();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void fifo_init(Fifo *pObj, size_t capacity, size_t itemSize, const char *pName)
|
||||
{
|
||||
pObj->wi = 0;
|
||||
@@ -15,11 +35,11 @@ void fifo_init(Fifo *pObj, size_t capacity, size_t itemSize, const char *pName)
|
||||
pObj->fill = 0;
|
||||
pObj->capacity = capacity;
|
||||
pObj->itemSize = itemSize;
|
||||
pObj->ppData = (void**)malloc(capacity);
|
||||
pObj->ppData = (uint8_t**)malloc(capacity);
|
||||
|
||||
for (int i=0; i < capacity; i++)
|
||||
{
|
||||
pObj->ppData[i] = (void*)malloc(itemSize);
|
||||
pObj->ppData[i] = (uint8_t*)malloc(itemSize);
|
||||
}
|
||||
pObj->pName = pName;
|
||||
}
|
||||
@@ -47,7 +67,7 @@ int fifo_push(Fifo *pObj, void *pItem)
|
||||
}
|
||||
for (size_t i=0; i < pObj->itemSize; i++)
|
||||
{
|
||||
((uint8_t*)pObj->ppData[pObj->wi])[i] = ((uint8_t*)pItem)[i];
|
||||
pObj->ppData[pObj->wi][i] = ((uint8_t*)pItem)[i];
|
||||
}
|
||||
pObj->wi++;
|
||||
pObj->fill++;
|
||||
@@ -73,7 +93,7 @@ int fifo_pop(Fifo *pObj, void *pItem)
|
||||
}
|
||||
for (size_t i=0; i < pObj->itemSize; i++)
|
||||
{
|
||||
((uint8_t*)pItem)[i] = ((uint8_t*)pObj->ppData[pObj->ri])[i];
|
||||
((uint8_t*)pItem)[i] = pObj->ppData[pObj->ri][i];
|
||||
}
|
||||
pObj->ri++;
|
||||
pObj->fill--;
|
||||
|
||||
Reference in New Issue
Block a user