📄 sendout.c
字号:
/* DSP32c c-code to support circular output FIFO 5-17-94 LMS
10-31-94 CAC adapted to CAC boards
*/
#include <math.h>
/* length of integer input sample buffer */
#define FIFO_LENGTH 0x800
#define FIFO_LENGTH_BYTES 0x1000
#define FILL_FIFO 0x7D0
/*
#define FILL_FIFO 0x5
*/
#define FIFO_TOO_FULL 0x7E0
void out_int_enable();
void int_disable();
void flush();
extern short out_fifo_buffer[];
extern short in_fifo_buffer[];
short *out_pin = out_fifo_buffer;
short *in_pout = in_fifo_buffer;
/* global interrupt on flag */
int out_int_flag = 0;
asm void push_fifo(fltnum)
{
% mem fltnum;
r2e = out_pin
r4e = *r2
r2e = *r2
r1e = fltnum
*r2 = a0 = int(*r1)
r4e = r4 + 2
r3e = out_fifo_buffer + FIFO_LENGTH_BYTES
r4e - r3
r3e = out_fifo_buffer
if (ge) r4e = r3
r2e = out_pin
*r2 = r4e
}
asm int get_pin()
{
r1e = out_pin
r1e = *r1
nop
}
asm int get_pout()
{
r1e = r21
}
void sendout(x)
float x;
{
register short *pin, *pout;
register int samples_in_buff;
/* round and clip to 16 bits */
push_fifo(x);
/* replaces: clip output to 16 bits
j = (short)x;
if(j > 32767) j = 32767;
else if(j < -32768) j = -32768;
*/
/* keep checking the out pointer until pout gets close to pin */
/* do only while interrupts are enabled */
pin = (short *) get_pin();
if(out_int_flag) {
/* determine number of samples in FIFO and
take care of circular buffer problems */
do {
pout = (short *) get_pout();
if (pin > pout)
samples_in_buff = pin - pout;
else
samples_in_buff = pin + FIFO_LENGTH - pout;
} while(samples_in_buff > FIFO_TOO_FULL);
}
else {
if(pin > (out_fifo_buffer + FILL_FIFO))
out_int_enable();
}
}
/* flush all samples out of the FIFO and then disable interrupts */
void flush()
{
register short *pin,*pout;
short j;
float sample,delta;
pin = (short *)get_pin();
if(pin == out_fifo_buffer) pin = out_fifo_buffer + FIFO_LENGTH-1; else pin--;
/* slowly drop the output to zero to avoid pop */
j = *pin;
delta = fabs((float)j)/5000;
if(delta <= 1.0) delta = 1.0;
if(j >= 0) {
sample = (float)j;
while(sample > 0.0) {
sendout(sample);
sample -= delta;
}
}
else {
sample = (float)j;
while(sample < 0.0) {
sendout(sample);
sample += delta;
}
}
if(!out_int_flag) out_int_enable();
pin = (short *) get_pin();
if(pin == out_fifo_buffer) pin = out_fifo_buffer + FIFO_LENGTH-1; else pin--;
/* wait for end of samples */
do {
pout = (short *)get_pout();
} while(pout != (pin - 1));
int_disable();
}
void initialize_ioc()
{
#ifdef DBDADA
asm("ioc = 0x30cc0");
#else
asm("ioc = 0x30880");
#endif
}
/* interrupt enable function */
void out_int_enable()
{
/* enable real-time serial output interrupt and serial output */
asm("r1 = 0; obuf = r1;");
initialize_ioc();
asm("r1 = pcw; nop; r1 = r1 | 0x800; pcw = r1 ");
out_int_flag = 1;
}
/* interrupt disable function - disables all serial i/o interrupts */
void int_disable()
{
/* disable real-time serial i/o interrupts and serial i/o */
asm(" r1 = pcw");
initialize_ioc();
asm("r1 = r1 & 0xe7ff");
asm("pcw = r1");
out_int_flag = 0;
out_pin = out_fifo_buffer;
in_pout = in_fifo_buffer;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -