thg_glue.c
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:13k
- /*******************************************************************************
- * Copyright(c) Philips Consumer Electronics B.V. 2001
- * The attached material and the information contained therein is proprietary
- * to Philips and is issued only under strict confidentiality arrangements.
- * It shall not be used, reproduced, copied in whole or in part, adapted,
- * modified, or disseminated without a written license of Philips.
- * It must be returned to Philips upon its first request.
- *
- * Project: SA-MP ( Super Audio Media Player )
- * File %name: thg_glue.c %
- * %version: 17 %
- * %date_modified: Fri Nov 15 09:39:38 2002 %
- * %derived_by: klerxm %
- * Creation date: Thu Jun 14 16:08:55 2001
- * First author: klerxm
- *
- * Advanced Systems and Applications Lab - Eindhoven
- *
- * Continuus %full_filespec: thg_glue.c~17:csrc:1 %
- *
- * Description: Test harness of the Glue layer
- *
- * Change history:
- *
- * Rev Date Who Comments
- * ---- ---------- -------- -----------------------------------------------------
- * 1 2001-06-06 klerxm Dummy version
- * 2 2001-06-14 klerxm Template update
- * 3 2001-07-30 klerxm Initial version
- * 4 2001-09-04 klerxm Changes required for new global header files
- * 5 2001-09-10 klerxm Added DBG_SetMask
- * 6 2001-12-17 kokh Added interrupt installation
- * 7 2002-02-19 klerxm See CRPR154: Added all required interface functions
- * for testing purposes
- * 8 2002-02-27 kokh TH_Send -> SAMP(TH_Send)
- * 9 2002-03-14 kokh Additions for tests on OSA interface
- * 10 2002-03-26 klerxm Added some #ifdef THG_GLUE 's
- * 11 2002-04-05 potm Extended DAC_SetMode with parameters for stereo DAC
- * and moved parameter conversion to glue layer (PR393)
- * 12 2002-04-19 klerxm Removed OS_Disable/EnableInterrupts (CRPR391)
- * 13 2002-05-15 klerxm Added time measurement for BE command (CRPR389)
- * 14 2002-05-24 klerxm Include OSA test functions only if DEVELOPMENT defined
- * 15 2002-10-14 potm Fixed some warnings
- * 16 2002-11-06 potm Replaced UInt16* with UInt32* in call to TH_GetParam
- * 17 2002-11-15 klerxm Solved implicit narrowing cast compiler warning
- *
- *******************************************************************************/
- #define COMP_PREFIX "GLUE"
- /*******************************************************************************
- * Include Files
- *******************************************************************************/
- #include "config.h"
- #ifdef TEST_HARNASS
- #include <samp_gen.h>
- #include <samp_sdm.h>
- #include <glue_be.h>
- #include <glue_dbg.h>
- #include <glue_test.h>
- #include <testharn.h>
- #include <stdlib.h>
- /*******************************************************************************
- * Macro Definitions
- *******************************************************************************/
- /*******************************************************************************
- * Data Definitions
- *******************************************************************************/
- #ifdef THGGLUE
- #ifdef DEVELOPMENT
- static char osaBuffer[2][1024];
- static int osaFill[2] = { 0, 0 };
- static int osaInt = 0;
- #endif
- #endif
- /*******************************************************************************
- * Function prototype
- *******************************************************************************/
- DECLARE_GROUPFUNC(THG_GLUE)
- /*******************************************************************************
- * Local Functions
- *******************************************************************************/
- #ifdef THGGLUE
- #ifdef DEVELOPMENT
- void TaskSpawn(int buf)
- {
- int i = 0;
- SAMP(TH_Send)(COMP_PREFIX, "TaskStarted", "%u", buf);
- while (i<osaFill[buf])
- {
- /* find the comma */
- int j = i;
- while (j < osaFill[buf])
- {
- if (osaBuffer[buf][j] == ',')
- {
- osaBuffer[buf][j] = ' ';
- j++;
- break;
- }
- j++;
- }
- THG_GLUE(&osaBuffer[buf][i], &osaBuffer[buf][j]);
- i += j + strlen(&osaBuffer[buf][j]) + 1;
- }
- osaBuffer[buf][0] = 0;
- osaFill[buf] = 0;
- SAMP(TH_Send)(COMP_PREFIX, "TaskEnded", "%u", buf);
- }
- void TaskSpawn0(void)
- {
- TaskSpawn(0);
- }
- void TaskSpawn1(void)
- {
- TaskSpawn(1);
- }
- void TaskSpawn2(void)
- {
- int i, j, prod;
- SAMP(UInt32) tm, tm2;
- SAMP(TH_Send)(COMP_PREFIX, "TaskStarted", "%u", 2);
- osaInt = 0;
- /* Just occupy CPU for a while! */
- i = 0;
- SAMP(OS_GetTime)(&tm);
- do {
- for (j=0; j<100000; j++)
- {
- prod = i*j + i + j;
- }
- SAMP(OS_GetTime)(&tm2);
- } while (tm2 < tm+10);
- i = i*20;
- while (i > 0)
- {
- for (j=0; j<100000; j++)
- {
- prod = i*j + i + j;
- }
- }
- SAMP(TH_Send)(COMP_PREFIX, "NotInterrupted", "%u", osaInt);
- SAMP(TH_Send)(COMP_PREFIX, "TaskEnded", "%u", 2);
- }
- void TaskSpawn3(void)
- {
- int i, j, prod;
- SAMP(UInt32) tm, tm2;
- SAMP(TH_Send)(COMP_PREFIX, "TaskStarted", "%u", 3);
- /* Just occupy CPU for a while! */
- i = 0;
- SAMP(OS_GetTime)(&tm);
- do {
- for (j=0; j<100000; j++)
- {
- prod = i*j + i + j;
- }
- osaInt = 1;
- SAMP(OS_GetTime)(&tm2);
- } while (tm2 < tm+200);
- SAMP(TH_Send)(COMP_PREFIX, "TaskEnded", "%u", 3);
- }
- #endif
- #endif
- /*******************************************************************************
- * Global test-harness function
- *******************************************************************************/
- DEFINE_GROUPFUNC(THG_GLUE)
- #ifdef THGGLUE
- GROUP_SWITCH
- #ifdef DEVELOPMENT
- CASE_CMD( "DBG_SetMask" )
- SAMP(UInt32) lMask;
- char lPrefix[8];
- TH_GetParam (OPTIONS, "%s%u", lPrefix, &lMask);
- SAMP(DBG_SetMask)( lPrefix, (SAMP(Int16))lMask );
- SAMP(TH_Send)(COMP_PREFIX, cmd, "%u", 0);
- END_CASE
- #endif
- CASE_CMD ("BE_Init")
- SAMP(ErrCode) lErr = SAMP(ERR_OK);
- lErr = SAMP(BE_Init)();
- SAMP(TH_Send)(COMP_PREFIX, cmd, "%u", (SAMP(UInt32))lErr);
- END_CASE
- CASE_CMD ("BE_Term")
- SAMP(ErrCode) lErr = SAMP(ERR_OK);
- lErr = SAMP(BE_Term)();
- SAMP(TH_Send)(COMP_PREFIX, cmd, "%u", (SAMP(UInt32))lErr);
- END_CASE
- CASE_CMD( "BE_Seek" )
- SAMP(ErrCode) lErr;
- SAMP(UInt32) lPos;
- SAMP(UInt32) lT0,lT1;
- TH_GetParam (OPTIONS, "%u", &lPos);
- SAMP(OS_GetTime)(&lT0);
- lErr = SAMP(BE_Seek)( lPos&~0xF );
- SAMP(OS_GetTime)(&lT1);
- SAMP(TH_Send)(COMP_PREFIX, cmd, "%u%u", (SAMP(UInt32))lErr, lT1-lT0);
- END_CASE
- CASE_CMD( "BE_SetTransferRate" )
- SAMP(ErrCode) lErr;
- SAMP(UInt32) lRate;
- SAMP(UInt32) lT0,lT1;
- TH_GetParam (OPTIONS, "%u", &lRate);
- SAMP(OS_GetTime)(&lT0);
- lErr = SAMP(BE_SetTransferRate)( lRate );
- SAMP(OS_GetTime)(&lT1);
- SAMP(TH_Send)(COMP_PREFIX, cmd, "%u%u", (SAMP(UInt32))lErr, lT1-lT0);
- END_CASE
- CASE_CMD( "BE_GetDataArea" )
- SAMP(ErrCode) lErr;
- SAMP(UInt32) lStart = 0, lEnd = 0, lLayer0 = 0;
- SAMP(UInt32) lT0,lT1;
- SAMP(OS_GetTime)(&lT0);
- lErr = SAMP(BE_GetDataArea)( &lStart, &lEnd, &lLayer0 );
- SAMP(OS_GetTime)(&lT1);
- SAMP(TH_Send)(COMP_PREFIX, cmd, "%u%u%u%u%u", lStart, lEnd, lLayer0, (SAMP(UInt32))lErr, lT1-lT0);
- END_CASE
- CASE_CMD ("BE_TrayOpen")
- SAMP(ErrCode) lErr;
- lErr = SAMP(BE_TrayOpen)();
- SAMP(TH_Send) (COMP_PREFIX, cmd, "%u", (SAMP(UInt32))lErr);
- END_CASE
- CASE_CMD ("BE_TrayClose")
- SAMP(ErrCode) lErr;
- lErr = SAMP(BE_TrayClose)();
- SAMP(TH_Send) (COMP_PREFIX, cmd, "%u", (SAMP(UInt32))lErr);
- END_CASE
- CASE_CMD ("BE_ReadToc")
- SAMP(ErrCode) lErr;
- SAMP(UInt32) lT0,lT1;
- SAMP(OS_GetTime)(&lT0);
- lErr = SAMP(BE_ReadToc)();
- SAMP(OS_GetTime)(&lT1);
- SAMP(TH_Send) (COMP_PREFIX, cmd, "%u", (SAMP(UInt32))lErr, lT1-lT0);
- END_CASE
- #ifdef THGSDM
- CASE_CMD( "ISR_Install" )
- void (*lFuroreISR)(void);
- SAMP(ErrCode) lErr = SAMP(ERR_OK);
- SAMP(SDM_GetHandler)( &lFuroreISR );
- lErr = SAMP(ISR_Install)( lFuroreISR );
- SAMP(TH_Send)(COMP_PREFIX, cmd, "%u", (SAMP(UInt32))lErr);
- END_CASE
- #endif
- CASE_CMD ("DAC_Init")
- SAMP(ErrCode) lErr = SAMP(ERR_OK);
- lErr = SAMP(DAC_Init)();
- SAMP(TH_Send)(COMP_PREFIX, cmd, "%u", (SAMP(UInt32))lErr);
- END_CASE
- CASE_CMD ("DAC_Term")
- SAMP(ErrCode) lErr = SAMP(ERR_OK);
- lErr = SAMP(DAC_Init)();
- SAMP(TH_Send)(COMP_PREFIX, cmd, "%u", (SAMP(UInt32))lErr);
- END_CASE
- CASE_CMD ("DAC_SetMode")
- SAMP(ErrCode) lErr = SAMP(ERR_OK);
- SAMP(UInt32) lStream6ch, lStream2ch, lBaseFrequency, lPcmUpsampling6ch, lPcmUpsampling2ch;
- TH_GetParam(OPTIONS, "%u%u%u%u%u", &lStream6ch, &lPcmUpsampling6ch, &lStream2ch, &lPcmUpsampling2ch, &lBaseFrequency);
- lErr = SAMP(DAC_SetMode)(lStream6ch, lPcmUpsampling6ch, lStream2ch, lPcmUpsampling2ch, lBaseFrequency);
- SAMP(TH_Send)(COMP_PREFIX, cmd, "%u", (SAMP(UInt32))lErr);
- END_CASE
- #ifdef DEVELOPMENT
- CASE_CMD ("StoreCmd")
- SAMP(ErrCode) lErr = SAMP(ERR_OK);
- int buf = atoi(OPTIONS);
- if (buf >= 0 && buf < 2)
- {
- if (osaFill[buf] + strlen(OPTIONS) > 1024)
- {
- lErr = SAMP(ERR_INVALID_PARAM);
- } else
- {
- /* find a comma */
- unsigned int i=0;
- while (i<strlen(OPTIONS))
- {
- if (OPTIONS[i] == ',')
- {
- i++;
- break;
- }
- i++;
- }
- /* copy the command */
- strcpy(&osaBuffer[buf][osaFill[buf]], &OPTIONS[i]);
- osaFill[buf] += strlen(OPTIONS) - i + 1;
- }
- } else
- {
- lErr = SAMP(ERR_INVALID_PARAM);
- }
- SAMP(TH_Send)(COMP_PREFIX, cmd, "%u", lErr);
- END_CASE
- CASE_CMD ("OS_TaskCreate")
- SAMP(ErrCode) lErr = SAMP(ERR_OK);
- SAMP(UInt32) prio;
- size_t stacksize;
- SAMP(UInt32) tasknum;
- SAMP(UInt32) id = 0;
- TH_GetParam (OPTIONS, "%u%u%u", &prio, &stacksize, &tasknum);
- if (tasknum == 0)
- {
- lErr = SAMP(OS_TaskCreate)(prio, stacksize, TaskSpawn0, &id);
- } else if (tasknum == 1)
- {
- lErr = SAMP(OS_TaskCreate)(prio, stacksize, TaskSpawn1, &id);
- } else if (tasknum == 2)
- {
- lErr = SAMP(OS_TaskCreate)(prio, stacksize, TaskSpawn2, &id);
- } else if (tasknum == 3)
- {
- lErr = SAMP(OS_TaskCreate)(prio, stacksize, TaskSpawn3, &id);
- } else
- {
- lErr = SAMP(ERR_INVALID_PARAM);
- }
- SAMP(TH_Send)(COMP_PREFIX, cmd, "%u%u", lErr, id);
- END_CASE
- CASE_CMD ("OS_TaskDelete")
- SAMP(ErrCode) lErr = SAMP(ERR_OK);
- SAMP(UInt32) id;
- TH_GetParam (OPTIONS, "%u", &id);
- lErr = SAMP(OS_TaskDelete)(id);
- SAMP(TH_Send)(COMP_PREFIX, cmd, "%u", lErr);
- END_CASE
- CASE_CMD ("OS_SemCreate")
- SAMP(ErrCode) lErr = SAMP(ERR_OK);
- SAMP(UInt32) units;
- SAMP(UInt32) id;
- TH_GetParam (OPTIONS, "%u", &units);
- lErr = SAMP(OS_SemCreate)(units, &id);
- SAMP(TH_Send)(COMP_PREFIX, cmd, "%u%u", lErr, id);
- END_CASE
- CASE_CMD ("OS_SemDelete")
- SAMP(ErrCode) lErr = SAMP(ERR_OK);
- SAMP(UInt32) id;
- TH_GetParam (OPTIONS, "%u", &id);
- lErr = SAMP(OS_SemDelete)(id);
- SAMP(TH_Send)(COMP_PREFIX, cmd, "%u", lErr);
- END_CASE
- CASE_CMD ("OS_SemP")
- SAMP(ErrCode) lErr = SAMP(ERR_OK);
- SAMP(UInt32) id;
- SAMP(UInt32) timeout;
- TH_GetParam (OPTIONS, "%u%u", &id, &timeout);
- lErr = SAMP(OS_SemP)(id, timeout);
- SAMP(TH_Send)(COMP_PREFIX, cmd, "%u", lErr);
- END_CASE
- CASE_CMD ("OS_SemV")
- SAMP(ErrCode) lErr = SAMP(ERR_OK);
- SAMP(UInt32) id;
- TH_GetParam (OPTIONS, "%u", &id);
- lErr = SAMP(OS_SemV)(id);
- SAMP(TH_Send)(COMP_PREFIX, cmd, "%u", lErr);
- END_CASE
- CASE_CMD ("OS_TimerEvery")
- SAMP(ErrCode) lErr = SAMP(ERR_OK);
- SAMP(UInt32) ticks;
- SAMP(UInt32) task;
- SAMP(UInt32) id=0;
- TH_GetParam (OPTIONS, "%u%u", &ticks, &task);
- if (task == 0)
- {
- lErr = SAMP(OS_TimerEvery)(ticks, TaskSpawn0, &id);
- } else if (task == 1)
- {
- lErr = SAMP(OS_TimerEvery)(ticks, TaskSpawn1, &id);
- } else
- {
- lErr = SAMP(ERR_INVALID_PARAM);
- }
- SAMP(TH_Send)(COMP_PREFIX, cmd, "%u%u", lErr, id);
- END_CASE
- CASE_CMD ("OS_TimerCancel")
- SAMP(ErrCode) lErr = SAMP(ERR_OK);
- SAMP(UInt32) id;
- TH_GetParam (OPTIONS, "%u", &id);
- lErr = SAMP(OS_TimerCancel)(id);
- SAMP(TH_Send)(COMP_PREFIX, cmd, "%u", lErr);
- END_CASE
- CASE_CMD ("OS_GetTime")
- SAMP(ErrCode) lErr = SAMP(ERR_OK);
- SAMP(UInt32) ticks;
- lErr = SAMP(OS_GetTime)(&ticks);
- SAMP(TH_Send)(COMP_PREFIX, cmd, "%u%u", lErr, ticks);
- END_CASE
- #endif
- DEFAULT
- SAMP(TH_Send)(COMP_PREFIX, cmd, "%s", "Unknown command");
- END_CASE
- #endif
- END_GROUPFUNC
- /*******************************************************************************
- * End of File
- *******************************************************************************/
- #endif