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

📄 overlay_manager.c

📁 LPC2102的keil vendor code
💻 C
字号:
/* Basic overlay manager */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* Number of overlays present */
#define NUM_OVERLAYS 2

/* struct to hold addresses and lengths */
typedef struct overlay_region_t_struct
{
	void* load_rw_base;
	void* exec_zi_base;
	unsigned int zi_length;
} overlay_region_t;

/* Record for current overlay */
int current_overlay = 0;

/* Array describing the overlays */
extern const overlay_region_t overlay_regions[NUM_OVERLAYS];

/* execution bases of the overlay regions - defined in overlay_list.s */
extern void * const data_base;

void load_overlay(int n)
{
 	const overlay_region_t * selected_region;

	if(n == current_overlay)
		return;
	
	/* boundary check */
	if(n<1 || n>NUM_OVERLAYS)
		exit(1);
	
	/* set selected region */
	selected_region = &overlay_regions[n-1];
	
	/* load data overlay */
	memcpy(data_base, selected_region->load_rw_base, (unsigned int)selected_region->exec_zi_base - (unsigned int)data_base);
	
	/* Comment out the next line if your overlays have any static ZI variables
	 * and should not be reinitialized each time, and move them out of the
	 * overlay region in your scatter file */
	memset(selected_region->exec_zi_base, 0, selected_region->zi_length);

	/* update record of current overlay */
	current_overlay=n;
}

⌨️ 快捷键说明

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