ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am trying to use FIFO for reading data in linux which have been sent from rtlinux. I noticed that the data is sent by rtlinux using rtf_put() but I am not receiving anything on the Linux read() side.
Can someone please advise on the possible problem.
Thanks.
Linux Code:
Code:
#define FIFO_FGLOG "/dev/rtf1"
sem_t sem_kill;
int fd;
unsigned int my_recv = 0;
pthread_t fifo_fglog_thread;
//----------------------------------------------------------------------int init_network(void)
{
}
//----------------------------------------------------------------------void catch_ctrl_c(int sig_num)
{
sem_post(&sem_kill);
printf("Ctrl-C\n");
}
//----------------------------------------------------------------------void *fifo_fglog_task(void *arg)
{
int n;
n = 0;
//
while (1) {
n = read(fd, &my_recv, sizeof(my_recv));
printf("FIFO Message Received. Size = %d\n", my_recv);
}
return NULL;
}
//======================================================================int main(int argc, char* argv[])
{
// Create semaphores
sem_init(&sem_kill, 1, 0);
// Install signal handler for Ctrl-C
signal(SIGINT, catch_ctrl_c);
// Initialize network
if (init_network()) {
printf("Cannot initialize network\n");
return 1;
};
if ((fd = open(FIFO_FGLOG, O_RDONLY)) < 0) {
printf("ERROR: could not open fifo\n");
return -1;
}
// Create threads for RT access
pthread_create(&udp_port.thread, 0, thread_udp_rx_code, 0);
pthread_create(&fifo_fglog_thread, 0, fifo_fglog_task, 0);
printf("FG running...\n");
// wait for kill semaphore
sem_wait(&sem_kill);
// Destroy threads
pthread_cancel(udp_port.thread);
pthread_cancel(fifo_fglog_thread);
close(fd);
// Finalize network
kill_network();
// Destroy semaphores
sem_destroy(&sem_kill);
return 0;
}
RtLinux Code:
Code:
unsigned int sent = 0;
void my_callback_func(uint32_t source_ip,
uint16_t source_port,
uint16_t dest_port,
void *data,
int len)
{
// test only
rtf_put(FIFO_NUM, &sent, sizeof(sent));
sent++;
}
//----------------------------------------------------------------------void *the_thread_task(void *t)
{
}
//------------------------------------------------------------------------------
static int init_test(void)
{
int ret;
sem_init(&the_sem, 1, 0);
rtf_destroy(FIFO_NUM);
rtf_create(FIFO_NUM, 1024); //16384);
ret = pthread_create(&the_thread, NULL, the_thread_task, 0);
ret = syncirq_install(0x378, 7, &the_sem, &the_time);
// Initialize REDDUDP
reddudp_init(atoip("192.168.205.111"), // RtLinux - local IP address - LJH
atoip("255.255.0.0")); // Subnet mask - LJH
reddudp_install_callback(10001, &my_callback_func);
rtl_printf("test module inserted\n");
return 0;
}
//----------------------------------------------------------------------static void cleanup_test(void)
{
reddudp_uninstall_callback(10001);
syncirq_uninstall();
pthread_cancel(the_thread);
pthread_join(the_thread, NULL);
rtf_destroy(FIFO_NUM);
sem_destroy(&the_sem);
rtl_printf("test module removed\n");
}
module_init(init_test);
module_exit(cleanup_test);
Hi
Are you sure, the device "rtf1" you have created in /dev/? and let me know if you are getting any error message when you read from the device in normal linux part. "dmesg" will give you some clue atleast. check it.
The program is working fine at the moment. For some reason the data is send successfully when I insert a rtl_print("\n") in the rtlinux code prior to sending the data via FIFO.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.