doc: Added group definitions for most common modules.
[bertos.git] / bertos / kern / msg.h
index 0b6a556d3718c2e7e3e764e0d30eb3561f2e42dc..6cbcc444e371a98bb540a46bbca97af60f157fe8 100644 (file)
  * -->
  *
  *
- * This module implements a common system for executing
- * a user defined action calling a hook function.
- *
- * \version $Id$
- *
- * \author Bernie Innocenti <bernie@codewiz.org>
+ * \defgroup kern_msg Message box IPC
+ * \ingroup kern
+ * \{
  *
  * \brief Simple inter-process messaging system
  *
- * Handle queues of messages associated an action.
+ * This module implements a common system for executing
+ * a user defined action calling a hook function.
  *
  * A message port is an abstraction used to exchange information
  * asynchronously between processes or other entities such as
  * receiver wakes up, it usually invokes msg_get() to pick
  * the next message from the port.
  *
+ * \note
+ * When you put a message into a port, such message becomes
+ * unavailable until you retrieve it using msg_get(), eg.
+ * you must not delete it or put it into another port.
+ *
  * Message ports can hold any number of pending messages,
  * and receivers usually process them in FIFO order.
  * Other scheduling policies are possible, but not implemented
  *     } TestMsg;
  *
  *
+ *  PROC_DEFINE_STACK(sender_stack, KERN_MINSTACKSIZE);
+ *
  *     // A process that sends two messages and waits for replies.
  *     static void sender_proc(void)
  *     {
  *             TestMsg msg2;
  *             Msg *reply;
  *
- *             msg_initPort(&reply_port,
- *                     event_createSignal(proc_current(), SIGF_SINGLE);
+ *             msg_initPort(&test_reply_port,
+ *                     event_createSignal(proc_current(), SIG_SINGLE);
  *
  *             // Fill-in first message and send it out.
  *             msg1.x = 3;
  *             msg1.y = 2;
  *             msg1.msg.replyPort = &test_reply_port;
- *             msg_put(&test_port, &msg1);
+ *             msg_put(&test_port, &msg1.msg);
  *
  *             // Fill-in second message and send it out too.
  *             msg2.x = 5;
  *             msg2.y = 4;
  *             msg2.msg.replyPort = &test_reply_port;
- *             msg_put(&test_port, &msg1);
+ *             msg_put(&test_port, &msg2.msg);
  *
  *             // Wait for a reply...
  *             sig_wait(SIG_SINGLE);
  *
*             reply = (TestMsg *)msg_get(&test_reply_port);
       reply = containerof(msg_get(&test_reply_port), TestMsg, msg);
  *             ASSERT(reply != NULL);
  *             ASSERT(reply->result == 5);
  *
  *             // Get reply to second message.
- *             while (!(reply = (TestMsg *)msg_get(&test_reply_port))
+ *             while (!(reply = containerof(msg_get(&test_reply_port), TestMsg, msg)))
  *             {
  *                     // Not yet, be patient and wait some more.
  *                     sig_wait(SIG_SINGLE);
  *     static void receiver_proc(void)
  *     {
  *             msg_initPort(&test_port,
- *                     event_createSignal(proc_current(), SIGF_EXAMPLE);
+ *                     event_createSignal(proc_current(), SIG_EXAMPLE);
  *
- *             proc_new(sender_proc, (iptr_t)&test_port,
- *                     sender_stack, sizeof(sender_stack);
+ *             proc_new(sender_proc, NULL,sizeof(sender_stack), sender_stack);
  *
  *             for (;;)
  *             {
- *                     sigmask_t sigs = sig_wait(SIGF_EXAMPLE | more_signals);
+ *                     sigmask_t sigs = sig_wait(SIG_EXAMPLE | more_signals);
  *
- *                     if (sigs & SIGF_EXAMPLE)
+ *                     if (sigs & SIG_EXAMPLE)
  *                     {
  *                             TestMsg *emsg;
- *                             while (emsg = (TestMsg *)msg_get(&test_port)
+ *                             while((emsg = containerof(msg_get(&test_port), TestMsg, msg)))
  *                             {
  *                                     // Do something with the message
  *                                     emsg->result = emsg->x + emsg->y;
- *                                     msg_reply((Msg *)msg);
+ *                                     msg_reply(emsg->msg);
  *                             }
  *                     }
  *             }
  *     }
  * \endcode
+ *
+ * \author Bernie Innocenti <bernie@codewiz.org>
+ *
+ * $WIZ$ module_name = "msg"
+ * $WIZ$ module_depends = "event", "signal", "kernel"
  */
 
 
@@ -282,4 +291,10 @@ INLINE void msg_reply(Msg *msg)
        msg_put(msg->replyPort, msg);
 }
 
+/** \} */ //defgroup kern_msg
+
+int msg_testRun(void);
+int msg_testSetup(void);
+int msg_testTearDown(void);
+
 #endif /* KERN_MSG_H */