📄 ddsetrate.c
字号:
/* Copyright (c) 1995 Entropic Research Laboratory, Inc. *//* Copyright (c) 1989,1990 AT&T *//* All Rights Reserved *//* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T *//* The copyright notice above does not evidence any *//* actual or intended publication of such source code. *//* ddsetrate.c *//* Set sample rate of the Ariel A/D-D/A daughter card. */static char *sccs_id = "@(#)ddsetrate.c 1.2 9/26/95 ATT/ERL";#if defined(SUN4) && !defined(OS5)typedef unsigned long ulong;/*typedef unsigned short ushort;typedef unsigned int uint;*/typedef unsigned char uchar;#include <stdio.h>#include <ctype.h>#include <errno.h>#include <sys/ioctl.h>#include <dsp32c.h>#include <vme32c.h>extern DC_IO *dcmap();extern int dsp32c_io;extern char *DSP_io;extern int use_dsp32;extern int P8574_type;extern int ARIEL_16;extern int ARIEL_HK;extern int debug_level;char *getenv();typedef struct freq_entry { double frequency; int code;} FREQ_ENT;/* The magic numbers sent to the Ariel interface cause it to assume the following sample rates: number 7 6 5 4 3 2 1 0 Basic Clock (MHz) rate 64000 32000 16000 8000 4000 2000 1000 500 16.384 rate 86400 43200 21600 10800 5400 2700 1350 675 22.1184 rate 96000 48000 24000 12000 6000 3000 1500 750 24.576 The multiplier for these rates is determined by a (changeable) crystal on the Ariel board. */FREQ_ENT freq_table24[] = { { 96000.0, 7 }, { 48000.0, 6 }, { 24000.0, 5 }, { 12000.0, 4 }, { 6000.0, 3 }, { 3000.0, 2 }, { 1500.0, 1 }, { 750.0, 0 }, { 0.0, -1 } /* list terminator */};FREQ_ENT freq_table16[] = {{ 64000.0, 7 },{ 32000.0, 6 },{ 16000.0, 5 },{ 8000.0, 4 },{ 4000.0, 3 },{ 2000.0, 2 },{ 1000.0, 1 },{ 500.0, 0 },{ 0.0, -1 }};FREQ_ENT freq_table_ariel[] = {/*{ 8000.0, 7 }, */{ 48000.0, 2 },{ 44100.0, 1 },{ 32000.0, 3 },{ 16000.0, 4 },{ 11025.0, 6 },{ 8000.0, 5 },{ 0.0, -1 }};FREQ_ENT *freq_table;#define PCF8574A 0x70#define PCF8574 0x40#define CAITLIO_A 0#define CAITLIO_B 2#define TRUE 1#define FALSE 0/*************************************************************************/closest_freq(rate) double *rate;{ int i, mini; double mindif, t, fabs(); if (ARIEL_16 || getenv("ARIEL_16")) { if (debug_level) fprintf(stderr,"ddsetrate: using tables for Ariel with 16Mhz crystal\n"); freq_table = freq_table16; } else if(ARIEL_HK || getenv("ARIEL_HK")) { freq_table = freq_table_ariel; if (debug_level) fprintf(stderr,"ddsetrate: using tables for Heurikon/Ariel ProPort\n"); } else { freq_table = freq_table24; if (debug_level) fprintf(stderr,"ddsetrate: using tables for Ariel with 24Mhz crystal\n"); } for(i=0, mini = -1, mindif=1.0e6; freq_table[i].code >= 0; i++) if((t = fabs(freq_table[i].frequency - *rate)) < mindif) { mindif = t; mini = i; } if(mini < 0) { mini = 5; fprintf(stderr,"A frequency close to %f can't be found; using %f\n", *rate, freq_table[mini].frequency); } else if((float)*rate != (float)freq_table[mini].frequency) fprintf(stderr, "Can't set rate to %fHz; using %fHz\n",*rate, freq_table[mini].frequency); *rate = freq_table[mini].frequency; return(freq_table[mini].code);}/*************************************************************************/#ifndef STARDENT_3000set_sam_rate(rate,cluster) double *rate; /* desired sample rate in Hz */ char *cluster; /* 'a' for dc00,dc01,dc02; 'b' for dc03... */{ int dsp, data, device; register DC_IO *mem; register unsigned short *iic0, *iic1; data = closest_freq(rate); /* get magic number corresponding to rate */ /* See Jim Snyder for explanation of the following: *//* * we have two serial ports, one for each cluster, A and B. * either cluster may or may not have a caitlio (i.e. serial * I/O) daughter card. A caitlio card may or may not have an * 8582 configuration EEROM. It may or may not have an 8574 * serial-to-parallel converter for controlling the sample * rate. When we get our act together, we'll interrogate the * EEROM to determine whether there's an 8574. For now, we're * just assuming the user knows what he's doing. (What a laugh.) * 8574 addresses are 0x40 & 0x41 for cluster A, and 0x42 and 0x43 * for cluster B. Also we're not taking a sample rate as input, * we're taking the binary data to be written to the 8574. * Eventually (like about the time we send this to betas) the * data the user provides should be sample rate, and the program * should interrogate the daughter card EEROMs to determine * what card we're dealing with, and then use built-in tables * (built-into the program, that is, not the EEROM) to pick up * the binary value corresponding to that sample rate. Manana .. */ if (!strcmp(cluster, "a") && (P8574_type && !getenv("P8574_type"))) /* P8574 part (not rev A) */ device = PCF8574 | CAITLIO_A; else if (!strcmp(cluster, "b") && (P8574_type && !getenv("P8574_type"))) /* P8574 part (not rev A) */ device = PCF8574 | CAITLIO_B; else if (!strcmp(cluster, "a") && (!P8574_type || getenv("P8574_type"))) /* P8574A */ device = PCF8574A | CAITLIO_A; else if (!strcmp(cluster, "b") && (!P8574_type || getenv("P8574_type"))) /* P8574A */ device = PCF8574A | CAITLIO_B; else { fprintf (stderr,"Bad cluster specified to set_sam_rate(%s)\n", cluster); return(FALSE); } if((dsp32c_io < 0) || !DSP_io) open_32c_io(global_dc_device("io")); if((dsp = dsp32c_io) >= 0) { if (!(mem = (DC_IO*)DSP_io)) { fprintf (stderr, "set_sam_rate(): open_32c_io() failed\n"); return(FALSE); } iic0 = &(mem->dc_iic1); iic1 = &(mem->dc_iic2); iicinit(iic0, iic1); *iic0 = device | IIC_ADDR_WRITE; /* slave address, write */ *iic1 = 0xC4; /* master, sio enabled, start, ack */ iicack(iic1, 0); *iic0 = data; /* write data to set rate */ iicack(iic1, 1); *iic1 = 0xC2; /* write stop */ return(TRUE); } else fprintf(stderr, "Can't open %s\n",global_dc_device("io")); return(FALSE);}/*************************************************************************/iicack(i1,flag) register ushort *i1; int flag;{ while (*i1 & IIC_STA_PIN); if (*i1 & (IIC_STA_BUSERR | IIC_STA_NAK)) { fprintf (stderr, "iicack: bus error, sta=0x%x, flag=0x%x\n", *i1 & 0xff, flag); fprintf (stderr, "You might have the a P8574AP instead of P8574P on your Ariel board.\n"); fprintf (stderr, "Try setting the xwaves global P8574_type to 0\n"); }}/*************************************************************************/iicinit(i0, i1) register ushort *i0, *i1;{ *i0 = 0x10; /* write "own addr", put chip in 68K mode */ *i1 = 0x20; /* point to clock select register */ *i0 = 0x18; /* load clock select register, 8MHz sysclk + 100Kbitclk */ *i1 = 0x40; /* enable serial bus */ if (!(*i1 & IIC_STA_BUSFREE)) { fprintf (stderr, "iicinit: bus busy, goodbye!\n"); fflush (stderr); exit(1); }}#elseset_sam_rate(){}#endif#elseset_same_rate(){}closest_freq(rate){}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -