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

📄 repeat.c

📁 < 嵌入式系统编程>>源代码解析光盘,包括这本书各章节的示例代码(无密码)
💻 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 period=100000000;
int fifo_size=4000;
pthread_t thread;
int fd_fifo;
char a[210]={};

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

		for(i=1;i<=20;i++)
		{
			//suspend the current thread until the next period
			pthread_wait_np();
		}

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


	} while (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);
	sched_param.sched_priority = 1;
	//dynamic thread scheduling parameters access
	pthread_attr_setschedparam (&attr, &sched_param);
	//creating the thread and maintaining its parameters status
	thread_status = pthread_create (&thread,  &attr, autorewind, (void *)1);


	return 0;
}

/* This module ends the entire process by clearing the  execution thread with cleanup_module */
void cleanup_module(void)
{
	//it delete the realtime thread
	pthread_delete_np (thread);
	rt_com_setup(0, -1, 0, 0, 0);
}

⌨️ 快捷键说明

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