//Output one sample when the timer goes off. void LPC24XX_DAC_Driver::ISR(void* Param) { #if defined(TIME_DAC_ISR) if(timesRun<TEST_SAMPLES_NUM) { execStartTicks[timesRun] = /*(UINT32)*/Time_CurrentTicks(); timesRun++; } #endif #if defined(MONITOR_BUFFER_LEVEL) bufferMonitorSampleCount++; if(!(bufferMonitorSampleCount%2000)) /*mark the buf lvl 4 times a sec @ 8kHz*/ { bufferLevel[bufLevelMarkCount] =(g_LPC24XX_DAC_Driver.FrameCount*100)/DAC_FRAME_BUFFERS_NUM; if(++bufLevelMarkCount==80) bufLevelMarkCount=0; } #endif LPC24XX_TIMER& TIMER = LPC24XX::TIMER(LPC24XX_DAC::Timer); //Reset match interrupt TIMER.IR = LPC24XX_TIMER::MR0_RESET; LPC24XX_DAC& DAC = LPC24XX::DAC(); if(g_LPC24XX_DAC_Driver.SampleCount>0) { if((g_LPC24XX_DAC_Driver.nextSampleRead>=g_LPC24XX_DAC_Driver.SamplesInFrame[g_LPC24XX_DAC_Driver.nextFrameRead]) ||(g_LPC24XX_DAC_Driver.nextSampleRead>=DAC_FRAME_BUFFER_SIZE_SAMPLES)) //if we reached the end of frame buffer { g_LPC24XX_DAC_Driver.nextSampleRead = 0; g_LPC24XX_DAC_Driver.nextFrameRead++; //jump to the next frame g_LPC24XX_DAC_Driver.FrameCount--; if(g_LPC24XX_DAC_Driver.nextFrameRead>=DAC_FRAME_BUFFERS_NUM) //if we reached the last frame g_LPC24XX_DAC_Driver.nextFrameRead = 0; //jump back to the first one //debug_printf("\r\nFrame %u:\r\n", (g_LPC24XX_DAC_Driver.nextFrameRead>=DAC_FRAME_BUFFERS_NUM)?0:g_LPC24XX_DAC_Driver.nextFrameRead); } // switch to unsigned // zero out the reserved bits // add the bias bit // write to DACR unsigned short sample = 0x7FFF+(signed long)g_LPC24XX_DAC_Driver.SamplesBuffer[g_LPC24XX_DAC_Driver.nextFrameRead*DAC_FRAME_BUFFER_SIZE_SAMPLES+g_LPC24XX_DAC_Driver.nextSampleRead]; DAC.DACR = DAC.TRADE_SPEED_FOR_POWER | (DAC.VALUE_MASK & (sample)); g_LPC24XX_DAC_Driver.SampleCount--; g_LPC24XX_DAC_Driver.nextSampleRead++; } else { //buffer empty, zero out the output DAC.DACR = 0x7FC0; } }
void __section("SectionForFlashOperations") Native_Profiler_Init() { s_native_profiler.ticksPerMicrosecond = CPU_TicksPerSecond() / 1000000; unsigned int availableSpace = &ProfilerBufferEnd - &ProfilerBufferBegin; s_native_profiler.useBuffer = FALSE; s_native_profiler.initTime = Native_Profiler_TimeInMicroseconds(); s_native_profiler.writtenData = FALSE; if(availableSpace >= 10) { GLOBAL_LOCK(irq); s_native_profiler.useBuffer = TRUE; s_native_profiler.isOn = TRUE; UINT64 timeBegin; UINT64 timeEnd; UINT64 timeToGetTicks; s_native_profiler.position = &ProfilerBufferBegin; // Measure time introduced by profiling. timeToGetTicks = Time_CurrentTicks(); timeBegin = Time_CurrentTicks(); { Native_Profiler testObj; } { Native_Profiler testObj; } timeEnd = Time_CurrentTicks(); // Count mean time spend in Native_Profiler constructor and destructor. s_native_profiler.engineTimeOffset = (UINT32)((timeEnd - timeBegin - 2 * (timeBegin - timeToGetTicks)) / (2 * s_native_profiler.ticksPerMicrosecond)); s_native_profiler.position = &ProfilerBufferBegin; *s_native_profiler.position++ = NATIVE_PROFILER_START_TAG; *s_native_profiler.position++ = s_native_profiler.engineTimeOffset; s_native_profiler.isOn = FALSE; } }
UINT64 __section("SectionForFlashOperations") Native_Profiler_TimeInMicroseconds() { return Time_CurrentTicks() / s_native_profiler.ticksPerMicrosecond; }
void LPC24XX_GPIO_Driver::GPIO_ISR( void* Param ) { //manage all flagged pin IRQs on port 0 LPC24XX_GPIOIRQ& GPIOIRQ = LPC24XX::GPIOIRQ(); LPC24XX_GPIO& GPIO = LPC24XX::GPIO(); UINT32 bit; PIN_ISR_DESCRIPTOR* pinIsr = NULL; for(bit = 0; (GPIOIRQ.IOIntStatus & 0x1) && (bit < 32); bit++) //exit when there are no pending IRQs or we reach P0.31 (should always be the first) { if(!(GPIOIRQ.IO0IntStatR & 0x1<<bit)&&!(GPIOIRQ.IO0IntStatF & 0x1<<bit)) //this is not the pin that detected an edge continue; //clear this pin's IRQ GPIOIRQ.IO0IntClr |= 0x1 << bit; pinIsr = &g_LPC24XX_GPIO_Driver.m_PinIsr[ bit /*+ 0 * LPC24XX_GPIO_Driver::c_PinsPerPort*/ ]; //Debounce if( (pinIsr->m_flags & PIN_ISR_DESCRIPTOR::c_Flags_Debounce)&& (Time_CurrentTicks() - pinIsr->m_lastExecTicks < g_LPC24XX_GPIO_Driver.m_DebounceTicks)) continue; //ignore this request //call this pin's ISR pinIsr->m_status = ((GPIO.Regs[0].FIOPIN_PX) >> bit) & 0x1; pinIsr->m_lastExecTicks = Time_CurrentTicks(); pinIsr->Fire((void*)pinIsr); //clear this pin's IRQ GPIOIRQ.IO0IntClr |= 0x1 << bit; } //manage all flagged pin IRQs on port 2 for(bit = 0; (GPIOIRQ.IOIntStatus & 0x4) && (bit < 32); bit++) // as above, but the guard value is P2.31 { if(!(GPIOIRQ.IO2IntStatR & 0x1<<bit)&&!(GPIOIRQ.IO2IntStatF & 0x1<<bit)) //this is not the pin that detected an edge continue; //clear this pin's IRQ GPIOIRQ.IO2IntClr |= 0x1 << bit; pinIsr = &g_LPC24XX_GPIO_Driver.m_PinIsr[ bit + 2 * LPC24XX_GPIO_Driver::c_PinsPerPort ]; //Debounce if( (pinIsr->m_flags & PIN_ISR_DESCRIPTOR::c_Flags_Debounce)&& (Time_CurrentTicks() - pinIsr->m_lastExecTicks < g_LPC24XX_GPIO_Driver.m_DebounceTicks)) { //debug_printf(" ignoring.\r\n"); continue; //ignore this request } //call this pin's ISR pinIsr->m_status = ((GPIO.Regs[2].FIOPIN_PX) >> bit) & 0x1; pinIsr->m_lastExecTicks = Time_CurrentTicks(); pinIsr->Fire((void*)pinIsr); } }
HRESULT CLR_RT_ExecutionEngine::Compile( const CLR_RT_MethodDef_Index& md, CLR_UINT32 flags ) { TINYCLR_HEADER(); MethodCompiler mc; #if !defined(BUILD_RTM) CLR_UINT64 stats_start; #endif #if defined(PLATFORM_WINDOWS) g_CLR_RT_ArmEmulator.InitializeExternalCalls(); #endif //////////////////////////////////////////////////////////////////////////// // // Create thunk table. // if(g_thunkTable.m_address__Internal_Initialize == 0) { TINYCLR_CHECK_HRESULT(mc.Initialize( NULL, (CLR_UINT32)(size_t)m_jitter_current )); TINYCLR_CHECK_HRESULT(mc.CreateThunks( &g_thunkTable )); if(s_CLR_RT_fJitter_Enabled) { size_t len = mc.m_Arm_Opcodes.Size() * sizeof(CLR_UINT32); FLASH_WORD* src = (FLASH_WORD*)&mc.m_Arm_Opcodes[ 0 ]; FLASH_WORD* dst = m_jitter_current; FLASH_WORD* end = CLR_RT_Persistence_Manager::Bank::IncrementPointer( dst, (CLR_UINT32)len ); //--// CODECOVERAGE_REGISTERTHUNK(Internal_Initialize ); CODECOVERAGE_REGISTERTHUNK(Internal_Restart ); CODECOVERAGE_REGISTERTHUNK(Internal_Error ); CODECOVERAGE_REGISTERTHUNK(Internal_ErrorNoFlush ); CODECOVERAGE_REGISTERTHUNK(Internal_ReturnFromMethod ); CODECOVERAGE_REGISTERTHUNK(CLR_RT_HeapBlock__Compare_Values ); CODECOVERAGE_REGISTERTHUNK(CLR_RT_HeapBlock__NumericMul ); CODECOVERAGE_REGISTERTHUNK(CLR_RT_HeapBlock__NumericDiv ); CODECOVERAGE_REGISTERTHUNK(CLR_RT_HeapBlock__NumericDivUn ); CODECOVERAGE_REGISTERTHUNK(CLR_RT_HeapBlock__NumericRem ); CODECOVERAGE_REGISTERTHUNK(CLR_RT_HeapBlock__NumericRemUn ); CODECOVERAGE_REGISTERTHUNK(CLR_RT_HeapBlock__NumericShl ); CODECOVERAGE_REGISTERTHUNK(CLR_RT_HeapBlock__NumericShr ); CODECOVERAGE_REGISTERTHUNK(CLR_RT_HeapBlock__NumericShrUn ); CODECOVERAGE_REGISTERTHUNK(CLR_RT_HeapBlock__InitObject ); CODECOVERAGE_REGISTERTHUNK(CLR_RT_HeapBlock__Convert ); CODECOVERAGE_REGISTERTHUNK(MethodCompilerHelpers__HandleBoxing ); CODECOVERAGE_REGISTERTHUNK(MethodCompilerHelpers__HandleIsInst ); CODECOVERAGE_REGISTERTHUNK(MethodCompilerHelpers__HandleCasting ); CODECOVERAGE_REGISTERTHUNK(MethodCompilerHelpers__CopyValueType ); CODECOVERAGE_REGISTERTHUNK(MethodCompilerHelpers__CloneValueType ); CODECOVERAGE_REGISTERTHUNK(MethodCompilerHelpers__LoadFunction ); CODECOVERAGE_REGISTERTHUNK(MethodCompilerHelpers__LoadString ); CODECOVERAGE_REGISTERTHUNK(MethodCompilerHelpers__NewArray ); CODECOVERAGE_REGISTERTHUNK(MethodCompilerHelpers__Call ); CODECOVERAGE_REGISTERTHUNK(MethodCompilerHelpers__CallVirtual ); CODECOVERAGE_REGISTERTHUNK(MethodCompilerHelpers__NewObject ); CODECOVERAGE_REGISTERTHUNK(MethodCompilerHelpers__NewDelegate ); CODECOVERAGE_REGISTERTHUNK(MethodCompilerHelpers__AccessStaticField); CODECOVERAGE_REGISTERTHUNK(MethodCompilerHelpers__Throw ); CODECOVERAGE_REGISTERTHUNK(MethodCompilerHelpers__Rethrow ); CODECOVERAGE_REGISTERTHUNK(MethodCompilerHelpers__Leave ); CODECOVERAGE_REGISTERTHUNK(MethodCompilerHelpers__EndFinally ); CODECOVERAGE_REGISTERTHUNK(MethodCompilerHelpers__LoadIndirect ); CODECOVERAGE_REGISTERTHUNK(MethodCompilerHelpers__StoreIndirect ); CODECOVERAGE_REGISTERTHUNK(MethodCompilerHelpers__LoadObject ); CODECOVERAGE_REGISTERTHUNK(MethodCompilerHelpers__CopyObject ); CODECOVERAGE_REGISTERTHUNK(MethodCompilerHelpers__StoreObject ); //--// if(end < m_jitter_end) { ::Flash_ChipReadOnly( FALSE ); while(dst < end) { ::Flash_WriteToSector( Flash_FindSector(dst), dst++, sizeof(FLASH_WORD), (byte *)src ); src ++; } ::Flash_ChipReadOnly( TRUE ); if(memcmp( m_jitter_current, &mc.m_Arm_Opcodes[ 0 ], len ) == 0) { m_jitter_current = dst; } else { CLR_Debug::Printf( "Jitter: failed to write thunk table!\r\n" ); } } else { CLR_Debug::Printf( "Jitter: no space for thunk table!\r\n" ); } } #if defined(PLATFORM_WINDOWS) else { size_t len = mc.m_Arm_Opcodes.Size() * sizeof(CLR_UINT32); m_jitter_current = CLR_RT_Persistence_Manager::Bank::IncrementPointer( m_jitter_current, (CLR_UINT32)len ); } #endif mc.Release(); } //////////////////////////////////////////////////////////////////////////// #if !defined(BUILD_RTM) if(s_CLR_RT_fJitter_Trace_Compile >= c_CLR_RT_Trace_Info) { CLR_Debug::Printf( "\r\n\r\nJitting " ); CLR_RT_DUMP::METHOD( md ); CLR_Debug::Printf( "\r\n" ); stats_start = Time_CurrentTicks(); } #endif TINYCLR_CHECK_HRESULT(mc.Initialize( &md, (CLR_UINT32)(size_t)m_jitter_current )); mc.ReferToThunks( &g_thunkTable ); //////////////////////////////////////////////////////////////////////////// if(mc.m_mdInst.m_target->RVA == CLR_EmptyIndex) { // // Native implementation. Nothing to do. // } else { TINYCLR_CHECK_HRESULT(mc.ParseArguments()); TINYCLR_CHECK_HRESULT(mc.ParseLocals ()); TINYCLR_CHECK_HRESULT(mc.ParseByteCode ()); TINYCLR_CHECK_HRESULT(mc.ParseEvalStack()); TINYCLR_CHECK_HRESULT(mc.GenerateCode()); #if !defined(BUILD_RTM) if(s_CLR_RT_fJitter_Trace_Compile >= c_CLR_RT_Trace_Verbose) { int milliSec = ((int)::Time_TicksToTime( Time_CurrentTicks() - stats_start ) + CLR_RT_Time::c_TickUnits - 1) / CLR_RT_Time::c_TickUnits; CLR_Debug::Printf( "Compile time: %dmsec\r\n", milliSec ); } #endif if(s_CLR_RT_fJitter_Enabled) { CLR_RT_Assembly* assm = mc.m_mdInst.m_assm; if(assm->m_jittedCode == NULL) { CLR_UINT32 size = assm->m_pTablesSize[ TBL_MethodDef ] * sizeof(CLR_RT_MethodHandler); assm->m_jittedCode = (CLR_RT_MethodHandler*)CLR_RT_Memory::Allocate_And_Erase( size ); } if(assm->m_jittedCode) { size_t len = mc.m_Arm_Opcodes.Size() * sizeof(CLR_UINT32); FLASH_WORD* src = (FLASH_WORD*)&mc.m_Arm_Opcodes[ 0 ]; FLASH_WORD* dst = m_jitter_current; FLASH_WORD* end = CLR_RT_Persistence_Manager::Bank::IncrementPointer( dst, (CLR_UINT32)len ); CodeCoverage::Register( dst, md ); if(end < m_jitter_end) { ::Flash_ChipReadOnly( FALSE ); while(dst < end) { Flash_WriteToSector( Flash_FindSector(dst), dst++, sizeof(FLASH_WORD),(byte *) src ); src ++; } ::Flash_ChipReadOnly( TRUE ); if(memcmp( m_jitter_current, &mc.m_Arm_Opcodes[ 0 ], len ) == 0) { assm->m_jittedCode[ mc.m_mdInst.Method() ] = (CLR_RT_MethodHandler)m_jitter_current; m_jitter_current = dst; } else { CLR_Debug::Printf( "Jitter: failed to write method!\r\n" ); } } else { CLR_Debug::Printf( "Jitter: no space for method!\r\n" ); } } else { CLR_Debug::Printf( "Jitter: cannot allocate method table!\r\n" ); } } #if defined(PLATFORM_WINDOWS) else { size_t len = mc.m_Arm_Opcodes.Size() * sizeof(CLR_UINT32); m_jitter_current = CLR_RT_Persistence_Manager::Bank::IncrementPointer( m_jitter_current, (CLR_UINT32)len ); } #endif } //////////////////////////////////////////////////////////////////////////// TINYCLR_CLEANUP(); mc.Release(); TINYCLR_CLEANUP_END(); }
BOOL GPIO_BUTTON_Driver::RegisterStateChange( UINT32 ButtonPressed, UINT32 ButtonReleased ) { NATIVE_PROFILE_PAL_BUTTONS(); GLOBAL_LOCK(irq); // limit to legitimate transitions from previous state UINT32 TransitionDown = ButtonPressed & ~g_GPIO_BUTTON_Driver.m_CurrentButtonState; UINT32 TransitionUp = ButtonReleased & g_GPIO_BUTTON_Driver.m_CurrentButtonState; // do we have any buttons remaining after debouncing? // also, only limit to changes to previous state if(TransitionDown | TransitionUp) { BUTTON_STATE_CHANGE* ptr = g_GPIO_BUTTON_Driver.m_ButtonFifo.Push(); if(ptr) { ptr->Down = TransitionDown; ptr->Up = TransitionUp; // update current state g_GPIO_BUTTON_Driver.m_CurrentButtonState |= TransitionDown; g_GPIO_BUTTON_Driver.m_CurrentButtonState &= ~TransitionUp; } else { // if the queue is full, just return lcd_printf ( "\fBUTTON QUEUE FULL\r\n" ); debug_printf( "BUTTON QUEUE FULL\r\n" ); // let's make sure the app knows that it is supposed to drain the queue Events_Set( SYSTEM_EVENT_FLAG_BUTTON ); return FALSE; } // set the event for the waiter, as the queue may be full (how?) Events_Set( SYSTEM_EVENT_FLAG_BUTTON ); } #if defined(HAL_TIMEWARP) if(ButtonReleased) { switch(s_timewarp_armingState) { case 0: case 1: if(ButtonReleased & BUTTON_B0) { s_timewarp_armingState++; } else { s_timewarp_armingState = 0; } break; case 2: if(ButtonReleased & BUTTON_B0) // Backlight == DISABLE { s_timewarp_lastButton = TIMEWARP_DISABLE; } if(ButtonReleased & BUTTON_B4) // Select == ARM { s_timewarp_lastButton = Time_TicksToTime( Time_CurrentTicks() ); } s_timewarp_armingState = 0; break; } } #endif return TRUE; }