ReferenceComLayerThe COM Layer is used to interface with communication devices, such as the CC2420 or CC1000 radio, as well as the serial ports. The interface is as follows: com_mode(IFACE, uint8_t mode) Change the mode of the specified interface. com_send(IFACE, comBuf* buffer) Sends data to the specified interface. comBuf* com_recv(IFACE) Receives data from the specified interface. void com_free_buf(comBuf* buffer) Releases a buffer returned from com_recv back to the system for reuse. It is important to call this when you are done with a comBuf, or the system might run out of free buffers. COM Buffers (comBuf) are structures used when sending and receiving from a com layer device. The COM Buffer has the following useful members: uint8_t data[COM_DATA_SIZE] uint8_t size the data byte array is the actual data that the comBuf is carrying. size indicates the number of bytes in the data array. COM_DATA_SIZE is the maximum number of bytes that can be carried in a single comBuf. The most commonly used interfaces are IFACE_RADIO and IFACE_SERIAL, which allow access to the radio (cc2420 or cc1000) and the terminal respectively. On TelosB nodes, IFACE_SERIAL2 is used to interact with the terminal. The following example application is a simple echo program, which will receive a packet over the radio and echo it back:
#include "mos.h"
#include "com.h"
#include "printf.h"
void echo_thread(void)
{
com_mode(IFACE_RADIO, IF_LISTEN);
while(1)
{
comBuf* p = com_recv(IFACE_RADIO);
com_send(IFACE_RADIO, p);
printf("echoed %d bytes\n", p->size);
// release the comBuf back to the OS.
com_free_buf(p);
}
}
void start(void)
{
mos_thread_new(echo_thread, 128, PRIORITY_NORMAL);
}
Created by: ledbettj last modification: Wednesday 01 of August, 2007 [19:50:46 UTC] by ledbettj |
Login Search Online users
1
online user
|