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

32 行
758B

  1. #include "DMAChannel.h"
  2. // The channel allocation bitmask is accessible from "C" namespace,
  3. // so C-only code can reserve DMA channels
  4. uint16_t dma_channel_allocated_mask = 0;
  5. DMAChannel::DMAChannel(uint8_t channelRequest) : TCD(*(TCD_t *)0), channel(16)
  6. {
  7. uint8_t next, ch=channelRequest;
  8. __disable_irq();
  9. while (1) {
  10. if (!(dma_channel_allocated_mask & (1 << ch))) {
  11. dma_channel_allocated_mask |= (1 << ch);
  12. __enable_irq();
  13. break;
  14. }
  15. next = (ch + 1) & 15;
  16. if (next == channelRequest) {
  17. __enable_irq();
  18. return; // no more channels available
  19. // attempts to use this object will hardfault
  20. }
  21. }
  22. channel = ch;
  23. TCD = *(TCD_t *)(0x40009000 + ch * 32);
  24. SIM_SCGC7 |= SIM_SCGC7_DMA;
  25. SIM_SCGC6 |= SIM_SCGC6_DMAMUX;
  26. DMA_CR = 0;
  27. }