예제 #1
0
파일: Main.c 프로젝트: bimopraks/tinythread
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);
}
예제 #2
0
파일: tth.c 프로젝트: alexcrichton/fargo
char* tth(const char* filename, char **tthl, size_t *tthl_len)
{
    char *tth = NULL;
    size_t numbytes;
    unsigned char root[24];
    unsigned char *cur;
    TT_CONTEXT tt;
    unsigned char buf[1 + 256 * BLOCKSIZE];
    struct stat sb;
    unsigned level;
    size_t leaf_blocksize;

    int fd = open(filename, O_RDONLY);
    if ((fd == -1) || ( fstat(fd, &sb) == -1)) {
        return NULL;
    }

    level = calc_block_level(sb.st_size, max_block_count);
    leaf_blocksize = 1 << (level+10);

    *tthl_len = 0;
    *tthl = NULL;

    tt_init(&tt, *tthl, level);
    tt.leaf = buf;
    buf[0] = '\0';

    while ( (numbytes = read(fd, &buf[1], sizeof(buf) - 1) ) > 0) {
        tt.index = BLOCKSIZE;
        for (cur = &buf[1]; cur + BLOCKSIZE <= &buf[numbytes + 1]; cur += BLOCKSIZE) {
            tt.leaf = cur - 1;
            tt.leaf[0] = '\0';
            tt_block(&tt);
        }
        tt.index = numbytes - (cur - &buf[1]);
        tt.leaf = cur - 1;
        tt.leaf[0] = '\0';
    }

    close(fd);

    tt_digest(&tt, root);

    tth = base32_encode(root, sizeof(root));

    return tth;
}
예제 #3
0
파일: Main.c 프로젝트: bimopraks/tinythread
int main()
{
	int i;
	THREAD_ARG_T	arg[THREAD_NUM];
	MY_SEM_T		sem;

	/* 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);

	/* Set semaphore value to 3, so that always 3 threads' LED is blinking */
	my_sem_init (&sem, 3);

	/* 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[3].gpio_group = LED_GPIO_GREEN_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;
	arg[3].gpio_bit = LED_GPIO_GREEN_BIT;

	for (i = 0; i < THREAD_NUM; ++i)
	{
		arg[i].sem = &sem;
		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 */
									 );	
	}
	

	tt_thread_exit ();
	return 0;
}
예제 #4
0
파일: Main.c 프로젝트: bimopraks/tinythread
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 */
	_GPIO_SET_PIN_MODE(LED0_GPIO_GRP, LED0_GPIO_BIT, GPIO_PMD_OUTPUT);
	_GPIO_SET_PIN_MODE(LED1_GPIO_GRP, LED1_GPIO_BIT, GPIO_PMD_OUTPUT);
	_GPIO_SET_PIN_MODE(LED2_GPIO_GRP, LED2_GPIO_BIT, GPIO_PMD_OUTPUT);
	_GPIO_SET_PIN_MODE(LED3_GPIO_GRP, LED3_GPIO_BIT, GPIO_PMD_OUTPUT);

	/* Test threads lock by value[]
	   the element in value should be the same,
	   if not, there must be an error */
	tt_rmutex_init(&mutex);
	for(i = 0; i < THREAD_NUM; ++i)
		value[i] = 0;

	arg[0].gpio_group = LED0_GPIO_GRP;
	arg[1].gpio_group = LED1_GPIO_GRP;
	arg[2].gpio_group = LED2_GPIO_GRP;
	arg[0].gpio_bit = LED0_GPIO_BIT;
	arg[1].gpio_bit = LED1_GPIO_BIT;
	arg[2].gpio_bit = LED2_GPIO_BIT;

	for(i = THREAD_NUM; i-- != 0; )
	{
		arg[i].value = value;
		arg[i].mutex = &mutex;
		thread[i] = tt_thread_create("th", 
			0,
			stack[i], sizeof(stack[i]),
			thread_entry, (void *)&arg[i]);
	}
	
	tt_sleep(1024);
	
	while(1);
	return 0;
}
예제 #5
0
static G_GNUC_COLD void
tt_check_digest(const char * const expected, const void *data, size_t size)
{
	char digest[TTH_BASE32_SIZE + 1];
	struct tth hash;
	TTH_CONTEXT ctx;

	tt_init(&ctx, size);
	tt_update(&ctx, data, size);
	tt_digest(&ctx, &hash);

	ZERO(&digest);
	base32_encode(digest, sizeof digest, hash.data, sizeof hash.data);
	digest[G_N_ELEMENTS(digest) - 1] = '\0';

	if (0 != strcmp(expected, digest)) {
		g_warning("tt_check_digest:\nExpected: \"%s\"\nGot:      \"%s\"",
			expected, digest);
		g_error("Tigertree implementation is defective.");
	}
}
예제 #6
0
파일: Main.c 프로젝트: xhawk18/TinyThread
int main()
{
	/* The clock frequency of systick may be changed by user's application.
	   Please change the value of SYSTICK_CLOCK according to real situration */
	uint32_t SysGet_HCLKFreq(void);
#define TT_SYSTICK_CLOCK		SysGet_HCLKFreq()
	/* Initialize TinyThread */
	tt_init(TT_SYSTICK_CLOCK);

	/* Initialize flag and event queue for timer interrupt */
	g_is_irq_detected = 0;
	tt_wq_init(&g_wait_queue);
	
	/* Initialize timer */
	init_timer();

	
	while(1)
	{
		int rt;
		/* Check flag and then wait interrupt */ 
		tt_disable_irq();

		while(!g_is_irq_detected)
		{
			/* tt_wq_wait_event and tt_wq_wait_event_timeout will enable irq internally */
			rt = tt_wq_wait_event_timeout(&g_wait_queue, 300);
			if(rt != 0) break;
		}
		g_is_irq_detected = 0;

		tt_enable_irq();
		
		if(rt == 0)
			printf("Interrupt detected!\n");
		else
			printf("Waiting timeout detected!\n");
	}
}
예제 #7
0
int sysInit (void)
{
	/* <0> Save threads debug entry. */
#ifndef ECOS
	{
		extern UCHAR ASM_THREADS_DUMP_FUN[];	//A buffer in wb_init.s
		UINT32 uThreadDebugFun_Addr = (UINT32) &tt_dump_threads;
		memcpy (ASM_THREADS_DUMP_FUN, &uThreadDebugFun_Addr, sizeof (UINT32));
	}
#endif
	
	/* <1> Enable flash. */
	sysFlushCache (I_D_CACHE);
	sysDisableCache ();
	sysEnableCache (CACHE_WRITE_BACK);

	/* <2> Disable almost all of the engines for safety. */
	outpw (REG_CLKCON, inpw (REG_CLKCON) | CPUCLK_EN | APBCLK_EN | HCLK2_EN);
	outpw (REG_CLKSEL, SYSTEM_CLK_FROM_XTAL);
	outpw (REG_APLLCON, PLL_OUT_OFF);
	outpw (REG_UPLLCON, PLL_OUT_OFF);
	
	/* <3> Initialize UART. */
	/*
	{
		WB_UART_T uart;
		
		TURN_ON_UART_CLOCK;
		uart.uiFreq = OPT_XIN_CLOCK;
		uart.uiBaudrate = 57600;
		uart.uiDataBits = WB_DATA_BITS_8;
		uart.uiStopBits = WB_STOP_BITS_1;
		uart.uiParity = WB_PARITY_NONE;
		uart.uiRxTriggerLevel = LEVEL_1_BYTE;
		sysInitializeUART(&uart);
		printf ("UART ok\n");
	}
	*/

	/* <4> Set PLL. */
	// SDRAM MCLK automatically on/off
	outpw(REG_SDICON, inpw(REG_SDICON) & 0xBFFFFFFF);
	// Force MPEG4 transfer length as 8 bytes
	outpw(REG_BBLENG1, (inpw(REG_BBLENG1) & 0xFFFFFFF8) | 0x2);
	
	// CLKDIV0
	// Bit 1~0 : APB = HCLK1/?  -------------------------+
	// Bit15~8 : VPOST = PLL/?  -----------------------+ |
	// Bit19~16: USB = PLL/?    ---------------------+ | |
	// Bit23~20: Audio = PLL/?  --------------------+| | |
	// Bit27~24: Sensor = PLL/? -------------------+|| | |
	// Bit31~28: System = PLL/? ------------------+||| | |
	                                         //   |||| | | 
	                                         //   ||||++ |
//	outpw(REG_CLKDIV0, inpw(REG_CLKDIV0)&0x0fc|0x01322302);	//(ok for 108)
#ifndef ECOS
	outpw(REG_CLKDIV0, inpw(REG_CLKDIV0)&0x0fc|0x25362401);	//(ok for 336(112))
#else
	//outpw(REG_CLKDIV0, inpw(REG_CLKDIV0)&0xf00000fc|0x05362401);	//can't modify system clock
	outpw(REG_CLKDIV0, inpw(REG_CLKDIV0)&0x0fc|0x25362401);	//(ok for 336(112))
#endif
//	outpw(REG_CLKDIV0, inpw(REG_CLKDIV0)&0x0fc|0x03331802);	//(ok for 144)

	//Adjust SDRAM
	printf("setting apll to 0x%x, upll to 0x%x\n", pllEvalPLLCON (OPT_XIN_CLOCK, OPT_APLL_OUT_CLOCK), pllEvalPLLCON (OPT_XIN_CLOCK, OPT_UPLL_OUT_CLOCK));
	outpw(REG_APLLCON, pllEvalPLLCON (OPT_XIN_CLOCK, OPT_APLL_OUT_CLOCK));
	outpw(REG_UPLLCON, pllEvalPLLCON (OPT_XIN_CLOCK, OPT_UPLL_OUT_CLOCK));

	                 //  +-------- Bit31~28 : HCLK (from system)
	                 //  |+------- Bit27~24 : CPU (from HCLK)
	                 //  ||+------ Bit23~20 : HCLK1 (from HCLK, must less or equal to HCLK and CPU)
	                 //  |||+----- Bit19~16 : HCLK2 (from HCLK)
	                 //  ||||+---- Bit15~12 : MPEG4, JPEG (from HCLK2)
	                 //  |||||+--- Bit11~8  : 2D, VPE (from HCLK2)
	                 //  ||||||+-- Bit 7~6  : DSP (from HCLK2)
	                 //  |||||||+- Bit 5~0  : Reserved.
//	outpw(REG_CLKDIV1, 0x00105045);	//(ok for 108)
	outpw(REG_CLKDIV1, 0x00105045);	//(ok for 112)
//	outpw(REG_CLKDIV1, 0x00110005);
#ifndef ECOS	//don't need to modify system clock source
	outpw(REG_CLKSEL, SYSTEM_CLK_FROM_UPLL);
#endif
printf("before system clock\n");
	outpw(REG_CLKSEL, SYSTEM_CLK_FROM_UPLL);
printf("system clock ok\n");

	/* <5> Initialize TinyThread to support multi-thread. */
#ifndef ECOS
	tt_init (OPT_XIN_CLOCK, OPT_UPLL_OUT_CLOCK);
#else
	//tt_init (OPT_XIN_CLOCK, OPT_UPLL_OUT_CLOCK);
	printf("reg_tcr0=0x%x reg_ticr0=0x%x\n", inpw(REG_TCR0), inpw(REG_TICR0));
	printf("reg_tcr1=0x%x reg_ticr1=0x%x\n", inpw(REG_TCR1), inpw(REG_TICR1));
#endif

	/* <6> Set other engine clocks. */

	/* Set vpost clock:
	Why I can NOT call it after HIC is transferred. */
	outpw (REG_CLKSEL, inpw (REG_CLKSEL) | VIDEO_CLK_FROM_UPLL);
	tt_msleep (30);
	TURN_ON_VPOST_CLOCK;
	tt_msleep (30);

	/* Set audio clock. */
	outpw (REG_CLKSEL, inpw (REG_CLKSEL) | AUDIO_CLK_FROM_APLL);
	tt_msleep (30);
	TURN_ON_AUDIO_CLOCK;
	tt_msleep (30);
	
	/* Set sensor clock. */
	outpw (REG_CLKSEL, inpw (REG_CLKSEL) | SENSOR_CLK_FROM_UPLL);
	//tt_msleep (30);
	//TURN_ON_DSP_CLOCK;
	//tt_msleep (30);
	//TURN_ON_CAP_CLOCK;

	/* Set MP4 clock. */
	//TURN_ON_MPEG4_CLOCK;
	//tt_msleep (30);
	
	/* Set VPE and 2D clock. */
	TURN_ON_VPE_CLOCK;
	tt_msleep (30);
	TURN_ON_GFX_CLOCK;
	tt_msleep (30);
	
	/* Set USB clock */
#if 0	
	writew(REG_SYS_CFG, readw(REG_SYS_CFG)&0xffffffbf);
	outpw (REG_CLKSEL, inpw (REG_CLKSEL) | USB_CLK_FROM_UPLL);
	tt_msleep (30);
	TURN_ON_USB_CLOCK;
	outpw(REG_GPIO_PE,inpw(REG_GPIO_PE)|0x00000200);//GPIO9,disable pull-up or pull-down  
#endif
	
	return 0;
}
예제 #8
0
파일: cache.c 프로젝트: Fierralin/gnugo
/* Initialize the cache for read results, using at most the given
 * number of bytes of memory. If the memory isn't sufficient to
 * allocate a single node or if the allocation fails, the caching is
 * disabled.
 */
void
reading_cache_init(int bytes)
{
  tt_init(&ttable, bytes);
}
예제 #9
0
static void
verify_tth_reset(filesize_t size)
{
	if G_LIKELY(verify_tth.context != NULL)
		tt_init(verify_tth.context, size);
}
예제 #10
0
static void
verify_tth_reset(filesize_t size)
{
	tt_init(verify_tth.context, size);
}