📄 com.h
字号:
// This file is part of MANTIS OS, Operating System// See http://mantis.cs.colorado.edu///// Copyright (C) 2003,2004,2005 University of Colorado, Boulder//// This program is free software; you can redistribute it and/or// modify it under the terms of the mos license (see file LICENSE)/** Project Mantis File: com.h Authors: Jeff Rose & Brian Shucker Date: 01-16-04 **//** @file com.h * @brief Primary com functions * @author Jeff Rose, Brian Shucker * @date 01/18/2004 */#ifndef _COM_H_#define _COM_H_#include "mos.h"#include "mutex.h"#include <stdarg.h>#ifdef SCONS#include "optsconfig.h"#else/* Defines which MAC layer to use *///#define CC1000_RAW#define CC1000_CSMA//#define CC1000_CSMA_ACK//#define CC1000_TDMA//#define CC1000_BMAC//ANS: Enable signal strenght measurement//#define GET_RSSI//#define TS_PACKET#endif#ifndef PLATFORM_LINUX// enable FEC code//#define RADIO_USE_FEC 1// send three size bytes instead of one, compute packet size from majority bits//#define RADIO_REDUNDANT_SIZE// Send 2 CRC bytes after the data that will be checked after FEC is done//#define RADIO_EXTRA_CRC#endif#ifdef RADIO_USE_FEC//#define FEC_SIZE_PARITY_COUNT 2#define FEC_DATA_PARITY_COUNT 8#endif#ifndef RADIO_EXTRA_CRC#define COM_DATA_SIZE 64 /* Size of com buffer. */#else// Add two more bytes to include a CRC that is checked AFTER error-correction// FIXME this is an ugly way to do this, since some protocols may use// this number to determine their payload sizes#define COM_DATA_SIZE 66#endif#ifdef PLATFORM_LINUX#define NUM_BUFS 255 /* Size of buffer pool. */#else#define NUM_BUFS 5#endif#ifdef TS_PACKET#ifdef ARCH_AVR#include "realtime.h"#endif#endif//ANS end/** @brief The standard comBuf data structure is designed to be used across multiple different communication devices */typedef struct comBuf_t { /** @brief A pointer to the next comBuf in the pool */ struct comBuf_t *next; /** @brief RSSI of the recvd packet */ //ANS hack:#ifdef GET_RSSI uint16_t signal;#endif#ifdef TS_PACKET uint32_t ts; uint8_t tcnt;#endif //ANS hack ends /** @brief Amount of actual data bytes */ uint8_t size; /** @brief Data buffer */ uint8_t data[COM_DATA_SIZE];} comBuf;#define IFACE_SERIAL 0 // serial port#define IFACE_SERIAL2 1#define IFACE_RADIO 2 // RF transceiver, simulated in xmos#define IFACE_LOOPBACK 3#ifdef PLATFORM_LINUX#define IFACE_UDP 4 // udp/ip sockets#define IFACE_TCP 5 // tcp/ip sockets#define IFACE_TERMINAL 6 // terminal (input reading)#endif#define MAX_IFS 7 // max num of interfaces#ifdef PLATFORM_TELOSB#define com_send_IFACE_STDIO com_send_IFACE_SERIAL2#define com_ioctl_IFACE_STDIO com_ioctl_IFACE_SERIAL2#define com_mode_IFACE_STDIO com_mode_IFACE_SERIAL2#else#define com_send_IFACE_STDIO com_send_IFACE_SERIAL#define com_ioctl_IFACE_STDIO com_ioctl_IFACE_SERIAL#define com_mode_IFACE_STDIO com_mode_IFACE_SERIAL#endif/********* Device-specific function prototypes ************/uint8_t com_send_IFACE_SERIAL(comBuf *buf);void com_mode_IFACE_SERIAL(uint8_t mode);void com_ioctl_IFACE_SERIAL(uint8_t request, ...);uint8_t com_send_IFACE_SERIAL2(comBuf *buf);void com_mode_IFACE_SERIAL2(uint8_t mode);void com_ioctl_IFACE_SERIAL2(uint8_t request, ...);uint8_t com_send_IFACE_RADIO(comBuf *buf);void com_mode_IFACE_RADIO(uint8_t mode);void com_ioctl_IFACE_RADIO(uint8_t request, ...);uint8_t com_send_IFACE_TERMINAL(comBuf *buf);void com_mode_IFACE_TERMINAL(uint8_t mode);void com_ioctl_IFACE_TERMINAL(uint8_t request, ...);uint8_t com_send_IFACE_UDP(comBuf *buf);void com_mode_IFACE_UDP(uint8_t mode);void com_ioctl_IFACE_UDP(uint8_t request, ...);uint8_t com_send_IFACE_LOOPBACK(comBuf *buf);void com_mode_IFACE_LOOPBACK(uint8_t mode);void com_ioctl_IFACE_LOOPBACK(uint8_t request, ...);/* The possible mode settings for interface devices. */enum { IF_OFF = 0, // Device can be powered down IF_STANDBY, // Device in low power mode w/ wakeup IF_IDLE, // Device is on but not receiving IF_LISTEN, // Device is on and receiving#ifdef RADIO_USE_FEC IF_FEC_ENABLE, // Device is using FEC IF_FEC_DISABLE // Device is not using FEC#endif};#define PREAMBLE 0x53#define PREAMBLE_SIZE 2/* Error messages for com layer funcs. */#define SELECT_IFACE_BUSY 150#define IFACE_NOT_REGISTERED 160/* different types of com_selects */#define COM_BLOCK -1#define COM_NOBLOCK 0typedef uint8_t IF_SET;/* NOTE: These implementations limit the number of devices to 8. */#define IF_SET(iface, set) (*set |= 1 << iface) // TODO: check shift direction #define IF_CLEAR(iface, set) (*set &= ~(1 << iface)) #define IF_ZERO(set) (*set = 0)#define IF_ISSET(iface, set) (*set & (1 << iface))/** Interfaces for upper layers. **//** @brief Init com layer. Must be called before any ifaces * try to register. * @return Always returns 0 */uint8_t com_init();/** @brief Flush the packets on a particular iface... */void com_flush (uint8_t iface);/** @brief Defined in com.c */extern mos_mutex_t if_send_mutexes[MAX_IFS];/** @brief Send data over specified interface. * * (NOTE: Blocks until the data has been transmitted.) * @param iface Interface to use * @param buf Buffer to use * @return Retval, else IFACE_NOT_REGISTERED */#define com_send(iface,buf) com_send_##iface (buf)/** @brief Receive data from a specified interface. * * (NOTE: Blocks until a packet is available.) * @param iface Interface to use * @return Buffer used */comBuf *com_recv(uint8_t iface);comBuf *com_recv_timed(uint8_t iface, uint32_t ticks);/** @brief Check a set of interfaces for valid data. * * Blocks if block is non null. * * NOTE: We will need to change some of the logic here if we want to support * more than eight interfaces. * @param iset Interface set * @return Error (SELECT_IFACE_BUSY or IFACE_NOT_REGISTERED) if an iface is already taken; ifcount if there are bufs to be had; 0 if they don't want to block */uint8_t com_select (IF_SET *iset, uint32_t msec);/** @brief Pass ioctl flag and data down to the given interface. * @param iface Interface used * @param request Request to send interface * @return Retval, else IFACE_NOT_REGISTERED */#define com_ioctl(iface,request,args...) com_ioctl_##iface (request, ##args)/** @brief Pass the mode setting down to the given interface. * @param iface Interface used * @param mode Mode func to call * @return Retval, else IFACE_NOT_REGISTERED */#define com_mode(iface,mode) com_mode_##iface (mode)/** @brief Throw the buffer into the free list. * @param buf Buffer to use */void com_free_buf (comBuf *buf);/** @brief Swaps full receive buffer with a fresh buffer. * * This is called by a driver when it has a full recv buffer. * Also called by a driver to just get another buffer, in * which case buf is null. * * Drivers must register before they call swap_bufs! * @param iface Interface to use * @param buf Buffer to use * @return New buffer */void com_swap_bufs (uint8_t iface, comBuf *buf, comBuf **ret);#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -