void vjpegInit(void) { #ifndef ECOS tt_rmutex_init(&g_vpJPEG.mtLock); tt_rmutex_init(&g_vpJPEG.mtLockEncoder); tt_rmutex_init(&g_vpJPEG.mtLockDecoder); tt_sem_init(&g_vpJPEG.semEncoder, 1); tt_sem_init(&g_vpJPEG.semDecoder, 1); tt_sem_down(&g_vpJPEG.semEncoder); tt_sem_down(&g_vpJPEG.semDecoder); #else cyg_mutex_init(&g_vpJPEG.mtLock); cyg_mutex_init(&g_vpJPEG.mtLockEncoder); cyg_mutex_init(&g_vpJPEG.mtLockDecoder); cyg_semaphore_init(&g_vpJPEG.semEncoder, 1); cyg_semaphore_init(&g_vpJPEG.semDecoder, 1); cyg_semaphore_wait(&g_vpJPEG.semEncoder); cyg_semaphore_wait(&g_vpJPEG.semDecoder); #endif g_vpJPEG.nRefCount = 0; g_vpJPEG.nRefCount_Encoder = 0; g_vpJPEG.nRefCount_Decoder = 0; g_vpJPEG.pJPEGEncodeBuffer = NULL; listInit (&g_vpJPEG.listEncodedJPEG); g_vpJPEG.nJPEGQua = 2; g_vpJPEG.bOnTheFly = TRUE; g_vpJPEG.nOnTheFlyCount = 0; #ifndef ECOS sysInstallISR(IRQ_LEVEL_1, IRQ_JPEG, (void*)jpegIntHandler); #else cyg_interrupt_disable(); cyg_interrupt_create(IRQ_JPEG, IRQ_LEVEL_1, NULL, &jpegIntHandler, &jpegIntHandler_DSR, &(g_vpJPEG.cygIntrHandle), &(g_vpJPEG.cygIntrBuffer)); cyg_interrupt_attach(g_vpJPEG.cygIntrHandle); cyg_interrupt_unmask(IRQ_JPEG); cyg_interrupt_enable(); #endif jpegSetIRQHandler(C_JPEG_CALLBACK_ENCODE_COMPLETE_INTERRUPT, vjpegEncoderCom_Callback); jpegSetIRQHandler(C_JPEG_CALLBACK_DECODE_COMPLETE_INTERRUPT, vjpegDecoderCom_Callback); jpegSetIRQHandler(C_JPEG_CALLBACK_DECODE_ERROR_INTERRUPT, vjpegDecoderErr_Callback); if(g_vpJPEG.bOnTheFly == TRUE) { jpegSetIRQHandler(C_JPEG_CALLBACK_ENCODE_SWONTHEFLY_WAIT_INTERRUPT, vjpegOnTheFlyCom_Callback); } bJPEGInit = TRUE; }
void vjpegWaitDecoderCom(void) { #ifndef ECOS tt_sem_down(&g_vpJPEG.semDecoder); #else cyg_semaphore_wait(&g_vpJPEG.semDecoder); #endif }
/* Available in: thread. */ void tt_pc_consume (TT_PC_T *pc, void (*consume) (void *arg), void *arg) { tt_sem_down (&pc->consumer); if (consume != NULL) (*consume) (arg); tt_sem_up (&pc->producer); }
int main() { int i; /* The clock frequency of systick may be changed by user's application. Please change the value of SYSTICK_CLOCK according to real situration */ #define TT_SYSTICK_CLOCK 22118400 /* Initialize TinyThread */ tt_init(TT_SYSTICK_CLOCK); /* Open LED GPIO for testing */ DrvGPIO_Open(LED_GPIO_GREEN_GRP, LED_GPIO_GREEN_BIT, E_IO_OUTPUT); DrvGPIO_Open(LED_GPIO_RED_GRP, LED_GPIO_RED_BIT, E_IO_OUTPUT); DrvGPIO_Open(LED_GPIO_ISP_GRP, LED_GPIO_ISP_BIT, E_IO_OUTPUT); DrvGPIO_Open(LED_GPIO_ICE_GRP, LED_GPIO_ICE_BIT, E_IO_OUTPUT); /* Create and run thread */ arg[0].gpio_group = LED_GPIO_RED_GRP; arg[1].gpio_group = LED_GPIO_ISP_GRP; arg[2].gpio_group = LED_GPIO_ICE_GRP; arg[0].gpio_bit = LED_GPIO_RED_BIT; arg[1].gpio_bit = LED_GPIO_ISP_BIT; arg[2].gpio_bit = LED_GPIO_ICE_BIT; for (i = 0; i < THREAD_NUM; ++i) { tt_sem_init (&join_sem[i], 0); arg[i].join_sem = &join_sem[i]; thread[i] = tt_thread_create("thread", /* thread Name */ 0, /* thread priority */ stack[i], /* stack pointer */ sizeof(stack[i]), /* stack size */ thread_entry, /* thread entry function */ (void *)&arg[i] /* argument for thread entry function */ ); } /* Join threads. * TinyThread does not support build-in tt_thread_join() * since it is easy to emulate by a semaphore. */ for (i = 0; i < THREAD_NUM; ++i) tt_sem_down (&join_sem[i]); /* Set LED to indicate that run to here */ DrvGPIO_SetBit(LED_GPIO_RED_GRP, LED_GPIO_RED_BIT); /* OFF */ DrvGPIO_SetBit(LED_GPIO_ISP_GRP, LED_GPIO_ISP_BIT); /* OFF */ DrvGPIO_SetBit(LED_GPIO_ISP_GRP, LED_GPIO_ISP_BIT); /* OFF */ DrvGPIO_ClrBit(LED_GPIO_GREEN_GRP, LED_GPIO_GREEN_BIT); /* ON */ while(1); }
void thread_entry(void *arg) { THREAD_ARG_T *the_arg = (THREAD_ARG_T *)arg; tt_sem_down (the_arg->sem); while (1) { int cur_ticks = tt_get_ticks (); if (cur_ticks % 1024 < 4) { tt_sem_up (the_arg->sem); tt_thread_yield (); tt_sem_down (the_arg->sem); } if(cur_ticks % 64 < 32) the_arg->gpio_group->DOUT &= ~(1 << the_arg->gpio_bit); /* Turn off LED */ else the_arg->gpio_group->DOUT |= (1 << the_arg->gpio_bit); /* Turn on LED */ } }