中断控制器移植

//=====================================================================
//TITLE:
//    中断控制器移植
//AUTHOR:
//    norains
//DATE:
//    Friday  29-October-2010
//Environment:
//    KEIL MDK 4.0
//    .NET Micro Framework Porting 4.1
//    RedCow Board
//=====================================================================

 

1. 复制文件

 

    将$(SPOCLIENT)/DeviceCode/drivers/stubs/processor下的stubs_INTC文件夹拷贝到$(SPOCLIENT)/ Solutions/STM32F103ZE_RedCow/DeviceCode,并且更名为INTC_HAL。

 

 

2. INTC_Hal/dotNetMF.proj

 

    打开INTC_Hal/dotNetMF.proj文件,并做如下更改:

<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <AssemblyName>CPU_HAL_STM32F103ZE_RedCow</AssemblyName>
    <ProjectGuid>{e9b7181a-070d-4902-bc4c-9b7a81ef9a02}</ProjectGuid>
    <Size>
    </Size>
    <Description>Interrupt controller stub library</Description>
    <Level>HAL</Level>
    <LibraryFile>CPU_HAL_STM32F103ZE_RedCow.$(LIB_EXT)</LibraryFile>
    <ProjectPath>$(SPOCLIENT)/Solutions/STM32F103ZE_RedCow/DeviceCode/INTC_HAL/dotNetMF.proj</ProjectPath>
    <ManifestFile>CPU_HAL_STM32F103ZE_RedCow.$(LIB_EXT).manifest</ManifestFile>
    <Groups>Processor/stubs</Groups>
    <LibraryCategory>
      <MFComponent xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Name="InterruptController_HAL" Guid="{08148BEE-6B1F-4050-AA21-510CA7F2FF98}" ProjectPath="" Conditional="" xmlns="">
        <VersionDependency xmlns="
http://schemas.microsoft.com/netmf/InventoryFormat.xsd">
          <Major>4</Major>
          <Minor>0</Minor>
          <Revision>0</Revision>
          <Build>0</Build>
          <Extra />
          <Date>2009-04-30</Date>
        </VersionDependency>
        <ComponentType xmlns="
http://schemas.microsoft.com/netmf/InventoryFormat.xsd">LibraryCategory</ComponentType>
      </MFComponent>
    </LibraryCategory>
    <Documentation>
    </Documentation>
    <PlatformIndependent>False</PlatformIndependent>
    <CustomFilter>
    </CustomFilter>
    <Required>False</Required>
    <IgnoreDefaultLibPath>False</IgnoreDefaultLibPath>
    <IsStub>True</IsStub>
    <Directory>Solutions/STM32F103ZE_RedCow/DeviceCode/INTC_HAL</Directory>
    <OutputType>Library</OutputType>
    <PlatformIndependentBuild>false</PlatformIndependentBuild>
    <Version>4.0.0.0</Version>
  </PropertyGroup>
  <Import Project="$(SPOCLIENT)/tools/targets/Microsoft.SPOT.System.Settings" />
  <PropertyGroup />
  <ItemGroup>
    <Compile Include="stubs_functions_INTC.cpp" />
    <Compile Include="INTC_Adapter.cpp" />
  </ItemGroup>
   <ItemGroup>
  <IncludePaths Include="Solutions/STM32F103ZE_RedCow/DeviceCode/Libraries/Configure" />
  <IncludePaths Include="Solutions/STM32F103ZE_RedCow/DeviceCode/Libraries/STM32F10x_StdPeriph_Driver/inc" />
  <IncludePaths Include="Solutions/STM32F103ZE_RedCow/DeviceCode/Libraries/CMSIS/Core/CM3/" />   
 </ItemGroup>
  <ItemGroup />
  <Import Project="$(SPOCLIENT)/tools/targets/Microsoft.SPOT.System.Targets" />
</Project>

 

 

3. INTC_Adapter

 

    增加INTC_Adapter.h和INTC_Adapter.cpp两个文件,分别输入如下内容:

 

   INTC_Adapter.h

#include <tinyhal.h> #include "stm32f10x_conf.h" #define IRQ_StackTop 0 #define IRQ_Reset 1 #define IRQ_NMI 2 #define IRQ_HardFault 3 #define IRQ_MemManage 4 #define IRQ_BusFault 5 #define IRQ_UsageFault 6 #define IRQ_SVC 11 #define IRQ_DebugMon 12 #define IRQ_PendSV 14 #define IRQ_SysTick 15 #define IRQ_WWDG 16 #define IRQ_PVD 17 #define IRQ_TAMPER 18 #define IRQ_RTC 19 #define IRQ_FLASH 20 #define IRQ_RCC 21 #define IRQ_EXTI0 22 #define IRQ_EXTI1 23 #define IRQ_EXTI2 24 #define IRQ_EXTI3 25 #define IRQ_EXTI4 26 #define IRQ_DMAChannel1 27 #define IRQ_DMAChannel3 29 #define IRQ_DMAChannel4 30 #define IRQ_DMAChannel5 31 #define IRQ_DMAChannel6 32 #define IRQ_DMAChannel7 33 #define IRQ_ADC 34 #define IRQ_USB_HP_CAN_TX 35 #define IRQ_USB_LP_CAN_RX0 36 #define IRQ_CAN_RX1 37 #define IRQ_CAN_SCE 38 #define IRQ_EXTI9_5 39 #define IRQ_TIM1_BRK 40 #define IRQ_TIM1_UP 41 #define IRQ_TIM1_TRG_COM 42 #define IRQ_TIM1_CC 43 #define IRQ_TIM2 44 #define IRQ_TIM3 45 #define IRQ_TIM4 46 #define IRQ_I2C1_EV 47 #define IRQ_I2C1_ER 48 #define IRQ_I2C2_EV 49 #define IRQ_I2C2_ER 50 #define IRQ_SPI1 51 #define IRQ_SPI2 52 #define IRQ_USART1 53 #define IRQ_USART2 54 #define IRQ_USART3 55 #define IRQ_EXTI15_10 56 #define IRQ_RTCAlarm 57 #define IRQ_USBWakeUp 58 //--------------------------------------------------------------- //Description: // Initialize resource // //--------------------------------------------------------------- BOOL INTC_Initialize(); //--------------------------------------------------------------- //Description: // Connect the function to the vector table // //Parameters: // irq : [in] The IRQ index // ISR : [in] The handler function // ISR_Param : [in] The ISR function parameter. //--------------------------------------------------------------- BOOL INTC_ActivateInterrupt(UINT32 Irq_Index, HAL_CALLBACK_FPN ISR, void* ISR_Param); //--------------------------------------------------------------- //Description: // Disconnect the function to the vector table // //Parameters: // irq : [in] The IRQ index //--------------------------------------------------------------- BOOL INTC_DeactivateInterrupt(UINT32 Irq_Index); //--------------------------------------------------------------- //Description: // Conver the IRQ index to channel // //Parameters: // dwIrq : [in] The IRQ index // uChannel : [out] The channel index for stm32f10x //--------------------------------------------------------------- BOOL IrqToChannel(UINT32 dwIrq,IRQn_Type &channel); //----------------------------------------------------------------------- //Description: // Conver the IRQ index to channel // //Parameters: // dwIrq : [in] The IRQ index // bEnable : [in] TRUE -- Enable interrupt. FALSE -- Disable interrupt. //------------------------------------------------------------------------ BOOL EnableIrq(UINT32 dwIrq,BOOL bEnable); //----------------------------------------------------------------------- //Description: // Call the real handler funciton // //Parameters: // dwIrq : [in] The IRQ index //------------------------------------------------------------------------ BOOL CallRealHandler(DWORD dwIrq); //The handler funtion extern "C" void NMI_Handler(); extern "C" void HardFault_Handler(); extern "C" void MemManage_Handler(); extern "C" void BusFault_Handler(); extern "C" void UsageFault_Handler(); extern "C" void SVC_Handler(); extern "C" void DebugMon_Handler(); extern "C" void PendSV_Handler(); extern "C" void SysTick_Handler(); extern "C" void WWDG_IRQHandler(); extern "C" void PVD_IRQHandler(); extern "C" void TAMPER_IRQHandler(); extern "C" void RTC_IRQHandler(); extern "C" void FLASH_IRQHandler(); extern "C" void RCC_IRQHandler(); extern "C" void EXTI0_IRQHandler(); extern "C" void EXTI1_IRQHandler(); extern "C" void EXTI2_IRQHandler(); extern "C" void EXTI3_IRQHandler(); extern "C" void EXTI4_IRQHandler(); extern "C" void DMAChannel1_IRQHandler(); extern "C" void DMAChannel2_IRQHandler(); extern "C" void DMAChannel3_IRQHandler(); extern "C" void DMAChannel4_IRQHandler(); extern "C" void DMAChannel5_IRQHandler(); extern "C" void DMAChannel6_IRQHandler(); extern "C" void DMAChannel7_IRQHandler(); extern "C" void ADC_IRQHandler(); extern "C" void USB_HP_CAN_TX_IRQHandler(); extern "C" void USB_LP_CAN_RX0_IRQHandler(); extern "C" void CAN_RX1_IRQHandler(); extern "C" void CAN_SCE_IRQHandler(); extern "C" void EXTI9_5_IRQHandler(); extern "C" void TIM1_BRK_IRQHandler(); extern "C" void TIM1_UP_IRQHandler(); extern "C" void TIM1_TRG_COM_IRQHandler(); extern "C" void TIM1_CC_IRQHandler(); extern "C" void TIM2_IRQHandler(); extern "C" void TIM3_IRQHandler(); extern "C" void TIM4_IRQHandler(); extern "C" void I2C1_EV_IRQHandler(); extern "C" void I2C1_ER_IRQHandler(); extern "C" void I2C2_EV_IRQHandler(); extern "C" void I2C2_ER_IRQHandler(); extern "C" void SPI1_IRQHandler(); extern "C" void SPI2_IRQHandler(); extern "C" void USART1_IRQHandler(); extern "C" void USART2_IRQHandler(); extern "C" void USART3_IRQHandler(); extern "C" void EXTI15_10_IRQHandler(); extern "C" void RTCAlarm_IRQHandler(); extern "C" void USBWakeUp_IRQHandler();

INTC_Adapter.cpp

#include "INTC_Adapter.h" #include "core_cm3.h" //--------------------------------------------------------- //Extern value extern UINT32 Vectors_Handler_Function; extern UINT32 Vectors_Handler_Parameter; extern UINT32 ARM_Vectors; extern UINT32 ARM_Vectors_End; //--------------------------------------------------------- //The vector size could be calculated by address. const UINT32 VECTOR_SIZE = (&ARM_Vectors_End - &ARM_Vectors); //--------------------------------------------------------- //Global variable UINT32 *g_pHandlerFun = NULL; UINT32 *g_pHandlerParam = NULL; //--------------------------------------------------------- BOOL INTC_Initialize() { /* //ERROR:The following code can not compile. g_pHandlerFun = new UINT32[VECTOR_SIZE / sizeof(UINT32)]; if(g_pHandlerFun == NULL) { return FALSE; } g_pHandlerParam = new UINT32[VECTOR_SIZE / sizeof(UINT32)]; if(g_pHandlerParam == NULL) { return FALSE; } */ g_pHandlerFun = reinterpret_cast<UINT32 *>(&Vectors_Handler_Function); g_pHandlerParam = reinterpret_cast<UINT32 *>(&Vectors_Handler_Parameter); memset(g_pHandlerFun,0,VECTOR_SIZE); memset(g_pHandlerParam,0,VECTOR_SIZE); return TRUE; } BOOL INTC_ActivateInterrupt(UINT32 Irq_Index, HAL_CALLBACK_FPN ISR, void* ISR_Param) { if(g_pHandlerFun == NULL || g_pHandlerParam == NULL) { return FALSE; } g_pHandlerFun[Irq_Index] = reinterpret_cast<UINT32>(ISR); g_pHandlerParam[Irq_Index] = reinterpret_cast<UINT32>(ISR_Param); return TRUE; } BOOL INTC_DeactivateInterrupt(UINT32 Irq_Index) { return INTC_ActivateInterrupt(Irq_Index,NULL,NULL); } BOOL IrqToChannel(UINT32 dwIrq,IRQn_Type &channel) { if(dwIrq == IRQ_StackTop || dwIrq == IRQ_Reset || dwIrq == IRQ_HardFault) { //There aren't the channels index suitable for the vector table,so return FALSE. return FALSE; } switch(dwIrq) { case IRQ_NMI: channel = NonMaskableInt_IRQn; break; case IRQ_MemManage: channel = MemoryManagement_IRQn; break; case IRQ_BusFault: channel = BusFault_IRQn; break; case IRQ_UsageFault: channel = UsageFault_IRQn; break; case IRQ_SVC: channel = SVCall_IRQn; break; case IRQ_DebugMon: channel = DebugMonitor_IRQn; break; case IRQ_PendSV: channel = PendSV_IRQn; break; case IRQ_SysTick: channel = SysTick_IRQn; break; default: channel = static_cast<IRQn_Type>(dwIrq - 16); break; } return TRUE; } BOOL EnableIrq(UINT32 dwIrq,BOOL bEnable) { switch(dwIrq) { case IRQ_MemManage: { if(bEnable == FALSE) { SCB->SHCSR &= ~(1 << SCB_SHCSR_MEMFAULTENA); } else { SCB->SHCSR |= (1 << SCB_SHCSR_MEMFAULTENA); } break; } case IRQ_BusFault: { if(bEnable == FALSE) { SCB->SHCSR &= ~(1 << SCB_SHCSR_BUSFAULTENA); } else { SCB->SHCSR |= (1 << SCB_SHCSR_BUSFAULTENA); } break; } case IRQ_UsageFault: { if(bEnable == FALSE) { SCB->SHCSR &= ~(1 << SCB_SHCSR_USGFAULTENA); } else { SCB->SHCSR |= (1 << SCB_SHCSR_USGFAULTENA); } break; } case IRQ_SysTick: { if(bEnable == FALSE) { SysTick->CTRL &= ~(1 << SYSTICK_ENABLE); } else { SysTick->CTRL |= (1 << SYSTICK_ENABLE); } break; } default: { //Convert to channel IRQn_Type channel; if(IrqToChannel(dwIrq,channel) == FALSE) { return FALSE; } //Enable or disable if(bEnable == FALSE) { NVIC_DisableIRQ(channel); } else { NVIC_EnableIRQ(channel); } break; } } //Ensure completion of memory access __DSB(); return TRUE; } BOOL CallRealHandler(DWORD dwIrq) { if(dwIrq == IRQ_StackTop || dwIrq == IRQ_Reset) { //The two IRQ should not be changed. return FALSE; } if(g_pHandlerFun == NULL || g_pHandlerParam == NULL) { return FALSE; } HAL_CALLBACK_FPN pFunc = reinterpret_cast<HAL_CALLBACK_FPN>(g_pHandlerFun[dwIrq]); if(pFunc == NULL) { return FALSE; } (*pFunc)(reinterpret_cast<void *>(g_pHandlerParam[dwIrq])); return TRUE; } extern "C" void NMI_Handler() { CallRealHandler(IRQ_NMI); } extern "C" void HardFault_Handler() { CallRealHandler(IRQ_HardFault); } extern "C" void MemManage_Handler() { CallRealHandler(IRQ_MemManage); } extern "C" void BusFault_Handler() { CallRealHandler(IRQ_BusFault); } extern "C" void UsageFault_Handler() { CallRealHandler(IRQ_UsageFault); } extern "C" void SVC_Handler() { CallRealHandler(IRQ_SVC); } extern "C" void DebugMon_Handler() { CallRealHandler(IRQ_DebugMon); } extern "C" void PendSV_Handler() { CallRealHandler(IRQ_PendSV); } extern "C" void SysTick_Handler() { CallRealHandler(IRQ_SysTick); } extern "C" void WWDG_IRQHandler() { CallRealHandler(IRQ_WWDG); } extern "C" void PVD_IRQHandler() { CallRealHandler(IRQ_PVD); } extern "C" void TAMPER_IRQHandler() { CallRealHandler(IRQ_TAMPER); } extern "C" void RTC_IRQHandler() { CallRealHandler(IRQ_RTC); } extern "C" void FLASH_IRQHandler() { CallRealHandler(IRQ_FLASH); } extern "C" void RCC_IRQHandler() { CallRealHandler(IRQ_RCC); } extern "C" void EXTI0_IRQHandler() { CallRealHandler(IRQ_EXTI0); } extern "C" void EXTI1_IRQHandler() { CallRealHandler(IRQ_EXTI1); } extern "C" void EXTI2_IRQHandler() { CallRealHandler(IRQ_EXTI2); } extern "C" void EXTI3_IRQHandler() { CallRealHandler(IRQ_EXTI3); } extern "C" void EXTI4_IRQHandler() { CallRealHandler(IRQ_EXTI4); } extern "C" void DMAChannel1_IRQHandler() { CallRealHandler(IRQ_DMAChannel1); } extern "C" void DMAChannel3_IRQHandler() { CallRealHandler(IRQ_DMAChannel3); } extern "C" void DMAChannel4_IRQHandler() { CallRealHandler(IRQ_DMAChannel4); } extern "C" void DMAChannel5_IRQHandler() { CallRealHandler(IRQ_DMAChannel5); } extern "C" void DMAChannel6_IRQHandler() { CallRealHandler(IRQ_DMAChannel6); } extern "C" void DMAChannel7_IRQHandler() { CallRealHandler(IRQ_DMAChannel7); } extern "C" void ADC_IRQHandler() { CallRealHandler(IRQ_ADC); } extern "C" void USB_HP_CAN_TX_IRQHandler() { CallRealHandler(IRQ_USB_HP_CAN_TX); } extern "C" void USB_LP_CAN_RX0_IRQHandler() { CallRealHandler(IRQ_USB_LP_CAN_RX0); } extern "C" void CAN_RX1_IRQHandler() { CallRealHandler(IRQ_CAN_RX1); } extern "C" void CAN_SCE_IRQHandler() { CallRealHandler(IRQ_CAN_SCE); } extern "C" void EXTI9_5_IRQHandler() { CallRealHandler(IRQ_EXTI9_5); } extern "C" void TIM1_BRK_IRQHandler() { CallRealHandler(IRQ_TIM1_BRK); } extern "C" void TIM1_UP_IRQHandler() { CallRealHandler(IRQ_TIM1_UP); } extern "C" void TIM1_TRG_COM_IRQHandler() { CallRealHandler(IRQ_TIM1_TRG_COM); } extern "C" void TIM1_CC_IRQHandler() { CallRealHandler(IRQ_TIM1_CC); } extern "C" void TIM2_IRQHandler() { CallRealHandler(IRQ_TIM2); } extern "C" void TIM3_IRQHandler() { CallRealHandler(IRQ_TIM3); } extern "C" void TIM4_IRQHandler() { CallRealHandler(IRQ_TIM4); } extern "C" void I2C1_EV_IRQHandler() { CallRealHandler(IRQ_I2C1_EV); } extern "C" void I2C1_ER_IRQHandler() { CallRealHandler(IRQ_I2C1_ER); } extern "C" void I2C2_EV_IRQHandler() { CallRealHandler(IRQ_I2C2_EV); } extern "C" void I2C2_ER_IRQHandler() { CallRealHandler(IRQ_I2C2_ER); } extern "C" void SPI1_IRQHandler() { CallRealHandler(IRQ_SPI1); } extern "C" void SPI2_IRQHandler() { CallRealHandler(IRQ_SPI2); } extern "C" void USART1_IRQHandler() { CallRealHandler(IRQ_USART1); } extern "C" void USART2_IRQHandler() { CallRealHandler(IRQ_USART2); } extern "C" void USART3_IRQHandler() { CallRealHandler(IRQ_USART3); } extern "C" void EXTI15_10_IRQHandler() { CallRealHandler(IRQ_EXTI15_10); } extern "C" void RTCAlarm_IRQHandler() { CallRealHandler(IRQ_RTCAlarm); } extern "C" void USBWakeUp_IRQHandler() { CallRealHandler(IRQ_USBWakeUp); }

 

 

4. NativeSample.proj

 

    打开$(SPOCLIENT)/Solutions/STM32F103ZE_RedCow/NativeSample/NativeSample.proj文件,重新定义INTC工程目录。

 

    原语句:
<ItemGroup>
    <DriverLibs Include="cpu_intc_stubs.$(LIB_EXT)" />
    <RequiredProjects Include="$(SPOCLIENT)/DeviceCode/drivers/stubs/processor/stubs_INTC/dotNetMF.proj" />
  </ItemGroup

 

    更改为:
<ItemGroup>
    <DriverLibs Include="CPU_HAL_STM32F103ZE_RedCow.$(LIB_EXT)" />
    <RequiredProjects Include="$(SPOCLIENT)/Solutions/STM32F103ZE_RedCow/DeviceCode/INTC_HAL/dotNetMF.proj" />
  </ItemGroup>

 

 

5. stubs_functions_INTC.cpp

    打开$(SPOCLIENT)/Solutions/STM32F103ZE_RedCow/DeviceCode/INTC_HAL/ stubs_functions_INTC.cpp,将代码更改为:

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Copyright (c) Microsoft Corporation. All rights reserved. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #include <tinyhal.h> #include "INTC_Adapter.h" //--// void __irq IRQ_Handler() { } void CPU_INTC_Initialize() { INTC_Initialize(); } BOOL CPU_INTC_ActivateInterrupt( UINT32 Irq_Index, HAL_CALLBACK_FPN ISR, void* ISR_Param ) { return INTC_ActivateInterrupt(Irq_Index,ISR,ISR_Param); } BOOL CPU_INTC_DeactivateInterrupt( UINT32 Irq_Index ) { return INTC_DeactivateInterrupt(Irq_Index); } BOOL CPU_INTC_InterruptEnable( UINT32 Irq_Index ) { return EnableIrq(Irq_Index,TRUE); } BOOL CPU_INTC_InterruptDisable( UINT32 Irq_Index ) { return EnableIrq(Irq_Index,FALSE); } BOOL CPU_INTC_InterruptEnableState( UINT32 Irq_Index ) { return FALSE; } BOOL CPU_INTC_InterruptState( UINT32 Irq_Index ) { return FALSE; }

你可能感兴趣的:(c,vector,function,null,callback,include)