ot.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Fundacion Inria Chile
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 
24 #ifndef OT_H
25 #define OT_H
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 #include "net/netopt.h"
32 #include "net/ieee802154.h"
33 #include "net/ethernet.h"
34 #include "net/netdev.h"
35 #include "thread.h"
36 #include "openthread/instance.h"
37 #include "event.h"
38 
44 #define OPENTHREAD_NUMBER_OF_SERIAL_BUFFER (1U)
45 
46 #define OPENTHREAD_SIZEOF_LENGTH_AND_FREEBUFF (4U)
47 
48 #define OPENTHREAD_SERIAL_BUFFER_SIZE OPENTHREAD_SIZEOF_LENGTH_AND_FREEBUFF + 100
49 
50 #define OPENTHREAD_SERIAL_BUFFER__PAYLOAD_SIZE OPENTHREAD_SERIAL_BUFFER_SIZE - OPENTHREAD_SIZEOF_LENGTH_AND_FREEBUFF
51 
52 #define OPENTHREAD_ERROR_NO_EMPTY_SERIAL_BUFFER -1
53 
54 #define OPENTHREAD_SERIAL_BUFFER_STATUS_FREE (0x0001)
55 
56 #define OPENTHREAD_SERIAL_BUFFER_STATUS_READY_TO_PROCESS (0x0002)
57 
58 #define OPENTHREAD_SERIAL_BUFFER_STATUS_FULL (0x0004)
59 
60 #define IEEE802154_MAX_LENGTH (127U)
61 
62 #define OPENTHREAD_NETDEV_BUFLEN (IEEE802154_MAX_LENGTH)
63 
68 typedef struct {
69  uint16_t length;
72 } serial_msg_t;
73 
77 typedef struct {
79  int status;
80  const char *command;
81  void *arg;
82  void *answer;
83 } ot_job_t;
84 
91 void recv_pkt(otInstance *aInstance, netdev_t *dev);
92 
100 void send_pkt(otInstance *aInstance, netdev_t *dev, netdev_event_t event);
101 
108 
114 otInstance* openthread_get_instance(void);
115 
119 void openthread_bootstrap(void);
120 
128 void openthread_radio_init(netdev_t *dev, uint8_t *tb, uint8_t *rb);
129 
130 
143 int openthread_netdev_init(char *stack, int stacksize, char priority, const char *name, netdev_t *netdev);
144 
151 
155 void ot_random_init(void);
156 
167 uint8_t ot_exec_command(otInstance *ot_instance, const char* command, void *arg, void* answer);
168 
181 uint8_t ot_call_command(char* command, void *arg, void* answer);
182 
183 #ifdef __cplusplus
184 }
185 #endif
186 
187 #endif /* OT_H */
188 
ot_random_init
void ot_random_init(void)
Init OpenThread random.
kernel_pid_t
int16_t kernel_pid_t
Unique process identifier.
Definition: sched.h:125
ieee802154.h
IEEE 802.15.4 header definitions.
ot_job_t::arg
void * arg
arg for the job
Definition: ot.h:81
ot_job_t::command
const char * command
A pointer to the job name string.
Definition: ot.h:80
ot_job_t
Struct containing an OpenThread job.
Definition: ot.h:77
netdev_event_t
netdev_event_t
Possible event types that are send from the device driver to the upper layer.
Definition: netdev.h:234
netopt.h
Definition of global configuration options.
ot_exec_command
uint8_t ot_exec_command(otInstance *ot_instance, const char *command, void *arg, void *answer)
Execute OpenThread command.
event
event structure
Definition: event.h:142
openthread_get_evq
event_queue_t * openthread_get_evq(void)
Get OpenThread event queue.
openthread_get_pid
kernel_pid_t openthread_get_pid(void)
get PID of OpenThread thread.
ethernet.h
Definitions for Ethernet.
event_queue_t
event queue structure
Definition: event.h:150
openthread_radio_init
void openthread_radio_init(netdev_t *dev, uint8_t *tb, uint8_t *rb)
Init OpenThread radio.
serial_msg_t::length
uint16_t length
length of the message
Definition: ot.h:69
openthread_bootstrap
void openthread_bootstrap(void)
Bootstrap OpenThread.
serial_msg_t
Struct containing a serial message.
Definition: ot.h:68
netdev.h
Definitions low-level network driver interface.
recv_pkt
void recv_pkt(otInstance *aInstance, netdev_t *dev)
Gets packet from driver and tells OpenThread about the reception.
OPENTHREAD_SERIAL_BUFFER__PAYLOAD_SIZE
#define OPENTHREAD_SERIAL_BUFFER__PAYLOAD_SIZE
sizeof the spinel payload data
Definition: ot.h:50
send_pkt
void send_pkt(otInstance *aInstance, netdev_t *dev, netdev_event_t event)
Inform OpenThread when tx is finished.
netdev
Structure to hold driver state.
Definition: netdev.h:302
ot_job_t::ev
event_t ev
Event associated to the OpenThread job.
Definition: ot.h:78
openthread_netdev_init
int openthread_netdev_init(char *stack, int stacksize, char priority, const char *name, netdev_t *netdev)
Starts OpenThread thread.
ot_job_t::status
int status
Status of the job.
Definition: ot.h:79
serial_msg_t::serial_buffer_status
uint16_t serial_buffer_status
status of the buffer
Definition: ot.h:70
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).
openthread_get_instance
otInstance * openthread_get_instance(void)
Get pointer to the OpenThread instance.
ot_job_t::answer
void * answer
answer from the job
Definition: ot.h:82