/** * \brief Attaches to a realtime clock slave device on \a bus. * * If \a oneHzPin is not 255, then it indicates a digital input pin * that is connected to the 1 Hz square wave output on the realtime clock. * This input is used by hasUpdates() to determine if the time information * has changed in a non-trivial manner. * * If you wish to use enableAlarmInterrupts(), then \a oneHzPin must be 255. * * \sa hasUpdates(), enableAlarmInterrupts() */ DS3232RTC::DS3232RTC(I2CMaster &bus, uint8_t oneHzPin) : _bus(&bus) , _oneHzPin(oneHzPin) , prevOneHz(false) , _isRealTime(true) , alarmInterrupts(false) { // Probe the device and configure it for our use. _bus->startWrite(DS3232_I2C_ADDRESS); _bus->write(DS3232_CONTROL); if (_bus->startRead(DS3232_I2C_ADDRESS, 1)) { uint8_t value = _bus->read() & DS3232_CONV; if (oneHzPin != 255) value |= DS3232_BBSQW | DS3232_RS_1HZ; _bus->startWrite(DS3232_I2C_ADDRESS); _bus->write(DS3232_CONTROL); _bus->write(value); _bus->write(DS3232_CRATE_64); _bus->endWrite(); } else { // Did not get an acknowledgement from the RTC chip. _isRealTime = false; } // Configure the 1 Hz square wave pin if required. if (oneHzPin != 255 && _isRealTime) { pinMode(oneHzPin, INPUT); digitalWrite(oneHzPin, HIGH); } // Initialize the alarms in the RTC chip's NVRAM. if (_isRealTime) initAlarms(); }
int main(void) { //audioInit(); //setVolume(254); WatchDogDisable(); //disable watchdog NutDelay(100); //wait for it to disable SysInitIO(); //initialise input and output SPIinit(); //initialise SPI-registers (speed, mode) LedInit(); //initialise led initLCD(); //initialise lcd Uart0DriverInit(); //initialise Universal asynchronous receiver/transmitter Uart0DriverStart(); //start Uart printf("\n\n\n\nHardware initialization done\n\n"); LogInit(); //initialise ability to log CardInit(); //initialise cardreader printf("\n----------------------------------------------START OF PROGRAM------------------------------------------------------------\n"); if (NutSegBufInit(8192) == 0) { puts("NutSegBufInit: Fatal error"); } /* * Initialize the MP3 decoder hardware. */ if (VsPlayerInit() || VsPlayerReset(0)) { puts("VsPlayer: Fatal error"); } if(X12Init() == -1){ printf("error initializing RTC"); //initialise X12RTC } tm gmt; if (X12RtcGetClock(&gmt) == 0) { LogMsg_P(LOG_INFO, PSTR("local storage time [%02d:%02d:%02d] (in RTC)\n"), gmt.tm_hour, gmt.tm_min, gmt.tm_sec); } if (At45dbInit() == AT45DB041B) { // ...... } RcInit(); //Initialise the Remote Control module KbInit(); //Initialise keyboard initMenu(); //Initialise menu NutThreadCreate("Bh", ButtonHandlerThread, NULL, 512); //create thread to handle button presses printf("\nInitialization done.\n"); initAlarms(); SysControlMainBeat(ON); //enable 4.4 msecs heartbeat interrupt printf("Heartbeat on.\n"); NutThreadSetPriority(1); //Increase our priority so we can feed the watchdog. sei(); //enable global interrupts NutThreadCreate("Bg", TimeSyncThread, NULL, 512); NutThreadCreate("Bq", RefreshSceenThread, NULL, 512); NutThreadCreate("Bl", AlarmCheckerThread, NULL, 512); printf("\nEntering main loop.\n"); LcdBackLight(LCD_BACKLIGHT_ON); for(;;){ NutSleep(100); WatchDogRestart(); //restart watchdog } return(0); }
//---------------------------------------------------------- // System initialization //---------------------------------------------------------- static inline void initSystem(void) { bool success; (void)success; // disable interrupts: disabled on msp430 by default, but other systems might need this DISABLE_INTS(); // stop the watchdog: GCC disables it by default, but other compilers might not be so helpful watchdogStop(); // TODO: init dynamic memory // platformMemInit(); // basic, platform-specific initialization: timers, platform-specific drivers (?) initPlatform(); // start energy accounting (as soon as timers are initialized) energyConsumerOn(ENERGY_CONSUMER_MCU); #ifdef USE_PRINT // init printing to serial (makes sense only after clock has been calibrated) if (printInit != NULL) printInit(); #endif INIT_PRINTF("starting MansOS...\n"); #ifdef USE_LEDS INIT_PRINTF("init LED(s)...\n"); ledsInit(); #endif #ifdef USE_BEEPER beeperInit(); #endif #ifdef RAMTEXT_START if ((MemoryAddress_t)&_end > RAMTEXT_START) { // Panic right aways on RAM overflow. // In case this happens, you might want to increase the address // specified by CONST_RAMTEXT_START in config file assertionFailed("Overflow between .data and .ramtext sections", __FILE__, __LINE__); } #endif #ifdef USE_ADC if (adcInit != NULL) { INIT_PRINTF("init ADC...\n"); adcInit(); } #endif #ifdef USE_RANDOM INIT_PRINTF("init RNG...\n"); randomInit(); #endif #if USE_ALARMS INIT_PRINTF("init alarms...\n"); initAlarms(); #endif #ifdef USE_RADIO INIT_PRINTF("init radio...\n"); radioInit(); #endif #ifdef USE_ADDRESSING INIT_PRINTF("init communication stack...\n"); networkingInit(); #endif #ifdef USE_EXT_FLASH INIT_PRINTF("init external flash...\n"); extFlashInit(); #endif #ifdef USE_SDCARD INIT_PRINTF("init SD card...\n"); sdcardInit(); #endif #ifdef USE_EEPROM INIT_PRINTF("init EEPROM...\n"); eepromInit(); #endif #ifdef USE_ISL29003 INIT_PRINTF("init ISL light sensor...\n"); success = islInit(); if (!success) { INIT_PRINTF("ISL init failed!\n"); } #endif #ifdef USE_ADS1115 INIT_PRINTF("init ADS111x ADC converter chip...\n"); adsInit(); #endif #if USE_ADS8638 INIT_PRINTF("init ADS8638 ADC converter chip...\n"); ads8638Init(); #endif #if USE_ADS8328 INIT_PRINTF("init ADS8328 ADC converter chip...\n"); ads8328Init(); #endif #if USE_AD5258 INIT_PRINTF("init AD5258 digital potentiometer...\n"); ad5258Init(); #endif #if USE_DAC7718 INIT_PRINTF("init DAC7718 DAC converter chip...\n"); dac7718Init(); #endif #if USE_ISL1219 INIT_PRINTF("init ISL1219 real-time clock chip...\n"); isl1219Init(); #endif #ifdef USE_HUMIDITY INIT_PRINTF("init humidity sensor...\n"); humidityInit(); #endif #ifdef USE_ACCEL INIT_PRINTF("init accelerometer...\n"); accelInit(); #endif #ifdef USE_TIMESYNC INIT_PRINTF("init base station time sync...\n"); timesyncInit(); #endif #ifdef USE_SMP INIT_PRINTF("init SSMP...\n"); smpInit(); #endif #ifdef USE_REPROGRAMMING INIT_PRINTF("init reprogramming...\n"); bootParamsInit(); #endif #ifdef USE_DCO_RECALIBRATION extern void dcoRecalibrationInit(void); INIT_PRINTF("init DCO recalibration...\n"); dcoRecalibrationInit(); #endif #ifdef USE_FS INIT_PRINTF("init file system...\n"); fsInit(); #endif #ifdef USE_FATFS INIT_PRINTF("init FAT file system...\n"); fatFsInit(); INIT_PRINTF("init POSIX-like file routines...\n"); posixStdioInit(); #endif #ifdef USE_WMP INIT_PRINTF("init WMP...\n"); wmpInit(); #endif #ifdef USE_SEAL_NET INIT_PRINTF("init SEAL networking...\n"); sealNetInit(); #endif INIT_PRINTF("starting the application...\n"); }