/* **********************************************************************
 * *                                                                    *
 * *             Custom Major Mode Opcodes Interfaces                   *
 * *                                                                    *
 * **********************************************************************
 * File: libs/dsp/customops.c
 *
 *                     COPYRIGHT (c) 2004, 2005  BY
 *          SIGMET INCORPORATED, WESTFORD MASSACHUSETTS, U.S.A.
 * 
 * THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND  COPIED
 * ONLY  IN  ACCORDANCE WITH  THE  TERMS  OF  SUCH  LICENSE  AND WITH THE
 * INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE  OR  ANY OTHER
 * COPIES  THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY
 * OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF  THE  SOFTWARE  IS  HEREBY
 * TRANSFERED.
 */
#include <stdio.h>
#include <stdlib.h>

#include "sigtypes.h"
#include "dsp.h"
#include "rvp8.h"
#include "user_lib.h"
#include "dsp_lib.h"
#include "dsp_def.h"

/* ------------------------------
 * BATCH mode Get/Set routines.  The real work is done by the
 * encode/decode routines located in 'libs/user/dspcustom.c', put
 * there so that they can be shared with the RVP8.
 */
MESSAGE dspw_batchSetup
( Dsp *dsp_a, volatile const struct rvp8BatchSetup *pUser_a )
{
  MESSAGE istatus ;
  if( PMODE_FROM_OPF( soprm_c.flg_agc ) != PMODE_BATCH )
    istatus = DSP_WRONG_MMODE ;
  else {
    icmd_c[0] = (BATCHOPARGLENGTH << 5) | OP_XARGS ;
    rvp8EncodeBatchOpcode( pUser_a, &icmd_c[1] ) ;
    istatus = dsp_write( dsp_a, icmd_c, 1+BATCHOPARGLENGTH ) ;
    if( istatus == SS_NORMAL ) {
      icmd_c[0] = BATCHOPARGSET | XOPC(XOP_USRINTR) ;
      istatus = dsp_write( dsp_a, icmd_c, 1 ) ;
    }
  }
  return( istatus ) ;
}

MESSAGE dspr_batchSetup
( Dsp *dsp_a, volatile struct rvp8BatchSetup *pUser_a )
{
  MESSAGE istatus ;
  if( PMODE_FROM_OPF( soprm_c.flg_agc ) != PMODE_BATCH )
    istatus = DSP_WRONG_MMODE ;
  else {
    icmd_c[0] = BATCHOPARGGET | XOPC(XOP_USRINTR) ;
    istatus = dsp_write( dsp_a, icmd_c, 1 ) ;
    if( istatus == SS_NORMAL ) {
      UINT2 args[ BATCHOPARGLENGTH ] ; SINT4 iActCount ;
      istatus = dsp_read( dsp_a, args, BATCHOPARGLENGTH, &iActCount ) ;
      if( istatus == SS_NORMAL ) {
	rvp8DecodeBatchOpcode( pUser_a, args, BATCHOPARGLENGTH ) ;
      }
    }
  }
  return( istatus ) ;
}
