test.c

来自「ARM嵌入式应用开发典型实例配书光盘,希望对你有用!」· C语言 代码 · 共 101 行

C
101
字号
#include <stdio.h>#include <stdlib.h>#include "fifo.h"#define	TOTAL_COUNT		100void proc_put(HFIFO handle){	int cnt, remain;	char buf[2048];	remain = 8;	for(cnt = 0; cnt < TOTAL_COUNT; cnt++)	{		sprintf(buf, "Count: %d", cnt);		fifo_put(handle, buf, strlen(buf), FIFO_FLG_BLOCK);		printf("[FIFO] [SEND] %s\n", buf);		remain--;		if(remain == 0)		{			fifo_tag_trigger(handle, 0);			remain = 8;		}		{			struct timespec tm;			tm.tv_sec	= 0;			tm.tv_nsec	= 1000000;			nanosleep(&tm, NULL);		}	}	fifo_tag_trigger(handle, 0);}void proc_get(){	int cnt;	HFIFO	handle;	size_t	slotsz;	int	len;	char buf[2048];	handle = fifo_find_handle("fifotest", &slotsz);	printf("We get it! Address: %p\n", handle);	for(cnt = 0; cnt < TOTAL_COUNT; )	{		if(fifo_tag_check(handle, 0))		{			while((len=fifo_get(handle, buf, 2048, FIFO_FLG_BLOCK)) >= 0)			{				buf[len] = 0;				printf("[FIFO] [RECV] %s\n", buf);				cnt++;			}		}		else		{			struct timespec tm;			tm.tv_sec	= 0;			tm.tv_nsec	= 1000000;			nanosleep(&tm, NULL);		}	}}main(){	HFIFO handle;	/* Create FIFO */	handle = fifo_create("fifotest", 128, 1460);	if(!fork())	{		proc_get();		sleep(1);	}	else	{		proc_put(handle);		sleep(10);		fifo_destroy(handle);	}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?