home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / PowerPC / Dev / PPCRelease / Examples / IPC / Msg4PPC.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-06  |  2.8 KB  |  122 lines

  1. /* Msg4 and Msg4PPC.elf
  2.  * 
  3.  * This test program sends 1000 messages to the M68k and
  4.  * shows how long this takes.
  5.  * The Messages are send synchron and every msg must
  6.  * be replied after another.
  7.  * Each Message has the Body "Text sent by PPC processor\n"
  8.  */
  9.  
  10. #include <exec/types.h>
  11. #include <exec/nodes.h>
  12. #include <exec/lists.h>
  13. #include <exec/memory.h>
  14. #include <utility/tagitem.h>
  15. #include <powerup/ppclib/interface.h>
  16. #include <powerup/ppclib/message.h>
  17. #include <powerup/ppclib/tasks.h>
  18. #include <powerup/gcclib/powerup_protos.h>
  19.  
  20. #define    DEBUG    0
  21.  
  22. #if DEBUG
  23. #define    D(x)    x;
  24. #else
  25. #define    D(x)    ;
  26. #endif
  27.  
  28. #define TEXT    "Text sent by PPC processor\n"
  29.  
  30. struct StartupData
  31. {
  32.     void    *MsgPort;
  33.     ULONG    MsgCount;
  34. };
  35.  
  36. BPTR    MyFile;
  37.  
  38. int    main(void)
  39. {
  40. struct TagItem        MyTags[1];
  41. struct StartupData    *StartupData;
  42. void            *ReplyPort;
  43. void            *M68kPort;
  44. void            *PPCMsg;
  45. void            *M68kMsg;
  46. void            *Body;
  47. ULONG            result;
  48. ULONG            MsgCount;
  49. ULONG            i;
  50.  
  51.   StartupData    =(struct StartupData *) PPCGetTaskAttr(PPCTASKTAG_STARTUP_MSGDATA);
  52.   MsgCount    =    StartupData->MsgCount;
  53. #if DEBUG
  54.   if (MyFile = PPCOpen("con:0/0/640/200/MessageDemo - PPC output/CLOSE", MODE_NEWFILE))
  55.   {
  56. #endif
  57.     if (M68kPort=StartupData->MsgPort)
  58.     {
  59.       D(PPCfprintf(MyFile,"Allocating memory for message body\n"));
  60.       if (Body = PPCAllocVec(sizeof(TEXT), MEMF_PUBLIC))
  61.       {
  62.         D(PPCfprintf(MyFile,"Creating reply port\n"));
  63.         MyTags[0].ti_Tag = TAG_DONE;
  64.         if (ReplyPort = PPCCreatePort(MyTags))
  65.         {
  66.           D(PPCfprintf(MyFile,"Creating message\n"));
  67.           if (PPCMsg = PPCCreateMessage(ReplyPort, sizeof(TEXT)))
  68.           {
  69.             D(PPCfprintf(MyFile,"Obtaining PPC port..."));
  70.  
  71.             strcpy(Body, TEXT);
  72.  
  73.             for (i=0;i<MsgCount;i++)
  74.             {
  75.               PPCSendMessage(M68kPort,
  76.                              PPCMsg,
  77.                              Body,
  78.                              sizeof(TEXT),
  79.                              0x12345678);
  80.               PPCWaitPort(ReplyPort);
  81.               PPCGetMessage(ReplyPort);
  82.             }
  83.  
  84.             D(PPCfprintf(MyFile,"Deleting Message\n"));
  85.             PPCDeleteMessage(PPCMsg);
  86.           }
  87.           else
  88.           {
  89.             D(PPCfprintf(MyFile,"Could not create ppc msg\n"));
  90.           }
  91.  
  92.           D(PPCfprintf(MyFile,"Deleting reply port\n"));
  93.           while (PPCDeletePort(ReplyPort) == FALSE);
  94.         }
  95.         else
  96.         {
  97.           D(PPCfprintf(MyFile,"Could not create reply port\n"));
  98.         }
  99.  
  100.         D(PPCfprintf(MyFile,"Freeing message body memory\n"));
  101.         PPCFreeVec(Body);
  102.       }
  103.       else
  104.       {
  105.         D(PPCfprintf(MyFile,"Could not alloc mem for msg body\n"));
  106.       }
  107.  
  108.     }
  109.     else
  110.     {
  111.       D(PPCfprintf(MyFile,"Could not get a M68k msgport\n"));
  112.     }
  113.  
  114.     D(PPCfprintf(MyFile,"Closing output\n"));
  115. #if DEBUG
  116.     PPCClose(MyFile);
  117.   }
  118. #endif
  119. }
  120.  
  121.  
  122.