#include <stdio.h>
#include <xparameters.h>
#include <xuartlite_l.h>
#include <sys/ipc.h>
#include <sys/msg.h>

struct _msg {
  short i ;
  char j ;
  char j1;
} ;
struct _msg msg ;

int main() 
{
  int key = 5 ;	
  char i = 0 ;
  int msgid ;	
  int retval;
  
  /*
   * Producer
   */
  msgid = msgget( key, 4, 1, IPC_CREAT ) ;
  if( msgid == -1 ) {
    print("Producer :: Error - Opening Message Queue \r\n") ;
    process_exit() ;
  }
  //print("Prod::\r\n") ; 
  while(i<2) {
    msg.i = i ;
    msg.j = 'a'+i ;
    msgsend( msgid, &msg, 4, 0 ); // blocking send
    //  while ((retval = msgsend( msgid, &msg, 4, 0 )) == -1 ) {
 // replace 0 with IPC_NOWAIT for non blocking
//        // keep trying until it succeeds
//        msg.j += 1;
//      }
    print("Producer : " ) ;
    outbyte(msg.j) ;
    print("\r\n") ;
    i++ ;
  }
  // msgctl( msgid, IPC_RMID, NULL ) ;
  process_exit() ;
} 

