📄 net.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)/**************************************************************************//* File: net.h *//* Author: Jeff Rose : rosejn@colorado.edu *//* Date: 04/15/04 *//* *//* networking layer. *//**************************************************************************//** @file net.h * @brief Top level event based networking layer. * @author Jeff Rose, Charles Gruenwald III * @author Modified: Cyrus Hall * @author Modified: Carl Hartung * @date Created: 04/15/2004 * @date Modified: 07/22/2004 * @date Modified: 11/12/2004 */#ifndef _NET_H_#define _NET_H_#include "mos.h"#include "com.h"#include "printf.h"#include <stdarg.h>/** @brief No space left in the comBuf. */#define NET_BUF_FULL -20 /** @brief Not a valid protocol id. */#define NET_PROTO_INVALID -1/** @brief Maximum number of protocols. */#define NET_PROTO_MAX 3/** PROTOCOL LIST **/#define SIMPLE_PROTO_ID 17#define MST_PROTO_ID 18#define RTS_PROTO_ID 19#define DELUGE_PROTO_ID 20/** END PROTOCOL LIST **/typedef int8_t (*net_proto_send)(comBuf *pkt, va_list args);typedef boolean (*net_proto_recv)(comBuf *pkt, uint8_t **footer, uint8_t port);typedef int8_t (*net_proto_ioctl)(uint8_t request, va_list args);/** @brief Net protocol data structure. */typedef struct{ /** @brief Protocol ID */ uint8_t proto_id; /** @brief Protocol send function */ net_proto_send sfunc; /** @brief Protocol receive function */ net_proto_recv rfunc; /** @brief Protocol io control function */ net_proto_ioctl ifunc;}net_proto;/** Setup the net layer. */void net_init();/** @brief Send an event with the currently selected protocol. * @param event_id Event ID * @param pkt Packet sent * @return NET_PROTO_INVALID if protocol invalid, else return ret */int8_t net_send(comBuf *pkt, uint8_t proto_id, uint8_t port, ...);/** @brief Register a new protocol to be used with the net layer. * @param proto New protocol * @param sfunc Protocol send function * @param rfunc Protocol receive function * @param ifunc Protocol io control function * @return NET_PROTO_INVALID if protocol invalid, -1 if no space left, else return */int8_t net_proto_register(uint8_t proto, net_proto_send sfunc, net_proto_recv rfunc, net_proto_ioctl ifunc);/** @brief Set some protocol specific options. * @param proto Protocol * @param request IO Request * @return NET_PROTO_INVALID if protocol invalid, else return retval */int8_t net_ioctl(uint8_t proto, uint8_t request, ...);/** @brief is_app_waiting_on() method called by protocols * @param port check all waiting threads for the specified port * @return true if it sent the packet to an app, false if it did not. */boolean is_app_waiting_on(uint8_t port); /** @brief net_recv method called by applications * @param port listening on specified port * @return returns comBuf to application */comBuf * net_recv(uint8_t port);/** @brief A background thread that listens on everything for event traffic.*/void net_thread();#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -