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

📄 jd5xxhst.c

📁 EVM板JPEG实现,Texas Instruments TMS320C54x EVM JPEG
💻 C
字号:
/*********************************************************************
*       (C) COPYRIGHT TEXAS INSTRUMENTS, INC. 1996                   *
**********************************************************************/
/* jd5xxhst.c
 * 'C54x EVM JPEG Decompression - Host Functions
 * This file contains all functions used by the host to communicate with
 * the EVM.
 * See jd5xx.h for an explanation of definitions used in this file.
 *
 * Kamal Swamidoss
 * 4 July 1996
 */

#include <stdio.h>
#include <dos.h>
#include <time.h>
#include "jd5xx.h"

#define HBIO         0x0800     /* HBIO bit in host control register       */
#define BASE_ADDR    0x0240     /* (default) PC base address for i/o space */

unsigned int PC_A  ;
unsigned int PC_B  ;
unsigned int PC_ST1;
unsigned int PC_ST2;
extern int debug_mode;
extern unsigned int recd_byte_count;
extern unsigned int sent_byte_count;

unsigned int receive_command(void);
int    get_word(void);
int    arst(void);
int    axst(void);
FILE  *out;
FILE  *in;
time_t timer_start;
time_t timer_now;

char  *fname(char *,int);
char   ifile[256];
char   ofile[256];

void init_target(void)
{
	PC_A   = BASE_ADDR + 0x0800;
	PC_B   = BASE_ADDR + 0x0804;
	PC_ST1 = BASE_ADDR + 0x0808;
	PC_ST2 = BASE_ADDR + 0x080A;

	fprintf(stderr,"\t\tInitiating communication...");
	timer_start = time(NULL);
	outport(PC_ST2,inport(PC_ST1));

   /* pulse HBIO until EVM acknowledges */
   while (!arst())
	{
		outport(PC_ST1,inport(PC_ST1) |  HBIO);
		outport(PC_ST1,inport(PC_ST1) & ~HBIO);
		if (time(NULL)-timer_start > 3)
		{
			fputs("EVM not responding. Exiting.\n",stderr);
			exit(0);
		}
	}

	outport(PC_ST2,inport(PC_ST1));
	timer_now = time(NULL);
	fprintf(stderr,"\n%d\t\tCommunication initiated.\n",timer_now-timer_start);
}

/* open input and output files */
void open_files(char *ifname,char *ofname)
{
	char ch[128];

	strcpy(ifile,ifname);
	strcpy(ofile,ofname);

	if ((in = fopen(ifile,"rb")) == NULL)
	{
		fclose(in);
		fprintf(stderr,"\t\tCannot open input file %s.\n",ifile);
		exit(EXIT_ERR);
	}

	if ((out = fopen(ofile,"rb")) != NULL)
	{
		fclose(out);
		fprintf(stderr,"\t\tOutput file %s exists. Overwrite? ",ofile);
		scanf("%s",ch);

		if ((*ch == 'y') || (*ch == 'Y'))
		{
			fputs("\t\tOverwriting.\n",stderr);
			out = fopen(ofile,"wb");
		}
		else
		{
			fclose(in);
			fputs("\t\tExiting.\n",stderr);
			exit(EXIT_VOL);
		}
	}
	else
	{
		fclose(out);
		out = fopen(ofile,"wb");
	}

	fprintf(stderr,"\t\tInput file %s opened successfully.\n",ifile);
}

/* close input and output files */
void close_files()
{
	fclose(in);
	fclose(out);
	timer_now = time(NULL);
	fprintf(stderr,"\t\tFiles %s and %s closed successfully.\n",ifile,ofile);
}

void send_command(unsigned int cmd)
{
	outport(PC_A,cmd);
	if (debug_mode >= 2)
		fprintf(stdout,"SENT CMD %d = 0x%4x\n",cmd,cmd);
 	while (axst());
}

unsigned int receive_command(void)
{
	static unsigned int tmp;
	while (!arst());
	tmp = inport(PC_A);
	if (debug_mode >= 2)
		fprintf(stdout,"RECD CMD %d = 0x%4x\n",tmp,tmp);
	return(tmp);
}

int receive_data(void)
{
	static int data;
	data = inport(PC_B);
	fputc(data,out);
	if (debug_mode >= 2)
		fprintf(stdout,"RECD DTA %d = 0x%4x\n",data,data);

	++recd_byte_count;
	return(data);
}

int send_data(void)
{
	static int data;
	data = fgetc(in);

	if (data == EOF)
	{
		timer_now = time(NULL);
      if (debug_mode >= 2)
			fprintf(stdout,"%d\t\tEnd of file.\n",timer_now-timer_start);
		fclose(in);
	}

	outport(PC_B,data);
	if (debug_mode >= 2)
		fprintf(stdout,"SENT DTA %d = 0x%4x\n",data,data);
	++sent_byte_count;
	return(data);
}

int arst(void)
{
	static unsigned int tmp;
	tmp = inport(PC_ST1);
	tmp = tmp&ARST;

	if (tmp == ARST)
		return(1);

	return(0);
}

int axst(void)
{
	static unsigned int tmp;
	tmp = inport(PC_ST1);
	tmp = tmp&AXST;

	if (tmp == AXST)
		return(1);

	return(0);
}

/* fname strips the path and optionally strips the extension from a given
 * filename string. fname returns the remaining string in lower-case.
 */
char *fname(char *full_name,int fname_code)
{
	char str[512];
	int  s;

	strcpy(str,full_name);
	s = strlen(str) - 1;

	if (fname_code == 1)        /* use code 1 to strip filename extension */
	{
		while (str[s] != '.')
		{
			if ((str[s] == '\\') || (s == 0))
			{
				s = strlen(str) - 1;
				break;
			}

			--s;
		}

		if (str[s] == '.')
			str[s--] = '\0';
	}

	while (str[s] != '\\')
		if (s == 0)
		{
			str[s--] = (char) tolower(str[s]);
			break;
		}
		else
		{
			str[s] = (char) tolower(str[s]);
			--s;
		}

	return (&str[s+1]);
}

⌨️ 快捷键说明

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