IM920地温観測システム CQ 2017ARMセミナー用サンプルプログラム

Dependencies:   C027_Support_ForIM920

Fork of C027_SupportTest by u-blox

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers RingBuf.h Source File

RingBuf.h

00001 #if !defined(__RINGBUF_H__)
00002 #define __RINGBUF_H__
00003 #include "mbed.h"
00004 
00005 
00006 /**
00007 * プロトンデータとタイムスタンプを保持する
00008 *
00009 * RingBuf classで使う
00010 *
00011 */
00012 typedef struct {
00013     int sn;
00014     int ad[3]; // LSB
00015 } RingBufType;
00016 
00017 /**
00018 * プロトンデータとタイムスタンプを保持するリングバッファclass
00019 *
00020 */
00021 class RingBuf {
00022 public:
00023     RingBuf(int size);
00024     ~RingBuf();
00025     /**
00026     * リングバッファにデータを1つpush
00027     * @param *d データ構造体へのpinter
00028     */
00029     void push(RingBufType *d);
00030     /**
00031     * リングバッファからデータを1つpop
00032     * @return データ構造体へのpointerを返す。データが無い時はNULLを返す。
00033     */
00034     RingBufType* pop(void);
00035     /**
00036     * バッファ内にある読み出し可能なデータ数を返す
00037     */
00038     int len_get(void);
00039     /**
00040     * バッファ全体のサイズを返す
00041     */
00042     int size_get(void);
00043     /**
00044     * バッファをクリアする
00045     */
00046     void clear();
00047     /**
00048     * 最新のデータ位置
00049     */
00050     volatile int latest;
00051     /**
00052     * リングバッファから指定位置のデータを1得る
00053     * @return データ構造体へのpointerを返す。データが無い時はNULLを返す。
00054     */
00055     RingBufType* peek(int p);
00056 private:
00057     int size;
00058     volatile int wp;
00059     volatile int rp;
00060     RingBufType *buf;
00061 };
00062 
00063 #endif