Exemplo n.º 1
0
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();
  rt_kprintf("Active PCB states:\n");
  for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next)
  {
    rt_kprintf("%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);
    rt_kprintf("state: %s\n", tcp_state_str[pcb->state]);
  }

  rt_kprintf("Listen PCB states:\n");
  for(pcb = (struct tcp_pcb *)tcp_listen_pcbs.pcbs; pcb != NULL; pcb = pcb->next)
  {
    rt_kprintf("local port %d ", pcb->local_port);
    rt_kprintf("state: %s\n", tcp_state_str[pcb->state]);
  }
  
  rt_kprintf("TIME-WAIT PCB states:\n");
  for(pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next)
  {
    rt_kprintf("%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);
    rt_kprintf("state: %s\n", tcp_state_str[pcb->state]);
  }
  rt_exit_critical();
}
Exemplo n.º 2
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;
}
Exemplo n.º 3
0
/* system timer thread entry */
static void rt_thread_timer_entry(void *parameter)
{
    rt_tick_t next_timeout;

    while (1)
    {
        /* get the next timeout tick */
        next_timeout = rt_timer_list_next_timeout(rt_soft_timer_list);
        if (next_timeout == RT_TICK_MAX)
        {
            /* no software timer exist, suspend self. */
            rt_thread_suspend(rt_thread_self());
            rt_schedule();
        }
        else
        {
            rt_tick_t current_tick;

            /* get current tick */
            current_tick = rt_tick_get();

            if ((next_timeout - current_tick) < RT_TICK_MAX/2)
            {
                /* get the delta timeout tick */
                next_timeout = next_timeout - current_tick;
                rt_thread_delay(next_timeout);
            }
        }

        /* lock scheduler */
        rt_enter_critical();
        /* check software timer */
        rt_soft_timer_check();
        /* unlock scheduler */
        rt_exit_critical();
    }
}
Exemplo n.º 4
0
/**
 * This function finds a device driver by specified name.
 *
 * @param name the device driver's name
 *
 * @return the registered device driver on successful, or RT_NULL on failure.
 */
rt_device_t rt_device_find(const char *name)
{
    struct rt_object *object;
    struct rt_list_node *node;
    struct rt_object_information *information;

    extern struct rt_object_information rt_object_container[];

    /* enter critical */
    if (rt_thread_self() != RT_NULL)
        rt_enter_critical();

    /* try to find device object */
    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);
        if (rt_strncmp(object->name, name, RT_NAME_MAX) == 0)
        {
            /* leave critical */
            if (rt_thread_self() != RT_NULL)
                rt_exit_critical();

            return (rt_device_t)object;
        }
    }

    /* leave critical */
    if (rt_thread_self() != RT_NULL)
        rt_exit_critical();

    /* not found */
    return RT_NULL;
}
Exemplo n.º 5
0
/** \brief set system date(time not modify).
 *
 * \param rt_uint32_t year  e.g: 2012.
 * \param rt_uint32_t month e.g: 12 (1~12).
 * \param rt_uint32_t day   e.g: e.g: 31.
 * \return rt_err_t if set success, return RT_EOK.
 *
 */
rt_err_t set_date(rt_uint32_t year, rt_uint32_t month, rt_uint32_t day)
{
    time_t now;
    struct tm * p_tm;
    struct tm tm_new;
    rt_device_t device;

    /* get current time */
    now = time(RT_NULL);

    /* lock scheduler. */
    rt_enter_critical();
    /* converts calendar time time into local time. */
    p_tm = localtime(&now);
    /* copy the statically located variable */
    memcpy(&tm_new, p_tm, sizeof(struct tm));
    /* unlock scheduler. */
    rt_exit_critical();

    /* update date. */
    tm_new.tm_year = year - 1900;
    tm_new.tm_mon  = month - 1; /* tm_mon: 0~11 */
    tm_new.tm_mday = day;

    /* converts the local time in time to calendar time. */
    now = mktime(&tm_new);

    device = rt_device_find("rtc");
    if (device == RT_NULL)
    {
        return -RT_ERROR;
    }

    /* update to RTC device. */
    return rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &now);
}
Exemplo n.º 6
0
/** \brief set system time(date not modify).
 *
 * \param rt_uint32_t hour   e.g: 0~23.
 * \param rt_uint32_t minute e.g: 0~59.
 * \param rt_uint32_t second e.g: 0~59.
 * \return rt_err_t if set success, return RT_EOK.
 *
 */
rt_err_t set_time(rt_uint32_t hour, rt_uint32_t minute, rt_uint32_t second)
{
    time_t now;
    struct tm * p_tm;
    struct tm tm_new;
    rt_device_t device;

    /* get current time */
    now = time(RT_NULL);

    /* lock scheduler. */
    rt_enter_critical();
    /* converts calendar time time into local time. */
    p_tm = localtime(&now);
    /* copy the statically located variable */
    memcpy(&tm_new, p_tm, sizeof(struct tm));
    /* unlock scheduler. */
    rt_exit_critical();

    /* update time. */
    tm_new.tm_hour = hour;
    tm_new.tm_min  = minute;
    tm_new.tm_sec  = second;

    /* converts the local time in time to calendar time. */
    now = mktime(&tm_new);

    device = rt_device_find("rtc");
    if (device == RT_NULL)
    {
        return RT_ERROR;
    }

    /* update to RTC device. */
    return rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &now);
}
Exemplo n.º 7
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 == RT_NULL)
                netif_set_default(ethif->netif);
#ifdef LWIP_IPV6
            ethif->netif->output_ip6 = ethip6_output;
            netif_create_ip6_linklocal_address(ethif->netif, 1);
#ifdef LWIP_IPV6_AUTOCONFIG
            ethif->netif->ip6_autoconfig_enabled = 1;
#endif
#ifdef LWIP_IPV6_MLD
            ethif->netif->mld_mac_filter = NULL;
#endif
#endif

#if LWIP_DHCP
            if (ethif->flags & NETIF_FLAG_DHCP)
            {
                /* if this interface uses DHCP, start the DHCP client */
                dhcp_start(ethif->netif);
            }
            else
#endif
            {
                /* set interface up */
                netif_set_up(ethif->netif);
            }

#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);
}
Exemplo n.º 8
0
/***********************************************************
* Function:
* Description:
* Input:
* Input:
* Output:
* Return:
* Others:
***********************************************************/
static void keypress( unsigned int key )
{
#if 0
	switch( key )
	{
		case KEY_MENU:

			if( ( data_fetch_comp == 1 ) || ( usb_error == 1 ) )
			{
				usb_error		= 0;
				data_fetch_comp = 0;
				pMenuItem		= &Menu_5_other;
				pMenuItem->show( );

				//if(tid_write_file)						///测试会复位
				//if(tid_write_file != RT_NULL)			///测试OK
				/* 调度器上锁,上锁后,将不再切换到其他线程,仅响应中断*/
				rt_enter_critical( );
				if( tid_write_file != RT_NULL && tid_write_file->stat != RT_THREAD_CLOSE ) ///测试OK
				{
					rt_thread_delete( tid_write_file );
				}
				/* 调度器解锁*/
				rt_exit_critical( );
			}

			DataOutStartFlag	= 0;
			DataOutStartFlag	= 0;
			OUT_DataCounter		= 0;
			DataOutInFlag		= 0;
			break;
		case KEY_OK:
			//本地升级
			if( DataOutInFlag == 1 )
			{
				DataOutInFlag = 2; //导出数据类型选择标志
				USB_OUTFileSe( OUT_DataCounter );
			}
			//文件导出
			else if( DataOutInFlag == 2 )
			{
				DataOutInFlag = 0;

				if( ( OUT_DataCounter >= 1 ) && ( OUT_DataCounter <= 3 ) )
				{
					DataOutStartFlag = OUT_DataCounter; //在timetick中显示导出过程
				}
				tid_write_file = rt_thread_create( "writefile", thread_usbout_udisk, (void*)msg, 1024, 8, 5 );
				if( tid_write_file != RT_NULL )
				{
					msg( "I导出存储的数据" );
					rt_thread_startup( tid_write_file );
				}else
				{
					msg( "E错误按菜单键" );
					usb_error = 1;
				}
			}
			break;
		case KEY_UP:
			if( DataOutInFlag == 2 )
			{
				if( OUT_DataCounter <= 1 )
				{
					OUT_DataCounter = 3;
				} else
				{
					OUT_DataCounter--;
				}
				USB_OUTFileSe( OUT_DataCounter );
			}
			break;
		case KEY_DOWN:
			if( DataOutInFlag == 2 )
			{
				if( OUT_DataCounter >= 3 )
				{
					OUT_DataCounter = 1;
				} else
				{
					OUT_DataCounter++;
				}
				USB_OUTFileSe( OUT_DataCounter );
			}
			break;
	}
#endif	
}
Exemplo n.º 9
0
rt_err_t i2c_register_write(struct rt_i2c_bus_device *bus,
						rt_uint16_t daddr,
						rt_uint8_t raddr,
						void *buffer,
						rt_size_t count)
{
	rt_int32_t ret;
	rt_tick_t tick=rt_tick_get();
#ifdef 	NO_RT_DEVICE
	rt_uint8_t * pBuffer=(rt_uint8_t *)buffer;
	
	rt_mutex_take(&I2C1_mutex,RT_WAITING_FOREVER);
	rt_enter_critical();
	I2C_GenerateSTART(I2C1, ENABLE);

	/* Test on EV5 and clear it */
	while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT))
		CHECKTIME(tick);

	/* Send MPU6050 address for write */
	I2C_Send7bitAddress(I2C1, daddr, I2C_Direction_Transmitter);

	/* Test on EV6 and clear it */
	while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
		CHECKTIME(tick);

	/* Send the MPU6050's internal address to write to */
	I2C_SendData(I2C1, raddr);

	/* Test on EV8 and clear it */
	while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED))
		CHECKTIME(tick);

	/* Send the byte to be written */
	I2C_SendData(I2C1, *pBuffer);

	/* Test on EV8 and clear it */
	while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED))
		CHECKTIME(tick);

	/* Send STOP condition */
	I2C_GenerateSTOP(I2C1, ENABLE);
	rt_exit_critical();
	rt_mutex_release(&I2C1_mutex);
#else
	struct rt_i2c_msg msgs[2];
	rt_err_t err;
    RT_ASSERT(bus != RT_NULL);
    RT_ASSERT(buffer != RT_NULL);
	
	if(count>1)
	{
		msgs[0].addr=daddr;
		msgs[0].buf=&raddr;
		msgs[0].len=1;
		msgs[0].flags=RT_I2C_WR;
		
		msgs[1].addr=daddr;
		msgs[1].buf=buffer;
		msgs[1].len=count;
		msgs[1].flags=RT_I2C_WR|RT_I2C_NO_START;
		
		err=rt_i2c_transfer(bus,msgs,2);
	}
	else
	{
		rt_uint8_t data[2];
		data[0]=raddr;
		data[1]=*((rt_uint8_t *)buffer);
		
		msgs[0].addr=daddr;
		msgs[0].buf=data;
		msgs[0].len=2;
		msgs[0].flags=RT_I2C_WR;
		
		err=rt_i2c_transfer(bus,msgs,1);
	}
#endif
	
	return RT_EOK;
	out:	
	
#ifdef 	NO_RT_DEVICE
//	I2C_GenerateSTOP(I2C1, ENABLE);
	rt_exit_critical();
	rt_mutex_release(&I2C1_mutex);
#endif
	return ret;
}
Exemplo n.º 10
0
rt_err_t i2c_register_read(struct rt_i2c_bus_device *bus,
						rt_uint16_t daddr,
						rt_uint8_t raddr,
						void *buffer,
						rt_size_t count)
{
	rt_int32_t ret;
	rt_tick_t tick=rt_tick_get();
#ifdef 	NO_RT_DEVICE
	rt_uint16_t NumByteToRead=count;
	rt_uint8_t * pBuffer=(rt_uint8_t *)buffer;
	rt_mutex_take(&I2C1_mutex,RT_WAITING_FOREVER);
	rt_enter_critical();
	  /* While the bus is busy */
	while(I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY))
		CHECKTIME(tick);

	/* Send START condition */
	I2C_GenerateSTART(I2C1, ENABLE);

	/* Test on EV5 and clear it */
	while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT))
	CHECKTIME(tick);

	/* Send MPU6050 address for write */
	I2C_Send7bitAddress(I2C1, daddr, I2C_Direction_Transmitter); 

	/* Test on EV6 and clear it */
	while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
		CHECKTIME(tick);

	/* Clear EV6 by setting again the PE bit */
	I2C_Cmd(I2C1, ENABLE);

	/* Send the MPU6050's internal address to write to */
	I2C_SendData(I2C1, raddr);

	/* Test on EV8 and clear it */
	while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED))
		CHECKTIME(tick);

	/* Send STRAT condition a second time */
	I2C_GenerateSTART(I2C1, ENABLE);

	/* Test on EV5 and clear it */
	while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT))
		CHECKTIME(tick);

	/* Send MPU6050 address for read */
	I2C_Send7bitAddress(I2C1, daddr, I2C_Direction_Receiver);

	/* Test on EV6 and clear it */
	while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))
		CHECKTIME(tick);

	/* While there is data to be read */
	while(NumByteToRead)
	{
		if(NumByteToRead == 1)
		{
			/* Disable Acknowledgement */
			I2C_AcknowledgeConfig(I2C1, DISABLE);

			/* Send STOP Condition */
			I2C_GenerateSTOP(I2C1, ENABLE);
		}

		/* Test on EV7 and clear it */
		while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED))
			CHECKTIME(tick);
		{
			/* Read a byte from the MPU6050 */
			*pBuffer = I2C_ReceiveData(I2C1);

			/* Point to the next location where the byte read will be saved */
			pBuffer++;

			/* Decrement the read bytes counter */
			NumByteToRead--;
			
		}
	}

	/* Enable Acknowledgement to be ready for another reception */
	I2C_AcknowledgeConfig(I2C1, ENABLE);
	//  EXT_CRT_SECTION();
	rt_exit_critical();
	rt_mutex_release(&I2C1_mutex);
#else
	struct rt_i2c_msg msgs[2];
    RT_ASSERT(bus != RT_NULL);
    RT_ASSERT(buffer != RT_NULL);
	
	msgs[0].addr=daddr;
	msgs[0].buf=&raddr;
	msgs[0].len=1;
	msgs[0].flags=RT_I2C_WR|I2C_RA;
	
	msgs[1].addr=daddr;
	msgs[1].buf=buffer;
	msgs[1].len=count;
	msgs[1].flags=RT_I2C_RD|RT_I2C_NO_READ_ACK;
	err=rt_i2c_transfer(bus,msgs,2);	
#endif
	
	return RT_EOK;
	out:	
#ifdef 	NO_RT_DEVICE
//	I2C_GenerateSTOP(I2C1, ENABLE);
	rt_exit_critical();
	rt_mutex_release(&I2C1_mutex);
#endif
	return ret;
}
Exemplo n.º 11
0
DRESULT disk_write (
	BYTE pdrv,			/* Physical drive nmuber (0..) */
	const BYTE *buff,	/* Data to be written */
	DWORD sector,		/* Sector address (LBA) */
	UINT count			/* Number of sectors to write (1..128) */
)
{
	SD_Error Status;
	
	if( !count )
	{    
		return RES_PARERR; 
	}
	switch (pdrv)
	{
	case SD_CARD:
				if(count==1)              
				{   
					rt_enter_critical();
					Status = SD_WriteBlock( (uint8_t *)(&buff[0]) ,sector << 9 , 512); 
					rt_exit_critical();
				}                                                
				else                  
				{    
					rt_enter_critical();
					Status = SD_WriteMultiBlocks( (uint8_t *)(&buff[0]) ,sector << 9 ,512,count);
					rt_exit_critical();
				} 
				/* Check if the Transfer is finished */
				Status = SD_WaitWriteOperation();
				rt_enter_critical();
				while(SD_GetStatus() != SD_TRANSFER_OK);	
				rt_exit_critical();
				if(Status == SD_OK)
				{
				   return RES_OK;
				}
				else
				{
				   return RES_ERROR;
				}
//	case ATA :
//		// translate the arguments here
//
//		result = ATA_disk_write(buff, sector, count);
//
//		// translate the reslut code here
//
//		return res;
//
//	case MMC :
//		// translate the arguments here
//
//		result = MMC_disk_write(buff, sector, count);
//
//		// translate the reslut code here
//
//		return res;
//
//	case USB :
//		// translate the arguments here
//
//		result = USB_disk_write(buff, sector, count);
//
//		// translate the reslut code here
//
//		return res;
	}
	return RES_PARERR;
}