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; }
void pipe_test(void) { uint32_t putsize; int getsize; uint32_t puttime[3]; int putcount; int pipe; kpriority_t TaskPrio; int prio; GetInfo getinfo; task_sem_reset(SEM0); task_sem_give(STARTRCV); /* action: */ /* non-buffered operation, matching (ALL_N) */ PRINT_STRING(dashline, output_file); PRINT_STRING("| " "P I P E M E A S U R E M E N T S" " |\n", output_file); PRINT_STRING(dashline, output_file); PRINT_STRING("| Send data into a pipe towards a " "receiving high priority task and wait |\n", output_file); PRINT_STRING(dashline, output_file); PRINT_STRING("| " "matching sizes (_ALL_N)" " |\n", output_file); PRINT_STRING(dashline, output_file); PRINT_ALL_TO_N_HEADER_UNIT(); PRINT_STRING(dashline, output_file); PRINT_STRING("| put | get | no buf | small buf| big buf |" " no buf | small buf| big buf |\n", output_file); PRINT_STRING(dashline, output_file); for (putsize = 8; putsize <= MESSAGE_SIZE_PIPE; putsize <<= 1) { for (pipe = 0; pipe < 3; pipe++) { putcount = NR_OF_PIPE_RUNS; pipeput(TestPipes[pipe], _ALL_N, putsize, putcount, &puttime[pipe]); task_fifo_get_wait(CH_COMM, &getinfo); /* waiting for ack */ } PRINT_ALL_TO_N(); } PRINT_STRING(dashline, output_file); /* Test with two different sender priorities */ for (prio = 0; prio < 2; prio++) { /* non-buffered operation, non-matching (1_TO_N) */ if (prio == 0) { PRINT_STRING("| " "non-matching sizes (1_TO_N) to higher priority" " |\n", output_file); TaskPrio = task_priority_get(); } if (prio == 1) { PRINT_STRING("| " "non-matching sizes (1_TO_N) to lower priority" " |\n", output_file); task_priority_set(task_id_get(), TaskPrio - 2); } PRINT_STRING(dashline, output_file); PRINT_1_TO_N_HEADER(); PRINT_STRING("| put | get | no buf | small buf| big buf | " "no buf | small buf| big buf |\n", output_file); PRINT_STRING(dashline, output_file); for (putsize = 8; putsize <= (MESSAGE_SIZE_PIPE); putsize <<= 1) { putcount = MESSAGE_SIZE_PIPE / putsize; for (pipe = 0; pipe < 3; pipe++) { pipeput(TestPipes[pipe], _1_TO_N, putsize, putcount, &puttime[pipe]); /* size*count == MESSAGE_SIZE_PIPE */ task_fifo_get_wait(CH_COMM, &getinfo); /* waiting for ack */ getsize = getinfo.size; } PRINT_1_TO_N(); } PRINT_STRING(dashline, output_file); task_priority_set(task_id_get(), TaskPrio); } }
/* Run the manager. This call only returns when everything is shut down. */ MME_ERROR MME_Run(void) { MME_ERROR result; EMBX_ERROR err; EMBX_RECEIVE_EVENT event; MME_UINT messageID; int running = 1; int oldTaskPriority; if (manager == NULL) { return MME_DRIVER_NOT_INITIALIZED; } /* Note that the manager should be running at high priority (e.g. 200 of 255). */ oldTaskPriority = task_priority_set(NULL, MANAGER_TASK_PRIORITY); while (running && manager->managerRunning) { /* Wait for a host request. */ MME_Info(MME_INFO_MANAGER, ("Waiting for host request... on port 0x%08x\n", manager->adminPort)); err = EMBX_ReceiveBlock(manager->adminPort, &event); if (err == EMBX_SUCCESS) { if (event.type == EMBX_REC_MESSAGE && event.size >= sizeof(MME_UINT) && event.data != NULL) { /* The message ID decides. */ messageID = *((MME_UINT*) event.data); switch (messageID) { case TMESSID_INIT: /* It is a TransformerInitMessage. */ receiveInitMessage((TransformerInitMessage *) event.data); break; case TMESSID_TERMINATE: /* It is a TransformerTerminateMessage to terminate a single transformer. */ receiveTerminateMessage((TransformerTerminateMessage *) event.data); break; case TMESSID_CAPABILITY: receiveCapabilityMessage((TransformerCapabilityMessage *) event.data); break; case TMESSID_TERMINATE_MME: { /* It is a TransformerTerminateMessage to terminate all of the MME! */ TransformerTerminateMMEMessage *msg = (TransformerTerminateMMEMessage*) event.data; result = MME_Term(); msg->result = result; running = 0; /* ??? Problem: We need to tell someone if termination worked, but there's no port to talk to, and EMBX has been shut down as well. */ break; } case TMESSID_TRANSFORMER_REGISTERED: receiveTransformerRegisteredMessage((TransformerRegisteredMessage*) event.data); break; default: MME_Info(MME_INFO_MANAGER, ("Received unknown message ID %d\n", messageID)); break; } } else { /* Strange message arrived. */ MME_Info(MME_INFO_MANAGER, ("Strange message: type %d, size %d, data %0x\n", event.type, event.size, event.data)); } } else { if (err == EMBX_INVALID_PORT || err == EMBX_PORT_INVALIDATED) { MME_Info(MME_INFO_MANAGER, ("RunMMEManager:EMBX_ReceiveBlock() returned due to invalid(ated) port, error=%d\n", err)); result = MME_Term(); if (result != MME_SUCCESS) { MME_Info(MME_INFO_MANAGER, ("TerminateMMEManager() failed, result=%d\n", result)); } running = 0; } else { MME_Info(MME_INFO_MANAGER, ("RunMMEManager: EMBX_ReceiveBlock() failed, error=%d\n", err)); } } } task_priority_set(NULL, oldTaskPriority); return MME_SUCCESS; }