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

📄 hpi-boot.cpp

📁 5402hpi自举加载的程序源码欢迎下载
💻 CPP
字号:
/*******************************************************************************
* Functions: main(); DSK_close(); DSK_init                                     *
* File: hpi-boot.cpp                                                           *
* Author: Scott Tater, Texas Instruments Inc.                                  *
* DSP: TMS320C5402                                                             *
* Language: C++                                                                *
* Tools: Microsoft Visual C++ V 6.0                                            *
* History:                                                                     *
*   04/27/02 - original (S. Tater)                                             *
*                                                                              *
* Description:                                                                 *
* This program demonstrates a method to boot load the 'C5402 using the         *
* Host Port Interface (HPI). The 'C5402 DSP Starter Kit (DSK) is used as a     *
* reference platform. A parsed COFF file is read into memory and transmitted   *
* to the 'C5402 through the HPI port.                                          *
*                                                                              *
* Host side libraries and include files have default root directory (CCS v2.0):*
* \ti\c5400\dsk5402\host                                                       *
*                                                                              *
* Notes: The Entry Point is hard wired in this code. It may be beneficial for  *
* the user to change this feature depending on the scope of its use. It is set *
* for the DSK Blink Demo at 0x500.                                             *
*******************************************************************************/
/* ***********************************************************
* THIS PROGRAM IS PROVIDED "AS IS". TI MAKES NO WARRANTIES OR
* REPRESENTATIONS, EITHER EXPRESS, IMPLIED OR STATUTORY,
* INCLUDING ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR
* COMPLETENESS OF RESPONSES, RESULTS AND LACK OF NEGLIGENCE.
* TI DISCLAIMS ANY WARRANTY OF TITLE, QUIET ENJOYMENT, QUIET
* POSSESSION, AND NON-INFRINGEMENT OF ANY THIRD PARTY
* INTELLECTUAL PROPERTY RIGHTS WITH REGARD TO THE PROGRAM OR
* YOUR USE OF THE PROGRAM.
*
* IN NO EVENT SHALL TI BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
* CONSEQUENTIAL OR INDIRECT DAMAGES, HOWEVER CAUSED, ON ANY
* THEORY OF LIABILITY AND WHETHER OR NOT TI HAS BEEN ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGES, ARISING IN ANY WAY OUT
* OF THIS AGREEMENT, THE PROGRAM, OR YOUR USE OF THE PROGRAM.
* EXCLUDED DAMAGES INCLUDE, BUT ARE NOT LIMITED TO, COST OF
* REMOVAL OR REINSTALLATION, COMPUTER TIME, LABOR COSTS, LOSS
* OF GOODWILL, LOSS OF PROFITS, LOSS OF SAVINGS, OR LOSS OF
* USE OR INTERRUPTION OF BUSINESS. IN NO EVENT WILL TI'S
* AGGREGATE LIABILITY UNDER THIS AGREEMENT OR ARISING OUT OF
* YOUR USE OF THE PROGRAM EXCEED FIVE HUNDRED DOLLARS
* (U.S.$500).
*
* Unless otherwise stated, the Program written and copyrighted
* by Texas Instruments is distributed as "freeware".  You may,
* only under TI's copyright in the Program, use and modify the
* Program without any charge or restriction.  You may
* distribute to third parties, provided that you transfer a
* copy of this license to the third party and the third party
* agrees to these terms by its first use of the Program. You
* must reproduce the copyright notice and any other legend of
* ownership on each copy or partial copy, of the Program.
*
* You acknowledge and agree that the Program contains
* copyrighted material, trade secrets and other TI proprietary
* information and is protected by copyright laws,
* international copyright treaties, and trade secret laws, as
* well as other intellectual property laws.  To protect TI's
* rights in the Program, you agree not to decompile, reverse
* engineer, disassemble or otherwise translate any object code
* versions of the Program to a human-readable form.  You agree
* that in no event will you alter, remove or destroy any
* copyright notice included in the Program.  TI reserves all
* rights not specifically granted under this license. Except
* as specifically provided herein, nothing in this agreement
* shall be construed as conferring by implication, estoppel,
* or otherwise, upon you, any license or other right under any
* TI patents, copyrights or trade secrets.
*
* You may not use the Program in non-TI devices.
* **********************************************************/

#include "stdafx.h"

//Globals
HANDLE hd; //DSK Handle
LPVOID hm; //HPI Handle

EVMDSK54X_BOARD_TYPE boardType = TYPE_C5402_DSK;
EVMDSK54X_OPEN_TYPE  openType = EVMDSK54X_PARALLEL_OPEN;

USHORT  port = 0x378;              // parallel port I/O address //

int DSK_init();
int DSK_close();

int main(int argc, char* argv[])
{
        FILE *fp;
        char line[80];
        char tokA[20], tokB[20], tokD[20]; //strings used to tokenize input
        int length, destaddr;
        short data[20000]; //Buffer used to hold data sections. Increase for large code
        short prog_entry=0x0500; //a default entry point

        int i,flag,eof_flag;


        if (argc == 1) { //error
                printf ("Correct Syntax: hpi-boot FILENAME\n");
                printf ("where FILENAME is a parsed COFF file\n");
                exit(1);
        } else {
                if ((fp = fopen(argv[1], "r")) == NULL)
                        printf ("File could not be opened for reading\n");
        }


        if (DSK_init()) //Initialize the DSK--open the DSK, HPI port, and configure
                exit(-1);

        eof_flag=0; //shows if end of sections reached

        //This section scans for a new data section in the parsed file.
        //The new section is read into memory and then written to the DSP
        //When there are no more sections to read, the entry point is
        //writen to stop the boot process
        while (!eof_flag){
                while ((fscanf(fp, "%s", tokA) != EOF) && (flag =(strncmp(tokA, "Section", 7)) != 0));
                if (!flag) {

                        fgets(line, sizeof(line), fp); //read src addr line
                        fgets(line, sizeof(line), fp); //read length line
                        fscanf(fp, "%s %s %x %s", tokA, tokB, &length, tokD);

                        fscanf(fp, "%s %s %x %s", tokA, tokB, &destaddr, tokD); //read dest addr


                        fgets(line, sizeof(line), fp); //read spc addr line
                        fgets(line, sizeof(line), fp); //read blank line


                        for (i=0; i< length; i++){ //reads and records data values
                                fscanf(fp, "%x,", &data[i]);
                        }

                        // write single program section to 'C5402
                        printf("\n**    Writing data section for HPI boot\n");
						printf("Section Length: %#x\n", length);
						printf("Destination Address: %#x\n\n", destaddr);
                        if (!evmdsk54x_hpi_write(hm, (PULONG) data, (PULONG) &length, (ULONG)destaddr, PROG_MEMORY, 0))
                        {
                                printf(" -- failed");
                                return (-1);
                        }

                }
                else {
                        eof_flag = 1;
                        //  write prog start address in data mem 0x007F
                        printf("**    Writing program entry point to complete HPI boot\n");
						printf("Entry point: %#x written at location 0x007f\n", prog_entry);
                        if (!evmdsk54x_hpi_write_single(hm, (PULONG) &prog_entry, (ULONG)0x7F, DATA_MEMORY, 0))
                        {
                                printf(" -- failed");
                                return (-1);
                        }

                        //  ** End of standard initialization for 5402 DSK HPI access and HPI booting **
        }
        }
                        printf("\nClosing...\n\n");
                        if (DSK_close())
                         exit (-1);

        return 0;
}


int DSK_init() {

        //  ** Standard initialization for 5402 DSK HPI access and HPI booting **

        //  open a communication port with the
        //  DSK parallel port interface
        printf ("\n**   Initializing DSK communication channel");
        if ((hd = evmdsk54x_open(port, boardType, openType, 1))
                == INVALID_HANDLE_VALUE)
        {
				printf ("!! Error:\n");
                printf ("evmdsk54x_open failed");
                return (-1);
        }

        //  open a communication port with the HPI
        printf ("\n**   Opening HPI");
        if (!(hm = evmdsk54x_hpi_open(hd)))
        {
				printf ("!! Error:\n");
                printf ("evmdsk54x_hpi_open failed");
                return (-1);
        }

        //  hold the DSP in reset
        printf("\n**    Resetting DSP");
        if (!evmdsk54x_reset_dsp(hd, (ULONG)0x00))
        {
				printf ("!! Error:\n");
                printf ("evmdsk54x_reset_dsp failed");
                return (-1);
        }

        //  take the DSP out of reset
        printf("\n**    Taking DSP out of reset");
        if (!evmdsk54x_unreset_dsp(hd, (ULONG) 0x00))
        {
			    printf ("!! Error:\n");
                printf ("evmdsk54x_unreset_dsp failed");
                return (-1);
        }

        //  disable on board flash access to ensure HPI
        //  memory access will not affect the on-board flash
        printf("\n**    Disabling FLASH access");
        if (!evmdsk54x_flash_access(hd, FALSE))
        {
			printf ("!! Error:\n");
            printf ("evmdsk54x_flash_access failed");
            return (-1);
        }
        printf("\n**    DSK Init Passed\n\n");
        return 0;
}


int DSK_close() {

        //  close HPI communication port
        printf ("**      Closing HPI\n");
        if (!evmdsk54x_hpi_close(hm))
        {
			printf ("!! Error:\n");
            printf ("evmdsk54x_hpi_close failed\n");
            return(-1);
        }

        //  close DSK communicaiton port
        printf ("**      Closing DSK communication channel\n");
        if (!evmdsk54x_close(hd))
        {
			printf ("!! Error:\n");
            printf ("evmdsk54x_close failed\n");
            return(-1);
        }
        return(0);
}

/******************************************************************************\
* End of hpi-boot.cpp
\******************************************************************************/

⌨️ 快捷键说明

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