vghjvghi
Fork of XBeeLib3 by
FrameBuffer/FrameBuffer.h@3:8662ebe83570, 2015-05-18 (annotated)
- Committer:
- spastor
- Date:
- Mon May 18 13:16:55 2015 +0200
- Revision:
- 3:8662ebe83570
- Parent:
- 0:fcaad0dfa051
- Child:
- 4:629712865107
Automatic upload
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
spastor | 0:fcaad0dfa051 | 1 | /** |
spastor | 0:fcaad0dfa051 | 2 | * Copyright (c) 2015 Digi International Inc., |
spastor | 0:fcaad0dfa051 | 3 | * All rights not expressly granted are reserved. |
spastor | 0:fcaad0dfa051 | 4 | * |
spastor | 0:fcaad0dfa051 | 5 | * This Source Code Form is subject to the terms of the Mozilla Public |
spastor | 0:fcaad0dfa051 | 6 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
spastor | 0:fcaad0dfa051 | 7 | * You can obtain one at http://mozilla.org/MPL/2.0/. |
spastor | 0:fcaad0dfa051 | 8 | * |
spastor | 0:fcaad0dfa051 | 9 | * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343 |
spastor | 0:fcaad0dfa051 | 10 | * ======================================================================= |
spastor | 0:fcaad0dfa051 | 11 | */ |
spastor | 0:fcaad0dfa051 | 12 | |
spastor | 0:fcaad0dfa051 | 13 | #if !defined(__FRAME_BUFFER_H_) |
spastor | 0:fcaad0dfa051 | 14 | #define __FRAME_BUFFER_H_ |
spastor | 0:fcaad0dfa051 | 15 | |
spastor | 0:fcaad0dfa051 | 16 | #include "config.h" |
spastor | 0:fcaad0dfa051 | 17 | #include "mbed.h" |
spastor | 0:fcaad0dfa051 | 18 | #include "Frames/ApiFrame.h" |
spastor | 0:fcaad0dfa051 | 19 | |
spastor | 0:fcaad0dfa051 | 20 | #if FRAME_BUFFER_SIZE > 255 |
spastor | 0:fcaad0dfa051 | 21 | # error "FRAME_BUFFER_SIZE must be lower than 256" |
spastor | 0:fcaad0dfa051 | 22 | #endif |
spastor | 0:fcaad0dfa051 | 23 | |
spastor | 0:fcaad0dfa051 | 24 | typedef struct element { |
spastor | 0:fcaad0dfa051 | 25 | ApiFrame *frame; |
spastor | 0:fcaad0dfa051 | 26 | uint8_t status; |
spastor | 0:fcaad0dfa051 | 27 | } buf_element_t; |
spastor | 0:fcaad0dfa051 | 28 | |
spastor | 0:fcaad0dfa051 | 29 | /** |
spastor | 0:fcaad0dfa051 | 30 | * @class FrameBuffer |
spastor | 0:fcaad0dfa051 | 31 | * @brief storage class for incoming frames |
spastor | 0:fcaad0dfa051 | 32 | */ |
spastor | 0:fcaad0dfa051 | 33 | class FrameBuffer |
spastor | 0:fcaad0dfa051 | 34 | { |
spastor | 0:fcaad0dfa051 | 35 | public: |
spastor | 0:fcaad0dfa051 | 36 | /** Constructor */ |
spastor | 0:fcaad0dfa051 | 37 | FrameBuffer(); |
spastor | 0:fcaad0dfa051 | 38 | |
spastor | 0:fcaad0dfa051 | 39 | FrameBuffer(const FrameBuffer& other); /* Intentionally not implemented */ |
spastor | 0:fcaad0dfa051 | 40 | /** Destructor */ |
spastor | 0:fcaad0dfa051 | 41 | ~FrameBuffer(); |
spastor | 0:fcaad0dfa051 | 42 | |
spastor | 0:fcaad0dfa051 | 43 | /** get_next_free_frame returns the next free frame |
spastor | 0:fcaad0dfa051 | 44 | * |
spastor | 0:fcaad0dfa051 | 45 | * @returns a pointer to the next free frame */ |
spastor | 0:fcaad0dfa051 | 46 | ApiFrame *get_next_free_frame(); |
spastor | 0:fcaad0dfa051 | 47 | |
spastor | 0:fcaad0dfa051 | 48 | /** complete_frame sets the status of the frame to complete once the |
spastor | 0:fcaad0dfa051 | 49 | * data has been set in the buffer. |
spastor | 0:fcaad0dfa051 | 50 | * |
spastor | 0:fcaad0dfa051 | 51 | * @param pointer to the buffer we want to set as complete |
spastor | 0:fcaad0dfa051 | 52 | * @returns true on success, false otherwise |
spastor | 0:fcaad0dfa051 | 53 | */ |
spastor | 0:fcaad0dfa051 | 54 | bool complete_frame(ApiFrame *frame); |
spastor | 0:fcaad0dfa051 | 55 | |
spastor | 0:fcaad0dfa051 | 56 | /** free_frame makes the frame available to be reused in future |
spastor | 0:fcaad0dfa051 | 57 | * |
spastor | 0:fcaad0dfa051 | 58 | * @param frame to release */ |
spastor | 0:fcaad0dfa051 | 59 | bool free_frame(ApiFrame *frame); |
spastor | 0:fcaad0dfa051 | 60 | |
spastor | 0:fcaad0dfa051 | 61 | /** get_next_complete_frame_app returns the pointer to the next complete frame using _tail_app |
spastor | 0:fcaad0dfa051 | 62 | * |
spastor | 0:fcaad0dfa051 | 63 | * @returns the pointer to the selected buffer |
spastor | 0:fcaad0dfa051 | 64 | */ |
spastor | 0:fcaad0dfa051 | 65 | ApiFrame *get_next_complete_frame_app(); |
spastor | 0:fcaad0dfa051 | 66 | |
spastor | 0:fcaad0dfa051 | 67 | /** get_next_complete_frame_syncr returns the pointer to the next complete frame using _tail_syncr |
spastor | 0:fcaad0dfa051 | 68 | * |
spastor | 0:fcaad0dfa051 | 69 | * @returns the pointer to the selected buffer |
spastor | 0:fcaad0dfa051 | 70 | */ |
spastor | 0:fcaad0dfa051 | 71 | ApiFrame *get_next_complete_frame_syncr(); |
spastor | 0:fcaad0dfa051 | 72 | |
spastor | 0:fcaad0dfa051 | 73 | /** get_dropped_frames_count returns the number of dropped frames since latest call to this method |
spastor | 0:fcaad0dfa051 | 74 | * |
spastor | 0:fcaad0dfa051 | 75 | * @returns the number of dropped frames since latest call to this method |
spastor | 0:fcaad0dfa051 | 76 | */ |
spastor | 0:fcaad0dfa051 | 77 | uint32_t get_dropped_frames_count(); |
spastor | 0:fcaad0dfa051 | 78 | |
spastor | 0:fcaad0dfa051 | 79 | |
spastor | 0:fcaad0dfa051 | 80 | protected: |
spastor | 0:fcaad0dfa051 | 81 | |
spastor | 0:fcaad0dfa051 | 82 | /** frame status */ |
spastor | 0:fcaad0dfa051 | 83 | enum FrameStatus { |
spastor | 0:fcaad0dfa051 | 84 | FrameStatusFree = 0, /**< Free */ |
spastor | 0:fcaad0dfa051 | 85 | FrameStatusAssigned, /**< Assigned */ |
spastor | 0:fcaad0dfa051 | 86 | FrameStatusComplete /**< Complete */ |
spastor | 0:fcaad0dfa051 | 87 | }; |
spastor | 0:fcaad0dfa051 | 88 | |
spastor | 0:fcaad0dfa051 | 89 | /** buffer array */ |
spastor | 0:fcaad0dfa051 | 90 | buf_element_t _frm_buf[FRAME_BUFFER_SIZE]; |
spastor | 0:fcaad0dfa051 | 91 | |
spastor | 0:fcaad0dfa051 | 92 | /** head frame index */ |
spastor | 0:fcaad0dfa051 | 93 | uint8_t _head; |
spastor | 0:fcaad0dfa051 | 94 | |
spastor | 0:fcaad0dfa051 | 95 | /** tail frame index for application */ |
spastor | 0:fcaad0dfa051 | 96 | uint8_t _tail_app; |
spastor | 0:fcaad0dfa051 | 97 | |
spastor | 0:fcaad0dfa051 | 98 | /** tail frame index for syncronous operations */ |
spastor | 0:fcaad0dfa051 | 99 | uint8_t _tail_syncr; |
spastor | 0:fcaad0dfa051 | 100 | |
spastor | 0:fcaad0dfa051 | 101 | /** dropped frames */ |
spastor | 0:fcaad0dfa051 | 102 | uint32_t _dropped_frames; |
spastor | 0:fcaad0dfa051 | 103 | |
spastor | 0:fcaad0dfa051 | 104 | /** get_next_complete_frame returns the pointer to the next complete frame |
spastor | 0:fcaad0dfa051 | 105 | * |
spastor | 0:fcaad0dfa051 | 106 | * @param tail tail index to use (either _tail_app or _tail_syncr) |
spastor | 0:fcaad0dfa051 | 107 | * @returns the pointer to the selected buffer |
spastor | 0:fcaad0dfa051 | 108 | */ |
spastor | 0:fcaad0dfa051 | 109 | ApiFrame *get_next_complete_frame(uint8_t* tail); |
spastor | 0:fcaad0dfa051 | 110 | }; |
spastor | 0:fcaad0dfa051 | 111 | |
spastor | 0:fcaad0dfa051 | 112 | #endif /* __FRAME_BUFFER_H_ */ |