PXA300+WINCE 5 添加UART功能

来源:互联网 发布:大华软件测试面试 编辑:程序博客网 时间:2024/05/17 06:12

 昨天解决了一个问题,UART添加了UART 功能后,系统启动时(白屏阶段),串口会发送21个数据,如果uart得connect 不连接起来,这会严重影响到启动时间.所以这个问题必须解决.下面我把问题记录下.

说一下环境:PXA300 +WINCE 5,BSP 为Marvell 的"BSP_WCE50_MHL_9_0_5.zip"

一共有3个串口,一个是全功能的FFUART,一个是作蓝牙的BTUART,还有一个作红外的STUART.目前FFUART作串口调试,STUART 作红外BTUART我们没有用,我所作的就是把这个BTUART做成简单的两线(TXD RXD)的UART.

一.准备工作,了解串口驱动架构

还是引用别人的文章,分析的很好,因为文章较长,我就把地址贴在这里:http://blog.csdn.net/fredzeng/archive/2006/09/27/1296195.aspx

   < <Intel PXA27x平台中的UART接口驱动>>

二.分析BSP

因为这个串口是作蓝牙用的,之前我们编译时把蓝牙功能关闭了,所以在这里我要把编译开关打开.

C:/WINCE500/PLATFORM/ZYLONITE_MHL/Zylonite_Common.bat文件里

改变设置

set BSP_NOBTUART=


REM Disable Bluetooth support
set BSP_BLUETOOTH=1

if "%BSP_BLUETOOTH%"=="1" set BSP_NOSERIAL=
if "%BSP_BLUETOOTH%"=="1" set BSP_NOBTUART=
if "%BSP_BLUETOOTH%"=="1" set BTD_COMPONENTS=hciuniv
if "%BSP_BLUETOOTH%"=="1" set IMGNOOBEX=

 

刚开始我把蓝牙相关的变量BSP_BLUETOOTH放开了,后来发现其实没必要把这个BSP_BLUETOOTH使能,只要BSP_NOBTUART= 设置了就可以了.BSP_BLUETOOTH变量使能了,就会多编译由此控制的编译项目.之前没有仔细看,所以才会有系统启动时,串口自动发送数据的问题,这个问题完全是我自己引进来的.唉,这个教训就是,当为了一个功能而改变一些设置时,还要查清楚,这个改变会不会引进新的问题,这个改变会不会影响到其他方面.不能顾此失彼!后面再讲BSP_BLUETOOTH所影响到的地方.

 


再看驱动文件

C:/WINCE500/PLATFORM/ZYLONITE_MHL/SRC/DRIVERS/SERIAL/ms2_serial.cpp

ms2_serial.cpp实现了3个串口的功能,其中BTUART 的初始化函数

 

  1.     virtual BOOL CBulPdd16550BUART::Init() {
  2. /*@ CYH MASK for UART function
  3.         BSP_ARGS args;
  4.         DWORD size;*/
  5.         /* Default, Bluetooth is disabled */
  6.         m_bBluetoothUsageFlag = FALSE; 
  7.         
  8.         /* Check EBOOT BSP Configuration if it need to turn Bluetooth Module */ 
  9.         /* @ CYH MASK for UART function 
  10. //注释掉这部分,这部分的功能是读取EBOOT中的配置,根据配置是否使能BlueTooth功能
  11.         if(KernelIoControl(IOCTL_GET_BSP_ARGS,NULL,0, &args, sizeof(args), &size))
  12.         {
  13.             NKDbgPrintfW(TEXT("[BTUART: Bluetooth] ConfigurePinout args.BTWLAMComboCardUsage = 0x%x!/r/n"), args.BTWLAMComboCardUsage);
  14.             if ((args.BTWLAMComboCardUsage&BSP_ARGS_BTWLAN_BT) || (args.BTWLAMComboCardUsage&BSP_ARGS_BTWLAN_BOTH))
  15.             {
  16.                 RETAILMSG(1, (_T("[BTUART: Bluetooth] Bluetooth will be enalbed +!/r/n")));
  17.                 
  18.                 m_bBluetoothUsageFlag = TRUE;
  19.                 // Map the I2C and OST register address
  20.                 PHYSICAL_ADDRESS PA;
  21.                 PA.QuadPart  = MONAHANS_BASE_REG_PA_I2C;
  22.                 m_pI2CReg  = (P_XLLP_I2C_T) MmMapIoSpace(PA, sizeof(XLLP_I2C_T), FALSE);    
  23.                 PA.QuadPart  = MONAHANS_BASE_REG_PA_OST;
  24.                 m_pOstReg  = (P_XLLP_OST_T) MmMapIoSpace(PA, sizeof(XLLP_OST_T), FALSE);                
  25.             }
  26.             else
  27.             {
  28.                 RETAILMSG(1, (_T("[BTUART: Bluetooth] Bluetooth will not be enalbed./r/n")));
  29.                 // Currently, the BTUART will not be loaded if the Bluetooth is not required /
  30.                 RETAILMSG(1, (_T("[BTUART] BTUART will not be enalbed./r/n")));
  31.                 m_bBluetoothUsageFlag = FALSE;
  32.                 return FALSE;
  33.             }
  34.         }
  35.        @ CYH MASK for UART function */
  36.         m_UART_Handle.UARTSelection = XLLP_BTUART;
  37.         
  38.         if (CBulPdd16550::Init())
  39.         {
  40.             ConfigurePinout();
  41.             RETAILMSG(1, (_T("[BTUART] Init Successful!/r/n")));                
  42.         }
  43.         else
  44.         {
  45.             RETAILMSG(1, (_T("[BTUART] Init Failed!/r/n")));                
  46.             return FALSE;
  47.         }
  48.         return TRUE;
  49.     }

在Open ,Close里把bloutooth 相关的I2C操作注释掉,D0CS相关的代码也注释掉.

  1.     virtual BOOL  CBulPdd16550BUART::Open()
  2.     {
  3.         BOOL bReturn;
  4.     RETAILMSG(1, (_T("[BTUART] Open./r/n")));
  5.         // Enable BTUART clock during driver is opened
  6.         XllpClockEnable(m_pDCCLKReg, XLLP_CLK_BTUART, XLLP_TRUE); 
  7. /*
  8.         // Deivce is opened, notify IPM that do not enter D0CS
  9.         RETAILMSG(1, (_T("[%s]:Deivce is opened, notify IPM that do not enter D0CS/r/n"), szName));
  10.         if ( (IPM_NotifyReadyForProcState(ClientID, IPM_PROCESSOR_D0_RDY ,3000)!=IPM_STATUS_SUCCESS)||
  11.             (IPM_SetMinOp(ClientID,IPM_OP_104MHZ, 3000) != IPM_STATUS_SUCCESS) )
  12.             RETAILMSG(1, (_T("[%s]: IPM_SetMinOp failed/r/n"), szName));
  13. */
  14.         bReturn = CBulPdd16550::Open();
  15.         /* Check if it need to turn on Bluetooth part on Combo card */
  16.         /* @ CYH MASK for UART function
  17.         if (m_bBluetoothUsageFlag)
  18.         {
  19.             RETAILMSG(1, (_T("[BTUART: Bluetooth] Start Enable BT./r/n")));
  20.             
  21.            // /* Currrently, only support Rev 1.2 combo card /            
  22.             // Enable the BT 26MHz clock
  23.             MBW_BTClkEnable(TRUE);
  24.             // Make the BT core out of the reset state
  25.             MBW_BTReset();
  26.         }
  27.           @ CYH MASK for UART function */
  28.         return bReturn;
  29.     }
  30.     
  31.     virtual BOOL  CBulPdd16550BUART::Close()
  32.     {
  33.     
  34.         BOOL bReturn =  CBulPdd16550::Close();
  35.         /*
  36.         // device is closed, notify IPM that no restricts from BTUART side.
  37.         RETAILMSG(1, (_T("[%s]: device is closed, notify IPM that no restricts from BTUART side./r/n"), szName));
  38.         if ( (IPM_NotifyReadyForProcState(ClientID, IPM_PROCESSOR_D0_RDY|IPM_PROCESSOR_RING_OSC_RDY | IPM_PROCESSOR_D2_RDY| IPM_PROCESSOR_D1_RDY ,3000)!=IPM_STATUS_SUCCESS)|| 
  39.             (IPM_ReleaseMinOp(ClientID, 3000) != IPM_STATUS_SUCCESS) )
  40.             RETAILMSG(1, (_T("[%s]: IPM_ReleaseMinOp failed/r/n"),szName));*/
  41.         /* Check if it need to turn off Bluetooth part on Combo card */
  42.         /*@ CYH MASK for UART function
  43.         if (m_bBluetoothUsageFlag)
  44.         {
  45.             RETAILMSG(1, (_T("[BTUART: Bluetooth] Start Disable BT./r/n")));
  46.             MBW_BTClkEnable(FALSE);
  47.         }@ CYH MASK for UART function*/
  48.         
  49.         // Disable BTUART clock during driver is cloesed
  50.         XllpClockEnable(m_pDCCLKReg, XLLP_CLK_BTUART, XLLP_FALSE); 
  51.             RETAILMSG(1, (_T("[BTUART] Close./r/n")));
  52.         return bReturn;
  53.     }

C:/WINCE500/PLATFORM/ZYLONITE_MHL/SRC/DRIVERS/xllp_plat/source下的文件xllp_uart_plat.c

static XLLP_STATUS_T Config_BTUART(P_XLLP_VUINT32_T pMfpRegBase,
    P_XLLP_MFP_RM_DB_ID_T pMfpRmDb,
       XLLP_MFP_RM_DB_ID_T MfpRmDBID)

中的用到的bluetooth设置定义,去掉RTS 和CTS 相关的定义


  1. static XLLP_UINT32_T xllp_btuart_mfp_list[] = {
  2.   //  XLLP_MFP_RSVD_BT_RTS_OFFSET,
  3.     XLLP_MFP_RSVD_BT_RXD_OFFSET,
  4.     XLLP_MFP_RSVD_BT_TXD_OFFSET,
  5.  //   XLLP_MFP_RSVD_BT_CTS_OFFSET,    
  6.     XLLP_MFP_PIN_EOLIST_MARKER
  7. };
  8. static XLLP_MFP_ALT_FN_T xllp_btuart_af_list[] = {
  9. //    XLLP_MFP_RSVD_BT_RTS_AF,
  10.     XLLP_MFP_RSVD_BT_RXD_AF,
  11.     XLLP_MFP_RSVD_BT_TXD_AF,
  12.  //   XLLP_MFP_RSVD_BT_CTS_AF 
  13. };
  14. static XLLP_MFP_DRIVE_STRENGTH_T xllp_btuart_ds_list[] = {
  15. //  XLLP_MFP_DEFAULT_DS,
  16. //  XLLP_MFP_DEFAULT_DS,
  17.     XLLP_MFP_DEFAULT_DS,
  18.     XLLP_MFP_DEFAULT_DS
  19. };
  20. static XLLP_MFP_LPM_OUTPUT_T xllp_btuart_lpm_output_list[] = {
  21. //  XLLP_MFP_RSVD_BT_RTS_LPM,
  22.     XLLP_MFP_RSVD_BT_RXD_LPM,
  23.     XLLP_MFP_RSVD_BT_TXD_LPM,
  24. //  XLLP_MFP_RSVD_BT_CTS_LPM
  25. };

 查看注册表,发现有BSP_BLUETOOTH 条件控制的注册表项,都是蓝牙相关的,是不需要的

C:/WINCE500/PLATFORM/ZYLONITE_MHL/FILES/zylonite_common.reg

 

  1. ;IF BSP_BLUETOOTH 
  2. ; @CESYSGEN IF CE_MODULES_BTD
  3. ; @XIPREGION IF PACKAGE_OEMDRIVERS
  4. [HKEY_LOCAL_MACHINE/Software/Microsoft/Bluetooth/HCI]
  5.   "Name"="COM5:"  ;LOC_FRIENDLYNAME_SERIAL2 ;"COM5:"
  6. ; disable hardware detect when external bluetooth card is inserted. Onlye support static bingding
  7. [HKEY_LOCAL_MACHINE/Software/Microsoft/Bluetooth/Settings]
  8. "IgnoreExternal"=dword:1     
  9. [HKEY_LOCAL_MACHINE/Software/Microsoft/Bluetooth/Transports/BuiltIn/1]
  10.     "driver"="bthcsr.dll"
  11. ;   "driver"="bthuart.dll"
  12.     "flags"=dword:4
  13.     "name"="COM5:" ;LOC_FRIENDLYNAME_SERIAL2 ;"COM5:"
  14.     "baud"=dword:1c200
  15.     "resetdelay"=dword:0
  16. ;      Ericsson dongle/dev board
  17. ;     SiW boxes
  18. ;[HKEY_LOCAL_MACHINE/ExtModems/bluetooth_dcn]
  19. ;"port"="COM8:"
  20. ;"DeviceType"=dword:0
  21. ;"FriendlyName"="BluetoothDCN"
  22. ;[HKEY_LOCAL_MACHINE/ExtModems/bluetooth_dun]
  23. ;    "port"="COM8:"
  24. ;    "DeviceType"=dword:1
  25. ;    "FriendlyName"="BluetoothDUN"
  26.     
  27. [HKEY_LOCAL_MACHINE/Software/Microsoft/Bluetooth/HandsfreeProfileOn]
  28. ; the next line is not required but it looks like
  29. if nothing is here the key "HandsfreeProfileOn" will not be added
  30. ; maybe this has already been fixed
  31.     @="HandsfreeProfileOn"
  32. [HKEY_LOCAL_MACHINE/Software/Microsoft/Bluetooth/AudioGateway]
  33.    "Capability"=dword:21
  34.    "MapAudioToPcmMode"=dword:1 ;0
  35.    "ConnectScoInAlways"=dword:0
  36. [HKEY_LOCAL_MACHINE/Software/Microsoft/Obex]
  37.      "IsEnabled"=dword:1
  38.      
  39. [HKEY_LOCAL_MACHINE/Software/Microsoft/Obex/Services/{00000000-0000-0000-0000-000000000000}]
  40.     "TransportAuthenticate"=dword:1
  41. [HKEY_LOCAL_MACHINE/Drivers/BuiltIn/BtScoSnd]
  42.    "Prefix"="WAV"
  43.    "Dll"="btscosnd.dll"
  44.    "Order"=dword:25
  45. [HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Bluetooth/ScoWav]
  46.    "Direction"=dword:0
  47.    "AirCoding"=dword:0
  48.    "ConnectInTimeout"=dword:10000
  49.    "8BitSignedSamples"=dword:1
  50. ;Specifying headset address for MapAudioToPcmMode=1
  51.    "AddressOut"=hex:00,00,00,00,00,00  ; 00,07,A4,01,C2,69   ;00,00,00,00,00,00 
  52. ; Set default Bluetooth Class of Device
  53. ; BTH_COD_MAJOR_DEVICE_CLASS_COMPUTER | BTH_COD_MINOR_COMPUTER_PDA | BTH_COD_MAJOR_SERVICE_CLASS_OBEX
  54. ;                0x100                +           0x14             +      0x100000
  55. [HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Bluetooth/SYS]
  56. "COD"=dword:920114  ;920100 ;100114
  57. ; @XIPREGION ENDIF PACKAGE_OEMDRIVERS
  58. ; @CESYSGEN ENDIF CE_MODULES_BTD
  59. ENDIF

在BSP所在路径下搜索了BSP_BLUETOOTH,发现以下的文件了也有相关的内容.

C:/WINCE500/PLATFORM/ZYLONITE_MHL/PB5x_Cmd_Line_Bld_Env_Vars.bat

  1. if /i "%BSP_BLUETOOTH%"=="" goto :SKIP_BLUETOOTH
  2. REM Bluetooth settings
  3. set SYSGEN_BTH=1
  4. set SYSGEN_BTH_PAN=1
  5. set PRJ_BTH_PAN_GN=1
  6. set SYSGEN_BTH_AG=1
  7. set SYSGEN_BTH_AUDIO=1
  8. set SYSGEN_BTH_MODEM=1
  9. set SYSGEN_BTH_UTILS=1
  10. set SYSGEN_BTH_AVDTP=1
  11. set SYSGEN_BTH_AVCTP=1
  12. set SYSGEN_BTH_AVRCP=1
  13. set SYSGEN_BTH_A2DP=1
  14. :SKIP_BLUETOOTH

重新设置回原来的值BSP_BLUETOOTH = 或者在注册表里把;IF BSP_BLUETOOTH ....那部分给注释掉, 便解决了串口启动时发送数据的问题.我觉得还是把BSP_BLUETOOTH =更为彻底.