lec15_16_zlabipc_mutex - Inter-process communication (FIFO...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Inter-process communication (FIFO and Shared Memory) RTOS Support NOT necessarily responsible everything RTOS system calls Interrupt Management rtl_request_irq rtl_free_irq rtl_hard_enable_irq rtl_hard_disable_irq Time Management clock_gethrtime clock_gettime clock_settime gethrtime nanosleep Task Management pthread_create pthread_setschedparam// pri. sched pthread_make_periodic_np pthread_wait_np pthread_delete_np pthread_cancel pthread_join Task Communication FIFO Shared Memory Signal Mutual Exclusion Lock Semaphore Device drivers rt_com rtsock
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Real-Time FIFO • A kernel object that allows FIFO order communications among threads (Most RTOS provide something like this) Thread1 Thread2 • In RT-Linux, it allows communications among rt- threads and linux(user space)-processes. FIFO related functions • FIFO object creation and destroy – In “init_module()” and “cleanup()” • #include <rtl_fifo.h> • int rtf_create(unsigned int fifo, int size); // fifo = 0, 1, 2, …, RTF_NO • int rtf_destroy(unsigned int fifo); • Communication through FIFO – Read and write (Non-blocked read/write in rt-threads ) • int rtf_get(unsigned int fifo, char *buff, int size); // return actual data size • int rtf_put(unsigned int fifo, char *buff, int size); // return size on success, otherwise return negative – Asynchronous communication with a Linux-process • int rtf_create_handler(unsigned int fifo, int (*handler)()); // invoked whenever a linux process read from or write to the fifo
Background image of page 2
3 Accessing rt_fifo from a Linux process • In a Linux-process – Regard rt_fifo just like standard device (or special file) • each rt_fifo has its predetermined file name, /dev/rtf0, /dev/rtf1, etc. • fd = open(“/dev/rtf0”, O_WRONLY); • close(int fd); • ssize_t read(int fd, char *buf, size_t size); // return actual read data size • ssize_t write(int fd, char *buf, size_t size); // return actual written data size – By default, they are blocked io. For Non-blocked i/o, use “select” Project • Problem 1 – Run “prj3_fifo” – Explain which time components are included in the measured data? Discuss about the accuracy of the measured data.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Project (Problem 1) #include <rtl.h> #include <time.h> #include <rtl_sched.h> #include <rtl_fifo.h> #define NO_OF_ITERATIONS 500 #define SENDER_DELAY_TIME 20000000 //nano seconds #define RECEIVER_DELAY_TIME 100 //nano seconds void *Receiver(void *param); void *Sender(void *param); pthread_t receiver, sender; #define FIFO0 0 int init_module(void) { rtl_printf("Ready to insert\n"); rtf_destroy(FIFO0); if(rtf_create(FIFO0, 4000) < 0) { rtl_printf("fifo0 create error\n"); return -1; } pthread_create(&receiver, NULL, Receiver, NULL); pthread_create(&sender, NULL, Sender, NULL); return 0; } void cleanup_module(void) { pthread_cancel(receiver); pthread_join(receiver,NULL); pthread_cancel(sender); pthread_join(sender, NULL); rtf_destroy(FIFO0); rtl_printf("Cleaned up\n"); }
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/02/2008 for the course COMPUTER S 664 taught by Professor Leechangkyu during the Spring '08 term at Korea University.

Page1 / 15

lec15_16_zlabipc_mutex - Inter-process communication (FIFO...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online