Deepika Bhavnani
/
mbed-os-example-circular-buffer
Contents of data stream are pushed and popped to demonstrate usage of CircularBuffer API's.
Revision 0:6c43979d0645, committed 2017-10-23
- Comitter:
- deepikabhavnani
- Date:
- Mon Oct 23 15:49:13 2017 +0000
- Commit message:
- Inital copy of circular buffer example
Changed in this revision
diff -r 000000000000 -r 6c43979d0645 .gitignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.gitignore Mon Oct 23 15:49:13 2017 +0000 @@ -0,0 +1,4 @@ +.build +.mbed +projectfiles +*.py*
diff -r 000000000000 -r 6c43979d0645 README.md --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.md Mon Oct 23 15:49:13 2017 +0000 @@ -0,0 +1,5 @@ +### Getting started with the CircularBuffer API ### + +CircularBuffer Example +This application demonstrates usage of CircularBuffer API's. Contents of data +stream are pushed till buffer is full, and popped back till buffer is empty.
diff -r 000000000000 -r 6c43979d0645 img/uvision.png Binary file img/uvision.png has changed
diff -r 000000000000 -r 6c43979d0645 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Oct 23 15:49:13 2017 +0000 @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2016-2016, ARM Limited, All Rights Reserved + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "mbed.h" +#include "platform/CircularBuffer.h" + +#define BUF_SIZE 10 + +CircularBuffer<char, BUF_SIZE> buf; +char data_stream[] = "DataToBeAddedToBuffer"; + +int main() +{ + uint32_t bytes_written = 0; + + while (!buf.full()) { + buf.push(data_stream[bytes_written++]); + } + + printf("Circular buffer is full: \"%s\" or empty: \"%s\" \n", + (buf.full()? "true":"false"), + (buf.empty()? "true":"false") ); + printf ("Bytes written %d \n", bytes_written); + + // If buffer is full, contents will be over-written + buf.push(data_stream[bytes_written++]); + + char data; + printf ("Buffer contents: "); + while (!buf.empty()) { + buf.pop(data); + printf("%c", data); + } + printf("\n"); + + printf("Circular buffer is full: \"%s\" or empty: \"%s\" \n", + (buf.full()? "true":"false"), + (buf.empty()? "true":"false") ); + + return 0; + +}
diff -r 000000000000 -r 6c43979d0645 mbed-os.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Mon Oct 23 15:49:13 2017 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#6e0d01cd13e8aca7bf4d697c3699ec9225386881