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

📄 jd5xx.c

📁 EVM板JPEG实现,Texas Instruments TMS320C54x EVM JPEG
💻 C
字号:
/*********************************************************************
*       (C) COPYRIGHT TEXAS INSTRUMENTS, INC. 1996                   *
**********************************************************************/
/* jd5xx.c
 * 'C54x EVM JPEG Decompression - Main Host File
 *
 * by Kamal Swamidoss
 * 4 July 1996
 */

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>                                  /* for kbhit()         */
#include <string.h>
#include <ctype.h>
#include <time.h>
#include "jd5xxhst.h"                               /* host dcmp. routines */

extern void close_files(void);
void  usage(char *);
char *extension(char *,char *,int);
int   debug_mode = 0;
unsigned int sent_byte_count=0;                  /* for debugging purposes */
unsigned int recd_byte_count=0;                  /* for debugging purposes */

int main(int argc, char *argv[])
{
	unsigned int tmp;
	int  main_done  = 0;
	char exfile[32];                    /* name of executable host file     */
	char buffer1[256],buffer2[256];
	FILE *errfile;

	fputs("Texas Instruments TMS320C54x JPEG Decompression\n",stdout);
   /* parse command line */
	strcpy(exfile,fname(argv[0],1));

	if ((argc > 3) || (argc == 1))
		usage(exfile);

	if (argc == 2)
	{
		debug_mode = 1;
		strcpy(buffer1,extension(argv[1],"jpg",0));
		strcpy(buffer2,extension(argv[1],"ppm",1));
	}
	else
	{
		strcpy(buffer1,argv[1]);

		if     ((strcmp(buffer1,"-debug") == 0) || (strcmp(buffer1,"-debug1") == 0))
		{
			debug_mode = 1;
			strcpy(buffer1,extension(argv[2],"jpg",0));
			strcpy(buffer2,extension(argv[2],"ppm",1));
		}
		else if (strcmp(buffer1,"-debug2") == 0)
		{
			debug_mode = 2;
			strcpy(buffer1,extension(argv[2],"jpg",0));
			strcpy(buffer2,extension(argv[2],"ppm",1));
		}
		else if (strcmp(buffer1,"-debug0") == 0)
		{
			debug_mode = 0;
			strcpy(buffer1,extension(argv[2],"jpg",0));
			strcpy(buffer2,extension(argv[2],"ppm",1));
		}
		else
		{
			debug_mode = 1;
			strcpy(buffer1,extension(argv[1],"jpg",0));
			strcpy(buffer2,extension(argv[2],"ppm",0));
		}
	}

   /* initialize communications with EVM */
	init_target();
   /* open input and output files, whose names are in buffer1 and buffer2 */
	open_files(buffer1,buffer2);

   /* wait for EVM to signal "done" */
	while (!main_done)
	{
      /* wait for EVM to send a command, and get it */
		tmp=receive_command();

		switch (tmp)
		{
			case (SND):	{
                        /* read a word of data from the input file
                         * and send it to the EVM
                         */
								if (send_data() == EOF)
									send_command(ERR8);        /* end-of-file error */
								else
									send_command(RCV);

								break;
							}
			case (RCV): {
                        /* receive a word of data from the EVM
                         * and write it to the output file
                         */
								receive_data();
								send_command(ACK);

								break;
							}
			case(NOMEM):{
								timer_now=time(NULL);
								fprintf(stdout,"%d\t\tError: EVM out of memory.\n",
									 timer_now-timer_start);
								send_command(ACK);
								main_done=1;
								break;
							}
			case (ERR0):{
								timer_now = time(NULL);
								fprintf(stdout,"%d\t\tError0\n",
									 timer_now-timer_start);
								send_command(ACK);
								main_done = 1;
								break;
							}
			case (ERR1):{
								timer_now = time(NULL);
								fprintf(stdout,"%d\t\tError 1: Unable to write PPM output.\n",
									 timer_now-timer_start);
								send_command(ACK);
								main_done = 1;
								break;
							}
			case (ERR2):{
								timer_now = time(NULL);
								fprintf(stdout,"%d\t\tError2\n",
									 timer_now-timer_start);
								send_command(ACK);
								main_done = 1;
								break;
							}
			case (ERR3):{
								timer_now = time(NULL);
								fprintf(stdout,"%d\t\tError 3: Insufficient memory.\n",
									 timer_now-timer_start);
								send_command(ACK);
								main_done = 1;
								break;
							}
			case (ERR4):{
								timer_now = time(NULL);
								if (debug_mode >= 1)
								fprintf(stdout,"%d\t\tWarning4\n",
									 timer_now-timer_start);
								break;
							}
			case (ERR5):{
								timer_now = time(NULL);
								if (debug_mode >= 1)
								fprintf(stdout,"%d\t\tWarning5\n",
									 timer_now-timer_start);
								break;
							}
			case (ERR6):{
								timer_now = time(NULL);
								fprintf(stdout,"%d\t\tError 6: Input not a JPEG file.\n",
									  timer_now-timer_start);
								send_command(ACK);
								main_done = 1;
								break;
							}
			case (ERR7):{
								timer_now = time(NULL);
								fprintf(stdout,"%d\t\tError7\n",
									 timer_now-timer_start);
								send_command(ACK);
								main_done = 1;
								break;
							}
			case (ERR8):{
								timer_now = time(NULL);
								fprintf(stdout,"%d\t\tError 8: PPM output must be grayscale or RGB.\n",
									 timer_now-timer_start);
								send_command(ACK);
								main_done = 1;
								break;
							}
			case (ERR9):{
								timer_now = time(NULL);
								fprintf(stdout,"%d\t\tError 9\n",
									 timer_now-timer_start);
								send_command(ACK);
								main_done = 1;
								break;
							}
			case (ERR10):{
								timer_now = time(NULL);
								fprintf(stdout,"%d\t\tError 10.\n",
									 timer_now-timer_start);
								send_command(ACK);
								main_done = 1;
								break;
							}
			case (ERR11):{
								timer_now = time(NULL);
								fprintf(stdout,"%d\t\tError 11\n",
									 timer_now-timer_start);
								send_command(ACK);
								main_done = 1;
								break;
							}
			case (ERR12):{
								timer_now = time(NULL);
								fprintf(stdout,"%d\t\tError reading input JFIF file.\n",
									 timer_now-timer_start);
								send_command(ACK);
								main_done = 1;
								break;
							}
			case (ERR13):{
								timer_now = time(NULL);
								if (debug_mode >= 1)
								fprintf(stdout,"%d\t\tWarning 13\n",
									 timer_now-timer_start);
								break;
							}
			case (DONE):{
								timer_now = time(NULL);
								fprintf(stdout,"%d\t\tDone.\n",timer_now-timer_start);
								send_command(ACK);
								main_done = 1;
								break;
							}
			default:{
								timer_now = time(NULL);
								fprintf(stdout,"%d\t\tDebug Error %d=0x%4x\n",
									 timer_now-timer_start,tmp,tmp);
								send_command(ACK);
								main_done = 1;
								break;
							}
		}
	}

   /* close input and output files */
	close_files();
	return(0);
}

void usage(char *exfile)
{
	fprintf(stderr,"usage: %s input_file output_file\n",exfile);
	exit(0);
}

/* extension()
 * append extension ext to filename string fn in a manner described by code;
 */
char *extension(char *fn,char *ext,int code)
{
	char buf[256];
	int  idx;

	strcpy(buf,fn);
	idx = strlen(buf) - 1;

	while ((buf[idx] != '.') && (idx > 0))
		--idx;

	if ((idx == 0) || (buf[idx+1] == '\\'))
	{
		strcat(buf,".");
		strcat(buf,ext);
	}
	else if (code == 1)
		strcpy(&buf[++idx],ext);

	return(buf);
}

⌨️ 快捷键说明

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