Exemple #1
0
/**
 * This function will allocate an usb device instance from system.
 *
 * @param parent the hub instance to which the new allocated device attached.
 * @param port the hub port.
 *
 * @return the allocate instance on successful, or RT_NULL on failure.
 */
uinst_t rt_usb_alloc_instance(void)
{
    int i;

    /* lock scheduler */
    rt_enter_critical();

    for(i = 0; i < USB_MAX_DEVICE; i++)
    {
        /* to find an idle instance handle */
        if(uinst[i].status != UINST_STATUS_IDLE) continue;

        /* initialize the usb device instance */
        rt_memset(&uinst[i], 0, sizeof(struct uinstance));

        uinst[i].status = UINST_STATUS_BUSY;
        uinst[i].index = i + 1;
        uinst[i].address = 0;
        uinst[i].max_packet_size = 0x8;

        /* unlock scheduler */
        rt_exit_critical();
        return &uinst[i];
    }

    /* unlock scheduler */
    rt_exit_critical();

    return RT_NULL;
}
Exemple #2
0
/**
 * This function will find the specified module.
 *
 * @param name the name of module finding
 *
 * @return the module
 */
rt_module_t rt_module_find(const char *name)
{
    struct rt_object_information *information;
    struct rt_object *object;
    struct rt_list_node *node;

    extern struct rt_object_information rt_object_container[];

    RT_DEBUG_NOT_IN_INTERRUPT;

    /* enter critical */
    rt_enter_critical();

    /* try to find device object */
    information = &rt_object_container[RT_Object_Class_Module];
    for (node = information->object_list.next;
        node != &(information->object_list);
        node = node->next)
    {
        object = rt_list_entry(node, struct rt_object, list);
        if (rt_strncmp(object->name, name, RT_NAME_MAX) == 0)
        {
            /* leave critical */
            rt_exit_critical();

            return (rt_module_t)object;
        }
    }

    /* leave critical */
    rt_exit_critical();

    /* not found */
    return RT_NULL;
}
Exemple #3
0
int pthread_mutex_lock(pthread_mutex_t *mutex)
{
	int mtype;
	rt_err_t result;

	if (!mutex) return EINVAL;

	if (mutex->attr == -1)
	{
		/* init mutex */
		pthread_mutex_init(mutex, RT_NULL);
	}

	mtype = mutex->attr & MUTEXATTR_TYPE_MASK;
	rt_enter_critical();
	if (mutex->lock.owner == rt_thread_self() && mtype != PTHREAD_MUTEX_RECURSIVE)
	{
		rt_exit_critical();
		return EDEADLK;
	}
	rt_exit_critical();

	result = rt_mutex_take(&(mutex->lock), RT_WAITING_FOREVER);
	if (result == RT_EOK) return 0;

	return EINVAL;
}
int pthread_cond_broadcast(pthread_cond_t *cond)
{
    rt_err_t result;
    if (cond->attr == -1)
        pthread_cond_init(cond, RT_NULL);

    rt_enter_critical();
    while (1)
    {
        /* try to take condition semaphore */
        result = rt_sem_trytake(&(cond->sem));
        if (result == -RT_ETIMEOUT)
        {
            /* it's timeout, release this semaphore */
            rt_sem_release(&(cond->sem));
        }
        else if (result == RT_EOK)
        {
            /* has taken this semaphore, release it */
            rt_sem_release(&(cond->sem));
            break;
        }
        else
        {
            rt_exit_critical();

            return EINVAL;
        }
    }
    rt_exit_critical();

    return 0;
}
static void tcpip_init_done_callback(void *arg)
{
	rt_device_t device;
	struct eth_device *ethif;
	struct ip_addr ipaddr, netmask, gw;
	struct rt_list_node* node;
	struct rt_object* object;
	struct rt_object_information *information;

	extern struct rt_object_information rt_object_container[];

	LWIP_ASSERT("invalid arg.\n",arg);

	IP4_ADDR(&gw, 0,0,0,0);
	IP4_ADDR(&ipaddr, 0,0,0,0);
	IP4_ADDR(&netmask, 0,0,0,0);

	/* enter critical */
	rt_enter_critical();

	/* for each network interfaces */
	information = &rt_object_container[RT_Object_Class_Device];
	for (node = information->object_list.next; node != &(information->object_list); node = node->next)
	{
		object = rt_list_entry(node, struct rt_object, list);
		device = (rt_device_t) object;
		if (device->type == RT_Device_Class_NetIf)
		{
			ethif = (struct eth_device*)device;

			/* leave critical */
			rt_exit_critical();

			netif_add(ethif->netif, &ipaddr, &netmask, &gw,
				ethif, netif_device_init, tcpip_input);

			if (netif_default == NULL)
				netif_set_default(ethif->netif);

#if LWIP_DHCP
			dhcp_start(ethif->netif);
#else
			netif_set_up(ethif->netif);
#endif

#ifdef LWIP_NETIF_LINK_CALLBACK
			netif_set_link_up(ethif->netif);
#endif

			/* enter critical */
			rt_enter_critical();
		}
	}

	/* leave critical */
	rt_exit_critical();

	rt_sem_release((rt_sem_t)arg);
}
Exemple #6
0
void pthread_cleanup_pop(int execute)
{
	_pthread_data_t* ptd;
	_pthread_cleanup_t* cleanup;

	/* get posix thread data */
	ptd = _pthread_get_data(rt_thread_self());
	RT_ASSERT(ptd != RT_NULL);

	if (execute)
	{
		rt_enter_critical();
		cleanup = ptd->cleanup;
		if (cleanup)
			ptd->cleanup = cleanup->next;
		rt_exit_critical();

		if (cleanup)
		{
			cleanup->cleanup_func(cleanup->parameter);

			rt_free(cleanup);
		}
	}
}
Exemple #7
0
static void _sleep_entry(void)
{
	rt_tick_t timeout;
	rt_uint32_t ms;
	rt_uint32_t count;

	system_set_sleepmode(SYSTEM_SLEEPMODE_STANDBY);
	timeout = rt_timer_next_timeout_tick() - rt_tick_get();

	ms = timeout * (1000 / RT_TICK_PER_SECOND);
	rt_kprintf("os tick:%u entry sleep:%u tick\r\n", rt_tick_get(), timeout);

	_rtc_timer_start(ms);

	system_sleep();

	rt_enter_critical();
	count = rtc_count_get_count(&rtc_instance);
	ms = (count + 32) / 32.768;
	rtc_count_disable(&rtc_instance);
	sleep_tick_adjust(ms);
	timeout = rt_tick_get();
	rt_exit_critical();
	rt_kprintf("sleep exited, os tick:%u\n", timeout);
}
void list_tcps()
{
	struct tcp_pcb *pcb;
	extern struct tcp_pcb *tcp_active_pcbs;
	extern union tcp_listen_pcbs_t tcp_listen_pcbs;
	extern struct tcp_pcb *tcp_tw_pcbs;
	extern const char *tcp_state_str[];

	rt_enter_critical();
	printf_syn("Active PCB states:\n");
	for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {
		printf_syn("%s:%d <==> %s:%d snd_nxt %d rcv_nxt %d ",
				   inet_ntoa(*((struct in_addr*)&(pcb->local_ip))), pcb->local_port,
				   inet_ntoa(*((struct in_addr*)&(pcb->remote_ip))), pcb->remote_port,
				   pcb->snd_nxt, pcb->rcv_nxt);
		printf_syn("state: %s\n", tcp_state_str[pcb->state]);
	}

	printf_syn("Listen PCB states:\n");
	for(pcb = (struct tcp_pcb *)tcp_listen_pcbs.pcbs; pcb != NULL; pcb = pcb->next) {
		printf_syn("local port %d ", pcb->local_port);
		printf_syn("state: %s\n", tcp_state_str[pcb->state]);
	}

	printf_syn("TIME-WAIT PCB states:\n");
	for(pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) {
		printf_syn("%s:%d <==> %s:%d snd_nxt %d rcv_nxt %d ",
				   inet_ntoa(*((struct in_addr*)&(pcb->local_ip))), pcb->local_port,
				   inet_ntoa(*((struct in_addr*)&(pcb->remote_ip))), pcb->remote_port,
				   pcb->snd_nxt, pcb->rcv_nxt);
		printf_syn("state: %s\n", tcp_state_str[pcb->state]);
	}
	rt_exit_critical();
}
Exemple #9
0
rt_sighandler_t rt_signal_install(int signo, rt_sighandler_t handler)
{
    rt_sighandler_t old;
    rt_thread_t tid = rt_thread_self();

	if (!sig_valid(signo)) return SIG_ERR;

    rt_enter_critical();
    if (tid->sig_vectors == RT_NULL)
    {
        rt_thread_alloc_sig(tid);
    }

    if (tid->sig_vectors)
    {
        old = tid->sig_vectors[signo];

        if (handler == SIG_IGN) tid->sig_vectors[signo] = RT_NULL;
        else if (handler == SIG_DFL) tid->sig_vectors[signo] = _signal_default_handler;
        else tid->sig_vectors[signo] = handler;
    }
    rt_exit_critical();

    return old;
}
Exemple #10
0
void pthread_exit (void* value)
{
	_pthread_data_t* ptd;
	_pthread_cleanup_t* cleanup;
	extern _pthread_key_data_t _thread_keys[PTHREAD_KEY_MAX];

	ptd = _pthread_get_data(rt_thread_self());

	rt_enter_critical();
	/* disable cancel */
	ptd->cancelstate = PTHREAD_CANCEL_DISABLE;
	/* set return value */
	ptd->return_value = value;
	rt_exit_critical();

	/* invoke pushed cleanup */
	while (ptd->cleanup != RT_NULL)
	{
		cleanup = ptd->cleanup;
		ptd->cleanup = cleanup->next;

		cleanup->cleanup_func(cleanup->parameter);
		/* release this cleanup function */
		rt_free(cleanup);
	}

	/* destruct thread local key */
	if (ptd->tls != RT_NULL)
	{
		void* data;
		rt_uint32_t index;
		
		for (index = 0; index < PTHREAD_KEY_MAX; index ++)
		{
			if (_thread_keys[index].is_used)
			{
				data = ptd->tls[index];
				if (data)
					_thread_keys[index].destructor(data);
			}
		}

		/* release tls area */
		rt_free(ptd->tls);
		ptd->tls = RT_NULL;
	}

	if (ptd->attr.detachstate == PTHREAD_CREATE_JOINABLE)
	{
		/* release the joinable pthread */
		rt_sem_release(ptd->joinable_sem);
	}

	/* detach thread */
	rt_thread_detach(ptd->tid);
	/* reschedule thread */
	rt_schedule();
}
Exemple #11
0
int pthread_once(pthread_once_t * once_control, void (*init_routine) (void))
{
	RT_ASSERT(once_control != RT_NULL);
	RT_ASSERT(init_routine != RT_NULL);

	rt_enter_critical();
	if (!(*once_control))
	{
		/* call routine once */
		*once_control = 1;
		rt_exit_critical();

		init_routine();
	}
	rt_exit_critical();

	return 0;
}
Exemple #12
0
void list_tcps(void)
{
    UInt32 num = 0;
    struct tcp_pcb *pcb;
    char local_ip_str[16];
    char remote_ip_str[16];

    extern struct tcp_pcb *tcp_active_pcbs;
    extern union tcp_listen_pcbs_t tcp_listen_pcbs;
    extern struct tcp_pcb *tcp_tw_pcbs;
    extern const char *tcp_state_str[];

    rt_enter_critical();
    printf("Active PCB states:\n");
    for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next)
    {
        strcpy(local_ip_str, ipaddr_ntoa(&(pcb->local_ip)));
        strcpy(remote_ip_str, ipaddr_ntoa(&(pcb->remote_ip)));

        printf("#%d %s:%d <==> %s:%d snd_nxt 0x%08X rcv_nxt 0x%08X ",
                   num++,
                   local_ip_str,
                   pcb->local_port,
                   remote_ip_str,
                   pcb->remote_port,
                   pcb->snd_nxt,
                   pcb->rcv_nxt);
        printf("state: %s\n", tcp_state_str[pcb->state]);
    }

    printf("Listen PCB states:\n");
    num = 0;
    for(pcb = (struct tcp_pcb *)tcp_listen_pcbs.pcbs; pcb != NULL; pcb = pcb->next)
    {
        printf("#%d local port %d ", num++, pcb->local_port);
        printf("state: %s\n", tcp_state_str[pcb->state]);
    }

    printf("TIME-WAIT PCB states:\n");
    num = 0;
    for(pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next)
    {
        strcpy(local_ip_str, ipaddr_ntoa(&(pcb->local_ip)));
        strcpy(remote_ip_str, ipaddr_ntoa(&(pcb->remote_ip)));

        printf("#%d %s:%d <==> %s:%d snd_nxt 0x%08X rcv_nxt 0x%08X ",
                   num++,
                   local_ip_str,
                   pcb->local_port,
                   remote_ip_str,
                   pcb->remote_port,
                   pcb->snd_nxt,
                   pcb->rcv_nxt);
        printf("state: %s\n", tcp_state_str[pcb->state]);
    }
    rt_exit_critical();
}
Exemple #13
0
int rt_thread_kill(rt_thread_t tid, int sig)
{
    siginfo_t si;
	rt_base_t level;
	struct siginfo_node *si_node;

    RT_ASSERT(tid != RT_NULL);
    if (!sig_valid(sig)) return -RT_EINVAL;

    dbg_log(DBG_INFO, "send signal: %d\n", sig);
    si.si_errno = RT_EINTR;
    si.si_signo = sig;
    si.si_code  = SI_USER;
    si.si_value.sival_ptr = RT_NULL;

	level = rt_hw_interrupt_disable();
    if (tid->sig_pending & sig_mask(sig))
    {
        /* whether already emits this signal? */
        struct rt_slist_node *node;
        struct siginfo_node  *entry;

		node = (struct rt_slist_node *)tid->si_list;
		rt_hw_interrupt_enable(level);

		/* update sig infor */
		rt_enter_critical();
        for (; (node) != RT_NULL; node = node->next)
        {
            entry = rt_slist_entry(node, struct siginfo_node, list);
            if (entry->si.si_signo == sig)
            {
                memcpy(&(entry->si), &si, sizeof(siginfo_t));
				rt_exit_critical();
                return 0;
            }
        }
		rt_exit_critical();

		/* disable interrupt to protect tcb */
		level = rt_hw_interrupt_disable();
    }
	else
	{
Exemple #14
0
/*
void Setting_Write(void)
{
	uint8_t t;
	while (1)
	{
		IIC_WriteSeq(AT24C32_ADDRESS,SETTING_BASE,Setting,SETTING_LENGTH);
		rt_thread_delay_hmsm(0,0,0,100);
		IIC_ReadSeq(AT24C32_ADDRESS,SETTING_BASE+1, &t,1);
		if (t!=Setting[1])
			rt_thread_delay_hmsm(0,0,0,100);
		else
			break;
	}
	return;
}

void Setting_Read(void)
{
	IIC_ReadSeq(AT24C32_ADDRESS,SETTING_BASE,Setting,SETTING_LENGTH);
	return;
}
void pomodoro_set(uint8_t a,uint8_t b,uint8_t c)
{
	Setting[POMODORO_TIME] = a;
	Setting[POMODORO_BREAK_TIME] = b;
	Setting[POMODORO_REST_TIME] = c;
	Setting_Write();
	return;
}
FINSH_FUNCTION_EXPORT_ALIAS(pomodoro_set,pomodoro,Set Interval of Pomodoro Clock(Working,Break,Rest))
*/
void time(void)
{
	rt_enter_critical();
	rt_kprintf("         Date:\t20%x-%x-%x\n         Time:\t%x:%x:%x\n  Temperature:\t%d C\n",\
	                      IIC_Read(DS3231_ADDRESS, DS3231_YEAR),IIC_Read(DS3231_ADDRESS,DS3231_MONTH)&0x7f,IIC_Read(DS3231_ADDRESS,DS3231_DAY),\
	                      IIC_Read(DS3231_ADDRESS, DS3231_HOUR),IIC_Read(DS3231_ADDRESS,DS3231_MINUTE),IIC_Read(DS3231_ADDRESS,DS3231_SECOND),\
	                      IIC_Read(DS3231_ADDRESS, DS3231_TEMP_MSB));
	rt_exit_critical();
	return;
}
Exemple #15
0
int pthread_key_delete(pthread_key_t key)
{
	if (key >= PTHREAD_KEY_MAX) return EINVAL;

	rt_enter_critical();
	_thread_keys[key].is_used = 0;
	_thread_keys[key].destructor = 0;
	rt_exit_critical();

	return 0;
}
Exemple #16
0
int dfs_device_fs_open(struct dfs_fd *file)
{
    rt_err_t result;
    rt_device_t device;

    if (file->flags & DFS_O_CREAT)
        return -DFS_STATUS_EINVAL;

    /* open root directory */
    if ((file->path[0] == '/') && (file->path[1] == '\0') &&
        (file->flags & DFS_O_DIRECTORY))
    {
        struct rt_object *object;
        struct rt_list_node *node;
        struct rt_object_information *information;
        struct device_dirent *root_dirent;
        rt_uint32_t count = 0;
        
        extern struct rt_object_information rt_object_container[];

        /* lock scheduler */
        rt_enter_critical();

        /* traverse device object */
        information = &rt_object_container[RT_Object_Class_Device];
        for (node = information->object_list.next; node != &(information->object_list); node = node->next)
        {
            count ++;
        }

        root_dirent = (struct device_dirent *)rt_malloc(sizeof(struct device_dirent) + 
            count * sizeof(rt_device_t));
        if (root_dirent != RT_NULL)
        {
            root_dirent->devices = (rt_device_t *)(root_dirent + 1);
            root_dirent->read_index = 0;
            root_dirent->device_count = count;
            count = 0;
            /* get all device node */
            for (node = information->object_list.next; node != &(information->object_list); node = node->next)
            {
                object = rt_list_entry(node, struct rt_object, list);
                root_dirent->devices[count] = (rt_device_t)object;
                count ++;
            }
        }
        rt_exit_critical();

        /* set data */
        file->data = root_dirent;
        
        return DFS_STATUS_OK;
    }
Exemple #17
0
int pthread_key_create(pthread_key_t *key, void (*destructor)(void*))
{
	rt_uint32_t index;

	rt_enter_critical();
	for (index = 0; index < PTHREAD_KEY_MAX; index ++)
	{
		if (_thread_keys[index].is_used == 0)
		{
			_thread_keys[index].is_used = 1;
			_thread_keys[index].destructor = destructor;

			*key = index;

			rt_exit_critical();
			return 0;
		}
	}

	rt_exit_critical();
	return EAGAIN;
}
Exemple #18
0
void list_if(void)
{
    rt_ubase_t index;
    struct netif * netif;

    rt_enter_critical();

    netif = netif_list;

    while( netif != NULL )
    {
        printf("network interface: %c%c%s\n",
                   netif->name[0],
                   netif->name[1],
                   (netif == netif_default)?" (Default)":"");
        printf("MTU: %d\n", netif->mtu);
        printf("MAC: ");
        for (index = 0; index < netif->hwaddr_len; index ++)
            printf("%02x ", netif->hwaddr[index]);
        printf("\nFLAGS:");
        if (netif->flags & NETIF_FLAG_UP) printf(" UP");
        else printf(" DOWN");
        if (netif->flags & NETIF_FLAG_LINK_UP) printf(" LINK_UP");
        else printf(" LINK_DOWN");
        if (netif->flags & NETIF_FLAG_DHCP) printf(" DHCP");
        if (netif->flags & NETIF_FLAG_POINTTOPOINT) printf(" PPP");
        if (netif->flags & NETIF_FLAG_ETHARP) printf(" ETHARP");
        if (netif->flags & NETIF_FLAG_IGMP) printf(" IGMP");
        printf("\n");
        printf("ip address: %s\n", ipaddr_ntoa(&(netif->ip_addr)));
        printf("gw address: %s\n", ipaddr_ntoa(&(netif->gw)));
        printf("net mask  : %s\n", ipaddr_ntoa(&(netif->netmask)));
        printf("\r\n");

        netif = netif->next;
    }

#if LWIP_DNS
    {
        struct ip_addr ip_addr;

        for(index=0; index<DNS_MAX_SERVERS; index++)
        {
            ip_addr = dns_getserver(index);
            printf("dns server #%d: %s\n", index, ipaddr_ntoa(&(ip_addr)));
        }
    }
#endif /**< #if LWIP_DNS */

    rt_exit_critical();
}
Exemple #19
0
/**
 * This function will find specified name object from object
 * container.
 *
 * @param name the specified name of object.
 * @param type the type of object
 *
 * @return the found object or RT_NULL if there is no this object
 * in object container.
 *
 * @note this function shall not be invoked in interrupt status.
 */
rt_object_t rt_object_find(const char* name, rt_uint8_t type)
{
    struct rt_object* object;
    struct rt_list_node* node;
    struct rt_object_information *information;
    extern volatile rt_uint8_t rt_interrupt_nest;

    /* parameter check */
    if ((name == RT_NULL) ||
            (type > RT_Object_Class_Unknown))
        return RT_NULL;

    /* which is invoke in interrupt status */
    if (rt_interrupt_nest != 0)
        RT_ASSERT(0);

    /* enter critical */
    rt_enter_critical();

    /* try to find object */
    information = &rt_object_container[type];
    for (node = information->object_list.next; node != &(information->object_list); node = node->next)
    {
        object = rt_list_entry(node, struct rt_object, list);
        if (rt_strncmp(object->name, name, RT_NAME_MAX) == 0)
        {
            /* leave critical */
            rt_exit_critical();

            return (rt_object_t)object;
        }
    }

    /* leave critical */
    rt_exit_critical();

    return RT_NULL;
}
static void _tc_cleanup()
{
	/* lock scheduler */
	rt_enter_critical();

	/* delete thread */
	if (tid1 != RT_NULL && tid1->stat != RT_THREAD_CLOSE)
		tc_stat(TC_STAT_FAILED);
	if (tid2 != RT_NULL && tid2->stat != RT_THREAD_CLOSE)
		tc_stat(TC_STAT_FAILED);

	/* unlock scheduler */
	rt_exit_critical();
}
Exemple #21
0
void rt_thread_temp_entry(void* parameter)
{
	int16_t t,h;
	rt_thread_delay_hmsm(0,0,1,0);
	while(1)
	{
		rt_enter_critical();
		DS18B20_StartConvTemp();
		rt_exit_critical();
		while (AM2302_Read(&h,&t)==ERROR)
		{
			t=999;h=000;
			rt_thread_delay_hmsm(0,0,2,500);
		}
		temperature=t;
		humidity=h;
		rt_thread_delay_hmsm(0,0,3,0);
		rt_enter_critical();
		outdoortemperature=(int16_t)(DS18B20_ReadTemp()*10);
		rt_exit_critical();
		rt_thread_delay_hmsm(0,0,10,0);
	}
}
static void _tc_cleanup()
{
    /* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
    rt_enter_critical();

    /* 执行定时器脱离 */
    rt_timer_detach(&timer1);
    rt_timer_detach(&timer2);

    /* 调度器解锁 */
    rt_exit_critical();

    /* 设置TestCase状态 */
    tc_done(TC_STAT_PASSED);
}
static void _tc_cleanup()
{
	/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
	rt_enter_critical();

	/* 删除定时器对象 */
	rt_timer_delete(timer1);
	timer1 = RT_NULL;

	/* 调度器解锁 */
	rt_exit_critical();

	/* 设置TestCase状态 */
	tc_done(TC_STAT_PASSED);
}
static void _tc_cleanup()
{
	/* lock scheduler */
	rt_enter_critical();

	if (thread1.stat != RT_THREAD_CLOSE)
		rt_thread_detach(&thread1);
	if (thread2.stat != RT_THREAD_CLOSE)
		rt_thread_detach(&thread2);

	/* unlock scheduler */
	rt_exit_critical();

	if (t1_count / t2_count != 2)
		tc_stat(TC_STAT_END | TC_STAT_FAILED);
}
Exemple #25
0
void task_temp_init(void)
{
	rt_err_t result;
	rt_enter_critical();
	DS18B20_StartConvTemp();
	rt_exit_critical();
	result = rt_thread_init(&temp_thread,
	                        "temperature",
	                        rt_thread_temp_entry,
	                        RT_NULL,
	                        (rt_uint8_t*)temp_stack,
	                        sizeof(temp_stack),
	                        PRIO_TEMP,
	                        2);
	if (result == RT_EOK) rt_thread_startup(&temp_thread);
}
Exemple #26
0
static void cpu_usage_idle_hook()
{
	rt_tick_t tick;
	rt_uint32_t count;
	volatile rt_uint32_t loop;

	if (total_count == 0)
	{
		loop = 0;

		/* get total count */
		rt_enter_critical();
		tick = rt_tick_get();
		while(rt_tick_get() - tick < CPU_USAGE_CALC_TICK)
		{
			total_count ++;
			while (loop < CPU_USAGE_LOOP) loop ++;
		}
		rt_exit_critical();
	}

	count = 0;
	loop  = 0;
	/* get CPU usage */
	tick = rt_tick_get();
	while (rt_tick_get() - tick < CPU_USAGE_CALC_TICK)
	{
		count ++;
		while (loop < CPU_USAGE_LOOP) loop ++;
	}

	/* calculate major and minor */
	if (count < total_count)
	{
		count = total_count - count;
		cpu_usage_major = (count * 100) / total_count;
		cpu_usage_minor = ((count * 100) % total_count) * 100 / total_count;
	}
	else
	{
		total_count = count;

		/* no CPU usage */
		cpu_usage_major = 0;
		cpu_usage_minor = 0;
	}
}
Exemple #27
0
static void pcap_thread_entry(void* parameter)
{
    pcap_if_t *netif;
    pcap_t *tap;
    char errbuf[PCAP_ERRBUF_SIZE];
    struct pcap_pkthdr *header;
    const u_char *pkt_data;
    int res;

    netif = (pcap_if_t *) parameter;

    /* Open the adapter */
    if ((tap = pcap_open_live(netif->name,
        65536, // portion of the packet to capture. 
        1,     // promiscuous mode (nonzero means promiscuous)
        1,     // read timeout, 0 blocked, -1 no timeout
        errbuf )) == NULL)
    {
        rt_kprintf("Unable to open the adapter. %s is not supported by WinPcap\n", netif->name);
        return;
    }

    NETIF_PCAP(&pcap_netif_device) = tap;

    /* Read the packets */
    while (1)
    {
        struct eth_device* eth;
        struct pbuf *p;

        rt_enter_critical();
        res = pcap_next_ex(tap, &header, &pkt_data);
        rt_exit_critical();

        if (res == 0) continue;

        eth = (struct eth_device*) &pcap_netif_device;

        p = pbuf_alloc(PBUF_LINK, header->len, PBUF_RAM);
        pbuf_take(p, pkt_data, header->len);
        
        /* send to packet mailbox */
        rt_mb_send_wait(packet_mb, (rt_uint32_t)p, RT_WAITING_FOREVER);
        /* notify eth rx thread to receive packet */
        eth_device_ready(eth);
    }
}
Exemple #28
0
static void _tc_cleanup()
{
	/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
	rt_enter_critical();

	/* 删除线程 */
	if (tid1 != RT_NULL && tid1->stat != RT_THREAD_CLOSE)
		rt_thread_delete(tid1);
	if (tid2 != RT_NULL && tid2->stat != RT_THREAD_CLOSE)
		rt_thread_delete(tid2);

	/* 调度器解锁 */
	rt_exit_critical();

	/* 设置TestCase状态 */
	tc_done(TC_STAT_PASSED);
}
static void _tc_cleanup()
{
	/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断 */
	rt_enter_critical();

	/* 执行线程脱离 */
	if (thread1.stat != RT_THREAD_CLOSE)
		rt_thread_detach(&thread1);
	if (thread2.stat != RT_THREAD_CLOSE)
		rt_thread_detach(&thread2);

	/* 调度器解锁 */
	rt_exit_critical();

	/* 设置TestCase状态 */
	tc_done(TC_STAT_PASSED);
}
Exemple #30
0
/* system timer thread entry */
static void rt_thread_timer_entry(void *parameter)
{
	while (1)
	{
		/* take software timer semaphore */
		rt_sem_take(&timer_sem, RT_WAITING_FOREVER);

		/* lock scheduler */
		rt_enter_critical();

		/* check software timer */
		rt_soft_timer_check();

		/* unlock scheduler */
		rt_exit_critical();
	}
}