I2CController *I2CController::get(controller_t controller) { static Mutex mutex; mutex.take(); if (!_controllers[controller]) { switch (controller) { case controller_0: _controllers[controller] = new I2CController(controller, SYSCTL_PERIPH_I2C0, I2C0_MASTER_BASE); I2CIntRegister(I2C0_MASTER_BASE, I2C0IntHandler); break; case controller_1: _controllers[controller] = new I2CController(controller, SYSCTL_PERIPH_I2C1, I2C1_MASTER_BASE); I2CIntRegister(I2C1_MASTER_BASE, I2C1IntHandler); break; case controller_count: while(1); break; } } mutex.give(); return _controllers[controller]; }
I2CController *I2CController::get(controller_t controller) { static Mutex lock; MutexGuard guard(&lock); if (!_controllers[controller]) { switch (controller) { case controller_0: _controllers[controller] = new I2CController(controller, SYSCTL_PERIPH_I2C0, I2C0_MASTER_BASE); I2CIntRegister(I2C0_MASTER_BASE, I2C0IntHandler); break; case controller_1: _controllers[controller] = new I2CController(controller, SYSCTL_PERIPH_I2C1, I2C1_MASTER_BASE); I2CIntRegister(I2C1_MASTER_BASE, I2C1IntHandler); break; case controller_count: while(1); break; } } return _controllers[controller]; }
/* ** Main function. The application starts here. */ int main(void) { unsigned char rxByte; unsigned int value = (unsigned int)E_FAIL; #ifdef __TMS470__ /* Relocate the required section to internal RAM */ memcpy((void *)(&relocstart), (const void *)(&iram_start), (unsigned int)(&iram_size)); #elif defined(__IAR_SYSTEMS_ICC__) #pragma section = "CodeRelocOverlay" #pragma section = "DataRelocOverlay" #pragma section = "DataOverlayBlk" #pragma section = "CodeOverlayBlk" char* srcAddr = (__section_begin("CodeRelocOverlay")); char* endAddr = (__section_end("DataRelocOverlay")); memcpy((void *)(__section_begin("CodeRelocOverlay")), (const void *)(__section_begin("CodeOverlayBlk")), endAddr - srcAddr); #else memcpy((void *)&(relocstart), (const void *)&(iram_start), (unsigned int)(((&(relocend)) - (&(relocstart))) * (sizeof(unsigned int)))); #endif MMUConfigAndEnable(); /* Enable Instruction Cache */ CacheEnable(CACHE_ALL); PeripheralsSetUp(); /* Initialize the ARM Interrupt Controller */ IntAINTCInit(); /* Register the ISRs */ Timer2IntRegister(); Timer4IntRegister(); EnetIntRegister(); RtcIntRegister(); CM3IntRegister(); HSMMCSDIntRegister(); IntRegister(127, dummyIsr); IntMasterIRQEnable(); pageIndex = 0; prevAction = 0; /* Enable system interrupts */ IntSystemEnable(SYS_INT_RTCINT); IntPrioritySet(SYS_INT_RTCINT, 0, AINTC_HOSTINT_ROUTE_IRQ); IntSystemEnable(SYS_INT_3PGSWTXINT0); IntPrioritySet(SYS_INT_3PGSWTXINT0, 0, AINTC_HOSTINT_ROUTE_IRQ); IntSystemEnable(SYS_INT_3PGSWRXINT0); IntPrioritySet(SYS_INT_3PGSWRXINT0, 0, AINTC_HOSTINT_ROUTE_IRQ); IntSystemEnable(SYS_INT_TINT2); IntPrioritySet(SYS_INT_TINT2, 0, AINTC_HOSTINT_ROUTE_IRQ); IntSystemEnable(SYS_INT_TINT4); IntPrioritySet(SYS_INT_TINT4, 0, AINTC_HOSTINT_ROUTE_IRQ); IntSystemEnable(SYS_INT_MMCSD0INT); IntPrioritySet(SYS_INT_MMCSD0INT, 0, AINTC_HOSTINT_ROUTE_IRQ); IntSystemEnable(SYS_INT_EDMACOMPINT); IntPrioritySet(SYS_INT_EDMACOMPINT, 0, AINTC_HOSTINT_ROUTE_IRQ); IntPrioritySet(SYS_INT_M3_TXEV, 0, AINTC_HOSTINT_ROUTE_IRQ ); IntSystemEnable(SYS_INT_M3_TXEV); IntSystemEnable(127); IntPrioritySet(127, 0, AINTC_HOSTINT_ROUTE_IRQ); IntSystemEnable(SYS_INT_UART0INT); IntPrioritySet(SYS_INT_UART0INT, 0, AINTC_HOSTINT_ROUTE_IRQ); IntRegister(SYS_INT_UART0INT, uartIsr); /* GPIO interrupts */ IntSystemEnable(SYS_INT_GPIOINT0A); IntPrioritySet(SYS_INT_GPIOINT0A, 0, AINTC_HOSTINT_ROUTE_IRQ); IntRegister(SYS_INT_GPIOINT0A, gpioIsr); IntSystemEnable(SYS_INT_GPIOINT0B); IntPrioritySet(SYS_INT_GPIOINT0B, 0, AINTC_HOSTINT_ROUTE_IRQ); IntRegister(SYS_INT_GPIOINT0B, gpioIsr); BoardInfoInit(); deviceVersion = DeviceVersionGet(); CM3EventsClear(); CM3LoadAndRun(); waitForM3Txevent(); /* Initialize console for communication with the Host Machine */ ConsoleUtilsInit(); /* ** Select the console type based on compile time check ** Note: This example is not fully complaint to semihosting. It is ** recommended to use Uart console interface only. */ ConsoleUtilsSetType(CONSOLE_UART); /* Print Board and SoC information on console */ ConsoleUtilsPrintf("\n\r Board Name : %s", BoardNameGet()); ConsoleUtilsPrintf("\n\r Board Version : %s", BoardVersionGet()); ConsoleUtilsPrintf("\n\r SoC Version : %d", deviceVersion); /* On CM3 init firmware version is loaded onto the IPC Message Reg */ ConsoleUtilsPrintf("\n CM3 Firmware Version: %d", readCM3FWVersion()); I2CIntRegister(I2C_0); IntPrioritySet(SYS_INT_I2C0INT, 0, AINTC_HOSTINT_ROUTE_IRQ); IntSystemEnable(SYS_INT_I2C0INT); I2CInit(I2C_0); IntSystemEnable(SYS_INT_TINT1_1MS); IntPrioritySet(SYS_INT_TINT1_1MS, 0, AINTC_HOSTINT_ROUTE_IRQ); IntRegister(SYS_INT_TINT1_1MS,clearTimerInt); configVddOpVoltage(); RtcInit(); HSMMCSDContolInit(); DelayTimerSetup(); initializeTimer1(); ConsoleUtilsPrintf("\r\n After intializing timer"); Timer2Config(); Timer4Config(); LedIfConfig(); MailBoxInit(); Timer2IntEnable(); Timer4IntEnable(); RtcSecIntEnable(); Timer4Start(); while(FALSE == tmr4Flag); tmr4Flag = FALSE; Timer4Stop(); ConsoleUtilsPrintf("\n\r Configuring for maximum OPP"); mpuOpp = ConfigMaximumOPP(); mpuFreq = FrequencyGet(mpuOpp); mpuVdd1 = VddVoltageGet(mpuOpp); PrintConfigDVFS(); /* Create menu page */ pageIndex = MENU_IDX_MAIN; ActionEnetInit(); /* ** Loop for ever. Necessary actions shall be taken ** after detecting the click. */ while(1) { /* ** Check for any any activity on Uart Console and process it. */ if (true == UARTCharsAvail(SOC_UART_0_REGS)) { /* Receiving bytes from the host machine through serial console. */ rxByte = UARTGetc(); /* ** Checking if the entered character is a carriage return. ** Pressing the 'Enter' key on the keyboard executes a ** carriage return on the serial console. */ if('\r' == rxByte) { ConsoleUtilsPrintf("\n"); UartAction(value); value = (unsigned int)E_FAIL; rxByte = 0; } /* ** Checking if the character entered is one among the decimal ** number set 0,1,2,3,....9 */ if(('0' <= rxByte) && (rxByte <= '9')) { ConsoleUtilsPrintf("%c", rxByte); if((unsigned int)E_FAIL == value) { value = 0; } value = value*10 + (rxByte - 0x30); } } /* ** Check if click is detected */ if(clickIdx != 0) { /* ** Take the Action for click */ ClickAction(); clickIdx = 0; } /* ** Check if the Timer Expired */ if(TRUE == tmrFlag) { /* Toggle the LED state */ LedToggle(); tmrFlag = FALSE; } /* ** Check if RTC Time is set */ if(TRUE == rtcSetFlag) { if(TRUE == rtcSecUpdate) { rtcSecUpdate = FALSE; RtcTimeCalDisplay(); ConsoleUtilsPrintf(" --- Selected: "); } } if(TRUE == tmr4Flag) { tmr4Flag = FALSE; /* Make sure that interrupts are disabled and no lwIP functions are executed while calling an lwIP exported API */ IntMasterIRQDisable(); etharp_tmr(); IntMasterIRQEnable(); } } }