msg.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Freie Universität Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
165 #ifndef MSG_H
166 #define MSG_H
167 
168 #include <stdint.h>
169 #include <stdbool.h>
170 
171 #include "sched.h"
172 
173 #ifdef __cplusplus
174 extern "C" {
175 #endif
176 
185 typedef struct {
188  uint16_t type;
189  union {
190  void *ptr;
191  uint32_t value;
192  } content;
193 } msg_t;
194 
195 
214 int msg_send(msg_t *m, kernel_pid_t target_pid);
215 
216 
233 int msg_try_send(msg_t *m, kernel_pid_t target_pid);
234 
235 
249 int msg_send_to_self(msg_t *m);
250 
254 #define KERNEL_PID_ISR (KERNEL_PID_LAST + 1)
255 
274 int msg_send_int(msg_t *m, kernel_pid_t target_pid);
275 
283 static inline int msg_sent_by_int(const msg_t *m)
284 {
285  return (m->sender_pid == KERNEL_PID_ISR);
286 }
287 
298 int msg_receive(msg_t *m);
299 
311 int msg_try_receive(msg_t *m);
312 
329 int msg_send_receive(msg_t *m, msg_t *reply, kernel_pid_t target_pid);
330 
342 int msg_reply(msg_t *m, msg_t *reply);
343 
356 int msg_reply_int(msg_t *m, msg_t *reply);
357 
364 int msg_avail(void);
365 
376 void msg_init_queue(msg_t *array, int num);
377 
381 void msg_queue_print(void);
382 
383 #ifdef __cplusplus
384 }
385 #endif
386 
387 #endif /* MSG_H */
388 
kernel_pid_t
int16_t kernel_pid_t
Unique process identifier.
Definition: sched.h:125
KERNEL_PID_ISR
#define KERNEL_PID_ISR
Value of msg_t::sender_pid if the sender was an interrupt service routine.
Definition: msg.h:254
msg_queue_print
void msg_queue_print(void)
Prints the message queue of the current thread.
msg_send_to_self
int msg_send_to_self(msg_t *m)
Send a message to the current thread.
msg_send_receive
int msg_send_receive(msg_t *m, msg_t *reply, kernel_pid_t target_pid)
Send a message, block until reply received.
msg_init_queue
void msg_init_queue(msg_t *array, int num)
Initialize the current thread's message queue.
msg_t::type
uint16_t type
Type field.
Definition: msg.h:188
sched.h
Scheduler API definition.
msg_try_receive
int msg_try_receive(msg_t *m)
Try to receive a message.
msg_t::ptr
void * ptr
Pointer content field.
Definition: msg.h:190
msg_reply
int msg_reply(msg_t *m, msg_t *reply)
Replies to a message.
msg_try_send
int msg_try_send(msg_t *m, kernel_pid_t target_pid)
Send a message (non-blocking).
msg_reply_int
int msg_reply_int(msg_t *m, msg_t *reply)
Replies to a message from interrupt.
msg_receive
int msg_receive(msg_t *m)
Receive a message.
msg_t::value
uint32_t value
Value content field.
Definition: msg.h:191
msg_send
int msg_send(msg_t *m, kernel_pid_t target_pid)
Send a message (blocking).
msg_sent_by_int
static int msg_sent_by_int(const msg_t *m)
Test if the message was sent inside an ISR.
Definition: msg.h:283
msg_avail
int msg_avail(void)
Check how many messages are available in the message queue.
msg_t::sender_pid
kernel_pid_t sender_pid
PID of sending thread.
Definition: msg.h:186
msg_t
Describes a message object which can be sent between threads.
Definition: msg.h:185
msg_send_int
int msg_send_int(msg_t *m, kernel_pid_t target_pid)
Send message from interrupt.