⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ser.c

📁 Windows CE 6.0 BSP for the Beagle Board.
💻 C
字号:
//
// Copyright (c) Special Computing.  All rights reserved. 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//------------------------------------------------------------------------------
//
//  File:  ser.c
//
//  This file implements bootloader functions related to serial download
//  
#include <oal_blserial.h>
#include <eboot.h>
#include <bsp.h>


extern BOOL   UARTInit(KITL_SERIAL_INFO *pInfo);
extern UINT16 UARTSend(UINT8 *pData, UINT16 size);
extern UINT16 UARTRecv(UINT8 *pData, UINT16 size);
extern VOID   UARTFlowControl(BOOL fOn);

//------------------------------------------------------------------------------
//
//  Function:  BLSerDownload
//
//  This function initialize serial download.
//
UINT32 BLSerDownload(BOOT_CFG *pConfig, OAL_KITL_DEVICE *pBootDevices)
{
	KITL_SERIAL_INFO info;
    UINT8 deviceId[OAL_KITL_ID_SIZE];
	
	UINT32 rc = BL_ERROR;
    BOOL  fGotJumpImg = FALSE;
	UINT32 *pPADCONF = (UINT32 *)(OMAP3_SCM_REGS_PA + 0x16C);	// point to GPIO pad 140/141
    OMAP3_CM_CORE_REGS *pCMRegs = (OMAP3_CM_CORE_REGS *)OMAP3_CM_CORE_REGS_PA;

	// configure expansion McBSP3 to UART2
	*pPADCONF = 0x00010119;		// MODE1 UART2 RTS/CTS
	pPADCONF++;					// point to GPIO pad 142/143
	*pPADCONF = 0x01010001;		// MODE1 UART2 RX/TX
	pPADCONF++;					// point to GPIO pad 144/145
	*pPADCONF = 0x00040004;		// UART2 RTS/CTS OFF
	pPADCONF++;					// point to GPIO pad 146/147
	*pPADCONF = 0x00040004;		// UART2 RX/TX OFF

    // turn on the clocks
    SETREG32(&pCMRegs->ulFCLKEN1, CM_CORE_FCLKEN1_EN_UART2);
    SETREG32(&pCMRegs->ulICLKEN1, CM_CORE_ICLKEN1_EN_UART2);


	info.pAddress = (UINT8 *)KITL_UART_REGS_PA;
	info.baudRate = CBR_115200;
	info.dataBits = DATABITS_8;
	info.stopBits = ONESTOPBIT;
	info.parity = NOPARITY;
	

	if (!UARTInit(&info))
	{
        OALLog(L"Error initializing serial kitl device!\r\n");
		goto cleanUp;
	}

    // Generate device name
    OALKitlCreateName(BSP_DEVICE_PREFIX, NULL, deviceId);
    OALMSG(OAL_INFO, (L"INFO: "
        L"*** Device Name %S ***\r\n", deviceId
    ));

	// Send boot requests indefinitely
    do
    {
        OALLog(L"Sending boot request...\r\n");
        if(!SerialSendBootRequest(BSP_DEVICE_PREFIX))
        {
            OALLog(L"Failed to send boot request\r\n");
            goto cleanUp;
        }
    }
    while(!SerialWaitForBootAck(&fGotJumpImg));
    
    // Ack block zero to start the download
    SerialSendBlockAck(0);

    if( fGotJumpImg )
    {
        OALLog(L"Received boot request ack... jumping to image\r\n");
    }
    else
    {
        OALLog(L"Received boot request ack... starting download\r\n");
    }
    fGotJumpImg  ? (rc = BL_JUMP) : (rc = BL_DOWNLOAD);
	
cleanUp:
    return rc;
}


//------------------------------------------------------------------------------
//
//  Function:  OEMSerialSendRaw
//
//  Sends raw data to the serial download transport.
//
//------------------------------------------------------------------------------
BOOL OEMSerialSendRaw(LPBYTE pbFrame, USHORT cbFrame)
{
	UINT16 count;

	count = UARTSend(pbFrame, cbFrame);

    return (0 != count);
}


//------------------------------------------------------------------------------
//
//  Function:  OEMSerialRecvRaw
//
//  Receives raw data from the serial download transport.
//
//------------------------------------------------------------------------------
BOOL OEMSerialRecvRaw(LPBYTE pbFrame, PUSHORT pcbFrame, BOOLEAN bWaitInfinite)
{
    USHORT ct = 0;
    DWORD tStart = 0;

	UARTFlowControl(TRUE);


	for(ct = 0; ct < *pcbFrame; ct++)
	{
		if (!bWaitInfinite)
		{
			tStart = OEMEthGetSecs();
		}

		while(0 == UARTRecv(pbFrame + ct, 1))
		{
			if(!bWaitInfinite && (OEMEthGetSecs() - tStart > TIMEOUT_RECV))
			{
				*pcbFrame = 0;
				UARTFlowControl(FALSE);
				return FALSE;
			}            
		}

		// check for comm errors
		if (OEM_DEBUG_COM_ERROR == *pbFrame)
		{
			*pcbFrame = 0;
			OALLog(L"Comm errors have occurred!\r\n");
			return FALSE;
		}
	}
	UARTFlowControl(FALSE);

	return TRUE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -