Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: DigiLogger
Fork of XBeeLib_vs by
FrameBuffer/FrameBuffer.h
- Committer:
- spastor
- Date:
- 2015-05-18
- Revision:
- 3:8662ebe83570
- Parent:
- 0:fcaad0dfa051
- Child:
- 4:629712865107
File content as of revision 3:8662ebe83570:
/**
* Copyright (c) 2015 Digi International Inc.,
* All rights not expressly granted are reserved.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
* =======================================================================
*/
#if !defined(__FRAME_BUFFER_H_)
#define __FRAME_BUFFER_H_
#include "config.h"
#include "mbed.h"
#include "Frames/ApiFrame.h"
#if FRAME_BUFFER_SIZE > 255
# error "FRAME_BUFFER_SIZE must be lower than 256"
#endif
typedef struct element {
ApiFrame *frame;
uint8_t status;
} buf_element_t;
/**
* @class FrameBuffer
* @brief storage class for incoming frames
*/
class FrameBuffer
{
public:
/** Constructor */
FrameBuffer();
FrameBuffer(const FrameBuffer& other); /* Intentionally not implemented */
/** Destructor */
~FrameBuffer();
/** get_next_free_frame returns the next free frame
*
* @returns a pointer to the next free frame */
ApiFrame *get_next_free_frame();
/** complete_frame sets the status of the frame to complete once the
* data has been set in the buffer.
*
* @param pointer to the buffer we want to set as complete
* @returns true on success, false otherwise
*/
bool complete_frame(ApiFrame *frame);
/** free_frame makes the frame available to be reused in future
*
* @param frame to release */
bool free_frame(ApiFrame *frame);
/** get_next_complete_frame_app returns the pointer to the next complete frame using _tail_app
*
* @returns the pointer to the selected buffer
*/
ApiFrame *get_next_complete_frame_app();
/** get_next_complete_frame_syncr returns the pointer to the next complete frame using _tail_syncr
*
* @returns the pointer to the selected buffer
*/
ApiFrame *get_next_complete_frame_syncr();
/** get_dropped_frames_count returns the number of dropped frames since latest call to this method
*
* @returns the number of dropped frames since latest call to this method
*/
uint32_t get_dropped_frames_count();
protected:
/** frame status */
enum FrameStatus {
FrameStatusFree = 0, /**< Free */
FrameStatusAssigned, /**< Assigned */
FrameStatusComplete /**< Complete */
};
/** buffer array */
buf_element_t _frm_buf[FRAME_BUFFER_SIZE];
/** head frame index */
uint8_t _head;
/** tail frame index for application */
uint8_t _tail_app;
/** tail frame index for syncronous operations */
uint8_t _tail_syncr;
/** dropped frames */
uint32_t _dropped_frames;
/** get_next_complete_frame returns the pointer to the next complete frame
*
* @param tail tail index to use (either _tail_app or _tail_syncr)
* @returns the pointer to the selected buffer
*/
ApiFrame *get_next_complete_frame(uint8_t* tail);
};
#endif /* __FRAME_BUFFER_H_ */
