コード例 #1
0
ファイル: embx_os21.c プロジェクト: Audioniek/Fortis-4G
/*
 * Block forever waiting for EVENT to be signalled,
 * or timeout after timeout (ms) have expired
 * set timeout to EMBX_TIMEOUT_INFINITE to wait forever
 *
 * Returns EMBX_SUCCESS if signalled, EMBX_SYSTEM_TIMEOUT otherwise
 */
EMBX_ERROR EMBX_OS_EventWaitTimeout(EMBX_EVENT ev, unsigned long timeout)
{
    int res;
    osclock_t time;

    EMBX_Assert(ev);

    if (timeout != EMBX_TIMEOUT_INFINITE)
    {
	/* OS21 semaphore timeout takes an absolute time value
	 * so we calculate that here
	 */
	time = time_plus(time_now(), (timeout*time_ticks_per_sec())/1000);
	res = semaphore_wait_timeout(ev->event, &time);
    }
    else
	/* Infinite wait */
	res = semaphore_wait(ev->event);

    if (res == OS21_FAILURE)
	return EMBX_SYSTEM_TIMEOUT;

    return EMBX_SUCCESS;
}
コード例 #2
0
int main(int argc, char **argv)
{
stm_display_plane_t    *pPlane;
stm_display_buffer_t    buffer_setup;
char                   *fbuffer;
void                   *fbufferphys;
interrupt_t            *vsync_interrupt=0;
interrupt_t            *hdmi_interrupt=0;
int                     err;
int                     seconds;
int                     clip;
int                     rgb;
int                     dvi;
stm_plane_id_t          planeid;
osclock_t               lasttime;

  kernel_initialize(NULL);
  kernel_start();
  kernel_timeslice(OS21_TRUE);

  framerate_sem      = semaphore_create_fifo(0);
  frameupdate_sem    = semaphore_create_fifo(0);
  hotplug_sem        = semaphore_create_fifo(0);

  task_create(displayupdate_task_fn, 0, OS21_DEF_MIN_STACK_SIZE, MAX_USER_PRIORITY, "displayupdate", 0);

  pDev = stm_display_get_device(0);
  if(!pDev)
  {
    printf("Unable to create device instance\n");
    return 1;
  }

  if(argc<2)
    usage();

  argc--;
  argv++;

  seconds = 60;
  rgb     = 0;
  dvi     = 0;
  clip    = 0;

  while(argc>0)
  {
    switch(**argv)
    {
      case 'C':
      {
        printf("Clipping video signal selected\n");
        clip = 1;
        break;
      }
      case 'd':
      {
        printf("Setting DVI mode on HDMI output\n");
        dvi = 1;
        break;
      }
      case 'h':
      {
        int refresh;

        argc--;
        argv++;

        if(argc <= 0)
        {
          fprintf(stderr,"Missing HD vertical refresh frequency\n");
          usage();
        }

        refresh = atoi(*argv);
        switch(refresh)
        {
          case 50:
            printf("Setting 1280x720-50\n");
            MODE      = STVTG_TIMING_MODE_720P50000_74250;
            STANDARD  = STM_OUTPUT_STD_SMPTE296M;
            framerate = 50;
            break;
          case 59:
            printf("Setting 1280x720-59\n");
            MODE      = STVTG_TIMING_MODE_720P59940_74176;
            STANDARD  = STM_OUTPUT_STD_SMPTE296M;
            framerate = 60;
            break;
          case 60:
            printf("Setting 1280x720-60\n");
            MODE      = STVTG_TIMING_MODE_720P60000_74250;
            STANDARD  = STM_OUTPUT_STD_SMPTE296M;
            framerate = 60;
            break;
          default:
            fprintf(stderr,"Unsupported HD vertical refresh frequency\n");
            usage();
        }
        break;
      }
      case 'r':
      {
        printf("Setting Component RGB Outputs\n");
        rgb = 1;
        break;
      }
      case 'p':
      {
        int refresh;

        argc--;
        argv++;

        if(argc <= 0)
        {
          fprintf(stderr,"Missing 1080p vertical refresh frequency\n");
          usage();
        }

        refresh = atoi(*argv);
        switch(refresh)
        {
          case 23:
            printf("Setting 1920x1080-23\n");
            MODE      = STVTG_TIMING_MODE_1080P23976_74176;
            STANDARD  = STM_OUTPUT_STD_SMPTE274M;
            framerate = 24;
            break;
          case 24:
            printf("Setting 1920x1080-24\n");
            MODE      = STVTG_TIMING_MODE_1080P24000_74250;
            STANDARD  = STM_OUTPUT_STD_SMPTE274M;
            framerate = 24;
            break;
          case 25:
            printf("Setting 1920x1080-25\n");
            MODE      = STVTG_TIMING_MODE_1080P25000_74250;
            STANDARD  = STM_OUTPUT_STD_SMPTE274M;
            framerate = 25;
            break;
          case 29:
            printf("Setting 1920x1080-29\n");
            MODE      = STVTG_TIMING_MODE_1080P29970_74176;
            STANDARD  = STM_OUTPUT_STD_SMPTE274M;
            framerate = 30;
            break;
          case 30:
            printf("Setting 1920x1080-30\n");
            MODE      = STVTG_TIMING_MODE_1080P30000_74250;
            STANDARD  = STM_OUTPUT_STD_SMPTE274M;
            framerate = 30;
            break;
          case 50:
            printf("Setting 1920x1080-50\n");
            MODE      = STVTG_TIMING_MODE_1080P50000_148500;
            STANDARD  = STM_OUTPUT_STD_SMPTE274M;
            framerate = 50;
            break;
          case 59:
            printf("Setting 1920x1080-59\n");
            MODE      = STVTG_TIMING_MODE_1080P59940_148352;
            STANDARD  = STM_OUTPUT_STD_SMPTE274M;
            framerate = 60;
            break;
          case 60:
            printf("Setting 1920x1080-60\n");
            MODE      = STVTG_TIMING_MODE_1080P60000_148500;
            STANDARD  = STM_OUTPUT_STD_SMPTE274M;
            framerate = 60;
            break;
          default:
            fprintf(stderr,"Unsupported HD vertical refresh frequency\n");
            usage();
        }
        break;
      }
      case 's':
      {
        int refresh;

        argc--;
        argv++;

        if(argc <= 0)
        {
          fprintf(stderr,"Missing SD vertical refresh frequency\n");
          usage();
        }

        refresh = atoi(*argv);
        switch(refresh)
        {
          case 50:
            printf("Setting 720x576-50\n");
            MODE      = STVTG_TIMING_MODE_576P50000_27000;
            STANDARD  = STM_OUTPUT_STD_SMPTE293M;
            framerate = 50;
            break;
          case 59:
            printf("Setting 720x480-59\n");
            MODE      = STVTG_TIMING_MODE_480P59940_27000;
            STANDARD  = STM_OUTPUT_STD_SMPTE293M;
            framerate = 60;
            break;
          case 60:
            printf("Setting 720x480-60\n");
            MODE      = STVTG_TIMING_MODE_480P60000_27027;
            STANDARD  = STM_OUTPUT_STD_SMPTE293M;
            framerate = 60;
            break;
          default:
            fprintf(stderr,"Unsupported SD vertical refresh frequency\n");
            usage();
        }
        break;
      }
      case 't':
      {
        argc--;
        argv++;

        if(argc <= 0)
        {
          fprintf(stderr,"Missing seconds\n");
          usage();
        }

        seconds = atoi(*argv);
        if(seconds<0)
          usage();

        break;
      }
      case 'v':
      {
        int refresh;

        argc--;
        argv++;

        if(argc <= 0)
        {
          fprintf(stderr,"Missing vertical refresh frequency\n");
          usage();
        }

        refresh = atoi(*argv);
        switch(refresh)
        {
          case 59:
            printf("Setting 640x480-59\n");
            MODE      = STVTG_TIMING_MODE_480P59940_25180;
            STANDARD  = STM_OUTPUT_STD_VESA;
            framerate = 60;
            break;
          case 60:
            printf("Setting 640x480-60\n");
            MODE      = STVTG_TIMING_MODE_480P60000_25200;
            STANDARD  = STM_OUTPUT_STD_VESA;
            framerate = 60;
            break;
          default:
            fprintf(stderr,"Unsupported vertical refresh frequency\n");
            usage();
        }
        break;
      }
      default:
        fprintf(stderr,"Unknown option '%s'\n",*argv);
        usage();
    }

    argc--;
    argv++;
  }


  planeid  = OUTPUT_GDP1;

  vsync_interrupt = get_main_vtg_interrupt();

  setup_soc();

  if(!vsync_interrupt)
  {
    printf("Cannot find VSYNC interrupt handler\n");
    return 1;
  }

  err  = interrupt_install(vsync_interrupt, vsync_isr, pDev);
  err += interrupt_enable(vsync_interrupt);
  if(err>0)
  {
    printf("Unable to install and enable VSYNC interrupt\n");
    return 1;
  }

  fbuffer = (char *)malloc(FBSIZE);
  if(!fbuffer)
  {
    printf("Unable to allocate framebuffer\n");
    return 1;
  }

  memset(fbuffer, 0x00, FBSIZE);
  create_test_pattern(fbuffer, FBWIDTH, FBHEIGHT, FBSTRIDE);
  cache_purge_data(fbuffer, FBSIZE);

  pOutput = stm_display_get_output(pDev, 0);
  if(!pOutput)
  {
    printf("Unable to get output\n");
    return 1;
  }


  setup_analogue_voltages(pOutput);
  stm_display_output_set_control(pOutput, STM_CTRL_SIGNAL_RANGE, clip?STM_SIGNAL_VIDEO_RANGE:STM_SIGNAL_FILTER_SAV_EAV);

  pDVO = get_dvo_output(pDev);

  {
    pHDMI = get_hdmi_output(pDev);

    if(pHDMI)
    {
      /*
       * Now we have a HDMI output pointer to handle hotplug interrupts,
       * we can enable the interrupt handlers.
       */
      hdmi_interrupt = get_hdmi_interrupt();
      if(hdmi_interrupt)
      {
        err  = interrupt_install(hdmi_interrupt, hdmi_isr, pHDMI);
        err += interrupt_enable(hdmi_interrupt);
      }

      if(err>0)
      {
        printf("Unable to install and enable hdmi interrupts\n");
        return 1;
      }

      stm_display_output_set_control(pHDMI, STM_CTRL_SIGNAL_RANGE, clip?STM_SIGNAL_VIDEO_RANGE:STM_SIGNAL_FILTER_SAV_EAV);

    }
    else
    {
      printf("Hmmm, no HDMI output available\n");
    }
  }


  pModeLine = stm_display_output_get_display_mode(pOutput, MODE);
  if(!pModeLine)
  {
    printf("Unable to use requested display mode\n");
    return 1;
  }

  pPlane = stm_display_get_plane(pDev, planeid);
  if(!pPlane)
  {
    printf("Unable to get graphics plane\n");
    return 1;
  }

  if(stm_display_plane_connect_to_output(pPlane, pOutput)<0)
  {
    printf("Unable to display plane on output\n");
    return 1;
  }

  if(stm_display_plane_lock(pPlane)<0)
  {
    printf("Unable to lock plane's buffer queue\n");
    return 1;
  }

  memset(&buffer_setup, 0, sizeof(buffer_setup));

  vmem_virt_to_phys(fbuffer, &fbufferphys);
  buffer_setup.src.ulVideoBufferAddr = (ULONG)fbufferphys;
  buffer_setup.src.ulVideoBufferSize = FBSIZE;

  buffer_setup.src.ulStride     = FBSTRIDE;
  buffer_setup.src.ulPixelDepth = FBDEPTH;
  buffer_setup.src.ulColorFmt   = FBPIXFMT;
  buffer_setup.src.Rect.width   = FBWIDTH;
  buffer_setup.src.Rect.height  = FBHEIGHT;
  buffer_setup.dst.Rect.width   = FBWIDTH;
  buffer_setup.dst.Rect.height  = FBHEIGHT;

  buffer_setup.info.ulFlags = STM_PLANE_PRESENTATION_PERSISTENT;

  printf("Clock is running at %ld ticks per second\n",(long)time_ticks_per_sec());

  ULONG format=0;

  format = rgb?STM_VIDEO_OUT_RGB:STM_VIDEO_OUT_YUV;

  stm_display_output_set_control(pOutput, STM_CTRL_VIDEO_OUT_SELECT, format);

  if(pHDMI)
  {
    ULONG format = 0;

    format |= rgb?STM_VIDEO_OUT_RGB:STM_VIDEO_OUT_YUV;
    format |= dvi?STM_VIDEO_OUT_DVI:STM_VIDEO_OUT_HDMI;

    stm_display_output_set_control(pHDMI, STM_CTRL_VIDEO_OUT_SELECT, format);
  }


  if(stm_display_output_start(pOutput, pModeLine, STANDARD)<0)
  {
    printf("Unable to start display\n");
    return 1;
  }

  if(pDVO)
  {
    printf("Info: Attempting to start DVO\n");
    if(stm_display_output_start(pDVO, pModeLine, STANDARD)<0)
    {
      printf("Info: Unable to start DVO\n");
    }
  }

  lasttime = time_now(); // VTG Start time (approx)

  if(stm_display_plane_queue_buffer(pPlane, &buffer_setup)<0)
  {
    printf("Unable to queue framebuffer for display on graphics plane\n");
    return 1;
  }

  task_create(hotplug_task_fn, 0, OS21_DEF_MIN_STACK_SIZE, MIN_USER_PRIORITY, "hotplug", 0);

  if(seconds == 0)
  {
    task_delay(time_ticks_per_sec()*5);
    task_priority_set(NULL,MIN_USER_PRIORITY);
    silent_hotplug = 1;
    err = get_yesno();
  }
  else
  {
    while(seconds>0)
    {
    osclock_t now,delta;

      semaphore_wait(framerate_sem);

      now   = time_now();
      delta = time_minus(now,lasttime);
      printf("%d frames took %ld ticks.\n",framerate, (long)delta);

      lasttime = now;
      seconds--;
    }

    err = 0;
  }

  stm_display_plane_flush(pPlane);
  stm_display_plane_disconnect_from_output(pPlane, pOutput);
  stm_display_output_stop(pOutput);

  interrupt_disable(vsync_interrupt);
  interrupt_disable(hdmi_interrupt);

  stm_display_plane_release(pPlane);

  if(pDVO)
    stm_display_output_release(pDVO);

  if(pHDMI)
    stm_display_output_release(pHDMI);

  stm_display_output_release(pOutput);

  stm_display_release_device(pDev);

  return err;
}
コード例 #3
0
ファイル: stgos21.c プロジェクト: MarkusVolk/martii-tdt
static TIME64 GetOneSecond(void)
{
  return time_ticks_per_sec();
}
コード例 #4
0
ファイル: stgos21.c プロジェクト: MarkusVolk/martii-tdt
static void StallExecution(ULONG ulDelay)
{
  task_delay(ulDelay * time_ticks_per_sec()/1000000);
}
コード例 #5
0
ファイル: host.c プロジェクト: henrryhe/beijing-7101
int main(void)
{
	MME_TransformerInitParams_t initParams[2] = {{ sizeof(MME_TransformerInitParams_t) },
                                                     { sizeof(MME_TransformerInitParams_t) }};
	MixerParamsInit_t mixerInit[2];
	MME_TransformerHandle_t remoteHdl[2];

	MME_ERROR err;

	/* initialize the underlying EMBX transport */
	setupEMBXAndOS();

	/* initialize the MME API */
	err = MME_Init();
	if (MME_SUCCESS != err) {
		printf("ERROR: cannot initialize the MME API (%d)\n", err);
	}

	/* other misc. initialization */
	OS_SIGNAL_INIT(&callbackSignal);

	/* pre-construct the data structure to be passed at transformer 
	 * initialization time
	 */
	initParams[0].Priority = MME_PRIORITY_NORMAL;
	initParams[0].Callback = mixerCallback;
	initParams[0].TransformerInitParamsSize = sizeof(MixerParamsInit_t);
	initParams[0].TransformerInitParams_p = &mixerInit[0];
	MME_INDEXED_PARAM(mixerInit[0], MixerParamsInit_volume, 0) = 1.0;
	MME_INDEXED_PARAM(mixerInit[0], MixerParamsInit_volume, 1) = 4.0/3.0;

	initParams[1].Priority = MME_PRIORITY_NORMAL;
	initParams[1].Callback = mixerCallback;
	initParams[1].TransformerInitParamsSize = sizeof(MixerParamsInit_t);
	initParams[1].TransformerInitParams_p = &mixerInit[1];
	MME_INDEXED_PARAM(mixerInit[1], MixerParamsInit_volume, 0) = 0.4;
	MME_INDEXED_PARAM(mixerInit[1], MixerParamsInit_volume, 1) = 0.7;
	
#if !(defined(__LINUX__) && !defined(__KERNEL__))
	/* register the transport for the remote transformer (at this point we will
	 * block until the remote processor initializes itself)
	 */
	printf("Trying to register transport shm\n");

	err = MME_RegisterTransport("shm");
	if (MME_SUCCESS != err) {
		printf("ERROR: cannot register transport to external processors (%d)\n", err);
	}
#endif

	/* repeatly attempt to connect to the remote transformer until it is registered or
	 * a serious error occurs.
	 */
	do {
		task_delay(time_ticks_per_sec() * 2);
		printf("Trying to init mme.8bit_mix_1\n");
		err = MME_InitTransformer("mme.8bit_mixer_1", &initParams[0], &remoteHdl[0]);
	} while (err == MME_UNKNOWN_TRANSFORMER);

	if (MME_SUCCESS != err) {
		printf("ERROR: cannot instantiate mme.8bit_mixer_1 (%d)\n", err);
	}

	do {
		task_delay(time_ticks_per_sec() * 2);
		printf("Trying to init mme.8bit_mix_2\n");
		err = MME_InitTransformer("mme.8bit_mixer_2", &initParams[1], &remoteHdl[1]);
	} while (err == MME_UNKNOWN_TRANSFORMER);

	if (MME_SUCCESS != err) {
		printf("ERROR: cannot instantiate mme.8bit_mixer_2 (%d)\n", err);
	}

	/* display the waveforms that will be mixed */
	printf("ORIGINAL WAVEFORMS\n"
	       "------------------\n\n");
	printTwinSignal(sample1, sample2, sizeof(sample1));

	printf("\nSIMPLE MIXING USING TWO REMOTELY REGISTERED TRANSFORMERS\n"
	         "--------------------------------------------------------\n\n");

	/* perform the mix as above using remotely registered transformer. the 
	 * results should be identical assuming both processors implement IEEE single
	 * precision floating point maths.
	 */
	err = simpleMix(remoteHdl);
	if (MME_SUCCESS != err) {
		printf("ERROR: cannot perform mixer transformer on mme.8bit_mixer (%d)\n", err);
	}

	/* clean up prior to shutting down */
	err = MME_TermTransformer(remoteHdl[0]);
	if (MME_SUCCESS != err) {
		printf("ERROR: cannot terminate mme.8bit_mixer (%d)\n", err);
	}

	err = MME_TermTransformer(remoteHdl[1]);
	if (MME_SUCCESS != err) {
		printf("ERROR: cannot terminate mme.8bit_mixer (%d)\n", err);
	}

	err = MME_Term();
	if (MME_SUCCESS != err) {
		printf("ERROR: cannot terminate the MME API (%d)\n", err);
	}

	(void) EMBX_Deinit();

	return 0;
}