FPGA / ARM / DSP Wishbone SoC
< Using DSP >
FPGA / ARM / DSP Wishbone SoC 整合實驗1
Lab1 : 3x3 Image Mask Filter
▋ Design Codes
xbus.h
/* Define EMIF Registers */
#define EMIF_GCR 0x1800000 /* Address of EMIF global control */
#define EMIF_CE0 0x1800008 /* Address of EMIF CE0 control */
#define EMIF_CE1 0x1800004 /* Address of EMIF CE1 control */
#define EMIF_CE2 0x1800010
#define EMIF_CE3 0x1800014
#define EMIF_SDCTRL 0x1800018 /* Address of EMIF SDRAM control */
#define EMIF_SDRP 0x180001c /* Address of EMIF SDRM refresh period */
#define EMIF_SDEXT 0x1800020 /* Address of EMIF SDRAM extension */
/* Define Timer0 Registers */
#define TIMER0_CTRL 0x1940000 /* Address of timer0 control reg. */
#define TIMER0_PRD 0x1940004 /* Address of timer0 period reg. */
#define TIMER0_COUNT 0x1940008 /* Address of timer0 counter reg. */
/* Define Timer1 Registers */
#define TIMER1_CTRL 0x1980000 /* Address of timer1 control reg. */
#define TIMER1_PRD 0x1980004 /* Address of timer1 period reg. */
#define TIMER1_COUNT 0x1980008 /* Address of timer1 counter reg. */
/* DMA / DSP LED reigsters */
#define DMA_SECCTL0 0x1840008
/* XBUS reigsters */
#define XBUS_XBGC 0x01880000
#define XBUS_XCECTL1 0x01880004
#define XBUS_XCECTL0 0x01880008
#define XBUS_XBHC 0x0188000C
#define XBUS_XCECTL2 0x01880010
#define XBUS_XCECTL3 0x01880014
#define XBUS_XBIMA 0x01880020
#define XBUS_XBEA 0x01880024
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
void delayns(unsigned int ns);
void delayms(unsigned int ms);
inline void led_on()
{
*(int *)DMA_SECCTL0 |= 0x10000;
}
inline void led_off()
{
*(int *)DMA_SECCTL0 &= ~(0x10000);
}
void led_blink(int count, int ms_period);
inline void xbdone()
{
uint32 cc;
while((cc=(*(volatile int *)XBUS_XBHC)&0xffff0000));
{
delayns(cc>>16);
};
}
void xbuswr(int iaddr,int taddr,int size);
void xbuswrs(int iaddr,int taddr,int size);
void xbusrd(int iaddr,int taddr,int size);
void xbusrds(int iaddr,int taddr,int size);
void cpymem(uint32 *iaddr,uint32 *taddr,int size);
uint32* cmpmem(uint32 *iaddr,uint32 *taddr,int size);
void inthost();
xbus.c
#define CHIP_6204
#include <stdio.h>
#include <stdlib.h>
#include <c6x.h>
#include "xbus.h"
int sclri[2]={0x1,0x0};
int sihost[2]={0x1,0x0};
int sgpiop[2]={0x12345678,0x0};
void delayns(unsigned int ns)
{
unsigned int j;
for(j=0;j<ns;j++) asm("nop;");
}
void delayms(unsigned int ms)
{
unsigned int j;
for(j=0;j<ms;j++)
delayns(0x400);
}
void led_blink(int count, int ms_period)
{
int i;
for (i=0;i<count;i++)
{
led_on();
delayms(ms_period/2);
led_off();
delayms(ms_period/2);
}
}
void xbuswr(int iaddr,int taddr,int size)
{
*(volatile int *)XBUS_XBHC = 0x00000000;
*(volatile int *)XBUS_XBEA = taddr;
*(volatile int *)XBUS_XBIMA = iaddr;
*(volatile int *)XBUS_XBHC = 0x00000008 | (size<<14);
}
void xbuswrs(int iaddr,int taddr,int size)
{
xbdone();
IER &= ~(0x0040); // disable int6
xbuswr(iaddr,taddr,size);
IER |= (0x0040); // enable int6
xbdone();
}
void xbusrd(int iaddr,int taddr,int size)
{
*(volatile int *)XBUS_XBHC = 0x00000000;
*(volatile int *)XBUS_XBEA = taddr;
*(volatile int *)XBUS_XBIMA = iaddr;
*(volatile int *)XBUS_XBHC = 0x00000010 | (size<<14);
}
void xbusrds(int iaddr,int taddr,int size)
{
xbdone();
IER &= ~(0x0040); // disable int6
xbusrd(iaddr,taddr,size);
IER |= (0x0040); // enable int6
xbdone();
}
void cpymem(uint32 *iaddr,uint32 *taddr,int size)
{
int i;
for(i=0;i<size;i++) *taddr++=*iaddr++;
}
uint32* cmpmem(uint32 *iaddr,uint32 *taddr,int size)
{
int i; uint32 a,b;
for(i=0;i<size;i++)
{
a=*iaddr++; b=*taddr++;
if(a!=b)
return (uint32 *)-1;
}
return iaddr;
}
void inthost()
{
xbuswrs((int)sihost,0x01f000d0,4);
//xbuswrs((int)sihost,0x01f08600,4);
}
fbgfx.h
#define xMin 0
#define xMac 479
#define xMax 480
#define yMin 0
#define yMac 271
#define yMax 272
#define cbRow (xMax*1)
#define xLMin xMin
#define xLMax xMax
#define xLMid ((xLMax+xLMin)/2)
#define yLMin (yMin + 8*8)
#define yLMax yMax
#define yLMid ((yLMax+yLMin)/2)
#define cbLine (480/8)
#define swap(a,b) if (1) { int t; t = (a); (a) = (b); (b) = t; } else
inline unsigned char* row(int r)
{
return (unsigned char*)((unsigned int)r*cbRow+fbBase);
}
inline void plotxyc(int x,int y,unsigned char c)
{
*((volatile unsigned char *)(fbBase+x+(y*cbRow)))=c;
}
void clear(unsigned char cc);
void putch(unsigned int x,unsigned int y, unsigned char c, unsigned char co,unsigned char bc);
void putstr(int x, int y, char* s,unsigned char cc,unsigned char bc);
void sputu(unsigned int p,char *str,int n);
void sputx(unsigned int p,char *str,int n);
void lineY1(volatile unsigned char* p, unsigned m, int e, int x, int dy, int _2dx, int _2dy,unsigned char cc);
void lineY2(volatile unsigned char* p, unsigned m, int e, int x, int dy, int _2dx, int _2dy,unsigned char cc);
void lineX(volatile unsigned char* p, unsigned m, int e, int x, int dx, int d, int _2dx, int _2dy,unsigned char cc);
void line(int x, int y, int x2, int y2,unsigned char cc);
void drawrect(int x0,int y0,int x1,int y1, int x2, int y2, int x3,int y3,unsigned char cc);
void initvga(int mode);
inline void imshow(int saddr,int taddr,int size)
{
xbuswrs(saddr,taddr,size);
}
inline void imshowx(int saddr,int taddr,int size)
{
xbuswr(saddr,taddr,size);
}
fbgfx.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
unsigned char *fbBase;
#include "fbgfx.h"
unsigned int vgainitm8[4]={0x101,0x10000000};
unsigned int vgainitc8[4]={0x103,0x10000000};
unsigned int vgainitc16[4]={0x105,0x10000000};
unsigned int vgainitc15[4]={0x107,0x10000000};
unsigned char tfont[(0x80-0x20)*8] = {
/* 20 ' ' */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 21 '!' */ 0x04, 0x04, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00,
/* 22 '"' */ 0x0A, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 23 '#' */ 0x0A, 0x1F, 0x0A, 0x1F, 0x0A, 0x00, 0x00, 0x00,
/* 24 '$' */ 0x0E, 0x14, 0x0E, 0x05, 0x0E, 0x00, 0x00, 0x00,
/* 25 '%' */ 0x19, 0x1A, 0x04, 0x0B, 0x13, 0x00, 0x00, 0x00,
/* 26 '&' */ 0x0C, 0x0A, 0x0C, 0x12, 0x0D, 0x00, 0x00, 0x00,
/* 27 ''' */ 0x04, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 28 '(' */ 0x04, 0x08, 0x08, 0x08, 0x04, 0x00, 0x00, 0x00,
/* 29 ')' */ 0x04, 0x02, 0x02, 0x02, 0x04, 0x00, 0x00, 0x00,
/* 2A '*' */ 0x15, 0x0E, 0x04, 0x0E, 0x15, 0x00, 0x00, 0x00,
/* 2B '+' */ 0x04, 0x04, 0x1F, 0x04, 0x04, 0x00, 0x00, 0x00,
/* 2C ',' */ 0x00, 0x00, 0x00, 0x06, 0x02, 0x04, 0x00, 0x00,
/* 2D '-' */ 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 2E '.' */ 0x00, 0x00, 0x00, 0x06, 0x06, 0x00, 0x00, 0x00,
/* 2F '/' */ 0x01, 0x02, 0x04, 0x08, 0x10, 0x00, 0x00, 0x00,
/* 30 '0' */ 0x0E, 0x11, 0x15, 0x11, 0x0E, 0x00, 0x00, 0x00,
/* 31 '1' */ 0x04, 0x0C, 0x04, 0x04, 0x0E, 0x00, 0x00, 0x00,
/* 32 '2' */ 0x0E, 0x01, 0x0E, 0x10, 0x1F, 0x00, 0x00, 0x00,
/* 33 '3' */ 0x0E, 0x01, 0x0E, 0x01, 0x0E, 0x00, 0x00, 0x00,
/* 34 '4' */ 0x12, 0x12, 0x1F, 0x02, 0x02, 0x00, 0x00, 0x00,
/* 35 '5' */ 0x1E, 0x10, 0x1E, 0x01, 0x1E, 0x00, 0x00, 0x00,
/* 36 '6' */ 0x0E, 0x10, 0x1E, 0x11, 0x0E, 0x00, 0x00, 0x00,
/* 37 '7' */ 0x1F, 0x02, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00,
/* 38 '8' */ 0x0E, 0x11, 0x0E, 0x11, 0x0E, 0x00, 0x00, 0x00,
/* 39 '9' */ 0x0E, 0x11, 0x0F, 0x01, 0x0E, 0x00, 0x00, 0x00,
/* 3A ':' */ 0x00, 0x06, 0x06, 0x00, 0x06, 0x06, 0x00, 0x00,
/* 3B ';' */ 0x00, 0x06, 0x06, 0x00, 0x06, 0x0C, 0x00, 0x00,
/* 3C '<' */ 0x02, 0x04, 0x08, 0x04, 0x02, 0x00, 0x00, 0x00,
/* 3D '=' */ 0x00, 0x1F, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00,
/* 3E '>' */ 0x08, 0x04, 0x02, 0x04, 0x08, 0x00, 0x00, 0x00,
/* 3F '?' */ 0x0E, 0x01, 0x06, 0x00, 0x04, 0x00, 0x00, 0x00,
/* 40 '@' */ 0x0E, 0x17, 0x17, 0x10, 0x0E, 0x00, 0x00, 0x00,
/* 41 'A' */ 0x0E, 0x11, 0x1F, 0x11, 0x11, 0x00, 0x00, 0x00,
/* 42 'B' */ 0x1E, 0x11, 0x1E, 0x11, 0x1E, 0x00, 0x00, 0x00,
/* 43 'C' */ 0x0E, 0x10, 0x10, 0x10, 0x0E, 0x00, 0x00, 0x00,
/* 44 'D' */ 0x1E, 0x11, 0x11, 0x11, 0x1E, 0x00, 0x00, 0x00,
/* 45 'E' */ 0x1F, 0x10, 0x1C, 0x10, 0x1F, 0x00, 0x00, 0x00,
/* 46 'F' */ 0x1F, 0x10, 0x1E, 0x10, 0x10, 0x00, 0x00, 0x00,
/* 47 'G' */ 0x0E, 0x10, 0x13, 0x11, 0x0E, 0x00, 0x00, 0x00,
/* 48 'H' */ 0x11, 0x11, 0x1F, 0x11, 0x11, 0x00, 0x00, 0x00,
/* 49 'I' */ 0x0E, 0x04, 0x04, 0x04, 0x0E, 0x00, 0x00, 0x00,
/* 4A 'J' */ 0x01, 0x01, 0x01, 0x11, 0x0E, 0x00, 0x00, 0x00,
/* 4B 'K' */ 0x11, 0x12, 0x1C, 0x12, 0x11, 0x00, 0x00, 0x00,
/* 4C 'L' */ 0x10, 0x10, 0x10, 0x10, 0x1F, 0x00, 0x00, 0x00,
/* 4D 'M' */ 0x11, 0x1B, 0x15, 0x11, 0x11, 0x00, 0x00, 0x00,
/* 4E 'N' */ 0x11, 0x19, 0x15, 0x13, 0x11, 0x00, 0x00, 0x00,
/* 4F 'O' */ 0x0E, 0x11, 0x11, 0x11, 0x0E, 0x00, 0x00, 0x00,
/* 50 'P' */ 0x1E, 0x11, 0x1E, 0x10, 0x10, 0x00, 0x00, 0x00,
/* 51 'Q' */ 0x0E, 0x11, 0x11, 0x13, 0x0F, 0x00, 0x00, 0x00,
/* 52 'R' */ 0x1E, 0x11, 0x1E, 0x12, 0x11, 0x00, 0x00, 0x00,
/* 53 'S' */ 0x0E, 0x10, 0x0E, 0x01, 0x0E, 0x00, 0x00, 0x00,
/* 54 'T' */ 0x1F, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00,
/* 55 'U' */ 0x11, 0x11, 0x11, 0x11, 0x0E, 0x00, 0x00, 0x00,
/* 56 'V' */ 0x11, 0x11, 0x0A, 0x0A, 0x04, 0x00, 0x00, 0x00,
/* 57 'W' */ 0x11, 0x11, 0x15, 0x15, 0x0A, 0x00, 0x00, 0x00,
/* 58 'X' */ 0x11, 0x0A, 0x04, 0x0A, 0x11, 0x00, 0x00, 0x00,
/* 59 'Y' */ 0x11, 0x0A, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00,
/* 5A 'Z' */ 0x1F, 0x02, 0x04, 0x08, 0x1F, 0x00, 0x00, 0x00,
/* 5B '[' */ 0x0E, 0x08, 0x08, 0x08, 0x0E, 0x00, 0x00, 0x00,
/* 5C '\' */ 0x10, 0x08, 0x04, 0x02, 0x01, 0x00, 0x00, 0x00,
/* 5D ']' */ 0x0E, 0x02, 0x02, 0x02, 0x0E, 0x00, 0x00, 0x00,
/* 5E '^' */ 0x04, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 5F '_' */ 0x00, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00,
/* 60 '`' */ 0x08, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 61 'a' */ 0x00, 0x0C, 0x02, 0x1E, 0x0E, 0x00, 0x00, 0x00,
/* 62 'b' */ 0x10, 0x1C, 0x12, 0x12, 0x1C, 0x00, 0x00, 0x00,
/* 63 'c' */ 0x00, 0x0E, 0x10, 0x10, 0x0E, 0x00, 0x00, 0x00,
/* 64 'd' */ 0x02, 0x0E, 0x12, 0x12, 0x0E, 0x00, 0x00, 0x00,
/* 65 'e' */ 0x00, 0x0C, 0x1E, 0x10, 0x0C, 0x00, 0x00, 0x00,
/* 66 'f' */ 0x04, 0x08, 0x1C, 0x08, 0x08, 0x00, 0x00, 0x00,
/* 67 'g' */ 0x00, 0x0C, 0x12, 0x12, 0x0E, 0x02, 0x0C, 0x00,
/* 68 'h' */ 0x10, 0x1C, 0x12, 0x12, 0x12, 0x00, 0x00, 0x00,
/* 69 'i' */ 0x00, 0x0C, 0x04, 0x04, 0x0E, 0x00, 0x00, 0x00,
/* 6A 'j' */ 0x00, 0x06, 0x02, 0x02, 0x02, 0x12, 0x0C, 0x00,
/* 6B 'k' */ 0x10, 0x12, 0x1C, 0x1C, 0x12, 0x00, 0x00, 0x00,
/* 6C 'l' */ 0x0C, 0x04, 0x04, 0x04, 0x0E, 0x00, 0x00, 0x00,
/* 6D 'm' */ 0x00, 0x1A, 0x15, 0x11, 0x11, 0x00, 0x00, 0x00,
/* 6E 'n' */ 0x00, 0x1C, 0x12, 0x12, 0x12, 0x00, 0x00, 0x00,
/* 6F 'o' */ 0x00, 0x0C, 0x12, 0x12, 0x0C, 0x00, 0x00, 0x00,
/* 70 'p' */ 0x00, 0x1C, 0x12, 0x12, 0x1C, 0x10, 0x10, 0x00,
/* 71 'q' */ 0x00, 0x0E, 0x12, 0x12, 0x0E, 0x02, 0x02, 0x00,
/* 72 'r' */ 0x00, 0x1C, 0x12, 0x10, 0x10, 0x00, 0x00, 0x00,
/* 73 's' */ 0x00, 0x0E, 0x18, 0x06, 0x1C, 0x00, 0x00, 0x00,
/* 74 't' */ 0x04, 0x0E, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00,
/* 75 'u' */ 0x00, 0x12, 0x12, 0x12, 0x0E, 0x00, 0x00, 0x00,
/* 76 'v' */ 0x00, 0x12, 0x12, 0x14, 0x08, 0x00, 0x00, 0x00,
/* 77 'w' */ 0x00, 0x11, 0x11, 0x15, 0x0A, 0x00, 0x00, 0x00,
/* 78 'x' */ 0x00, 0x12, 0x0C, 0x0C, 0x12, 0x00, 0x00, 0x00,
/* 79 'y' */ 0x00, 0x12, 0x12, 0x12, 0x0E, 0x02, 0x0C, 0x00,
/* 7A 'z' */ 0x00, 0x1E, 0x04, 0x08, 0x1E, 0x00, 0x00, 0x00,
/* 7B '{' */ 0x04, 0x08, 0x1C, 0x08, 0x04, 0x00, 0x00, 0x00,
/* 7C '|' */ 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00,
/* 7D '}' */ 0x04, 0x02, 0x07, 0x02, 0x04, 0x00, 0x00, 0x00,
/* 7E '~' */ 0x08, 0x15, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 7F *** */ 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00
};
/*inline int abs(int n)
{
return (n >= 0) ? n : -n;
}*/
char tAHexChar[16]={'0','1','2','3','4','5','6','7','8','9',
'A','B','C','D','E','F'};
#pragma DATA_SECTION(tfont,".imgbulk");
#pragma DATA_SECTION(tAHexChar,".imgbulk");
void clear(unsigned char cc)
{
unsigned int p,pEnd;
unsigned int uic;
uic=cc; uic=uic<<24+uic<<16+uic<<8+uic;
pEnd = (unsigned int)row(yMax);
for (p = (unsigned int)row(yMin); p < pEnd; p+=4)
{ *(volatile unsigned int*)p = uic; }
}
void putch(unsigned int x,unsigned int y, unsigned char c, unsigned char co,unsigned char bc)
{
unsigned int i,j;
unsigned char *pp=tfont+((c-0x20)<<3);
for(i=0; i<7;i++)
{
unsigned char bb=*pp; pp++;
for(j=0;j<=7;j++)
{
if(bb&0x80) plotxyc(x+j,y+i,co);
else if(bc!=0xff) plotxyc(x+j,y+i,bc);
bb<<=1;
}
}
}
void putstr(int x, int y, char* s,unsigned char cc,unsigned char bc)
{
int i=0;
unsigned char ch;
while((i<cbLine))
{
(ch=s[i++]);
if (ch==0) break;
putch(x,y,ch,cc,bc);
x+=8;
}
}
void sputu(unsigned int p,char *str,int n)
{
int i;
str[n]=0;
for(i=n-1;i>=0;i--)
{
str[i]=p%10+'0';
p/=10;
}
}
void sputx(unsigned int p,char *str,int n)
{
int i;
str[n]=0;
for(i=n-1;i>=0;i--)
{
str[i]=tAHexChar[p&0xf];
p>>=4;
}
}
void lineY1(volatile unsigned char* p, unsigned m, int e, int x, int dy, int _2dx, int _2dy,unsigned char cc)
{
p += (unsigned)x;// << 2;
*p = cc;
while (dy--) {
if (e > 0) {
p++;//=4;
e -= _2dy;
}
e += _2dx;
p += cbRow;
*p = cc;
}
}
void lineY2(volatile unsigned char* p, unsigned m, int e, int x, int dy, int _2dx, int _2dy,unsigned char cc)
{
p += (unsigned)x << 2;
*p = cc;
while (dy--) {
if (e > 0) {
p--;//=4;
e -= _2dy;
}
e += _2dx;
p += cbRow;
*p = cc;
}
}
void lineX(volatile unsigned char* p, unsigned m, int e, int x, int dx, int d, int _2dx, int _2dy,unsigned char cc)
{
int dbRow = (d > 0) ? cbRow : -cbRow;
p += (unsigned)x;// << 2;
*p = cc;
while (dx--) {
if (e > 0) {
p += dbRow;
e -= _2dx;
}
e += _2dy;
p++;//=4;
*p = cc;
}
}
void line(int x, int y, int x2, int y2,unsigned char cc)
{
int dx, dy, d;
int e;
dx = x2 - x;
dy = y2 - y;
if (abs(dx) >= abs(dy)) {
int _2dx, _2dy;
if (x > x2) {
swap(x, x2);
swap(y, y2);
dx = x2 - x;
dy = y2 - y;
}
if (dy >= 0) {
d = 1;
}
else {
d = -1;
dy = -dy;
}
_2dx = dx + dx;
_2dy = dy + dy;
e = _2dy - dx;
lineX(row(y), 0, e, x, dx, d, _2dx, _2dy, cc);
}
else {
int _2dx, _2dy;
if (y > y2) {
swap(x, x2);
swap(y, y2);
dx = x2 - x;
dy = y2 - y;
}
if (dx >= 0)
d = 1;
else {
d = -1;
dx = -dx;
}
_2dx = dx + dx;
_2dy = dy + dy;
e = _2dx - dy;
if (d == 1)
lineY1(row(y), 0, e, x, dy, _2dx, _2dy, cc);
else
lineY2(row(y), 0, e, x, dy, _2dx, _2dy, cc);
}
}
void drawrect(int x0,int y0,int x1,int y1, int x2, int y2, int x3,int y3,unsigned char cc)
{
line(x0,y0,x1,y1,cc);
line(x1,y1,x2,y2,cc);
line(x2,y2,x3,y3,cc);
line(x3,y3,x0,y0,cc);
}
void initvga(int mode)
{
switch(mode)
{
case 0: xbuswrs((int)vgainitm8,0x01f00020,0x2*4); break; // mono 8bpp
case 1: xbuswrs((int)vgainitc8,0x01f00020,0x2*4); break; // color 8bpp
case 2: xbuswrs((int)vgainitc16,0x01f00020,0x2*4); break; // color
case 3: xbuswrs((int)vgainitc15,0x01f00020,0x2*4); break; // color 16bpp
default: xbuswrs((int)vgainitm8,0x01f00020,0x2*4); break; // mono 8bpp
}
}
imask.c
#define CHIP_6204
#include <stdio.h>
#include <stdlib.h>
#include "IMG_idct_8x8.h"
#include "csl.h"
#include "csl_dat.h"
const unsigned char pica[]=
#include "00012.h"
#include "xbus.h"
extern unsigned char *fbBase;
#include "fbgfx.h"
unsigned char dpic[480*272];
#pragma DATA_SECTION(pica,".imgtbl");
#pragma DATA_SECTION(dpic,".imgbulk");
#pragma DATA_ALIGN(pica, 4);
#pragma DATA_ALIGN(dpic, 4);
char maski[9] =
{
0, 0, 0,
0, 1, 0,
0, 0, 0
};
char maska[9] =
{
-1, -2, -1,
-2, 12, -2,
-1, -2, -1
};
char maskb[9] =
{
-1, -2, -1,
0, 0, 0,
1, 2, 1
};
char maskc[9] =
{
-1, 0, 1,
-2, 0, 2,
-1, 0, 1
};
char maskd[9] =
{
1, 2, 1,
2, 4, 2,
1, 2, 1
};
char mask[9];
#define SHIFT (6)
int max(int a,int b)
{
return (a>b)?a:b;
}
void setmask(char *masko,char *maska,int gaina,char *maskb,int gainb)
{
int i,s;
for(i=0;i<9;i++) {
s=((int)maska[i]*gaina+(int)maskb[i]*gainb);
if(s>0x7f) masko[i]=0x7f;
else if(s<-0x80) masko[i]=-0x80;
else masko[i]=s;}
}
void setmaska(char *masko, char g00,char g01,char g02,
char g10,char g11,char g12,
char g20,char g21,char g22)
{
masko[0]=g00; masko[1]=g01; masko[2]=g02;
masko[3]=g10; masko[4]=g11; masko[5]=g12;
masko[6]=g20; masko[7]=g21; masko[8]=g22;
}
void addmaska(char *masko, char g00,char g01,char g02,
char g10,char g11,char g12,
char g20,char g21,char g22)
{
masko[0]+=g00; masko[1]+=g01; masko[2]+=g02;
masko[3]+=g10; masko[4]+=g11; masko[5]+=g12;
masko[6]+=g20; masko[7]+=g21; masko[8]+=g22;
}
void img3x3mask(unsigned char* inpic,unsigned char* outpic,int xsize,int ysize)
{
int yi;
for(yi=0;yi<ysize;yi++)
{
IMG_conv_3x3(inpic, outpic, xsize, mask, SHIFT);
inpic+=xsize;
outpic+=xsize;
}
}
void showparam()
{
int i,j; char str[16];
for(j=0;j<3;j++)
for(i=0;i<3;i++)
{
sputx(mask[i+j*3],str,2);
putstr(8+i*3*8,16+j*8, str,0xff,0xff);
}
}
void inc3x3mask(int inc,int dly,int dlyb,
char g00,char g01,char g02,
char g10,char g11,char g12,
char g20,char g21,char g22)
{
int i;
for(i=0;i<inc;i++)
{
addmaska(mask, g00,g01,g02,
g10,g11,g12,
g20,g21,g22);
img3x3mask((unsigned char *)&pica[0],&dpic[0],480,272);
showparam();
imshow((int)&dpic[0],0,480*272);
delayms(dly);
}
delayms(dlyb);
}
void sethdr(unsigned char *ss,unsigned char cmd,unsigned short len)
{
ss[0]=(unsigned char)(len&0xff);
ss[1]=(unsigned char)((len&0xff00)>>8);
ss[2]=cmd;
ss[3]=(0x00-(0x55+(ss[0]^0xaa)+(ss[1]^0xaa)+(ss[2]^0xaa)))^0xaa;
}
int main()
{
initvga(0);
fbBase=dpic;
imshow((int)&pica[0],0,480*272);
while(1)
{
setmaska(mask, 0, 0, 0,
0, 0, 0,
0, 0, 0);
inc3x3mask(0x40,0x8,0x8,
0, 0, 0,
0, 1, 0,
0, 0, 0);
inc3x3mask(0x30,0x8,0x8,
0, 0, 0,
0, -1, 0,
0, 0, 0);
inc3x3mask(0x9,0x20,0x8000,
-1, -2, -1,
-2, 12, -2,
-1, -2, -1);
inc3x3mask(0x10,0x20,0x8000,
0, 0, 0,
0,-1, 0,
0, 0, 0);
inc3x3mask(0x10,0x20,0x8,
0, 0, 0,
0, 1, 0,
0, 0, 0);
inc3x3mask(0x9,0x20,0x8,
1, 2, 1,
2, -12, 2,
1, 2, 1);
inc3x3mask(0x1b,0x20,0x8000,
0, 0, -1,
0, 4, -2,
0, 0, -1);
inc3x3mask(0x10,0x20,0x8000,
0, 0, 0,
0,-1, 0,
0, 0, 0);
inc3x3mask(0x10,0x20,0x8,
0, 0, 0,
0, 1, 0,
0, 0, 0);
inc3x3mask(0x1b,0x20,0x8,
0, 0, 1,
0, -4, 2,
0, 0, 1);
inc3x3mask(0x1b,0x20,0x8000,
0, 0, 1,
0, -4, 2,
0, 0, 1);
inc3x3mask(0x10,0x20,0x8000,
0, 0, 0,
0,-1, 0,
0, 0, 0);
inc3x3mask(0x10,0x20,0x8,
0, 0, 0,
0, 1, 0,
0, 0, 0);
inc3x3mask(0x1b,0x20,0x8,
0, 0, -1,
0, 4, -2,
0, 0, -1);
inc3x3mask(0x10,0x20,0x8000,
0, 0, -1,
0, 6, -2,
0, -2, -1);
inc3x3mask(0x10,0x20,0x8000,
0, 0, 0,
0, -1, 0,
0, 0, 0);
inc3x3mask(0x10,0x20,0x8,
0, 0, 0,
0, 1, 0,
0, 0, 0);
inc3x3mask(0x10,0x20,0x8,
0, 0, 1,
0, -6, 2,
0, 2, 1);
inc3x3mask(0x10,0x20,0x8000,
0, 0, 1,
0, -6, 2,
0, 2, 1);
inc3x3mask(0x10,0x20,0x8000,
0, 0, 0,
0, -1, 0,
0, 0, 0);
inc3x3mask(0x10,0x20,0x8,
0, 0, 0,
0, 1, 0,
0, 0, 0);
inc3x3mask(0x10,0x20,0x8,
0, 0, -1,
0, 6, -2,
0, -2, -1);
inc3x3mask(0x10,0x20,0x8,
0, 0, 0,
0,-1, 0,
0, 0, 0);
}
}
請先 登入 以發表留言。