Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2013
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.54 KB | None | 0 0
  1. extern unsigned int GET32(unsigned int);
  2. extern void PUT32(unsigned int, unsigned int);
  3.  
  4. #include "gpio.h"
  5. #include "timer.h"
  6. #define MAILBOX_FULL 0x80000000
  7. #define MAILBOX_EMPTY 0x40000000
  8. #define MAILBOX0READ 0x2000b880
  9. #define MAILBOX0STATUS 0x2000b898
  10. #define MAILBOX0WRITE 0x2000b8a0
  11.  
  12. int cmain(void)
  13. {
  14.     LedInit();
  15.    
  16.     // 1. Fill out the FB request
  17.     volatile unsigned int fbInfo[256] __attribute__ ((aligned (16)));
  18.     fbInfo[0] = 1024;   // Physical Width
  19.     fbInfo[1] = 768;    // Physical Height
  20.     fbInfo[2] = 1024;   // Virtual Width
  21.     fbInfo[3] = 768;    // Virtual Height
  22.     fbInfo[4] = 0;      // Pitch (will be filled in my GPU)
  23.     fbInfo[5] = 16;     // Depth
  24.     fbInfo[6] = 0;      // X offset
  25.     fbInfo[7] = 0;      // Y offset
  26.     fbInfo[8] = 0;      // FB pointer (will be filled in my GPU)
  27.     fbInfo[9] = 0;      // FB Size (will be filled in my GPU)
  28.    
  29.     // 2. Send struct to GPU
  30.     while(GET32(MAILBOX0STATUS) & MAILBOX_FULL){ } // Wait for mailbox to become available 
  31.     PUT32(MAILBOX0WRITE, (((unsigned int)&fbInfo + 0x40000000) << 4) | 1); // Offset struct addr to prevent caching
  32.    
  33.     // 3. Read Response
  34.     unsigned int data = 0;
  35.     while(1)
  36.     {
  37.         while(GET32(MAILBOX0STATUS) & MAILBOX_EMPTY){} // Wait for mail
  38.         data = GET32(MAILBOX0READ);
  39.        
  40.         if((data &0xF) == 1) // Data on channel 1
  41.         {
  42.             data = data >> 4;
  43.             break;
  44.         }
  45.     }
  46.    
  47.     // 4. Check if we got a valid FB response
  48.     if(fbInfo[8] == 0)
  49.     {
  50.         LedOn(); // We did not get a pointer :-(
  51.         while(1);
  52.     }
  53.     else
  54.     {
  55.         while(1)
  56.         {
  57.             LedOff();   // All is well 
  58.             Wait(1);       
  59.             LedOn();       
  60.             Wait(1);
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement