Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3fe99d4

Browse files
authoredOct 19, 2020
Fix circular buffer to overflow properly (#1163)
* Bug fix, the instance comparision was wrong * Update circular buffer to take into account the number of channels being sampled * Update cb_init function, remove floating operations from the microblaze. Fix the computation of the log_capacity * Fix variable name * Add head overflow in the circular buffer structure to allow reseting it everytime it's initialized * Remove overflow bit * Enhance class to support a single channel * Update changelog * Modify MAX_SAMPLES to be multiple of 1, 2 and 3 channels * Fix comments * Include 'raw' APIs calling for backwards compatibility
1 parent 8e10b3b commit 3fe99d4

File tree

17 files changed

+163
-262
lines changed

17 files changed

+163
-262
lines changed
 

‎boards/Pynq-Z1/base/notebooks/arduino/arduino_analog.ipynb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
{
6767
"data": {
6868
"text/plain": [
69-
"[0.6403, 0.6848]"
69+
"array([0.6403, 0.6848])"
7070
]
7171
},
7272
"execution_count": 3,
@@ -106,7 +106,7 @@
106106
}
107107
],
108108
"source": [
109-
"analog1.read_raw()[0]"
109+
"analog1.read('raw')[0]"
110110
]
111111
},
112112
{
@@ -196,6 +196,8 @@
196196
" 'bs', label=\"Y-axis of joystick\")\n",
197197
"plt.title('Arduino Analog Voltage Log')\n",
198198
"plt.axis([0, len(log1[0]), 0.0, 3.3])\n",
199+
"plt.xlabel('Sample number')\n",
200+
"plt.ylabel('Voltage')\n",
199201
"plt.legend(loc=4,bbox_to_anchor=(1, -0.3),\n",
200202
" ncol=2, borderaxespad=0.,\n",
201203
" handler_map={line1: HandlerLine2D(numpoints=1),\n",
@@ -294,6 +296,8 @@
294296
" 'g^', label=\"potentiometer\")\n",
295297
"plt.title('Arduino Analog Voltage Log')\n",
296298
"plt.axis([0, len(log2[0]), 0.0, 3.3])\n",
299+
"plt.xlabel('Sample number')\n",
300+
"plt.ylabel('Voltage')\n",
297301
"plt.legend(loc=4,bbox_to_anchor=(1, -0.3),\n",
298302
" ncol=2, borderaxespad=0.,\n",
299303
" handler_map={line1: HandlerLine2D(numpoints=1),\n",

‎boards/sw_repo/pynqmb/src/circular_buffer.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
* 1.00 yrq 01/09/18 release
4747
* 1.01 mrn 09/28/20 Bug fix, the head of the circular
4848
* buffer did not overflow
49+
* 1.02 mrn 10/11/20 Update initialize function. Bug fix: move the head
50+
* according to the number of channels.
4951
*
5052
* </pre>
5153
*
@@ -54,13 +56,14 @@
5456

5557
/************************** Function Definitions ***************************/
5658
int cb_init(circular_buffer *cb, volatile u32* log_start_addr,
57-
size_t capacity, size_t sz){
59+
size_t capacity, size_t sz, size_t channels){
5860
cb->buffer = (volatile char*) log_start_addr;
5961
if(cb->buffer == NULL)
6062
return -1;
6163
cb->buffer_end = (char *)cb->buffer + capacity * sz;
6264
cb->capacity = capacity;
6365
cb->sz = sz;
66+
cb->channels = channels;
6467
cb->head = cb->buffer;
6568
cb->tail = cb->buffer;
6669

@@ -106,11 +109,11 @@ void cb_push_incr_ptrs(circular_buffer *cb){
106109
cb->tail = cb->buffer;
107110

108111
if (cb->tail == cb->head) {
109-
cb->head = (char*)cb->head + cb->sz;
112+
cb->head = (char*)cb->head + cb->sz * cb->channels;
113+
// Move the head pointer to buffer start
110114
if (cb->head >= cb->buffer_end)
111115
cb->head = cb->buffer;
112116
}
113-
114117
// update mailbox head and tail
115118
MAILBOX_DATA(2) = (u32) cb->head;
116119
MAILBOX_DATA(3) = (u32) cb->tail;

‎boards/sw_repo/pynqmb/src/circular_buffer.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
* Ver Who Date Changes
4545
* ----- --- ------- -----------------------------------------------
4646
* 1.00 yrq 01/09/18 release
47+
* 1.01 mrn 10/11/18 Include channels in the init function.
4748
*
4849
* </pre>
4950
*
@@ -72,7 +73,7 @@ typedef struct circular_buffer
7273
volatile void *buffer; // data buffer
7374
void *buffer_end; // end of data buffer
7475
size_t capacity; // maximum number of items in the buffer
75-
size_t count; // number of items in the buffer
76+
size_t channels; // number of channels in the buffer
7677
size_t sz; // size of each item in the buffer
7778
volatile void *head; // pointer to head
7879
volatile void *tail; // pointer to tail
@@ -81,7 +82,7 @@ typedef struct circular_buffer
8182
circular_buffer circular_log;
8283

8384
int cb_init(circular_buffer *cb, volatile u32* log_start_addr,
84-
size_t capacity, size_t sz);
85+
size_t capacity, size_t sz, size_t channels);
8586
void cb_push_back(circular_buffer *cb, const void *item);
8687
void cb_push_back_float(circular_buffer *cb, const float *item);
8788
void cb_push_incr_ptrs(circular_buffer *cb);

‎docs/source/overlay_design_methodology/pynq_microblaze_subsystem.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,8 @@ Remaining code:
803803
804804
case READ_AND_LOG:
805805
// initialize logging variables, reset cmd
806-
cb_init(&circular_log, LOG_BASE_ADDRESS, LOG_CAPACITY, LOG_ITEM_SIZE);
806+
cb_init(&circular_log,
807+
LOG_BASE_ADDRESS, LOG_CAPACITY, LOG_ITEM_SIZE, 1);
807808
delay = MAILBOX_DATA(1);
808809
MAILBOX_CMD_ADDR = 0x0;
809810
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.