?? 解碼程序.c
字號:
/* * * Copyright (c) 2004 Xilinx, Inc. All rights reserved. * * Xilinx, Inc. * XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" AS A * COURTESY TO YOU. BY PROVIDING THIS DESIGN, CODE, OR INFORMATION AS * ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION OR * STANDARD, XILINX IS MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION * IS FREE FROM ANY CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE * FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION * XILINX EXPRESSLY DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO * THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO * ANY WARRANTIES OR REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE * FROM CLAIMS OF INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE. *//* * Xilinx EDK 7.1.2 EDK_H.12.5.1 * * This file is a sample test application * * This application is intended to test and/or illustrate some * functionality of your system. The contents of this file may * vary depending on the IP in your system and may use existing * IP driver functions. These drivers will be generated in your * XPS project when you run the "Generate Libraries" menu item * in XPS. * * Your XPS project directory is at: * D:\spartan3_decode */
// Located in: microblaze_0/include/xparameters.h#include "xparameters.h"#include "stdio.h"
#include "math.h"
#include "stdlib.h"
#include "xutil.h"
#include "xbasic_types.h"
#include "xstatus.h"
#include "xuartlite_l.h"
#include "xuartlite.h"//====================================================#define LENGTH 128
#define MAXCHAR 30000
#define MAXNODE 255
#define XPAR_RS232_1_DEVICE_ID 1
#define XPAR_RS232_1_BASEADDR 0x40600000
#define BUFFER 300
//用到的串口地址的定義
#define RS232_BASEADDR XPAR_RS232_1_BASEADDR
//用到的檢測狀態的宏定義
#define STATUS_CHECK(Status) \
{ \
if (Status != XST_SUCCESS) \
{ \
return Status; \
} \
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
struct HtNode
{
int ww;
char info;
int parentIndex;
int llinkIndex;
int rlinkIndex;
};
struct HtNode ht[255];
int rootIndex;
typedef struct
{
char asciiCode;
unsigned long haffCode;
int haffCodeLen;
}HaffCode;
void haffmanAlgorithm(int m, int * w)
{
//PHtTree pht;
int i,j;
int firstMinIndex, secondMinIndex;
int firstMinW, secondMinW;
char ch1;
Xuint32 data=0;
ch1=(char)m;
//XUartLite_SendByte(RS232_BASEADDR,m);
//pht = (PHtTree)malloc(sizeof(struct HtTree));///// meiyou malloc hanshu
//assertF(pht != NULL, "in huffman algorithsm, mem apply failure!\n");
for(i=0; i<2*m-1; i++)
{
ht[i].llinkIndex = -1;
ht[i].rlinkIndex = -1;
ht[i].parentIndex = -1;
//XUartLite_SendByte(RS232_BASEADDR,ht[i].llinkIndex);
if(i<m)
{
ht[i].ww = w[i];
ht[i].info = (char)i; //
//XUartLite_SendByte(RS232_BASEADDR, i);
//XUartLite_SendByte(RS232_BASEADDR,ht[i].info);
}
else
{
//XUartLite_SendByte(RS232_BASEADDR, i);
ht[i].ww = -1;
//XUartLite_SendByte(RS232_BASEADDR, ht[i].ww);
}
}
//for(i=0; i<m; i++)
// XUartLite_SendByte(RS232_BASEADDR,ht[i].info);//
for(i=0; i<m-1; i++)
{
firstMinW = MAXCHAR;
firstMinIndex = -1;
secondMinW = MAXCHAR;
secondMinIndex = -1;
for(j=0; j<m+i; j++)
{
if(ht[j].ww<firstMinW && ht[j].parentIndex==-1)
{
secondMinIndex = firstMinIndex;
secondMinW = firstMinW;
firstMinIndex = j;
firstMinW = ht[j].ww;
}
else if(ht[j].ww<secondMinW && ht[j].parentIndex==-1)
{
secondMinW = ht[j].ww;
secondMinIndex = j;
}
}
ht[firstMinIndex].parentIndex = m+i;
ht[secondMinIndex].parentIndex = m+i;
ht[m+i].ww = firstMinW + secondMinW;
ht[m+i].llinkIndex = firstMinIndex;
ht[m+i].rlinkIndex = secondMinIndex;
rootIndex = m+i;
}
//XUartLite_SendByte(RS232_BASEADDR,ht[i].rootIndex);
//for(i=0; i<255; i++)
//XUartLite_SendByte(RS232_BASEADDR,ht[i].parentIndex);
}
void wait(int loop_count)
{
int sum, data;
sum = 0;
for (data = 0; data < loop_count; data++) {
sum = (data << 8);
}
}
//////////////////////////////////////////////////////////////////////////////////////
int main (void) {
//print("-- Entering main() --\r\n");
XUartLite Uart;
XStatus Status;
Status = XUartLite_Initialize( &Uart, XPAR_RS232_DEVICE_ID);
STATUS_CHECK(Status);
int wList[LENGTH] = {0,0,0,0,0,0,0,0,0,0,261,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4470,3,92,0,9,4,8,56,17,17,1,7,264,104,237,3,112,68,43,41,28,21,31,14,17,29,4,3,1,1,1,4,3,119,43,65,55,28,20,28,36,76,29,12,20,66,39,23,28,1,7,135,96,26,13,49,20,11,13,0,0,0,0,0,0,1728,270,576,851,2588,453,447,1033,1564,19,114,837,510,1641,1586,407,22,1274,1283,1723,494,225,302,39,331,21,1,0,1,0,0};
char Temp[BUFFER],output[BUFFER];//, Temp1[BUFFER];
int q;
for(q=0;q<BUFFER;q++)
{
//Temp[q]=0;
output[q]=0;
}
while(1)
{
int Stat=0;
int count1=0;
while(!Stat)
{
Temp[count1++]=XUartLite_RecvByte(RS232_BASEADDR);
wait(5000);
Stat=XUartLite_mIsReceiveEmpty(RS232_BASEADDR);
}
break;
}
char inData='0';
unsigned long curCode,tmpBinData;
int curLen,realLen,curIndex;
int i,j=0,k=0, nodeIndex,count;
haffmanAlgorithm(LENGTH, wList);
count=8;
nodeIndex=rootIndex;
while(inData != 0)
{
if(count==8)
{
inData=Temp[j++];
if(inData == 0)
break;
// curIndex=7;
count=0;
}
// when its the child node search a unuseful step.
// tmpBinData=(inData>>curIndex)&0x01;
if(ht[nodeIndex].llinkIndex==-1&&ht[nodeIndex].rlinkIndex==-1)
{
//send out data.
output[k++] = ht[nodeIndex].info; //fputc(myHtTree->ht[nodeIndex].info,outputFile);
nodeIndex=rootIndex;
}
else
{
tmpBinData=(inData>>(7-count))&0x01;
if(tmpBinData==0x00)
nodeIndex=ht[nodeIndex].llinkIndex;
else if(tmpBinData==0x01)
nodeIndex=ht[nodeIndex].rlinkIndex;
else
printf("error happen in read bin!\n");
// curIndex--;
count++;
}
}
i=0;
//XUartLite_SendByte(RS232_BASEADDR,i);
//print("-- The encrypted code is --\r\n");
while(i<BUFFER)
{
if(Temp[i]!=0)
XUartLite_SendByte(RS232_BASEADDR,output[i]);
else
break;
i++;
}
//print("-- Exiting main() --\r\n"); return 0;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -