contiki系统的网络能力很强大,里面有最新的6LoWPAN协议和Rime协议还有思科提供的ipv6,可以很轻松的实现基于IP的物联网。
想要把contiki移植到samr21 平台上最重要的就是要实现下面这些函数:(contiki把整个框架已经写好了,我们只要去针对不同的平台是实现这些函数即可)
/**
* The structure of a device driver for a radio in Contiki.
*/
struct radio_driver {
int (* init)(void);
/** Prepare the radio with a packet to be sent. */
int (* prepare)(const void *payload, unsigned short payload_len);
/** Send the packet that has previously been prepared. */
int (* transmit)(unsigned short transmit_len);
/** Prepare & transmit a packet. */
int (* send)(const void *payload, unsigned short payload_len);
/** Read a received packet into a buffer. */
int (* read)(void *buf, unsigned short buf_len);
/** Perform a Clear-Channel Assessment (CCA) to find out if there is
a packet in the air or not. */
int (* channel_clear)(void);
/** Check if the radio driver is currently receiving a packet */
int (* receiving_packet)(void);
/** Check if the radio driver has just received a packet */
int (* pending_packet)(void);
/** Turn the radio on. */
int (* on)(void);
/** Turn the radio off. */
int (* off)(void);
/** Get a radio parameter value. */
radio_result_t (* get_value)(radio_param_t param, radio_value_t *value);
/** Set a radio parameter value. */
radio_result_t (* set_value)(radio_param_t param, radio_value_t value);
/**
* Get a radio parameter object. The argument 'dest' must point to a
* memory area of at least 'size' bytes, and this memory area will
* contain the parameter object if the function succeeds.
*/
radio_result_t (* get_object)(radio_param_t param, void *dest, size_t size);
/**
* Set a radio parameter object. The memory area referred to by the
* argument 'src' will not be accessed after the function returns.
*/
radio_result_t (* set_object)(radio_param_t param, const void *src,
size_t size);
};
只要移植好了contiki 里面有很多例子和文档,直接就能跑起来,例如 webserver slip-radio coap等
samr21运行udp-ipv6 服务器 例子
samr21运行udp-ipv6 客户端 例子
边缘路由 例子(这个例子需要加enc28j60网卡和运行contiki的ip64协议即可实现——ipv6转ipv4)
webserver-ipv6 例子