Naze32 clone with Frysky receiver
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

GETC.cpp 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. Copyright (c) 2010 Andy Kirkham
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #include "MODSERIAL.h"
  20. #include "MACROS.h"
  21. namespace AjK {
  22. int
  23. MODSERIAL::__getc(bool block)
  24. {
  25. // If no buffer is in use fall back to standard RX FIFO usage.
  26. // Note, we must block in this case and ignore bool "block"
  27. // so as to maintain compat with Mbed Serial.
  28. if (buffer_size[RxIrq] == 0 || buffer[RxIrq] == (char *)NULL) {
  29. while(! MODSERIAL_RBR_HAS_DATA ) ;
  30. return (int)(_RBR & 0xFF);
  31. }
  32. if (block) { while ( MODSERIAL_RX_BUFFER_EMPTY ) ; } // Blocks.
  33. else if ( MODSERIAL_RX_BUFFER_EMPTY ) return -1;
  34. int c = buffer[RxIrq][buffer_out[RxIrq]];
  35. buffer_out[RxIrq]++;
  36. if (buffer_out[RxIrq] >= buffer_size[RxIrq]) {
  37. buffer_out[RxIrq] = 0;
  38. }
  39. // If we have made space in the RX Buffer then copy over
  40. // any characters in the RX FIFO that my reside there.
  41. // Temporarily disable the RX IRQ so that we do not re-enter
  42. // it under interrupts.
  43. if ( ! MODSERIAL_RX_BUFFER_FULL ) {
  44. uint32_t ier = _IER;
  45. _IER &= ~(1UL << 0);
  46. isr_rx();
  47. _IER = ier;
  48. }
  49. __disable_irq();
  50. buffer_count[RxIrq]--;
  51. __enable_irq();
  52. return c;
  53. }
  54. } // namespace AjK ends