⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testcom.c

📁 最新rtlinux内核源码
💻 C
字号:
/** * rt_com test * =========== * * RT-Linux kernel module for communication across serial lines. * * Copyright (C) 1999 Michael Barabanov <Michael.Barabanov@windriver.com> */#include <rtl.h>#include <rtl_fifo.h>#include <rtl_sched.h>#include <time.h>#include <pthread.h>#include <asm/io.h>#include "../rt_com.h"int period=100000000;int fifo_size=4000;pthread_t thread;int fd_fifo;void *thread_code(void *t) {	pthread_make_periodic_np (thread, gethrtime(), period);	do {		int n;		char buf[210];		pthread_wait_np();		n = rt_com_read(0, buf, sizeof(buf));		if (n > 0) {			buf[n] = 0;			rtl_printf("%s", buf);		}		rt_com_write(0, "AT\r", 3);	} while (1);	return 0;}int init_module(void){	pthread_attr_t attr;	struct sched_param sched_parameters;	int thread_status;	rt_com_setup(0, 38400, RT_COM_PARITY_NONE, 1, 8);	pthread_attr_init (&attr);	pthread_attr_setcpu_np(&attr, 0);	sched_parameters.sched_priority = 1;	pthread_attr_setschedparam (&attr, &sched_parameters);	thread_status = pthread_create (&thread, &attr, thread_code, (void *)1);	if (thread_status < 0) {		printk("failed to create RT-thread\n");		return -1;	} else {		printk("created RT-thread\n");	}	return 0;}void cleanup_module(void){	printk ("Removing module on CPU %d\n", rtl_getcpuid());	pthread_delete_np (thread);	rt_com_setup(0, -1, 0, 0, 0);}/** * Local Variables: * mode: C * c-file-style: "Stroustrup" * End: */

⌨️ 快捷键说明

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