prefect
Home Engineering Publications
DACS: Mixer Unit Main Code, mixmain.c
 
  next up previous contents
Next: Interrupt Vector Table, mixvect.c Up: Mixer Unit Previous: Firmware Build, Makefile   Contents

Mixer Unit Main Code, mixmain.c

The following is the main code body for the mixer unit firmware. At present, it is a test bed for exercising the serial routines that were being developed at the time of this writing. A routine called oldmain() contains older code that was used to implement very basic functionality of the mixer unit. This code receives MIDI controller data on the serial port and adjusts mixer registers accordingly. Much of the designed firmware functionality is currently unimplemented.
/*****************************************************************************
 * DACS : Distributed Audio Control System
 *============================================================================
 *         File: mixmain.c
 *       Author: Stephen S. Richardson
 * Date Created: 04.14.97
 *  Environment: ICC11 v4.0, 68HC11 target
 *        Build: library, not standalone
 *============================================================================
 * The code, executables, documentation, firmware images, and all related
 * material of DACS are  
 * Copyright (C) 1997 Stephen S. Richardson - ALL RIGHTS RESERVED
 *****************************************************************************
 * Source code control:
 *
 * $Id: mixmain.c,v 1.1 1997/07/13 01:22:04 prefect Exp prefect $
 *
 *****************************************************************************/

#include <hc11.h>
#include "ACIAserial.h"
#include "pbus.h"
#include "pbusdefn.h"
#include "mixdrv.h"
#include "stdlcd.h"
#include "lcddefn.h"

struct mixer_unit_info unit;

void main (void) 
{
  struct raw_frame in_raw;
  struct cooked_frame out_cooked;
  int n;
   
  ACIA_prep_raw (&in_raw);
  ACIA_prep_cooked (&out_cooked);

  mix_system_init();             /* initialize the mixer system */

  ACIA_data_to_cooked ("First", 5, &out_cooked);
   
  while (1) {
    ACIA_service (&in_raw, &out_cooked);

    if (in_raw.done==1) {

      stdlcd_clrhome(HITACHI40x2);   /* clear the LCD */
      stdlcd_out(HITACHI40x2, (char *) in_raw.data);
      
      ACIA_prep_raw (&in_raw);
    } else if (in_raw.done == ERRTOOBIG) {
      stdlcd_clrhome(HITACHI40x2);   /* clear the LCD */
      stdlcd_out(HITACHI40x2, "** Frame too large **");
      ACIA_prep_raw (&in_raw);
    }
     
    if ((out_cooked.done==1) && (n++>1000)) {
      n=0;
      ACIA_data_to_cooked ("Incoming...", 11, &out_cooked);
    }
  }
}


void oldmain (void)
{
  unsigned char ch, r, i, j;
  unsigned char chan, cmd;
  unsigned char dbytes;
  unsigned char brd, chip, minp, lev;
  unsigned char chipmasks[]={CHIP0,CHIP1,CHIP2,CHIP3};
  unsigned char data[10];
  unsigned char *dptr;
  int ticks,bytes;
  unsigned char spin[]={0xA5,'*','O','*'};
  unsigned char spincount;
 
  mix_system_init();      /* initialize the mixer system */
  stdlcd_clrhome(HITACHI40x2);   /* clear the LCD */
  /*                        1234567890123456789012345678901234567890*/
  stdlcd_out (HITACHI40x2, "run [ ] load [                         ]");
  stdlcd_goto (HITACHI40x2, 0x40);
  stdlcd_out (HITACHI40x2, "mode [8x16 ] mixmodules [ 4] outs [u][b]");

  ticks=0;
  bytes=0;
  cmd=0;
  dbytes=0;
  spincount=0;

  while (1) {
    if (ACIA_poll_in (&ch)) {
      /* we got a character */

      PBC_PC^=0x04;  /* green link LED on */
      
      if (ch&0x80) {
	/* MIDI command -- MSB is set */

	if (ch == 0xFF) {
	  /* reset the mixer to a known state */
	  PBC_PC&=~0x04; /* green link LED off */
	  PBC_PC^=0x08;  /* red link LED on */
	  
	  for (i=0;i<4;i++) {
	    for (j=0;j<8;j++) {
	      pbus_mwrite (PBADX_MIX0+i, 0x98+j, 0x98+j, 0x98+j, 0x98+j, CHIPALL);
	      pbus_mwrite (PBADX_MIX0+i, 63, 63, 63, 63, CHIPALL);
	    }
	  }
	  PBC_PC&=~0x08; /* red link LED off */
	} else {
	  /* set stuff for new command + data */
	  cmd = ch&0xF0;  /* upper nybble is command */
	  chan = ch&0x0F; /* lower nybble is channel */
	}
      
	dptr=data;
	dbytes=0;
	bytes++;  /* increase bytecount for 'load' graph */
	ticks++;
      } else {
	*dptr=ch;
	dptr++;
	dbytes++;
	bytes++;  /* increase bytecount for 'load' graph */
	ticks++;

	if ( (cmd == 0xB0) && (dbytes == 2) ) {
	  /* controller change - 1st datum=ctrl# 2nd datum=value */


	  /* "address decoding" for figuring out where to write */

	  brd = (data[0]&0x60)>>5;          /* mix board # */
	  chip = (data[0]&0x18)>>3;         /* chip on the board */
	  minp = (data[0]&0x07)+0x98;       /* input on chip + SSM2163 ofs */

	  lev = 0x7F - ((data[1]/2)&0x7F);  /* attenuation level */


	  /* write the address */
	  pbus_mwrite (0x10+brd, minp, minp, minp, minp, chipmasks[chip]);
	  /* write the level data */
	  pbus_mwrite (0x10+brd, lev, lev, lev, lev, chipmasks[chip]);
	} 
      }
    } else {

      ticks++;

      if (ticks>=8192) {
	/* update LCD and such, enough ticks have passed */
	
	stdlcd_goto (HITACHI40x2, 5);
	stdlcd_writechar (HITACHI40x2, spin[spincount]);

	if (spincount<3) spincount++;
	else {
	  spincount=0;
	}

	
	/*stdlcd_bar (HITACHI40x2, 14, bytes/2, 25);*/

	bytes=0;  /* zero byte counter */
	ticks=0;  /* zero ticks counter */
      }
      PBC_PC&=~0x04;  /* green link LED off */

    }      
  }
}


Steve Richardson 2000-07-06
Table of Contents

[PDF] [Whole document in PDF 1.9MB]

[more photos and information]

 
Page last modified:
Copyright © 1993-2000 prefect - All Rights Reserved.