- initial import
git-svn-id: http://moon:8086/svn/mips@1 a8ebac50-d88d-4704-bea3-6648445a41b3
This commit is contained in:
+407
@@ -0,0 +1,407 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
#include "libsys.h"
|
||||
#include "gpio.h"
|
||||
|
||||
#define PI 3.1415926535897932384626433832795
|
||||
#define SAMPLE_RATE 48000
|
||||
#define BUF_SIZE (2*4800)
|
||||
#define REC_BUF_SIZE (5*60*2*SAMPLE_RATE)
|
||||
|
||||
gpio_if_t gpio;
|
||||
|
||||
INT32 *buffer;
|
||||
INT32 *rec_buffer;
|
||||
UINT32 buf_size;
|
||||
|
||||
INT32 * volatile pPtr_r;
|
||||
INT32 * volatile pPtr_w;
|
||||
UINT32 gcnt, led_cnt;
|
||||
volatile INT32 sample_left, sample_right;
|
||||
|
||||
#define SCREEN_X 800
|
||||
#define SCREEN_Y 600
|
||||
UINT32 *g_gx_buff;
|
||||
volatile INT32 scope_buf_left[SCREEN_X], scope_buf_right[SCREEN_X];
|
||||
UINT32 scope_idx;
|
||||
|
||||
#define AC97_REG_RESET 0x00
|
||||
#define AC97_REG_VOLO_MST 0x02
|
||||
#define AC97_REG_VOLO_HP 0x04
|
||||
#define AC97_REG_VOLO_MONO 0x06
|
||||
#define AC97_REG_VOLI_BEEP 0x0A
|
||||
#define AC97_REG_VOLI_PHONE 0x0C
|
||||
#define AC97_REG_VOLI_MIC 0x0E
|
||||
#define AC97_REG_VOLI_LINE 0x10
|
||||
#define AC97_REG_VOLI_CD 0x12
|
||||
#define AC97_REG_VOLI_VIDEO 0x14
|
||||
#define AC97_REG_VOLI_AUX 0x16
|
||||
#define AC97_REG_VOLI_PCM 0x18
|
||||
#define AC97_REG_REC_SRC 0x1A
|
||||
#define AC97_REG_REC_GAIN 0x1C
|
||||
#define AC97_REG_EXTCTRL 0x2A
|
||||
#define AC97_REG_RATE_DAC 0x2C
|
||||
#define AC97_REG_RATE_ADC 0x32
|
||||
|
||||
UINT32 ac97_status(UINT32 reg)
|
||||
{
|
||||
UINT32 offset;
|
||||
volatile UINT32 *pAC_stat = (UINT32*)SYS_AC97_STAT;
|
||||
volatile UINT32 *pAC_stat_ac = (UINT32*)SYS_AC97_ACSTAT;
|
||||
|
||||
offset = (reg & 0x7E);
|
||||
|
||||
// Wait if previous command is still pending
|
||||
while(*pAC_stat & 1);
|
||||
|
||||
*(pAC_stat_ac + offset) = 0;
|
||||
|
||||
// Wait for data valid
|
||||
while(!(*pAC_stat & 2));
|
||||
|
||||
return *pAC_stat_ac;
|
||||
}
|
||||
|
||||
void ac97_ctrl(UINT32 reg, UINT16 value)
|
||||
{
|
||||
UINT32 offset;
|
||||
volatile UINT32 *pAC_stat = (UINT32*)SYS_AC97_STAT;
|
||||
volatile UINT32 *pAC_ctrl_ac = (UINT32*)SYS_AC97_ACCTRL;
|
||||
|
||||
offset = (reg & 0x7E);
|
||||
|
||||
// Wait if previous command is still pending
|
||||
while(*pAC_stat & 1);
|
||||
|
||||
*(pAC_ctrl_ac + offset) = value;
|
||||
|
||||
}
|
||||
|
||||
void ac97_isr_rec(void)
|
||||
{
|
||||
int i, size;
|
||||
volatile UINT32 *pAC_stat = (UINT32*)SYS_AC97_STAT;
|
||||
volatile INT32 *pAC_pcm = (INT32*)SYS_AC97_PCM;
|
||||
|
||||
if (!gcnt)
|
||||
{
|
||||
gcnt = SAMPLE_RATE;
|
||||
gpio_write(&gpio, GPIO_0_MASK_LED, GPIO_0_ALIGN_LED, GPIO_DATA_OFFSET, led_cnt++);
|
||||
}
|
||||
gcnt--;
|
||||
|
||||
*pPtr_w++ = pAC_pcm[3];
|
||||
if (pPtr_w == &buffer[buf_size])
|
||||
pPtr_w = buffer;
|
||||
|
||||
*pPtr_w++ = pAC_pcm[4];
|
||||
if (pPtr_w == &buffer[buf_size])
|
||||
pPtr_w = buffer;
|
||||
|
||||
CP0_TR_write(pAC_pcm[3]);
|
||||
CP0_TR_write(pAC_pcm[4]);
|
||||
|
||||
}
|
||||
|
||||
void ac97_isr_play(void)
|
||||
{
|
||||
int i, size;
|
||||
volatile UINT32 *pAC_stat = (UINT32*)SYS_AC97_STAT;
|
||||
volatile INT32 *pAC_pcm = (INT32*)SYS_AC97_PCM;
|
||||
|
||||
if (!gcnt)
|
||||
{
|
||||
gcnt = SAMPLE_RATE;
|
||||
gpio_write(&gpio, GPIO_0_MASK_LED, GPIO_0_ALIGN_LED, GPIO_DATA_OFFSET, led_cnt++);
|
||||
}
|
||||
gcnt--;
|
||||
|
||||
*pAC_pcm = *pPtr_r++;
|
||||
if (pPtr_r == &buffer[buf_size])
|
||||
pPtr_r = buffer;
|
||||
}
|
||||
|
||||
void ac97_isr_pass(void)
|
||||
{
|
||||
int i, size;
|
||||
volatile UINT32 *pAC_stat = (UINT32*)SYS_AC97_STAT;
|
||||
volatile INT32 *pAC_pcm = (INT32*)SYS_AC97_PCM;
|
||||
|
||||
if (!gcnt)
|
||||
{
|
||||
gcnt = SAMPLE_RATE;
|
||||
gpio_write(&gpio, GPIO_0_MASK_LED, GPIO_0_ALIGN_LED, GPIO_DATA_OFFSET, led_cnt++);
|
||||
}
|
||||
gcnt--;
|
||||
|
||||
if (*pAC_stat & 0x08)
|
||||
{
|
||||
|
||||
// CP0_TR_write(pAC_pcm[3]);
|
||||
// CP0_TR_write(pAC_pcm[4]);
|
||||
|
||||
*pPtr_w++ = pAC_pcm[3];
|
||||
if (pPtr_w == &buffer[buf_size])
|
||||
pPtr_w = buffer;
|
||||
|
||||
*pPtr_w++ = pAC_pcm[4];
|
||||
if (pPtr_w == &buffer[buf_size])
|
||||
pPtr_w = buffer;
|
||||
|
||||
if (scope_idx < SCREEN_X)
|
||||
{
|
||||
scope_buf_left[scope_idx] = pAC_pcm[3];
|
||||
scope_buf_right[scope_idx] = pAC_pcm[4];
|
||||
scope_idx++;
|
||||
}
|
||||
}
|
||||
|
||||
if (pPtr_r != pPtr_w)
|
||||
{
|
||||
*pAC_pcm = *pPtr_r++;
|
||||
if (pPtr_r == &buffer[buf_size])
|
||||
pPtr_r = buffer;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#define NUM_BUF_HISTORY 1
|
||||
|
||||
UINT32 hist_buf[NUM_BUF_HISTORY][SCREEN_X];
|
||||
|
||||
void timer_isr(void)
|
||||
{
|
||||
volatile UINT32 *pTim_stat = (UINT32*)SYS_ITIM_STAT;
|
||||
volatile UINT32 *pTim_ctrl = (UINT32*)SYS_ITIM_CTRL;
|
||||
volatile UINT32 *pTim0_cmp = (UINT32*)SYS_ITIM0_CMP;
|
||||
volatile INT32 *pAC_pcm = (INT32*)SYS_AC97_PCM;
|
||||
int i, j;
|
||||
INT32 zeroline = 2<<18;
|
||||
INT32 y;
|
||||
UINT32 px_y;
|
||||
|
||||
if (*pTim_stat & 1)
|
||||
{
|
||||
// fprintf(stdout, "timer_isr()\n");
|
||||
// fprintf(stdout, "pAC_pcm(L) = %08X\n", zeroline + pAC_pcm[3]);
|
||||
// fprintf(stdout, "pAC_pcm(R) = %08X\n", zeroline + pAC_pcm[4]);
|
||||
|
||||
*pTim_stat = 1;
|
||||
|
||||
if (scope_idx == SCREEN_X)
|
||||
{
|
||||
// Clear screen
|
||||
for (j=0; j < NUM_BUF_HISTORY; j++)
|
||||
for (i=0; i < SCREEN_X; i++)
|
||||
g_gx_buff[hist_buf[j][i]+i] = 0x0;
|
||||
|
||||
for (i=0; i < SCREEN_X; i++)
|
||||
{
|
||||
y = scope_buf_left[i]/((2<<17)/SCREEN_Y);
|
||||
if (y > SCREEN_Y/2-1)
|
||||
y = SCREEN_Y/2-1;
|
||||
|
||||
if (y < -SCREEN_Y/2)
|
||||
y = -SCREEN_Y/2;
|
||||
|
||||
px_y = (y+SCREEN_Y/2)*SCREEN_X;
|
||||
g_gx_buff[px_y+i] = 0xFFFF;
|
||||
hist_buf[0][i] = px_y;
|
||||
|
||||
}
|
||||
scope_idx = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void gx_init(void)
|
||||
{
|
||||
volatile UINT32 *pVGA_ctrl = (UINT32*)SYS_VGA_CTRL;
|
||||
volatile UINT32 *pVGA_front = (UINT32*)SYS_VGA_FB_FRONT;
|
||||
volatile UINT32 *pVGA_back = (UINT32*)SYS_VGA_FB_BACK;
|
||||
|
||||
sleep(500);
|
||||
|
||||
g_gx_buff = (UINT32*)malloc(SCREEN_X*SCREEN_Y*sizeof(UINT32));
|
||||
memset(g_gx_buff, 0, SCREEN_X*SCREEN_Y*sizeof(UINT32));
|
||||
printf("g_gx_buff : %8.8X\n", (UINT32)g_gx_buff);
|
||||
|
||||
*pVGA_front = (UINT32)g_gx_buff;
|
||||
*pVGA_back = (UINT32)g_gx_buff;
|
||||
*pVGA_ctrl = SYS_VGA_BIT_MSTEN;
|
||||
|
||||
}
|
||||
|
||||
int main (void)
|
||||
{
|
||||
int result, i, j;
|
||||
volatile UINT32 *pAC_ctrl = (UINT32*)SYS_AC97_CTRL;
|
||||
volatile UINT32 *pAC_stat = (UINT32*)SYS_AC97_STAT;
|
||||
volatile UINT32 *pAC_ctrl_ac = (UINT32*)SYS_AC97_ACCTRL;
|
||||
volatile UINT32 *pAC_stat_ac = (UINT32*)SYS_AC97_ACSTAT;
|
||||
volatile UINT32 *pAC_pcm = (UINT32*)SYS_AC97_PCM;
|
||||
volatile UINT32 *pTim_stat = (UINT32*)SYS_ITIM_STAT;
|
||||
volatile UINT32 *pTim_ctrl = (UINT32*)SYS_ITIM_CTRL;
|
||||
volatile UINT32 *pTim0_cmp = (UINT32*)SYS_ITIM0_CMP;
|
||||
volatile UINT32 *pTim0_cnt = (UINT32*)SYS_ITIM0_CNT;
|
||||
double phi, dphi, y, mean;
|
||||
char sel, cmd;
|
||||
char buf[1024];
|
||||
FILE *pFile = stdout;
|
||||
|
||||
// setbuf(stderr, NULL);
|
||||
//
|
||||
interrupt_register(7, timer_isr);
|
||||
fprintf(pFile, "Timer interrupt registered.\n");
|
||||
*pTim_ctrl = 0;
|
||||
*pTim0_cnt = 0;
|
||||
*pTim0_cmp = 10E6;
|
||||
*pTim_stat = 1;
|
||||
*pTim_ctrl = 3;
|
||||
interrupt_enable(7);
|
||||
|
||||
fprintf(pFile, "AC-97 Test\n");
|
||||
fprintf(pFile, "Status : %8.8X\n", *pAC_ctrl);
|
||||
|
||||
ac97_ctrl(AC97_REG_VOLO_MST, 0);
|
||||
ac97_ctrl(AC97_REG_VOLO_HP, 0);
|
||||
ac97_ctrl(AC97_REG_VOLI_LINE, 0x8808);
|
||||
ac97_ctrl(AC97_REG_VOLI_PCM, 0x0808);
|
||||
ac97_ctrl(AC97_REG_REC_SRC, 0x0404);
|
||||
ac97_ctrl(AC97_REG_REC_GAIN, 0);
|
||||
ac97_ctrl(AC97_REG_EXTCTRL, 1);
|
||||
|
||||
ac97_ctrl(AC97_REG_RATE_DAC, SAMPLE_RATE);
|
||||
ac97_ctrl(AC97_REG_RATE_ADC, SAMPLE_RATE);
|
||||
|
||||
led_cnt = 0;
|
||||
gcnt = SAMPLE_RATE;
|
||||
|
||||
fprintf(pFile, "DAC-Rate : %d\n", ac97_status(AC97_REG_RATE_DAC));
|
||||
fprintf(pFile, "ADC-Rate : %d\n", ac97_status(AC97_REG_RATE_ADC));
|
||||
|
||||
gpio_init(&gpio, SYS_GPIO_0_BASE);
|
||||
gpio_write(&gpio, GPIO_0_AC97_INTEN, GPIO_0_ALIGN_AC97, GPIO_DATA_OFFSET, GPIO_0_AC97_INTEN);
|
||||
|
||||
gx_init();
|
||||
scope_idx = 0;
|
||||
|
||||
while(1)
|
||||
{
|
||||
fprintf(pFile, "Aufnehmen und Abspielen (1)\n");
|
||||
fprintf(pFile, "Sinus Ton (2)\n");
|
||||
fprintf(pFile, "Pass through (3)\n");
|
||||
fprintf(pFile, "Eingabe: ");
|
||||
|
||||
scanf("%c", &sel);
|
||||
// sel = 0x31;
|
||||
|
||||
if (sel == 0x31)
|
||||
{
|
||||
buf_size = REC_BUF_SIZE;
|
||||
buffer = (INT32*)malloc(REC_BUF_SIZE*sizeof(INT32));
|
||||
// memset(buffer, 0, sizeof(REC_BUF_SIZE*sizeof(INT32)));
|
||||
pPtr_r = buffer;
|
||||
pPtr_w = buffer;
|
||||
|
||||
ac97_ctrl(AC97_REG_VOLI_LINE, 0x0808);
|
||||
|
||||
cmd = 0;
|
||||
while(1)
|
||||
{
|
||||
switch (cmd)
|
||||
{
|
||||
case 'r':
|
||||
ac97_ctrl(AC97_REG_VOLI_LINE, 0x0808);
|
||||
pPtr_w = buffer;
|
||||
fprintf(pFile, "Aufnahme\n");
|
||||
interrupt_register(5, ac97_isr_rec);
|
||||
interrupt_enable(5);
|
||||
*pAC_ctrl = 0x24;
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
ac97_ctrl(AC97_REG_VOLI_LINE, 0x8808);
|
||||
pPtr_r = buffer;
|
||||
fprintf(pFile, "Wiedergabe\n");
|
||||
interrupt_register(5, ac97_isr_play);
|
||||
interrupt_enable(5);
|
||||
*pAC_ctrl = 0x12;
|
||||
break;
|
||||
|
||||
case ' ':
|
||||
ac97_ctrl(AC97_REG_VOLI_LINE, 0x0808);
|
||||
fprintf(pFile, "Stop\n");
|
||||
memset(buffer, 0, sizeof(REC_BUF_SIZE*sizeof(INT32)));
|
||||
*pAC_ctrl = 0x00;
|
||||
pPtr_r = buffer;
|
||||
pPtr_w = buffer;
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(pFile, "Aufnahme (R)\n");
|
||||
fprintf(pFile, "Wiedergabe (P)\n");
|
||||
fprintf(pFile, "Stop (Space)\n");
|
||||
break;
|
||||
}
|
||||
cmd = readchar(0);
|
||||
}
|
||||
}
|
||||
if (sel == 0x32)
|
||||
{
|
||||
buf_size = BUF_SIZE;
|
||||
buffer = (INT32*)malloc(REC_BUF_SIZE*sizeof(INT32));
|
||||
memset(buffer, 0, sizeof(REC_BUF_SIZE*sizeof(INT32)));
|
||||
pPtr_r = buffer;
|
||||
pPtr_w = buffer;
|
||||
|
||||
dphi = 120*2*PI/BUF_SIZE;
|
||||
phi = 0;
|
||||
for (i=0; i < BUF_SIZE/2; i++)
|
||||
{
|
||||
y = cos(phi);
|
||||
buffer[2*i+0] = (INT32)(32000*y);
|
||||
buffer[2*i+1] = (INT32)(32000*y);
|
||||
phi = fmod((phi + dphi), 2.0*PI);
|
||||
}
|
||||
|
||||
fprintf(stderr, "Status : %8.8X\n", *pAC_ctrl);
|
||||
|
||||
interrupt_register(5, ac97_isr_play);
|
||||
interrupt_enable(5);
|
||||
*pAC_ctrl = 0x12;
|
||||
|
||||
fprintf(stderr, "Status : %8.8X\n", *pAC_ctrl);
|
||||
|
||||
while(1)
|
||||
{
|
||||
fprintf(stderr, "Status : %8.8X\n", *pAC_ctrl);
|
||||
}
|
||||
}
|
||||
if (sel == 0x33)
|
||||
{
|
||||
|
||||
buf_size = BUF_SIZE;
|
||||
buffer = (INT32*)malloc(BUF_SIZE*sizeof(INT32));
|
||||
memset(buffer, 0, sizeof(BUF_SIZE*sizeof(INT32)));
|
||||
pPtr_r = buffer;
|
||||
pPtr_w = buffer;
|
||||
*pAC_ctrl = 0x32;
|
||||
interrupt_register(5, ac97_isr_pass);
|
||||
interrupt_enable(5);
|
||||
|
||||
fprintf(stdout, "Status : %8.8X\n", *pAC_ctrl);
|
||||
|
||||
while(1);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user