?? dpram.c
字號:
/*************************************************************/
/* dpram - A program for test DPRAM communication between */
/* PowerPC405EP and DSP320VC33 with DualPort RAM */
/* This program is meant as an aid only and is */
/* not supported by tomxue gbe.tao.xue@gmail.com */
/* Usage: dpram */
/*************************************************************/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <getopt.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/termios.h>
#include <sys/time.h>
#include <string.h>
#include <signal.h>
static struct sigaction irq1_act;
static struct sigaction irq2_act;
static unsigned long count;
static unsigned char buffer_ready;
static int dpram_fd;
static unsigned char buffer[128*1024];//we use a 128KBytes buffer for dpram opration
/* DPRAM memory table: */
/* 0x0000 - 0x7FFF PowerPC->DSP data transmit */
/* 0x8000 - 0xAFFF PowerPC<-DSP data receive */
/* 0xB000 - 0xFFFF PowerPC<-DSP data receive reserved */
//signal process for IRQ1
void irq1_drvSigHandler(int signo)
{
//unsigned char *buffer;
unsigned char i;
int tom, status;
//printf("signal is %d.\n", signo);
if(46 == signo)
{
//TODO: do something here.
//read 16KBytes here
//printf("Read DPRAM 16KBytes.\n");
status = read(dpram_fd, buffer, (32*1024)); //read data and save in buffer[]
//for(count=0;count<16;count++)
//{
// printf("0x%02X.\n", buffer[count]);
//}
buffer_ready = 0;
//read 16KBytes end
}
}
//signal process for IRQ2
void irq2_drvSigHandler(int signo)
{
//unsigned char *buffer;
unsigned char i;
int tom, status;
printf("signal is %d.\n", signo);
if(47 == signo)
{
//TODO: do something here.
//read 16KBytes here
printf("Read DPRAM 16KBytes.\n");
status = read(dpram_fd, buffer, (16*1024)); //read data and save in buffer[]
for(count=0;count<16;count++)
{
printf("0x%02X.\n", buffer[count]);
}
buffer_ready = 0;
//read 16KBytes end
}
}
void init_dpram_system(void)
{
int ret;
buffer_ready = 1;
//register signal
printf("register the signal process function.\n");
//irq1
irq1_act.sa_handler = irq1_drvSigHandler;
irq1_act.sa_flags = 0;
sigemptyset(&irq1_act.sa_mask);
//irq2
irq2_act.sa_handler = irq2_drvSigHandler;
irq2_act.sa_flags = 0;
sigemptyset(&irq2_act.sa_mask);
//register
ret = sigaction(46, &irq1_act, NULL);
if (ret == -1)
printf("Request signal 46 failed.\n");
ret = sigaction(47, &irq2_act, NULL);
if (ret == -1)
printf("Request signal 47 failed.\n");
//open a device
dpram_fd = open("/dev/dpram",O_SYNC | O_RDWR,0);
printf("Transmit pid of %d to driver.\n", getpid());
ret = ioctl(dpram_fd, 0xAA, getpid());
}
unsigned long offset_address;
int main(int argc, char *argv[])
{
unsigned char i;
int status, ret;
char * mychar;
char my;
mychar = argv[1];
my = mychar[0];
init_dpram_system();
//process
if(my=='t')
{
//printf("Write 32KBytes to DPRAM.\n");
for(count=0;count<(64*1024);count++)
{
//fill data to buffer;
buffer[count] = count;
}
offset_address = 0x00018000;
lseek(dpram_fd, offset_address, SEEK_SET);
status = write(dpram_fd, buffer, (64*1024));
printf("Output a low pulse on output1.\n");
ioctl(dpram_fd, 1, 0);//set output1 high
ioctl(dpram_fd, 0, 0);//set output1 low
ioctl(dpram_fd, 1, 0);//set output1 high
//read 16KBytes here
printf("Read DPRAM 16KBytes.\n");
status = read(dpram_fd, buffer, (16*1024)); //read data and save in buffer[]
for(count=0;count<16;count++)
{
printf("0x%02X.\n", buffer[count]);
}
}
else if(my=='r')
{
while(1)
{
//printf("Wait for IRQ signal for DSP data ready.\n");
/*
read(dpram_fd, buffer, (16*1024));
for(count=(0);count<((0) + 16);count++)
{
printf("0x%02X.\n", buffer[count]);
}
*/
while(buffer_ready == 1)
{};
//printf("Output a low pulse on output2.\n");
ioctl(dpram_fd, 4, 0);//set output2 high
ioctl(dpram_fd, 3, 0);//set output2 low
ioctl(dpram_fd, 4, 0);//set output2 high
buffer_ready = 1;
}
}
else
{
printf("Usage: testdpram t for write 32KBytes to DPRAM.\n");
printf(" testdpram r for read 16KBytes from DPRAM.\n");
}
//close a device
close(dpram_fd);
printf("End of test PowerPC DSP data tranceiver function with DPRAM.\n");
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -