An open source implementation of Thread stack. More...

Detailed Description

An open source implementation of Thread stack.

See also
https://github.com/openthread/openthread

Thread is a mesh oriented network stack running for IEEE802.15.4 networks.

The RIOT port allows to directly call OpenThread API functions using Event Queue. For example:

#include "ot.h"
#include "openthread/thread.h"
static void _panid_handler(event_t *event);
static event_t event_panid = {
.handler = _panid_handler
};
static void _panid_handler(event_t *event)
{
(void) event;
uint16_t panid = otLinkGetPanId(openthread_get_instance());
do_something_with_panid(panid);
}
int main(void)
{
event_post(openthread_get_evq(), &event_panid);
return 0;
}
otInstance * openthread_get_instance(void)
Get pointer to the OpenThread instance.
event_queue_t * openthread_get_evq(void)
Get OpenThread event queue.
void event_post(event_queue_t *queue, event_t *event)
Queue an event.
event structure
Definition: event.h:147
event_handler_t handler
pointer to event handler function
Definition: event.h:149
See also
https://openthread.io/releases/thread-reference-20180619

Files

file  ot.h
 

Data Structures

struct  serial_msg_t
 Struct containing a serial message. More...
 
struct  ot_job_t
 Struct containing an OpenThread job. More...
 

Functions

void recv_pkt (otInstance *aInstance, netdev_t *dev)
 Gets packet from driver and tells OpenThread about the reception. More...
 
void send_pkt (otInstance *aInstance, netdev_t *dev, netdev_event_t event)
 Inform OpenThread when tx is finished. More...
 
event_queue_topenthread_get_evq (void)
 Get OpenThread event queue. More...
 
otInstance * openthread_get_instance (void)
 Get pointer to the OpenThread instance. More...
 
void openthread_bootstrap (void)
 Bootstrap OpenThread.
 
void openthread_radio_init (netdev_t *dev, uint8_t *tb, uint8_t *rb)
 Init OpenThread radio. More...
 
int openthread_netdev_init (char *stack, int stacksize, char priority, const char *name, netdev_t *netdev)
 Starts OpenThread thread. More...
 
void ot_random_init (void)
 Init OpenThread random.
 
uint8_t ot_exec_command (otInstance *ot_instance, const char *command, void *arg, void *answer)
 Execute OpenThread command. More...
 
uint8_t ot_call_command (char *command, void *arg, void *answer)
 Call OpenThread command in same thread as OT core (due to concurrency). More...
 

Openthread constants

#define OPENTHREAD_NUMBER_OF_SERIAL_BUFFER   (1U)
 number of serial reception buffer
 
#define OPENTHREAD_SIZEOF_LENGTH_AND_FREEBUFF   (4U)
 sizeof in bytes the two first members of she serial structure
 
#define OPENTHREAD_SERIAL_BUFFER_SIZE   OPENTHREAD_SIZEOF_LENGTH_AND_FREEBUFF + 100
 sizeof the serial buffer
 
#define OPENTHREAD_SERIAL_BUFFER__PAYLOAD_SIZE   OPENTHREAD_SERIAL_BUFFER_SIZE - OPENTHREAD_SIZEOF_LENGTH_AND_FREEBUFF
 sizeof the spinel payload data
 
#define OPENTHREAD_ERROR_NO_EMPTY_SERIAL_BUFFER   -1
 error when no more buffer available
 
#define OPENTHREAD_SERIAL_BUFFER_STATUS_FREE   (0x0001)
 serial buffer ready to use
 
#define OPENTHREAD_SERIAL_BUFFER_STATUS_READY_TO_PROCESS   (0x0002)
 serial buffer ready for processing
 
#define OPENTHREAD_SERIAL_BUFFER_STATUS_FULL   (0x0004)
 serial buffer payload full
 
#define IEEE802154_MAX_LENGTH   (127U)
 Max length for IEEE802154 frame.
 
#define OPENTHREAD_NETDEV_BUFLEN   (IEEE802154_MAX_LENGTH)
 Max length for a netdev buffer

 

Function Documentation

◆ openthread_get_evq()

event_queue_t* openthread_get_evq ( void  )

Get OpenThread event queue.

Returns
pointer to the event queue

◆ openthread_get_instance()

otInstance* openthread_get_instance ( void  )

Get pointer to the OpenThread instance.

Returns
pointer to the OpenThread instance

◆ openthread_netdev_init()

int openthread_netdev_init ( char *  stack,
int  stacksize,
char  priority,
const char *  name,
netdev_t netdev 
)

Starts OpenThread thread.

Parameters
[in]stackpointer to the stack designed for OpenThread
[in]stacksizesize of the stack
[in]prioritypriority of the OpenThread stack
[in]namename of the OpenThread stack
[in]netdevpointer to the netdev interface
Returns
PID of OpenThread thread
-EINVAL if there was an error creating the thread

◆ openthread_radio_init()

void openthread_radio_init ( netdev_t dev,
uint8_t *  tb,
uint8_t *  rb 
)

Init OpenThread radio.

Parameters
[in]devpointer to a netdev interface
[in]tbpointer to the TX buffer designed for OpenThread
[in]rbpointer to the RX buffer designed for Open_Thread

◆ ot_call_command()

uint8_t ot_call_command ( char *  command,
void *  arg,
void *  answer 
)

Call OpenThread command in same thread as OT core (due to concurrency).

Note
An OpenThread command allows direct calls to OpenThread API (otXXX functions) without worrying about concurrency issues. All API calls should be made in OT_JOB type functions.
Deprecated:
This function is not needed anymore since it's possible to run OpenThread code via Event Queue (see openthread_get_evq). Therefore it will be removed after the 2022.01 release.
Parameters
[in]commandname of the command to call
[in]argarg for the command
[out]answeranswer for the command
Returns
0 on success, 1 on error

◆ ot_exec_command()

uint8_t ot_exec_command ( otInstance *  ot_instance,
const char *  command,
void *  arg,
void *  answer 
)

Execute OpenThread command.

Call this function only in OpenThread thread

Deprecated:
This function is not needed anymore since it's possible to run OpenThread code via Event Queue (see openthread_get_evq). Therefore it will be removed after the 2022.01 release.
Parameters
[in]ot_instanceOpenThread instance
[in]commandOpenThread command name
[in]argarg for the command
[out]answeranswer for the command
Returns
0 on success, 1 on error

◆ recv_pkt()

void recv_pkt ( otInstance *  aInstance,
netdev_t dev 
)

Gets packet from driver and tells OpenThread about the reception.

Parameters
[in]aInstancepointer to an OpenThread instance
[in]devpointer to a netdev instance

◆ send_pkt()

void send_pkt ( otInstance *  aInstance,
netdev_t dev,
netdev_event_t  event 
)

Inform OpenThread when tx is finished.

Parameters
[in]aInstancepointer to an OpenThread instance
[in]devpointer to a netdev interface
[in]eventjust occurred netdev event