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 
9 #pragma once
10 
178 #include <stdint.h>
179 #include <stdbool.h>
180 
181 #include "sched.h"
182 
183 #ifdef __cplusplus
184 extern "C" {
185 #endif
186 
195 typedef struct {
198  uint16_t type;
199  union {
200  void *ptr;
201  uint32_t value;
202  } content;
203 } msg_t;
204 
223 int msg_send(msg_t *m, kernel_pid_t target_pid);
224 
241 int msg_try_send(msg_t *m, kernel_pid_t target_pid);
242 
257 
261 #define KERNEL_PID_ISR (KERNEL_PID_LAST + 1)
262 
281 int msg_send_int(msg_t *m, kernel_pid_t target_pid);
282 
290 static inline int msg_sent_by_int(const msg_t *m)
291 {
292  return (m->sender_pid == KERNEL_PID_ISR);
293 }
294 
306 
319 
342 int msg_send_receive(msg_t *m, msg_t *reply, kernel_pid_t target_pid);
343 
355 int msg_reply(msg_t *m, msg_t *reply);
356 
369 int msg_reply_int(msg_t *m, msg_t *reply);
370 
384 
393 unsigned msg_avail(void);
394 
402 
416 void msg_init_queue(msg_t *array, int num);
417 
421 #ifndef CONFIG_MSG_QUEUE_PRINT_MAX
422 # define CONFIG_MSG_QUEUE_PRINT_MAX 16U
423 #endif
424 
430 void msg_queue_print(void);
431 
432 #ifdef __cplusplus
433 }
434 #endif
435 
int msg_send_receive(msg_t *m, msg_t *reply, kernel_pid_t target_pid)
Send a message, block until reply received.
int msg_reply_int(msg_t *m, msg_t *reply)
Replies to a message from interrupt.
int msg_try_receive(msg_t *m)
Try to receive a message.
int msg_send_int(msg_t *m, kernel_pid_t target_pid)
Send message from interrupt.
int msg_reply(msg_t *m, msg_t *reply)
Replies to a message.
void msg_queue_print(void)
Prints the message queue of the current thread.
void msg_init_queue(msg_t *array, int num)
Initialize the current thread's message queue.
unsigned msg_queue_capacity(kernel_pid_t pid)
Get maximum capacity of a thread's queue length.
unsigned msg_avail(void)
Check how many messages are available (waiting) in the message queue.
static int msg_sent_by_int(const msg_t *m)
Test if the message was sent inside an ISR.
Definition: msg.h:290
int msg_send_to_self(msg_t *m)
Send a message to the current thread.
int msg_try_send(msg_t *m, kernel_pid_t target_pid)
Send a message (non-blocking).
int msg_send(msg_t *m, kernel_pid_t target_pid)
Send a message (blocking).
#define KERNEL_PID_ISR
Value of msg_t::sender_pid if the sender was an interrupt service routine.
Definition: msg.h:261
int msg_receive(msg_t *m)
Receive a message.
unsigned msg_avail_thread(kernel_pid_t pid)
Check how many messages are available (waiting) in the message queue of a specific thread.
int16_t kernel_pid_t
Unique process identifier.
Definition: sched.h:138
Scheduler API definition.
Describes a message object which can be sent between threads.
Definition: msg.h:195
uint16_t type
Type field.
Definition: msg.h:198
kernel_pid_t sender_pid
PID of sending thread.
Definition: msg.h:196
void * ptr
Pointer content field.
Definition: msg.h:200
uint32_t value
Value content field.
Definition: msg.h:201