u16 read16(const u32 address) { switch (address >> 24) { case 8: case 9: case 10: case 11: case 12: if (rtcIsEnabled() && (address == 0x80000c4 || address == 0x80000c6 || address == 0x80000c8)) return rtcRead(address); else return READ16LE(((u16 *)&rom[address & 0x1FFFFFE])); break; case 13: if (game.hasEEPROM()) return eepromRead(address); break; case 14: if (game.hasSRAM()) return sramRead(address); else if (game.hasFlash()) return flashRead(address); break; default: break; } return 0; }
time_t rtcGetEpochSeconds (unsigned int *milliseconds) { struct tm tm; rtcRead (&tm, milliseconds); return mktime (&tm); }
/* get current time */ EXPORT ER cdGetDateTime(void *date_tim) { DATE_TIM dt; INT sec; /* get current time */ do { dt.d_sec = rtcRead(rxSEC); dt.d_min = rtcRead(rxMIN); dt.d_hour = rtcRead(rxHOUR); dt.d_day = rtcRead(rxDAY); dt.d_month = rtcRead(rxMONTH); dt.d_year = rtcRead(rxYEAR); sec = rtcRead(rxSEC); } while (sec != dt.d_sec); /* make sure data is read consistently in a whole second */ dt.d_wday = 0; // not supported (0 - pretend it is sunday) dt.d_days = 0; // not used dt.d_week = 0; // not used dt.d_year = BCDtoBIN(dt.d_year) + 100; /* 00-99 -> 2000-2099 */ dt.d_month = BCDtoBIN(dt.d_month); dt.d_wday = BCDtoBIN(dt.d_wday); dt.d_day = BCDtoBIN(dt.d_day); dt.d_hour = BCDtoBIN(dt.d_hour); dt.d_min = BCDtoBIN(dt.d_min); dt.d_sec = BCDtoBIN(dt.d_sec); *((DATE_TIM *)date_tim) = dt; return E_OK; }
/* FUNCION PRINCIPAL, PUNTO DE ENTRADA AL PROGRAMA LUEGO DE RESET. */ int main(void){ /* ------------- INICIALIZACIONES ------------- */ /* Inicializar la placa */ boardConfig(); /* Inicializar el conteo de Ticks con resolución de 1ms, sin tickHook */ tickConfig( 1, 0 ); /* Inicializar DigitalIO */ digitalConfig( 0, ENABLE_DIGITAL_IO ); /* Configuración de pines de entrada para Teclas de la CIAA-NXP */ digitalConfig( TEC1, INPUT ); digitalConfig( TEC2, INPUT ); digitalConfig( TEC3, INPUT ); digitalConfig( TEC4, INPUT ); /* Configuración de pines de salida para Leds de la CIAA-NXP */ digitalConfig( LEDR, OUTPUT ); digitalConfig( LEDG, OUTPUT ); digitalConfig( LEDB, OUTPUT ); digitalConfig( LED1, OUTPUT ); digitalConfig( LED2, OUTPUT ); digitalConfig( LED3, OUTPUT ); /* Inicializar UART_USB a 115200 baudios */ uartConfig( UART_USB, 115200 ); /* Estructura RTC */ RTC_t rtc; rtc.year = 2016; rtc.month = 7; rtc.mday = 3; rtc.wday = 1; rtc.hour = 13; rtc.min = 17; rtc.sec= 0; bool_t val = 0; uint8_t i = 0; /* Inicializar RTC */ val = rtcConfig( &rtc ); delay_t delay1s; delayConfig( &delay1s, 1000 ); delay(2000); for( i=0; i<10; i++ ){ /* Leer fecha y hora */ val = rtcRead( &rtc ); /* Mostrar fecha y hora en formato "DD/MM/YYYY, HH:MM:SS" */ showDateAndTime( &rtc ); delay(1000); } rtc.year = 2016; rtc.month = 7; rtc.mday = 3; rtc.wday = 1; rtc.hour = 14; rtc.min = 30; rtc.sec= 0; /* Establecer fecha y hora */ val = rtcWrite( &rtc ); /* ------------- REPETIR POR SIEMPRE ------------- */ while(1) { if( delayRead( &delay1s ) ){ /* Leer fecha y hora */ val = rtcRead( &rtc ); /* Mostrar fecha y hora en formato "DD/MM/YYYY, HH:MM:SS" */ showDateAndTime( &rtc ); } } /* NO DEBE LLEGAR NUNCA AQUI, debido a que a este programa no es llamado por ningun S.O. */ return 0 ; }