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

PUTC.cpp 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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::__putc(int c, bool block) {
  24. // If no buffer is in use fall back to standard TX FIFO usage.
  25. // Note, we must block in this case and ignore bool "block"
  26. // so as to maintain compat with Mbed Serial.
  27. if (buffer[TxIrq] == (char *)NULL || buffer_size[TxIrq] == 0) {
  28. while (! MODSERIAL_THR_HAS_SPACE) ; // Wait for space in the TX FIFO.
  29. _THR = (uint32_t)c;
  30. return 0;
  31. }
  32. if ( MODSERIAL_THR_HAS_SPACE && MODSERIAL_TX_BUFFER_EMPTY && dmaSendChannel == -1 ) {
  33. _THR = (uint32_t)c;
  34. }
  35. else {
  36. if (block) {
  37. uint32_t ier = _IER; _IER = 1;
  38. while ( MODSERIAL_TX_BUFFER_FULL ) { // Blocks!
  39. // If putc() is called from an ISR then we are stuffed
  40. // because in an ISR no bytes from the TX buffer will
  41. // get transferred to teh TX FIFOs while we block here.
  42. // So, to work around this, instead of sitting in a
  43. // loop waiting for space in the TX buffer (which will
  44. // never happen in IRQ context), check to see if the
  45. // TX FIFO has space available to move bytes from the
  46. // TX buffer to TX FIFO to make space. The easiest way
  47. // to do this is to poll the isr_tx() function while we
  48. // are blocking.
  49. isr_tx(false);
  50. }
  51. _IER = ier;
  52. }
  53. else if( MODSERIAL_TX_BUFFER_FULL ) {
  54. buffer_overflow[TxIrq] = c; // Oh dear, no room in buffer.
  55. _isr[TxOvIrq].call(&this->callbackInfo);
  56. return -1;
  57. }
  58. _IER &= ~2;
  59. buffer[TxIrq][buffer_in[TxIrq]] = c;
  60. __disable_irq();
  61. buffer_count[TxIrq]++;
  62. __enable_irq();
  63. buffer_in[TxIrq]++;
  64. if (buffer_in[TxIrq] >= buffer_size[TxIrq]) {
  65. buffer_in[TxIrq] = 0;
  66. }
  67. _IER |= 2;
  68. }
  69. return 0;
  70. }
  71. } // namespace AjK ends