LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-09-2009, 05:23 AM   #1
overberg
LQ Newbie
 
Registered: Mar 2009
Posts: 23

Rep: Reputation: 0
Getting data via FIFO


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);
 
Old 07-25-2009, 10:13 AM   #2
asprakash
Member
 
Registered: May 2006
Location: Chennai, India
Posts: 74
Blog Entries: 3

Rep: Reputation: 18
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.
 
Old 07-27-2009, 04:06 AM   #3
overberg
LQ Newbie
 
Registered: Mar 2009
Posts: 23

Original Poster
Rep: Reputation: 0
Thanks for the reply.

The "rtf1" is correct. It is defined in /dev/

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.

I am not sure if this is the norm?

Kind regards
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
FIFO in QT navderm Programming 2 01-05-2009 11:06 AM
A Help with FIFO navderm Programming 1 12-29-2008 04:07 PM
Linux 2.6 FIFO vs Linux 2.4 FIFO gjpc Programming 4 03-19-2008 07:26 PM
fifo help !! matlin Linux - Newbie 1 02-21-2008 01:51 PM
Clonning data, fifo/pipe/tee problem : Resource temporarily unavailable rmarco Linux - General 2 05-05-2005 11:15 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration