Guest User

Untitled

a guest
Apr 22nd, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.03 KB | None | 0 0
  1. typedef REG unsigned int;
  2. REG* dma1Ctrl = ..., dma2Ctrl = ...;
  3. REG* dma1Status = ..., dma2Status = ...;
  4. REG* dma1Address = ..., dma2Address = ...;
  5. REG* dma1Count = ..., dma2Count = ...;
  6.  
  7. struct IORequest{
  8.     REG* buffer;
  9.     unsigned size;
  10.     int status;
  11.     IORequest* next;
  12. }
  13. IORequest ioHead;
  14.  
  15. static IORequest* ioPending1 = null, ioPending2 = null;
  16.  
  17. void transfer() {
  18.     if (!ioHead && ioPending1!=null) {
  19.         ioPending1 = ioHead;
  20.         startDMA1();
  21.         ioHead = ioHead->next;
  22.     }
  23.     if (!ioHead && ioPending2!=null){
  24.         ioPending2 = ioHead;
  25.         startDMA2();
  26.         ioHead = ioHead->next;
  27.     }
  28. }
  29.  
  30. void startDMA1() {
  31.     *dma1Address = ioPending->buffer;
  32.     *dma1Count = ioPending->size;
  33.     *dma1Ctrl = 1;
  34. }
  35.  
  36. void startDMA2() {
  37.     *dma2Address = ioPending->buffer;
  38.     *dma2Count = ioPending->size;
  39.     *dma2Ctrl = 1;
  40. }
  41.  
  42. interrupt void dmaInterrupt() {
  43.     if (*dma1Status & 1) {
  44.         ioPending1->status = *dma1Status;
  45.         ioPending1 = null;
  46.         transfer();
  47.     }
  48.     if (*dma2Status & 1) {
  49.         ioPending2->status = *dma2Status;
  50.         ioPending2 = null;
  51.         transfer();
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment