Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. #include "pxa255_RTC.h"
  2. #include "mem.h"
  3.  
  4.  
  5.  
  6. void pxa255rtcPrvUpdate(Pxa255rtc* rtc){
  7.        
  8.         UInt32 time = rtcCurTime();
  9.        
  10.         if(rtc->lastSeenTime != time){  //do not triger alarm more than once per second please
  11.                
  12.                 if((rtc->RTSR & 0x4) && (time + rtc->RCNR_offset == rtc->RTAR)){        //check alarm
  13.                         rtc->RTSR |= 1;
  14.                 }
  15.                 if(rtc->RTSR & 0x8){                                                    //send HZ interrupt
  16.                         rtc->RTSR |= 2;
  17.                 }
  18.         }
  19.         pxa255icInt(rtc->ic, PXA255_I_RTC_ALM, (rtc->RTSR & 1) != 0);
  20.         pxa255icInt(rtc->ic, PXA255_I_RTC_HZ, (rtc->RTSR & 2) != 0);
  21. }
  22.  
  23. static Boolean pxa255rtcPrvMemAccessF(void* userData, UInt32 pa, UInt8 size, Boolean write, void* buf){
  24.  
  25.         Pxa255rtc* rtc = userData;
  26.         UInt32 val = 0;
  27.        
  28.         if(size != 4) {
  29.                 err_str(__FILE__ ": Unexpected ");
  30.         //      err_str(write ? "write" : "read");
  31.         //      err_str(" of ");
  32.         //      err_dec(size);
  33.         //      err_str(" bytes to 0x");
  34.         //      err_hex(pa);
  35.         //      err_str("\r\n");
  36.                 return true;            //we do not support non-word accesses
  37.         }
  38.        
  39.         pa = (pa - PXA255_RTC_BASE) >> 2;
  40.        
  41.         if(write){
  42.                 val = *(UInt32*)buf;
  43.                
  44.                 switch(pa){
  45.                         case 0:
  46.                                 rtc->RCNR_offset = rtcCurTime() - val;
  47.                                 break;
  48.                        
  49.                         case 1:
  50.                                 rtc->RTAR = val;
  51.                                 pxa255rtcPrvUpdate(rtc);
  52.                                 break;
  53.                        
  54.                         case 2:
  55.                                 rtc->RTSR = (val &~ 3UL) | ((rtc->RTSR &~ val) & 3UL);
  56.                                 pxa255rtcPrvUpdate(rtc);
  57.                                 break;
  58.                        
  59.                         case 3:
  60.                                 if(!(rtc->RTTR & 0x80000000UL)) rtc->RTTR = val;
  61.                                 break;
  62.                 }
  63.         }
  64.         else{
  65.                 switch(pa){
  66.                         case 0:
  67.                                 val = rtcCurTime() - rtc->RCNR_offset;
  68.                                 break;
  69.                        
  70.                         case 1:
  71.                                 val = rtc->RTAR;
  72.                                 break;
  73.                        
  74.                         case 2:
  75.                                 val = rtc->RTSR;
  76.                                 break;
  77.                        
  78.                         case 3:
  79.                                 val = rtc->RTTR;
  80.                                 break;
  81.                 }
  82.                 *(UInt32*)buf = val;
  83.         }
  84.        
  85.         return true;
  86. }
  87.  
  88.  
  89. Boolean pxa255rtcInit(Pxa255rtc* rtc, ArmMem* physMem, Pxa255ic* ic){
  90.        
  91.         __mem_zero(rtc, sizeof(Pxa255rtc));
  92.         rtc->ic = ic;
  93.         rtc->RCNR_offset = 0;
  94.         rtc->RTTR = 0x7FFF;     //nice default value
  95.         rtc->lastSeenTime = rtcCurTime();
  96.         return memRegionAdd(physMem, PXA255_RTC_BASE, PXA255_RTC_SIZE, pxa255rtcPrvMemAccessF, rtc);
  97. }
  98.  
  99. void pxa255rtcUpdate(Pxa255rtc* rtc){
  100.         pxa255rtcPrvUpdate(rtc);
  101. }
  102.