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.
Fork of mbed-os-example-circular-buffer by
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
--- /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*
--- /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.
Binary file img/uvision.png has changed
--- /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;
+
+}
--- /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
