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

📄 jc5xx.c

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

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <ctype.h>
#include <time.h>
#include "jc5xxhst.h"

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

/* main()
 * get arguments from command line, initialize communications with EVM,
 * open input and output files, send input data to EVM, receive output
 * data from EVM, close input and output files
 */
int main(int argc, char *argv[])
{
   unsigned int tmp;
	int  main_done = 0;
	char exfile[32];
	char buffer1[256],buffer2[256];

   fputs("Texas Instruments TMS320C54x JPEG Compression\n",stderr);
	strcpy(exfile,fname(argv[0],1));

   /* parse command line */
	if ((argc > 3) || (argc == 1))
		usage(exfile);

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

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

   /* initialize communications with the 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 command from EVM 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
                         */
								send_data();
								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);
								outport(PC_A,ACK);
								main_done=1;
								break;
							}
			case (ERR0):{
								timer_now = time(NULL);
								fprintf(stdout,"%d\t\tError: not a GIF file.\n",
										 timer_now-timer_start);
								outport(PC_A,ACK);
								main_done = 1;
								break;
							}
			case (ERR1):{
								timer_now = time(NULL);
								fprintf(stdout,"%d\t\tError: premature EOF in GIF file.\n",
										 timer_now-timer_start);
								outport(PC_A,ACK);
								main_done = 1;
								break;
							}
			case (ERR2):{
								timer_now = time(NULL);
								fprintf(stdout,"%d\t\tError: too few images in GIF file.\n",
										 timer_now-timer_start);
								outport(PC_A,ACK);
								main_done = 1;
								break;
							}
			case (ERR3):{
								timer_now = time(NULL);
								if (debug_mode >= 1)
								fprintf(stdout,"%d\t\tWarning: ignoring bogus input character\n",
										 timer_now-timer_start);
								break;
							}
			case (ERR4):{
								timer_now = time(NULL);
								if (debug_mode >= 1)
								fprintf(stdout,"%d\t\tWarning: ran out of GIF bits\n",
										 timer_now-timer_start);
								break;
							}
			case (ERR5):{
								timer_now = time(NULL);
								if (debug_mode >= 1)
								fprintf(stdout,"%d\t\tWarning: corrupt data in GIF file\n",
										 timer_now-timer_start);
								break;
							}
			case (ERR6):{
								timer_now = time(NULL);
								if (debug_mode >= 1)
								fprintf(stdout,"%d\t\tWarning: premature end of GIF image\n",
										  timer_now-timer_start);
								break;
							}
			case (ERR7):{
								timer_now = time(NULL);
								fprintf(stdout,"%d\t\tGeneric error\n",
										 timer_now-timer_start);
								outport(PC_A,ACK);
								main_done = 1;
								break;
							}
			case (DONE):{
								timer_now = time(NULL);
								fprintf(stdout,"%d\t\tDone.\n",
										 timer_now-timer_start);

								outport(PC_A,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);
								outport(PC_A,ACK);
								main_done = 1;
								break;
							}
		}
	}

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

/* usage()
 * output usage message
 */
void usage(char *exfile)
{
	fprintf(stdout,"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 + -