Go Down

Topic: Creating Circular Buffer lib (Read 5 times) previous topic - next topic

jraskell

ditto for your usage of queueDuplicateExists as well.

nick_p

Oops - thanks for pointing those out.

I had already corrected those mistakes but the code was very messy because I was trying different things so I pasted an earlier 'clean' version.

My main concern is with the functions that add & read to/from the queue -- those currently don't work I don't think. Has anybody spotted the mistake in those?

nick_p

Actually, I'm having a little trouble passing on arguments to an function called inside another one...

Code: [Select]
void queueAdd(queue *q, char *task) {
  if (queueDuplicateExists) return;
  if (queueIsFull) return;   
  else {
      int tail = (q->head + q->count) % q->size;
      q->tasks[tail] = *task;
      ++ q->count; } }


How can I correctly pass the queue to the test functions inside the queueAdd function?

bperrybap


Bill, could you recommend any debug tools? I have Linux at home and Windows at work. No Mac though.

For debugging I write the code on a platform with the best debug tools.
It is worth the time to get source level debugging up and working.

Currently I use linux to get the logic debugged then move it to the AVR.
I use command-line gdb on linux for source level debugging.
gdb is nice because it works on pretty much everything including
embedded environments once you have the proper gdb interfaces set up.
I like gdb because it  means only one environment to learn. (been using it for about 25 years)
There are some GUI wrappers and full IDEs like eclipse but I still use the command-line
as the command-line works the same everywhere.

Quote

From what I understand from your post, I will need to consider a trade-off between using a handful of big functions (slower execution), or to use lots of small functions (lots of memory).

No. The trade off I was referring to was between RAM usage for Q entries
and function call latency. i.e. the amount of time it takes to figure out
what function to call once the entry is pulled from the Q not the functions themselves.
The code you have now is using a case statement to figure out what function to call based on a "char" token.
As the number of functions increases, this method becomes less efficient, requiring more code and taking more time.
If the Q entries contained a function pointer instead, then there is no additional code to figure out what function
to call, and the code size and latency is a constant no matter how many functions are being used.
In the situations where I needed to do this in the past,
I also needed some context information, so my Q entries contained a function pointer and an argument.
Each function then received a single argument.
This allows doing things like scheduling the same function but with a different argument to be able to deal with say
multiple instances of something.
It would use the Q mechanism to Q tasks from the ISRs.
I've also had systems that had multiple Qs (usually 2) so that there could be a high priority Q and a low priority Q.

When using this mechanism, the idle loop did nothing more than process the Qs.
Everything else was scheduled through the Qs.
Essentially it is callback Q. And the idle loop runs the Q(s) and processes
all the callbacks.

--- bill

PeterH


Actually, I'm having a little trouble passing on arguments to an function called inside another one...

Code: [Select]
void queueAdd(queue *q, char *task) {
  if (queueDuplicateExists) return;
  if (queueIsFull) return;   
  else {
      int tail = (q->head + q->count) % q->size;
      q->tasks[tail] = *task;
      ++ q->count; } }


How can I correctly pass the queue to the test functions inside the queueAdd function?


If you're trying to call a function or method, you need to put parentheses () after the function/method name.

The logic you have there to check for duplicates and queue full conditions and increment pointers and so on would IMO be much better encapsulated into a CircularBuffer class rather than as a struct with separate independent functions.
I only provide help via the forum - please do not contact me for private consultancy.

Go Up