play.c

来自「gps 源码.GPS工作原理,对开发GPS软件有帮助」· C语言 代码 · 共 66 行

C
66
字号
/*
 * play.c
 */

#include <rtl.h>
#include <rtl_fifo.h>

#include <time.h>
#include <pthread.h>
#include <asm/io.h>
#include "rt_com.h"
#include "rt_comP.h"
int fd_fifo;
char a[210]={};
pthread_t thread;
int fifo_size=4000;
int period=100000000;



void *play(void *t) {
//makes  a realtime thread as periodic
	pthread_make_periodic_np (thread, gethrtime(), period);

		a[0]='2';
//writes 1 chraracter from buffer to the realtime serial port com
		rt_com_write(0, a, 1);


	return 0;
}

/* This module begins the entire process by creating an execution thread with init_module */

int init_module(void)
{
	pthread_attr_t attr;
	struct sched_param sched_param;
	int thread_status;
	//it is used to dynamically changed the parameters of each realtime serial port
	rt_com_setup(0, 38400, RT_COM_PARITY_NONE, 1, 8);

	//to initialize threads attribute object
	pthread_attr_init (&attr);
	//to examine and change the CPU pthread attribute
	pthread_attr_setcpu_np(&attr, 0);
	//dynamic thread scheduling parameters access
	sched_param.sched_priority = 1;
	pthread_attr_setschedparam (&attr, &sched_param);
	//creating the thread and maintaining its parameters status
	thread_status = pthread_create (&thread,  &attr, play, (void *)1);


	return 0;
}

/* This module ends the entire process by clearing the  execution thread with cleanup_module */
void cleanup_module(void)
{
    printk ("Removing module on CPU %d\n", rtl_getcpuid());
	//it delete the realtime thread
	pthread_delete_np (thread);
	rt_com_setup(0, -1, 0, 0, 0);
}

⌨️ 快捷键说明

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