static unsigned int hs008_data_buffer[8];
static int r,w = 0;
static void put_Data(unsigned int val)
{
if ((w + 1) & 7) != r)
{
hs0038_data_buf[w] = val;
w = (w + 1) & 7;
}
}
static int get_Data(unsigned int *val)
{
if (r == w)
{
return -1;
}
else
{
*val = hs0038_data_buf[r];
r = (r + 1) & 7;
return 0;
}
}
static int has_data(void)
{
if (r == w)
return 0;
else
return 1;
}
#define BUF_LEN 128
static int g_keys[ BUF_LEN];
static int r, w;
#define NEXT_POS(x) ((x+1) % BUF_LEN)
static int is_key_buf_empty(void)
{
return (r == w);
}
static int is_key_buf_full(void)
{
return (r == NEXT_POS(w));
}
static void put_key(int key)
{
if (!is_key_buf_full())
{
g_keys[w] = key;
w = NEXT_POS(w);
}
}
static int get_key(void)
{
int key = 0;
if (!is_key_buf_empty())
{
key = g_keys[r];
r = NEXT_POS(r);
}
return key;
}
|