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

📄 mp_downloader.c

📁 用于TM1300/PNX1300系列DSP(主要用于视频处理)的下载程序
💻 C
字号:
/*
 * Copyright (c) 1995,2000 TriMedia Technologies Inc.           
 *
 * +------------------------------------------------------------------+
 * | This software is furnished under a license and may only be used  |
 * | and copied in accordance with the terms and conditions of  such  |
 * | a license and with the inclusion of this copyright notice. This  |
 * | software or any other copies of this software may not be provided|
 * | or otherwise made available to any other person.  The ownership  |
 * | and title of this software is not transferred.                   |
 * |                                                                  |
 * | The information in this software is subject  to change without   |
 * | any  prior notice and should not be construed as a commitment by |
 * | TriMedia Technologies.                                           |
 * |                                                                  |
 * | this code and information is provided "as is" without any        |
 * | warranty of any kind, either expressed or implied, including but |
 * | not limited to the implied warranties of merchantability and/or  |
 * | fitness for any particular purpose.                              |
 * +------------------------------------------------------------------+
 *
 *  Module name              : MP_downloader.c    1.3
 *
 *  Last update              : 16:53:03 - 00/06/16
 *
 *  Description              :
 *
 *      This program is a demonstration of a multiprocessor 
 *      downloader; it loads and relocates a single executable
 *      object on to different processors of which information
 *      has been supplied. When this program loads on one of the
 *      processors itself, i.e. when the current processor is one
 *      of the download targets, then this MP downloader must itself
 *      be downloaded in the stack/heap gap of the loaded object;
 *      L1.c is an example of this.
 *
 *      This program simulates the loaded executable being in EEPROM:
 *      it is assumed that the EEPROM is completely memory mapped.
 *      The start and length of the EEPROM area are supplied to the
 *      first call to the downloader library. In this example, EEPROM
 *      is simulated by a region of SDRAM in to which the object is
 *      loaded from file.
 *
 */

#include "tmlib/TMDownLoader.h"
#include "assert.h"
#include "stdio.h"
#include "sys/types.h"
#include "sys/stat.h"
#include "tm1/mmio.h"

#define OBJECTFILE "program.out"
#define E(x) assert(!(x))

typedef void (*Func) ();

void        _syscall();
custom_op void iclr(void);


extern          UInt32	_host_type_init[];
extern          UInt32	_clock_freq_init[];
extern          UInt32	_begin_stack_init[];
extern volatile UInt32	_MMIO_base_init[];


Bool 
get_EEPROM_address(Pointer * address, Int * length)
{
/* fake; read it from file into memory */
	FILE       *f;
	struct stat buf;
	String      path = OBJECTFILE;

	f = fopen(path, "rb");

	if (f == Null) {
		return False;
	}
	else {

		stat(path, &buf);
		*address = (Address) malloc(buf.st_size);
		*length = buf.st_size;

		fread(*address, 1, buf.st_size, f);
		fclose(f);

		return True;
	}
}


LoadMPCluster(UInt nrof_nodes,
	      Pointer eeprom_address,
	      Int eeprom_length,
	      tmHostType_t host_type,
	      Address mmio_bases[],
	      UInt cpu_frequencies[],
	      Address sdram_bases[],
	      UInt sdram_lengths[]
)
{
	Int         node;
	TMDwnLdr_SharedSectionTab_Handle shared_sections;


	TMDwnLdr_create_shared_section_table(&shared_sections);


	for (node = 0; node < nrof_nodes; node++) {
		TMDwnLdr_Object_Handle handle;
		Int         alignment, minimal_image_size;


		E(TMDwnLdr_load_object_from_mem(eeprom_address, eeprom_length, shared_sections, &handle));

		E(TMDwnLdr_resolve_symbol(handle, "__syscall", (Int) _syscall));

		E(TMDwnLdr_multiproc_relocate(handle, host_type, mmio_bases, node, nrof_nodes,
					      cpu_frequencies[node], sdram_bases[node], sdram_lengths[node],
					TMDwnLdr_LeaveCachingToDownloader));


		E(TMDwnLdr_get_image_size(handle, &minimal_image_size, &alignment));

		assert(minimal_image_size < (Int) sdram_bases[node] + sdram_lengths[node]);
		assert((Int) sdram_bases[node] % alignment == 0);

		E(TMDwnLdr_get_memory_image(handle, sdram_bases[node]));

		E(TMDwnLdr_unload_object(handle));
	}

	TMDwnLdr_unload_shared_section_table(shared_sections);
}


#define TOP_MEM_HOLE 1000


main()
{
	Pointer     eeprom_address;
	Int         eeprom_length;

	Address     mmio_base = (Address) _MMIO_base_init;
	UInt        cpu_frequency = (UInt) _clock_freq_init;
	Address     sdram_base = (Address) MMIO(DRAM_BASE);
	UInt        sdram_length = MMIO(DRAM_LIMIT) - MMIO(DRAM_BASE) - TOP_MEM_HOLE;

	get_EEPROM_address(&eeprom_address, &eeprom_length);

	printf("Loading %s in 0x%08x - 0x%08x...\n", OBJECTFILE, sdram_base, ((UInt) sdram_base) + sdram_length);

	LoadMPCluster(1, eeprom_address, eeprom_length,
		      (tmHostType_t) _host_type_init,
		    &mmio_base, &cpu_frequency, &sdram_base, &sdram_length);

	printf("Running %s...\n", OBJECTFILE);
	_cache_copyback(sdram_base, sdram_length);
	iclr();

	((Func) sdram_base) ();
	/* never come back */
}

⌨️ 快捷键说明

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