昨天解决了一个问题,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.youkuaiyun.com/fredzeng/archive/2006/09/27/1296195.aspx
二.分析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 的初始化函数
- virtual BOOL CBulPdd16550BUART::Init() {
- /*@ CYH MASK for UART function
- BSP_ARGS args;
- DWORD size;*/
- /* Default, Bluetooth is disabled */
- m_bBluetoothUsageFlag = FALSE;
- /* Check EBOOT BSP Configuration if it need to turn Bluetooth Module */
- /* @ CYH MASK for UART function
- //注释掉这部分,这部分的功能是读取EBOOT中的配置,根据配置是否使能BlueTooth功能
- if(KernelIoControl(IOCTL_GET_BSP_ARGS,NULL,0, &args, sizeof(args), &size))
- {
- NKDbgPrintfW(TEXT("[BTUART: Bluetooth] ConfigurePinout args.BTWLAMComboCardUsage = 0x%x!/r/n"), args.BTWLAMComboCardUsage);
- if ((args.BTWLAMComboCardUsage&BSP_ARGS_BTWLAN_BT) || (args.BTWLAMComboCardUsage&BSP_ARGS_BTWLAN_BOTH))
- {
- RETAILMSG(1, (_T("[BTUART: Bluetooth] Bluetooth will be enalbed +!/r/n")));
- m_bBluetoothUsageFlag = TRUE;
- // Map the I2C and OST register address
- PHYSICAL_ADDRESS PA;
- PA.QuadPart = MONAHANS_BASE_REG_PA_I2C;
- m_pI2CReg = (P_XLLP_I2C_T) MmMapIoSpace(PA, sizeof(XLLP_I2C_T), FALSE);
- PA.QuadPart = MONAHANS_BASE_REG_PA_OST;
- m_pOstReg = (P_XLLP_OST_T) MmMapIoSpace(PA, sizeof(XLLP_OST_T), FALSE);
- }
- else
- {
- RETAILMSG(1, (_T("[BTUART: Bluetooth] Bluetooth will not be enalbed./r/n")));
- // Currently, the BTUART will not be loaded if the Bluetooth is not required /
- RETAILMSG(1, (_T("[BTUART] BTUART will not be enalbed./r/n")));
- m_bBluetoothUsageFlag = FALSE;
- return FALSE;
- }
- }
- @ CYH MASK for UART function */
- m_UART_Handle.UARTSelection = XLLP_BTUART;
- if (CBulPdd16550::Init())
- {
- ConfigurePinout();
- RETAILMSG(1, (_T("[BTUART] Init Successful!/r/n")));
- }
- else
- {
- RETAILMSG(1, (_T("[BTUART] Init Failed!/r/n")));
- return FALSE;
- }
- return TRUE;
- }
在Open ,Close里把bloutooth 相关的I2C操作注释掉,D0CS相关的代码也注释掉.
- virtual BOOL CBulPdd16550BUART::Open()
- {
- BOOL bReturn;
- RETAILMSG(1, (_T("[BTUART] Open./r/n")));
- // Enable BTUART clock during driver is opened
- XllpClockEnable(m_pDCCLKReg, XLLP_CLK_BTUART, XLLP_TRUE);
- /*
- // Deivce is opened, notify IPM that do not enter D0CS
- RETAILMSG(1, (_T("[%s]:Deivce is opened, notify IPM that do not enter D0CS/r/n"), szName));
- if ( (IPM_NotifyReadyForProcState(ClientID, IPM_PROCESSOR_D0_RDY ,3000)!=IPM_STATUS_SUCCESS)||
- (IPM_SetMinOp(ClientID,IPM_OP_104MHZ, 3000) != IPM_STATUS_SUCCESS) )
- RETAILMSG(1, (_T("[%s]: IPM_SetMinOp failed/r/n"), szName));
- */
- bReturn = CBulPdd16550::Open();
- /* Check if it need to turn on Bluetooth part on Combo card */
- /* @ CYH MASK for UART function
- if (m_bBluetoothUsageFlag)
- {
- RETAILMSG(1, (_T("[BTUART: Bluetooth] Start Enable BT./r/n")));
- // /* Currrently, only support Rev 1.2 combo card /
- // Enable the BT 26MHz clock
- MBW_BTClkEnable(TRUE);
- // Make the BT core out of the reset state
- MBW_BTReset();
- }
- @ CYH MASK for UART function */
- return bReturn;
- }
- virtual BOOL CBulPdd16550BUART::Close()
- {
- BOOL bReturn = CBulPdd16550::Close();
- /*
- // device is closed, notify IPM that no restricts from BTUART side.
- RETAILMSG(1, (_T("[%s]: device is closed, notify IPM that no restricts from BTUART side./r/n"), szName));
- 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)||
- (IPM_ReleaseMinOp(ClientID, 3000) != IPM_STATUS_SUCCESS) )
- RETAILMSG(1, (_T("[%s]: IPM_ReleaseMinOp failed/r/n"),szName));*/
- /* Check if it need to turn off Bluetooth part on Combo card */
- /*@ CYH MASK for UART function
- if (m_bBluetoothUsageFlag)
- {
- RETAILMSG(1, (_T("[BTUART: Bluetooth] Start Disable BT./r/n")));
- MBW_BTClkEnable(FALSE);
- }@ CYH MASK for UART function*/
- // Disable BTUART clock during driver is cloesed
- XllpClockEnable(m_pDCCLKReg, XLLP_CLK_BTUART, XLLP_FALSE);
- RETAILMSG(1, (_T("[BTUART] Close./r/n")));
- return bReturn;
- }
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 相关的定义
- static XLLP_UINT32_T xllp_btuart_mfp_list[] = {
- // XLLP_MFP_RSVD_BT_RTS_OFFSET,
- XLLP_MFP_RSVD_BT_RXD_OFFSET,
- XLLP_MFP_RSVD_BT_TXD_OFFSET,
- // XLLP_MFP_RSVD_BT_CTS_OFFSET,
- XLLP_MFP_PIN_EOLIST_MARKER
- };
- static XLLP_MFP_ALT_FN_T xllp_btuart_af_list[] = {
- // XLLP_MFP_RSVD_BT_RTS_AF,
- XLLP_MFP_RSVD_BT_RXD_AF,
- XLLP_MFP_RSVD_BT_TXD_AF,
- // XLLP_MFP_RSVD_BT_CTS_AF
- };
- static XLLP_MFP_DRIVE_STRENGTH_T xllp_btuart_ds_list[] = {
- // XLLP_MFP_DEFAULT_DS,
- // XLLP_MFP_DEFAULT_DS,
- XLLP_MFP_DEFAULT_DS,
- XLLP_MFP_DEFAULT_DS
- };
- static XLLP_MFP_LPM_OUTPUT_T xllp_btuart_lpm_output_list[] = {
- // XLLP_MFP_RSVD_BT_RTS_LPM,
- XLLP_MFP_RSVD_BT_RXD_LPM,
- XLLP_MFP_RSVD_BT_TXD_LPM,
- // XLLP_MFP_RSVD_BT_CTS_LPM
- };
查看注册表,发现有BSP_BLUETOOTH 条件控制的注册表项,都是蓝牙相关的,是不需要的
C:/WINCE500/PLATFORM/ZYLONITE_MHL/FILES/zylonite_common.reg
- ;IF BSP_BLUETOOTH
- ; @CESYSGEN IF CE_MODULES_BTD
- ; @XIPREGION IF PACKAGE_OEMDRIVERS
- [HKEY_LOCAL_MACHINE/Software/Microsoft/Bluetooth/HCI]
- "Name"="COM5:" ;LOC_FRIENDLYNAME_SERIAL2 ;"COM5:"
- ; disable hardware detect when external bluetooth card is inserted. Onlye support static bingding
- [HKEY_LOCAL_MACHINE/Software/Microsoft/Bluetooth/Settings]
- "IgnoreExternal"=dword:1
- ;
- [HKEY_LOCAL_MACHINE/Software/Microsoft/Bluetooth/Transports/BuiltIn/1]
- "driver"="bthcsr.dll"
- ; "driver"="bthuart.dll"
- "flags"=dword:4
- "name"="COM5:" ;LOC_FRIENDLYNAME_SERIAL2 ;"COM5:"
- "baud"=dword:1c200
- "resetdelay"=dword:0
- ; Ericsson dongle/dev board
- ; SiW boxes
- ;[HKEY_LOCAL_MACHINE/ExtModems/bluetooth_dcn]
- ;"port"="COM8:"
- ;"DeviceType"=dword:0
- ;"FriendlyName"="BluetoothDCN"
- ;[HKEY_LOCAL_MACHINE/ExtModems/bluetooth_dun]
- ; "port"="COM8:"
- ; "DeviceType"=dword:1
- ; "FriendlyName"="BluetoothDUN"
- [HKEY_LOCAL_MACHINE/Software/Microsoft/Bluetooth/HandsfreeProfileOn]
- ; the next line is not required but it looks like
- ; if nothing is here the key "HandsfreeProfileOn" will not be added
- ; maybe this has already been fixed
- @="HandsfreeProfileOn"
- [HKEY_LOCAL_MACHINE/Software/Microsoft/Bluetooth/AudioGateway]
- "Capability"=dword:21
- "MapAudioToPcmMode"=dword:1 ;0
- "ConnectScoInAlways"=dword:0
- [HKEY_LOCAL_MACHINE/Software/Microsoft/Obex]
- "IsEnabled"=dword:1
- [HKEY_LOCAL_MACHINE/Software/Microsoft/Obex/Services/{00000000-0000-0000-0000-000000000000}]
- "TransportAuthenticate"=dword:1
- [HKEY_LOCAL_MACHINE/Drivers/BuiltIn/BtScoSnd]
- "Prefix"="WAV"
- "Dll"="btscosnd.dll"
- "Order"=dword:25
- [HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Bluetooth/ScoWav]
- "Direction"=dword:0
- "AirCoding"=dword:0
- "ConnectInTimeout"=dword:10000
- "8BitSignedSamples"=dword:1
- ;Specifying headset address for MapAudioToPcmMode=1
- "AddressOut"=hex:00,00,00,00,00,00 ; 00,07,A4,01,C2,69 ;00,00,00,00,00,00
- ; Set default Bluetooth Class of Device
- ; BTH_COD_MAJOR_DEVICE_CLASS_COMPUTER | BTH_COD_MINOR_COMPUTER_PDA | BTH_COD_MAJOR_SERVICE_CLASS_OBEX
- ; 0x100 + 0x14 + 0x100000
- [HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Bluetooth/SYS]
- "COD"=dword:920114 ;920100 ;100114
- ; @XIPREGION ENDIF PACKAGE_OEMDRIVERS
- ; @CESYSGEN ENDIF CE_MODULES_BTD
- ENDIF
在BSP所在路径下搜索了BSP_BLUETOOTH,发现以下的文件了也有相关的内容.
C:/WINCE500/PLATFORM/ZYLONITE_MHL/PB5x_Cmd_Line_Bld_Env_Vars.bat
- if /i "%BSP_BLUETOOTH%"=="" goto :SKIP_BLUETOOTH
- REM Bluetooth settings
- set SYSGEN_BTH=1
- set SYSGEN_BTH_PAN=1
- set PRJ_BTH_PAN_GN=1
- set SYSGEN_BTH_AG=1
- set SYSGEN_BTH_AUDIO=1
- set SYSGEN_BTH_MODEM=1
- set SYSGEN_BTH_UTILS=1
- set SYSGEN_BTH_AVDTP=1
- set SYSGEN_BTH_AVCTP=1
- set SYSGEN_BTH_AVRCP=1
- set SYSGEN_BTH_A2DP=1
- :SKIP_BLUETOOTH
重新设置回原来的值BSP_BLUETOOTH = 或者在注册表里把;IF BSP_BLUETOOTH ....那部分给注释掉, 便解决了串口启动时发送数据的问题.我觉得还是把BSP_BLUETOOTH =更为彻底.