/* ** sst1InitExecuteDacRdWr(): ** Execute DAC read/write command sequence defined in "voodoo.ini" file ** */ FxBool sst1InitExecuteDacRdWr(FxU32 *sstbase, sst1InitDacRdWrStruct *dacRdWrBase) { sst1InitDacRdWrStruct *dacRdWrPtr = dacRdWrBase; FxU32 data; FxBool retVal = FXTRUE; int helper = (GETENV(("SST_DEBUGDAC"))) ? 1 : 0; while(dacRdWrPtr) { if(dacRdWrPtr->type == DACRDWR_TYPE_WR) { sst1InitDacWr(sstbase, dacRdWrPtr->addr, dacRdWrPtr->data); } else if(dacRdWrPtr->type == DACRDWR_TYPE_RDMODWR) { data = sst1InitDacRd(sstbase, dacRdWrPtr->addr); if(helper) INIT_PRINTF(("dacRdWr(Read=0x%x)\n", data)); data &= dacRdWrPtr->mask; sst1InitDacWr(sstbase, dacRdWrPtr->addr, (data | dacRdWrPtr->data)); } else if(dacRdWrPtr->type == DACRDWR_TYPE_WRMOD_POP) { data = iniStack[--iniStackPtr]; if(iniStackPtr < 0) { retVal = FXFALSE; break; } if(helper) INIT_PRINTF(("dacWrModPop(Stack=0x%x,Mask=0x%x)\n", data, dacRdWrPtr->mask)); data &= dacRdWrPtr->mask; sst1InitDacWr(sstbase, dacRdWrPtr->addr, (data | dacRdWrPtr->data)); } else if(dacRdWrPtr->type == DACRDWR_TYPE_RDNOCHECK) { sst1InitDacRd(sstbase, dacRdWrPtr->addr); } else if(dacRdWrPtr->type == DACRDWR_TYPE_RDPUSH) { data = sst1InitDacRd(sstbase, dacRdWrPtr->addr); iniStack[iniStackPtr++] = data; if(iniStackPtr == DACRDWR_MAX_PUSH) { retVal = FXFALSE; break; } } else if(dacRdWrPtr->type == DACRDWR_TYPE_RDCHECK) { if(sst1InitDacRd(sstbase, dacRdWrPtr->addr) != dacRdWrPtr->data) { retVal = FXFALSE; break; } } else { retVal = FXFALSE; break; } dacRdWrPtr = dacRdWrPtr->nextRdWr; } return(retVal); }
FxBool sst1InitDacDetectICS(FxU32 * sstbase) { FxU32 n; int helper = (GETENV(("SST_DEBUGDAC"))) ? 1 : 0; if(helper) INIT_PRINTF(("sst1InitDacDetectICS(): Entered...\n")); /* Detect ICS... */ /* Sometimes the DACs seem to go into never-never land, so */ /* try and initialize the DAC multiple times */ n = 0; while(1) { FxU32 gclk1, vclk1, vclk7; if(++n > 100) break; /* Must guarantee that no rendering is being performed */ sst1InitIdleFBINoNOP(sstbase); sst1InitDacWr(sstbase, SST_DACREG_ICS_PLLADDR_RD, SST_DACREG_ICS_PLLADDR_GCLK1); gclk1 = sst1InitDacRd(sstbase, SST_DACREG_ICS_PLLADDR_DATA); sst1InitDacRd(sstbase, SST_DACREG_ICS_PLLADDR_DATA); sst1InitDacWr(sstbase, SST_DACREG_ICS_PLLADDR_RD, SST_DACREG_ICS_PLLADDR_VCLK1); vclk1 = sst1InitDacRd(sstbase, SST_DACREG_ICS_PLLADDR_DATA); sst1InitDacRd(sstbase, SST_DACREG_ICS_PLLADDR_DATA); sst1InitDacWr(sstbase, SST_DACREG_ICS_PLLADDR_RD, SST_DACREG_ICS_PLLADDR_VCLK7); vclk7 = sst1InitDacRd(sstbase, SST_DACREG_ICS_PLLADDR_DATA); sst1InitDacRd(sstbase, SST_DACREG_ICS_PLLADDR_DATA); if((gclk1 == SST_DACREG_ICS_PLLADDR_GCLK1_DEFAULT) && (vclk1 == SST_DACREG_ICS_PLLADDR_VCLK1_DEFAULT) && (vclk7 == SST_DACREG_ICS_PLLADDR_VCLK7_DEFAULT)) { /* found ICS DAC... */ sst1CurrentBoard->fbiDacType = SST_FBI_DACTYPE_ICS; if(helper) INIT_PRINTF(("sst1InitDacDetectICS(): Exiting...\n")); return(FXTRUE); } } if(helper) INIT_PRINTF(("sst1InitDacDetectICS(): Exiting...\n")); return(FXFALSE); }
/* ** sst1InitDacDetect(): ** Detect type of on-board DAC ** NOTE: sst1InitDacDetect() resets the PCI fifo and the graphics subsystem ** of FBI ** */ FX_EXPORT FxBool FX_CSTYLE sst1InitDacDetect(FxU32 * sstbase) { FxU32 n; FxU32 fbiInit1_save; FxU32 fbiInit2_save; volatile Sstregs *sst = (Sstregs *) sstbase; FxBool retVal = FXFALSE; int helper = (GETENV(("SST_DEBUGDAC"))) ? 1 : 0; if(!sst) return(FXFALSE); if(helper) INIT_PRINTF(("sst1InitDacDetect(): Entered...\n")); sst1InitIdleFBINoNOP(sstbase); /* Save init register states before overwriting them */ fbiInit1_save = IGET(sst->fbiInit1); fbiInit2_save = IGET(sst->fbiInit2); /* Reset video unit to guarantee no contentions on the memory bus */ ISET(sst->fbiInit1, IGET(sst->fbiInit1) | SST_VIDEO_RESET); /* Turn off dram refresh to guarantee no contentions on the memory bus */ ISET(sst->fbiInit2, IGET(sst->fbiInit2) & ~SST_EN_DRAM_REFRESH); sst1InitIdleFBINoNOP(sstbase); /* Enable reads from the DAC (multiplexed on the fbiInit2 address) */ /* Disallow writes to pass through the PCI FIFO */ PCICFG_WR(SST1_PCI_INIT_ENABLE, SST_INITWR_EN | SST_FBIINIT23_REMAP); sst1InitIdleFBINoNOP(sstbase); if(sst1InitUseVoodooFile == FXTRUE) { retVal = sst1InitDacDetectINI(sstbase); } else { if((retVal = sst1InitDacDetectICS(sstbase)) == FXTRUE) goto done; if((retVal = sst1InitDacDetectATT(sstbase)) == FXTRUE) goto done; retVal = sst1InitDacDetectTI(sstbase); } done: /* Disable fbiinit23 address remapping */ PCICFG_WR(SST1_PCI_INIT_ENABLE, SST_INITWR_EN | SST_PCI_FIFOWR_EN); /* Restore init register states */ sst1InitIdleFBINoNOP(sstbase); ISET(sst->fbiInit1, fbiInit1_save); ISET(sst->fbiInit2, fbiInit2_save); sst1InitIdleFBINoNOP(sstbase); return(retVal); }
/* ** sst1InitCalcGrxClk(): ** Determine graphics clock frequency ** NOTE: sst1InitCalcGrxClk() must be called prior to sst1InitGrxClk() ** */ FX_EXPORT FxBool FX_CSTYLE sst1InitCalcGrxClk(FxU32 *sstbase) { FxU32 clkFreq; if(sst1InitCheckBoard(sstbase) == FXFALSE) return(FXFALSE); if(GETENV(("SST_GRXCLK"))) { INIT_PRINTF(("sst1InitCalcGrxClk(): Overriding default clk frequency with SST_GRXCLK\n")); clkFreq = ATOI(GETENV(("SST_GRXCLK"))); if(clkFreq < 16) clkFreq = 16; } else { /* Setup memory clock frequency based on board strapping bits... */ if(sst1CurrentBoard->fbiBoardID == 0x0) { /* Obsidian GE Fab */ clkFreq = 40 + (((sst1CurrentBoard->tmuConfig >> 3) & 0x7) << 2) + (sst1CurrentBoard->fbiConfig & 0x3); } else {
/* ** sst1InitDacWr(): ** Write to external DAC registers ** NOTE: The video unit of FBI must be in reset before calling this routine. ** The rendering engines of FBI and TREX must be idle before calling ** this routine. ** ** Valid addresses are 0 <= addr <= 3 ** */ FX_EXPORT void FX_CSTYLE sst1InitDacWr(FxU32 *sstbase, FxU32 addr, FxU32 data) { volatile Sstregs *sst = (Sstregs *) sstbase; static FxBool firstPass = FXTRUE; static int helper; if(firstPass == FXTRUE) { firstPass = FXFALSE; helper = (GETENV(("SST_DEBUGDAC"))) ? 1 : 0; } ISET(sst->dacData, (data & SST_DACDATA_DATA) | ((addr) << SST_DACDATA_ADDR_SHIFT) | SST_DACDATA_WR); sst1InitIdleFBINoNOP(sstbase); if(helper) INIT_PRINTF(("dacWr(0x%x,0x%x)\n", addr, data)); }
/* ** sst1InitDacRd(): ** Read external DAC registers ** NOTE: The video unit of FBI must be in reset before calling this routine. ** The rendering engines of FBI and TREX must be idle before calling ** this routine. ** fbiInit23 register remapping (PCI config. initEnable[2]=1) must be ** enabled before calling this routine ** ** Valid addresses are 0 <= addr <= 3 ** */ FX_EXPORT FxU32 FX_CSTYLE sst1InitDacRd(FxU32 *sstbase, FxU32 addr) { volatile Sstregs *sst = (Sstregs *) sstbase; FxU32 retVal; static FxBool firstPass = FXTRUE; static int helper; if(firstPass == FXTRUE) { firstPass = FXFALSE; helper = (GETENV(("SST_DEBUGDAC"))) ? 1 : 0; } ISET(sst->dacData, ((addr) << SST_DACDATA_ADDR_SHIFT) | SST_DACDATA_RD); sst1InitIdleFBINoNOP(sstbase); retVal = IGET(sst->fbiInit2) & SST_DACDATA_DATA; if(helper) INIT_PRINTF(("dacRd(0x%x,0x%x)\n", addr, retVal)); return(retVal); }
FxBool sst1InitDacDetectTI(FxU32 * sstbase) { FxU32 n, j, dacmir, dacdir; int helper = (GETENV(("SST_DEBUGDAC"))) ? 1 : 0; if(helper) INIT_PRINTF(("sst1InitDacDetectTI(): Entered...\n")); /* Detect TI */ /* Sometimes the DACs seem to go into never-never land, so */ /* try and initialize the DAC multiple times */ n = 0; while(1) { if(++n > 100) break; /* Must guarantee that no rendering is being performed */ sst1InitIdleFBINoNOP(sstbase); /* Reset current state of DAC command register 0 (CR0) via the read */ /* mask register (RMR) */ sst1InitDacWr(sstbase, SST_DACREG_WMA, 0x0); /* reset backdoor fsm */ sst1InitDacRd(sstbase, SST_DACREG_RMR); /* RMR must be read 5 times */ sst1InitDacRd(sstbase, SST_DACREG_RMR); sst1InitDacRd(sstbase, SST_DACREG_RMR); sst1InitDacRd(sstbase, SST_DACREG_RMR); sst1InitDacRd(sstbase, SST_DACREG_RMR); /* Returns contents of CR0 */ /* Enable indexed programming by setting CR0[0] = 1 */ sst1InitDacWr(sstbase, SST_DACREG_WMA, 0x0); /* reset backdoor fsm */ sst1InitDacRd(sstbase, SST_DACREG_RMR); /* RMR must be read 4 times */ sst1InitDacRd(sstbase, SST_DACREG_RMR); sst1InitDacRd(sstbase, SST_DACREG_RMR); sst1InitDacRd(sstbase, SST_DACREG_RMR); sst1InitDacWr(sstbase, SST_DACREG_RMR, SST_DACREG_CR0_INDEXED_ADDRESSING | SST_DACREG_CR0_8BITDAC); /* NOW DAC IS IN INDEXED ADDRESS MODE... */ /* Check the manufacturing ID */ j = 0; DAC_INDEXWRADDR(SST_DACREG_INDEX_MIR); dacmir = DAC_INDEXRD(); if(dacmir == SST_DACREG_INDEX_MIR_TI_DEFAULT) j++; else continue; /* Check the device ID */ DAC_INDEXWRADDR(SST_DACREG_INDEX_DIR); dacdir = DAC_INDEXRD(); if(dacmir == SST_DACREG_INDEX_MIR_TI_DEFAULT && dacdir == SST_DACREG_INDEX_DIR_TI_DEFAULT) j++; else continue; if(j == 2) { /* Found TI DAC... */ sst1CurrentBoard->fbiDacType = SST_FBI_DACTYPE_TI; sst1InitIdleFBINoNOP(sstbase); /* Disable indexed-mode addressing */ sst1InitDacWr(sstbase, SST_DACREG_INDEXADDR, SST_DACREG_INDEX_CR0); sst1InitDacWr(sstbase, SST_DACREG_INDEXDATA, sst1InitDacRd(sstbase, SST_DACREG_INDEXDATA) & ~SST_DACREG_CR0_INDEXED_ADDRESSING); if(helper) INIT_PRINTF(("sst1InitDacDetectTI(): Exiting...\n")); return(FXTRUE); } } if(helper) INIT_PRINTF(("sst1InitDacDetectTI(): Exiting...\n")); return(FXFALSE); }
//---------------------------------------------------------- // 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"); }