?? queue.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)#ifndef QUEUE_H_#define QUEUE_H_#include <inttypes.h>/*error codes*/#define Q_OK 0#define Q_FULL 1#define Q_UNDERFLOW 2#define Q_EMPTY 3/** @file queue.h * @brief Small circular queue library *//** @brief Queue data structure */typedef struct{ /** @brief Data pointer to the buffer */ uint8_t *buf; /** @brief Maximum size of the buffer */ uint8_t size; // uint8_t head, tail; /** @brief Length of the actual data */ uint8_t length; /** @brief Head of the buffer */ uint8_t head; // uint8_t tail = (head + length - 1) % size} queue_t;/** @brief Init the queue. * * Inits a new byte queue. The elements of the queue will be stored * in buffer. * @param q Queue to init * @param buffer A byte array * @param size Size of buffer */void mos_queue_init(queue_t *q, uint8_t *buffer, uint8_t size);/** @brief Add a new byte to the tail of the queue. * @param q Queue to add a byte to * @param byte Byte to add * @return Q_OK or Q_UNDERFLOW */uint8_t mos_queue_add(queue_t *q, uint8_t byte);/** @brief Return the length of a given queue. * @param q Queue to check length of * @return Length of the queue */uint8_t mos_queue_length(queue_t *q);/** @brief Remove the first byte from the head of the queue. * @param q Queue to remove a byte from * @param byte Byte that was removed * @return Q_OK or Q_UNDERFLOW */uint8_t mos_queue_remove(queue_t *q, uint8_t *byte);/** @brief Dump specific number of bytes out from the buffer. * * These bytes are removed from the buffer * @param q Queue to dump bytes from * @param dumpNum Number of bytes to dump * @return Number of dumped bytes */uint8_t mos_queue_dump(queue_t *q, uint8_t dumpNum);/** @brief "peek" one byte from the queue. * * Doesn't delete the byte, just looks * @param q Queue to peek * @param index Index to peek at * @param byte Peeked byte * @return Q_OK, Q_EMPTY */uint8_t mos_queue_peek(queue_t *q, uint8_t index, uint8_t *byte);/** @brief Empty the queue. * @param q Queue to empty */void mos_queue_cleanup(queue_t *q);#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -