Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef REG unsigned int;
- REG* dma1Ctrl = ..., dma2Ctrl = ...;
- REG* dma1Status = ..., dma2Status = ...;
- REG* dma1Address = ..., dma2Address = ...;
- REG* dma1Count = ..., dma2Count = ...;
- struct IORequest{
- REG* buffer;
- unsigned size;
- int status;
- IORequest* next;
- }
- IORequest ioHead;
- static IORequest* ioPending1 = null, ioPending2 = null;
- void transfer() {
- if (!ioHead && ioPending1!=null) {
- ioPending1 = ioHead;
- startDMA1();
- ioHead = ioHead->next;
- }
- if (!ioHead && ioPending2!=null){
- ioPending2 = ioHead;
- startDMA2();
- ioHead = ioHead->next;
- }
- }
- void startDMA1() {
- *dma1Address = ioPending->buffer;
- *dma1Count = ioPending->size;
- *dma1Ctrl = 1;
- }
- void startDMA2() {
- *dma2Address = ioPending->buffer;
- *dma2Count = ioPending->size;
- *dma2Ctrl = 1;
- }
- interrupt void dmaInterrupt() {
- if (*dma1Status & 1) {
- ioPending1->status = *dma1Status;
- ioPending1 = null;
- transfer();
- }
- if (*dma2Status & 1) {
- ioPending2->status = *dma2Status;
- ioPending2 = null;
- transfer();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment