View previous topic :: View next topic |
Author |
Message |
qwwe
Joined: 17 Sep 2017 Posts: 59
|
|
Posted: Tue Oct 03, 2017 10:22 am |
|
|
Hello,
Now that I'm in the sisr example.
I wrote the program, I want to know how to clear the buffer we defined for the one at the beginning of the program.
To wastes in memory.
Such as arrays where once we put the null character to clear the garbage. |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1315
|
|
Posted: Tue Oct 03, 2017 11:12 am |
|
|
Depends on what you mean by clear the buffer. Generally to clear it from a buffer perspective, you just do
while(bkbhit){ bgetc(); }
And that reads out all the data resetting the buffer to empty. It doesn't actually put nulls anywhere.
If you actually want to put values in the buffer as well as set it to empty, then you need to:
1. disable the interrupt so you can't put received data on
2. do a for loop through the buffer, setting each array element to the value of your choosing
3. ensure that next_in = next_out to reset the buffer to empty
4. re-enable interrupts |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19215
|
|
Posted: Wed Oct 04, 2017 12:43 am |
|
|
Or (of course), to just reset the buffer so it is seen as having no data, with the minimum instructions, just use:
Code: |
disable_interrupts(GLOBAL);
next_in=next_out;
enable_interrupts(GLOBAL);
|
bkbkit will then say there is no data in the buffer. |
|
|
|