テスト用のあれこれ共用フォルダ
修订版 | 36a744c12ea00a90b1ccf8e169d76a1d6edcb11a (tree) |
---|---|
时间 | 2018-02-28 22:19:13 |
作者 | takemasa <suikan@user...> |
Commiter | takemasa |
Correct initialize processing.
@@ -19,6 +19,13 @@ BaseFifo::BaseFifo(unsigned int buffer_size): | ||
19 | 19 | MURASAKI_ASSERT(size_of_buffer_ != 0); // very explicit check |
20 | 20 | MURASAKI_ASSERT(buffer_ != nullptr); |
21 | 21 | |
22 | + // set both pointer same value ( empty buffer ). | |
23 | + tail_ = head_ = 0; | |
24 | + | |
25 | + // Clean up buffer. | |
26 | + // This is essential to outptu clear data when ReWind() is called at very initial stage. | |
27 | + ::memset(buffer_, ' ', size_of_buffer_); | |
28 | + | |
22 | 29 | } |
23 | 30 | |
24 | 31 |
@@ -58,7 +65,7 @@ unsigned int BaseFifo::Put(uint8_t const data[], unsigned int size) | ||
58 | 65 | |
59 | 66 | // wrap around the head index; |
60 | 67 | if (head_ >= size_of_buffer_) |
61 | - head_ = 0; | |
68 | + head_ -= size_of_buffer_; | |
62 | 69 | } // end for loop. |
63 | 70 | |
64 | 71 | return copy_size; |
@@ -89,7 +96,7 @@ unsigned int BaseFifo::Get(uint8_t data[], unsigned int size) | ||
89 | 96 | |
90 | 97 | // if tail_ reaches the end, wrap around. |
91 | 98 | if (tail_ >= size_of_buffer_) |
92 | - tail_ = 0; | |
99 | + head_ -= size_of_buffer_; | |
93 | 100 | } |
94 | 101 | |
95 | 102 |
@@ -103,7 +110,7 @@ void BaseFifo::ReWind() | ||
103 | 110 | |
104 | 111 | // wrap arround; |
105 | 112 | if (tail_ >= size_of_buffer_) |
106 | - tail_ = 0; | |
113 | + head_ -= size_of_buffer_; | |
107 | 114 | } |
108 | 115 | |
109 | 116 | } /* namespace murasaki */ |