hello_shm.c

来自「fsmlabs的real time linux的内核」· C语言 代码 · 共 60 行

C
60
字号
/* * Written by Der Herr Hofrat, der.herr@hofr.at * (C) 2002 FSMLabs * License: GPL Version 2 *//* * RTLinux "Hello World" example using schared memmory (mbuff) */#include <rtl.h>#include <pthread.h>#include "hello_shm.h"pthread_t thread;void * start_routine(void *arg){	hrtime_t next=clock_gethrtime(CLOCK_REALTIME) + 1000000000;	while(1){		clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME,			hrt2ts(next), NULL);		next += 500000000;		rtl_printf("I'm here; found `%s` in hello_shm\n", 			(char *)hello_shm);	}	return 0;}int init_module(void) {	int ret;	hello_shm=(volatile char*) mbuff_alloc("hello_shm",1024);	if(hello_shm == NULL) {		printk("mbuff_alloc failed\n");		return -1;		}	sprintf((char*)hello_shm,"hello world");	printk("Init module wrote `%s` to hello_shm\n", (char*)hello_shm);	ret = pthread_create (&thread, NULL, start_routine, 0);	if(ret != 0){		printk("Failed to create RT-thread: %d\n",ret);		mbuff_free("hello_shm",(void*)hello_shm);		return -1;	}	return 0;}void cleanup_module(void){	pthread_cancel (thread);	pthread_join (thread, NULL);	mbuff_free("hello_shm",(void*)hello_shm);}

⌨️ 快捷键说明

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