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

📄 parallel.c

📁 CIRRUS 公司EP93XX系列CPU的WINCE下的BSP
💻 C
字号:
//**********************************************************************
//                                                                      
// Filename: parallel.c
//                                                                      
// Description: Used for downloading through the parallel port.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
// Copyright(c) Cirrus Logic Corporation 2001, All Rights Reserved                       
//                                                                      
//**********************************************************************
#include <windows.h>
#include <hwdefs.h>
#include <mdppfs.h>
#include <halether.h>



//
// Global defines and declarations
//
const unsigned char   BootHeader[] = {
    0xAA,                               // header = 4 bytes
    0x55,
    0x55,
    0xAA,
    0x00,                               // opcode = 2 bytes (0 = BOOT)
    0x00,
    };
#define BOOT_HEADER_SIZE (sizeof(BootHeader) / sizeof(BootHeader[0]))

const unsigned char   BootTail[] = {
    0x5A,                               // trail = 4 bytes
    0xA5,
    0x0A,
    0x1A
    };
#define BOOT_TAIL_SIZE (sizeof(BootTail) / sizeof(BootTail[0]))

#define BOOT_TYPE           -1

//***************************************************************************
//  ParallelPortRead - read bytes from parallel port
//
//  Syntax:
//
//    int
//    ParallelPortRead(
//        unsigned char * pByteReceived,
//        unsigned int    cb
//        );
//
//  Arguments:
//
//    pByteReceived (a0)  : points to the buffer to receive data
//    cb            (a1)  : number of bytes to read
//
//Return Value:
//
//    returns the number of bytes left to read (in our case, always 0)
//***************************************************************************
BOOL  ParallelPortRead (DWORD cb, LPBYTE pByteReceived)
{
    //for(;;) { OEMParallelPortGetByte();}

    int result;
    while (cb && (result=OEMParallelPortGetByte()) != -1) {
        *pByteReceived++= (unsigned char)result;
        cb--;
    }
    return cb;
}

/*++

ParallelPortWrite:

    This routine has been optimized for parallel port output.

Syntax:

    int
    ParallelPortWrite(
        unsigned char * pByteReceived,
        unsigned int    cb
        );

Arguments:

    pByteReceived (a0)  : points to the buffer to send
    cb            (a1)  : number of bytes to send

Return Value:

    in v0, the number bytes left to write

--*/
//***************************************************************************
//  ParallelPortWrite
//***************************************************************************
int ParallelPortWrite(const unsigned char *pByteSend, unsigned int cb) 
{
    while (cb--)
        OEMParallelPortSendByte(*pByteSend++);
    return cb;
}


//****************************************************************************
// ParallelPreDownload
//****************************************************************************
// Sends out the boot header to the PC.
// 
// Return   TRUE successful, FALSE failure.
//
DWORD ParallelPreDownload(void)
{
    unsigned char * pDestByte;
    unsigned int    chksum;
    unsigned int    uiTemp;
    int             bootType;
    unsigned        len;
    int             i;
    int             nReturn=0;
    unsigned char   ParallelSendBuffer[2 + sizeof(int) + BOOT_TAIL_SIZE];

    EdbgOutputDebugString(".");
    //
    // Prepare boot packet
    //
    pDestByte = ParallelSendBuffer;
    for (i = 0; i < BOOT_HEADER_SIZE; i++) 
    {
        *pDestByte++ = BootHeader[i];
    }
    
    chksum = 0;
    len = sizeof(unsigned int) + 5;
    
    bootType = BOOT_TYPE; 
    
    uiTemp = len;
    for (i = 0; i < 2; i++) 
    {
        *pDestByte++ = (unsigned char)(uiTemp & 0xFF);
        chksum += (uiTemp & 0xFF);
        uiTemp >>= 8;
    }
    
    uiTemp = bootType;
    for (i = 0; i < sizeof(int); i++) 
    {
        *pDestByte++ = (unsigned char)(uiTemp & 0xFF);
        chksum += (uiTemp & 0xFF);
        uiTemp >>= 8;
    }
    
    *pDestByte++ = (unsigned char)((~chksum) & 0xFF);
    
    for (i = 0; i < BOOT_TAIL_SIZE; i++) 
    {
        *pDestByte++ = BootTail[i];
    }

    nReturn=ParallelPortWrite
    (
        ParallelSendBuffer, 
        (unsigned int)(pDestByte - ParallelSendBuffer)
    );
    
    return nReturn;
}

⌨️ 快捷键说明

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