本文整理汇总了C++中rt_free函数的典型用法代码示例。如果您正苦于以下问题:C++ rt_free函数的具体用法?C++ rt_free怎么用?C++ rt_free使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rt_free函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: rt_serial_close
static rt_err_t rt_serial_close(struct rt_device *dev)
{
struct rt_serial_device *serial;
RT_ASSERT(dev != RT_NULL);
serial = (struct rt_serial_device *)dev;
/* this device has more reference count */
if (dev->ref_count > 1) return RT_EOK;
if (dev->open_flag & RT_DEVICE_FLAG_INT_RX)
{
struct rt_serial_rx_fifo* rx_fifo;
rx_fifo = (struct rt_serial_rx_fifo*)serial->serial_rx;
RT_ASSERT(rx_fifo != RT_NULL);
rt_free(rx_fifo);
serial->serial_rx = RT_NULL;
dev->open_flag &= ~RT_DEVICE_FLAG_INT_RX;
/* configure low level device */
serial->ops->control(serial, RT_DEVICE_CTRL_CLR_INT, (void*)RT_DEVICE_FLAG_INT_TX);
}
else if (dev->open_flag & RT_DEVICE_FLAG_DMA_RX)
{
struct rt_serial_rx_dma* rx_dma;
rx_dma = (struct rt_serial_rx_dma*)serial->serial_tx;
RT_ASSERT(rx_dma != RT_NULL);
rt_free(rx_dma);
serial->serial_rx = RT_NULL;
dev->open_flag &= ~RT_DEVICE_FLAG_DMA_RX;
}
if (dev->open_flag & RT_DEVICE_FLAG_INT_TX)
{
struct rt_serial_tx_fifo* tx_fifo;
tx_fifo = (struct rt_serial_tx_fifo*)serial->serial_rx;
RT_ASSERT(tx_fifo != RT_NULL);
rt_free(tx_fifo);
serial->serial_tx = RT_NULL;
dev->open_flag &= ~RT_DEVICE_FLAG_INT_TX;
/* configure low level device */
serial->ops->control(serial, RT_DEVICE_CTRL_CLR_INT, (void*)RT_DEVICE_FLAG_INT_TX);
}
else if (dev->open_flag & RT_DEVICE_FLAG_DMA_TX)
{
struct rt_serial_tx_dma* tx_dma;
tx_dma = (struct rt_serial_tx_dma*)serial->serial_tx;
RT_ASSERT(tx_dma != RT_NULL);
rt_free(tx_dma);
serial->serial_tx = RT_NULL;
dev->open_flag &= ~RT_DEVICE_FLAG_DMA_TX;
}
return RT_EOK;
}
开发者ID:CHINAoneBOY,项目名称:rt-thread-stm32f405-enc28j60-,代码行数:62,代码来源:serial.c
示例2: msh_auto_complete_path
void msh_auto_complete_path(char *path)
{
DIR* dir = RT_NULL;
struct dirent *dirent = RT_NULL;
char *full_path, *ptr, *index;
full_path = (char*)rt_malloc(256);
if (full_path == RT_NULL) return; /* out of memory */
ptr = full_path;
if (*path != '/')
{
getcwd(full_path, 256);
if (full_path[rt_strlen(full_path) - 1] != '/')
strcat(full_path, "/");
}
else *full_path = '\0';
index = RT_NULL; ptr = path;
for (;;)
{
if (*ptr == '/') index = ptr + 1; if (!*ptr) break; ptr ++;
}
if (index == RT_NULL) index = path;
if (index != RT_NULL)
{
char *dest = index;
/* fill the parent path */
ptr = full_path;
while (*ptr) ptr ++;
for (index = path; index != dest;)
*ptr++ = *index++;
*ptr = '\0';
dir = opendir(full_path);
if (dir == RT_NULL) /* open directory failed! */
{
rt_free(full_path);
return;
}
/* restore the index position */
index = dest;
}
/* auto complete the file or directory name */
if (*index == '\0') /* display all of files and directories */
{
for (;;)
{
dirent = readdir(dir);
if (dirent == RT_NULL) break;
rt_kprintf("%s\n", dirent->d_name);
}
}
else
{
int length, min_length;
min_length = 0;
for (;;)
{
dirent = readdir(dir);
if (dirent == RT_NULL) break;
/* matched the prefix string */
if (strncmp(index, dirent->d_name, rt_strlen(index)) == 0)
{
if (min_length == 0)
{
min_length = rt_strlen(dirent->d_name);
/* save dirent name */
strcpy(full_path, dirent->d_name);
}
length = str_common(dirent->d_name, full_path);
if (length < min_length)
{
min_length = length;
}
}
}
if (min_length)
{
if (min_length < rt_strlen(full_path))
{
/* list the candidate */
rewinddir(dir);
for (;;)
{
dirent = readdir(dir);
if (dirent == RT_NULL) break;
//.........这里部分代码省略.........
开发者ID:1847123212,项目名称:EasyFlash,代码行数:101,代码来源:msh.c
示例3: tcpecho_socket_entry
void tcpecho_socket_entry(void *parameter)
{
char *recv_data;
rt_uint32_t sin_size;
int sock = -1, connected, bytes_received;
struct sockaddr_in server_addr, client_addr;
recv_data = rt_malloc(TCP_SOCKET_BUFFER_SIZE);
if (recv_data == RT_NULL)
{
rt_kprintf("no memory\n");
goto _exit;
}
/* create a TCP socket */
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{
rt_kprintf("create socket error\n");
goto _exit;
}
/* initialize server address */
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(TCP_SOCKET_ECHO_PORT);
server_addr.sin_addr.s_addr = INADDR_ANY;
rt_memset(&(server_addr.sin_zero),8, sizeof(server_addr.sin_zero));
/* bind to server address */
if (bind(sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) == -1)
{
rt_kprintf("bind address failed\n");
goto _exit;
}
/* listen */
if (listen(sock, 5) == -1)
{
rt_kprintf("listen error\n");
goto _exit;
}
sin_size = sizeof(struct sockaddr_in);
while(1)
{
/* accept client connected */
connected = accept(sock, (struct sockaddr *)&client_addr, &sin_size);
if (connected > 0)
{
int timeout;
/* set timeout option */
timeout = 5000; /* 5second */
setsockopt(connected, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
/* handle this client */
while (1)
{
/* receive data from this connection */
bytes_received = recv(connected,recv_data, TCP_SOCKET_BUFFER_SIZE, 0);
if (bytes_received <= 0)
{
rt_kprintf("close client connection, errno: %d, socket error: %d\n",
rt_get_errno(),
lwip_get_error());
/* connection closed. */
lwip_close(connected);
break;
}
/* send data to client */
send(connected, recv_data, bytes_received, 0);
}
}
}
_exit:
/* close socket */
if (sock != -1) lwip_close(sock);
rt_free(recv_data);
return ;
}
开发者ID:CollinsLiu,项目名称:rt-thread-pc,代码行数:82,代码来源:net_test.c
示例4: rt_free_link
URET rt_free_link(struct uffs_DeviceSt *dev, void *p)
{
rt_free(p);
return 0;
}
开发者ID:malooei,项目名称:yeejoin-workspace,代码行数:5,代码来源:uffs_mem.c
示例5: fs_test
void fs_test(const char* filename)
{
unsigned int i = 512;
unsigned int speed;
float speed_mb[32][2]; //read and write speed
int fd;
char *buff_ptr;
rt_size_t total_length; //file length
unsigned int readspeed_avg = 0;
unsigned int writespeed_avg = 0;
unsigned int speed_count = 0;
rt_kprintf("\nStart test...\n");
for(i = 512;i < 4096000 ; i+= i)
{
total_length = 256*i;
if(total_length > TEST_FILE_SIZE_MAX)
total_length = TEST_FILE_SIZE_MAX;
//write speed test
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0);
if (fd < 0)
{
rt_kprintf("open file:%s failed\n", filename);
break;
}
buff_ptr = rt_malloc(i);
if (buff_ptr == RT_NULL)
{
rt_kprintf("no more RAM for test.\n");
close(fd);
break;
}
rt_kprintf("BlockSize:%6d Byte ->| ", i);
speed = writespeed(fd, buff_ptr, total_length,i);
rt_kprintf("WriteSpeed:%8d byte/s ", speed);
writespeed_avg += speed;
speed_mb[speed_count][0] = (float)speed/(1024.f*1024.f); //writespeed in float
close(fd);
rt_free(buff_ptr);
//read speed test
fd = open(filename, O_RDONLY, 0);
if (fd < 0)
{
rt_kprintf("open file:%s failed\n", filename);
break;
}
buff_ptr = rt_malloc(i);
if (buff_ptr == RT_NULL)
{
rt_kprintf("no memory\n");
close(fd);
break;
}
speed = readspeed(fd, buff_ptr, total_length, i);
rt_kprintf("| ReadSpeed:%8d byte/s\n", speed);
readspeed_avg += speed;
speed_mb[speed_count][1] = (float)speed/(1024.f*1024.f); //read_speed in float
close(fd);
rt_free(buff_ptr);
//
speed_count ++;
}
//draw graph
{
char buf[32];
int block_max = i;
int block = 0;
int count_of_chars;
float max = speed_mb[speed_count-1][1];
float scale = (1.f/max)*50.f;
speed_count = 0;
rt_kprintf("\nBlock Size (byte) Writespeed = \"WR\" Readspeed = \"RD\"\n");
for(block=512; block<block_max; block+=block)
{
//write speed
rt_kprintf("%6d->| ",block);
count_of_chars = 1+ speed_mb[speed_count][0] * scale;
while(count_of_chars--)
{
// rt_thread_delay(15);
rt_kprintf(">");
}
//.........这里部分代码省略.........
开发者ID:cvrobot,项目名称:deepblueplane,代码行数:101,代码来源:fs_test.c
示例6: wlan_cmd_802_11_key_material
/**
* @brief This function prepares command of key_material.
*
* @param priv A pointer to WlanCard structure
* @param cmd A pointer to HostCmd_DS_COMMAND structure
* @param cmd_action the action: GET or SET
* @param cmd_oid OID: ENABLE or DISABLE
* @param pdata_buf A pointer to data buffer
* @return WLAN_STATUS_SUCCESS or WLAN_STATUS_FAILURE
*/
int wlan_cmd_802_11_key_material(WlanCard *cardinfo, u16 cmd_action,
WLAN_OID cmd_oid, void *pdata_buf)
{
WlanCard *card = cardinfo;
HostCmd_DS_COMMAND *CmdPtr = NULL;
HostCmd_DS_802_11_KEY_MATERIAL *pKeyMaterial;
WLAN_802_11_KEY *pKey = (WLAN_802_11_KEY *) pdata_buf;
u16 KeyParamSet_len;
int ret = WLAN_STATUS_SUCCESS;
CmdPtr = rt_malloc(sizeof(HostCmd_DS_COMMAND));
if (CmdPtr == NULL)
{
WlanDebug(WlanErr,"memory allocate failed for set Key\r\n");
return WLAN_STATUS_FAILURE;
}
card->SeqNum++;
CmdPtr->SeqNum = card->SeqNum;
CmdPtr->Command = HostCmd_CMD_802_11_KEY_MATERIAL;
CmdPtr->Result = 0;
pKeyMaterial = &CmdPtr->params.keymaterial;
pKeyMaterial->Action = cmd_action;
if (cmd_action == HostCmd_ACT_GET)
{
CmdPtr->Size = 2 + S_DS_GEN;
ret = WLAN_STATUS_SUCCESS;
goto done;
}
rt_memset(&pKeyMaterial->KeyParamSet, 0, sizeof(MrvlIEtype_KeyParamSet_t));
if (pKey->KeyLength == WPA_AES_KEY_LEN)
{
pKeyMaterial->KeyParamSet.KeyTypeId = KEY_TYPE_ID_AES;
if (cmd_oid == (WLAN_OID) KEY_INFO_ENABLED)
pKeyMaterial->KeyParamSet.KeyInfo = KEY_INFO_AES_ENABLED;
else
pKeyMaterial->KeyParamSet.KeyInfo = !(KEY_INFO_AES_ENABLED);
if (pKey->KeyIndex & 0x40000000)
pKeyMaterial->KeyParamSet.KeyInfo |= KEY_INFO_AES_UNICAST;
else
pKeyMaterial->KeyParamSet.KeyInfo |= KEY_INFO_AES_MCAST;
}
else if (pKey->KeyLength == WPA_TKIP_KEY_LEN)
{
pKeyMaterial->KeyParamSet.KeyTypeId = KEY_TYPE_ID_TKIP;
pKeyMaterial->KeyParamSet.KeyInfo = KEY_INFO_TKIP_ENABLED;
if (pKey->KeyIndex & 0x40000000)
pKeyMaterial->KeyParamSet.KeyInfo |= KEY_INFO_TKIP_UNICAST;
else
pKeyMaterial->KeyParamSet.KeyInfo |= KEY_INFO_TKIP_MCAST;
}
if (pKeyMaterial->KeyParamSet.KeyTypeId)
{
pKeyMaterial->KeyParamSet.Type = TLV_TYPE_KEY_MATERIAL;
pKeyMaterial->KeyParamSet.KeyLen = pKey->KeyLength;
rt_memcpy(pKeyMaterial->KeyParamSet.Key, pKey->KeyMaterial,
pKey->KeyLength);
pKeyMaterial->KeyParamSet.Length = pKey->KeyLength + 6;
#define TYPE_LEN_FIELDS_LEN (4)
#define ACTION_FIELD_LEN (2)
KeyParamSet_len = (pKey->KeyLength + 6) + TYPE_LEN_FIELDS_LEN;
CmdPtr->Size = KeyParamSet_len + ACTION_FIELD_LEN + S_DS_GEN;
}
ret = WlanExecuteCommand(cardinfo, CmdPtr);
if (ret)
{
WlanDebug(WlanErr,"Falure for Wlan Set Key\r\n");
ret = WLAN_STATUS_FAILURE;
}
rt_free(CmdPtr);
ret = WLAN_STATUS_SUCCESS;
done:
return ret;
}
开发者ID:lynx19890808,项目名称:LynxFlyOpen,代码行数:96,代码来源:wlan_cmd.c
示例7: ftp_process_request
int ftp_process_request(struct ftp_session* session, char *buf)
{
int fd;
struct timeval tv;
fd_set readfds;
char filename[256];
int numbytes;
char *sbuf;
char *parameter_ptr, *ptr;
rt_uint32_t addr_len = sizeof(struct sockaddr_in);
struct sockaddr_in local, pasvremote;
sbuf =(char *)rt_malloc(FTP_BUFFER_SIZE);
tv.tv_sec=3, tv.tv_usec=0;
local.sin_family=PF_INET;
local.sin_addr.s_addr=INADDR_ANY;
/* remove \r\n */
ptr = buf;
while (*ptr) {
if (*ptr == '\r' || *ptr == '\n') *ptr = 0;
ptr ++;
}
/* get request parameter */
parameter_ptr = strchr(buf, ' ');
if (parameter_ptr != NULL) parameter_ptr ++;
// debug:
rt_kprintf("%s requested: \"%s\"\n", inet_ntoa(session->remote.sin_addr), buf);
//
//-----------------------
if(str_begin_with(buf, "USER")==0) {
rt_kprintf("%s sent login \"%s\"\n", inet_ntoa(session->remote.sin_addr), parameter_ptr);
// login correct
if(strcmp(parameter_ptr, "anonymous") == 0) {
session->is_anonymous = RT_TRUE;
rt_sprintf(sbuf, "331 Anonymous login OK send e-mail address for password.\r\n", parameter_ptr);
send(session->sockfd, sbuf, strlen(sbuf), 0);
} else if (strcmp(parameter_ptr, FTP_USER) == 0) {
session->is_anonymous = RT_FALSE;
rt_sprintf(sbuf, "331 Password required for %s\r\n", parameter_ptr);
send(session->sockfd, sbuf, strlen(sbuf), 0);
} else {
// incorrect login
rt_sprintf(sbuf, "530 Login incorrect. Bye.\r\n");
send(session->sockfd, sbuf, strlen(sbuf), 0);
rt_free(sbuf);
return -1;
}
return 0;
} else if(str_begin_with(buf, "PASS")==0) {
rt_kprintf("%s sent password \"%s\"\n", inet_ntoa(session->remote.sin_addr), parameter_ptr);
if (strcmp(parameter_ptr, FTP_PASSWORD)==0 ||
session->is_anonymous == RT_TRUE) {
// password correct
rt_sprintf(sbuf, "230 User logged in\r\n");
send(session->sockfd, sbuf, strlen(sbuf), 0);
rt_free(sbuf);
return 0;
}
// incorrect password
rt_sprintf(sbuf, "530 Login or Password incorrect. Bye!\r\n");
send(session->sockfd, sbuf, strlen(sbuf), 0);
rt_free(sbuf);
return -1;
} else if(str_begin_with(buf, "LIST")==0 ) {
memset(sbuf,0,FTP_BUFFER_SIZE);
rt_sprintf(sbuf, "150 Opening Binary mode connection for file list.\r\n");
send(session->sockfd, sbuf, strlen(sbuf), 0);
do_list(session->currentdir, session->pasv_sockfd);
closesocket(session->pasv_sockfd);
session->pasv_active = 0;
rt_sprintf(sbuf, "226 Transfert Complete.\r\n");
send(session->sockfd, sbuf, strlen(sbuf), 0);
} else if(str_begin_with(buf, "NLST")==0 ) {
memset(sbuf, 0, FTP_BUFFER_SIZE);
rt_sprintf(sbuf, "150 Opening Binary mode connection for file list.\r\n");
send(session->sockfd, sbuf, strlen(sbuf), 0);
do_simple_list(session->currentdir, session->pasv_sockfd);
closesocket(session->pasv_sockfd);
session->pasv_active = 0;
rt_sprintf(sbuf, "226 Transfert Complete.\r\n");
send(session->sockfd, sbuf, strlen(sbuf), 0);
} else if(str_begin_with(buf, "PWD")==0 || str_begin_with(buf, "XPWD")==0) {
rt_sprintf(sbuf, "257 \"%s\" is current directory.\r\n", session->currentdir);
send(session->sockfd, sbuf, strlen(sbuf), 0);
} else if(str_begin_with(buf, "TYPE")==0) {
// Ignore it
if(strcmp(parameter_ptr, "I")==0) {
rt_sprintf(sbuf, "200 Type set to binary.\r\n");
send(session->sockfd, sbuf, strlen(sbuf), 0);
} else {
rt_sprintf(sbuf, "200 Type set to ascii.\r\n");
send(session->sockfd, sbuf, strlen(sbuf), 0);
}
} else if(str_begin_with(buf, "PASV")==0) {
//.........这里部分代码省略.........
开发者ID:malooei,项目名称:yeejoin-workspace,代码行数:101,代码来源:ftpd.c
示例8: rtgui_fileview_update_current
/* update fileview */
void rtgui_fileview_update_current(rtgui_fileview_t* fview)
{
rtgui_fileview_item_t *item;
rtgui_rect_t rect, item_rect, image_rect;
rtgui_dc_t *dc;
RT_ASSERT(fview != RT_NULL);
/* begin drawing */
dc = rtgui_dc_begin_drawing(fview);
if(dc == RT_NULL)return;
/* if directory is null, no dispost */
if(fview->items==RT_NULL)return;
rtgui_widget_get_rect(fview, &rect);
if(fview->sbar && !RTGUI_WIDGET_IS_HIDE(fview->sbar))
rect.x2 -= RC_W(fview->sbar->parent.extent);
if((fview->old_item >= fview->first_item) &&
(fview->old_item < fview->first_item+fview->item_per_page) &&
(fview->old_item != fview->now_item))
{
/* these condition dispell blinked when drawed */
/* get old item rect */
item_rect = rect;
item_rect.x1 += RTGUI_WIDGET_BORDER_SIZE(fview);
item_rect.x2 -= RTGUI_WIDGET_BORDER_SIZE(fview);
item_rect.y1 += RTGUI_WIDGET_BORDER_SIZE(fview);
item_rect.y1 += ((fview->old_item-fview->first_item) % fview->item_per_page) * (1 + RTGUI_SEL_H);
item_rect.y2 = item_rect.y1 + (1 + RTGUI_SEL_H);
/* get image rect */
image_rect.x1 = RTGUI_MARGIN;
image_rect.y1 = 0;
image_rect.x2 = RTGUI_MARGIN + file_image->w;
image_rect.y2 = file_image->h;
rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
/* draw old item */
item = &(fview->items[fview->old_item]);
if(item->type == RTGUI_FITEM_FILE) /* draw item image */
rtgui_image_paste(file_image, dc, &image_rect, Black);
else
rtgui_image_paste(folder_image, dc, &image_rect,Black);
item_rect.x1 += RTGUI_MARGIN + file_image->w + 2;
item_rect.x2 = item_rect.x1 + rtgui_font_get_string_width(RTGUI_DC_FONT(dc), item->name);
RTGUI_DC_BC(dc) = theme.blankspace;
RTGUI_DC_FC(dc) = theme.foreground;
rtgui_dc_fill_rect(dc,&item_rect);
rtgui_dc_draw_text(dc, item->name, &item_rect);
}
/* draw current item */
item_rect = rect;
item_rect.x1 += RTGUI_WIDGET_BORDER_SIZE(fview);
item_rect.x2 -= RTGUI_WIDGET_BORDER_SIZE(fview);
item_rect.y1 += RTGUI_WIDGET_BORDER_SIZE(fview);
item_rect.y1 += ((fview->now_item-fview->first_item) % fview->item_per_page) * (1 + RTGUI_SEL_H);
item_rect.y2 = item_rect.y1 + (1 + RTGUI_SEL_H);
/* get image base rect */
image_rect.x1 = RTGUI_MARGIN;
image_rect.y1 = 0;
image_rect.x2 = RTGUI_MARGIN + file_image->w;
image_rect.y2 = file_image->h;
rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
item = &(fview->items[fview->now_item]);
if(item->type == RTGUI_FITEM_FILE) /* draw item image */
rtgui_image_paste(file_image, dc, &image_rect, Black);
else
rtgui_image_paste(folder_image, dc, &image_rect, Black);
if(fview->dlg != RT_NULL)
{
if(fview->dlg->filename != RT_NULL)
{
rt_free(fview->dlg->filename);
fview->dlg->filename = RT_NULL;
}
fview->dlg->filename = rt_strdup(item->name);
}
item_rect.x1 += RTGUI_MARGIN + file_image->w + 2;
item_rect.x2 = item_rect.x1 + rtgui_font_get_string_width(RTGUI_DC_FONT(dc), item->name);
{
if(RTGUI_WIDGET_IS_FOCUSED(fview))
{
RTGUI_DC_BC(dc) = DarkBlue;
RTGUI_DC_FC(dc) = theme.blankspace;
}
else
{
RTGUI_DC_BC(dc) = Gray;
RTGUI_DC_FC(dc) = theme.foreground;
}
rtgui_dc_fill_rect(dc, &item_rect);
//.........这里部分代码省略.........
开发者ID:amsl,项目名称:RTGUI,代码行数:101,代码来源:fileview.c
示例9: rtgui_fileview_set_directory
void rtgui_fileview_set_directory(rtgui_fileview_t* fview, const char* directory)
{
char fullpath[256];
rtgui_fileview_item_t *item;
fview->first_item = 0;
fview->item_count = 0;
/* clear file information */
rtgui_fileview_clear(fview);
if(directory != RT_NULL)
{
DIR* dir;
struct stat s;
rt_uint32_t i;
struct dirent* dirent;
fview->item_count = 0;
/* open directory */
dir = opendir(directory);
if(dir == RT_NULL) return;
/* set current directory */
if(fview->current_dir != RT_NULL)
{
rt_free(fview->current_dir);
fview->current_dir = RT_NULL;
}
fview->current_dir = rt_strdup(directory);
if(fview->dlg != RT_NULL)
{
if(fview->dlg->path != RT_NULL)
rt_free(fview->dlg->path);
fview->dlg->path = rt_strdup(fview->current_dir);
if(fview->dlg->tbox_path != RT_NULL)
{
rtgui_textbox_set_value(fview->dlg->tbox_path,fview->dlg->path);
rtgui_textbox_ondraw(fview->dlg->tbox_path);
}
}
do
{
dirent = readdir(dir);
if(dirent == RT_NULL) break;
fview->item_count ++;
}
while(dirent != RT_NULL);
closedir(dir);
if((fview->item_count > fview->item_per_page) && fview->sbar!=RT_NULL)
{
RTGUI_WIDGET_SHOW(fview->sbar);
rtgui_scrollbar_set_line_step(fview->sbar,1);
rtgui_scrollbar_set_page_step(fview->sbar, fview->item_per_page);
rtgui_scrollbar_set_range(fview->sbar, fview->item_count);
}
else
{
RTGUI_WIDGET_HIDE(fview->sbar);
}
rtgui_widget_update_clip(fview);
/* apply to memory for store all items. */
fview->items = (rtgui_fileview_item_t*) rt_malloc(sizeof(rtgui_fileview_item_t) * fview->item_count);
if(fview->items == RT_NULL) goto __return; /* under the folder has not sub files. */
/* reopen directory */
dir = opendir(directory);
if(dir == RT_NULL) goto __return;
for(i=0; i < fview->item_count; i ++)
{
dirent = readdir(dir);
if(dirent == RT_NULL) break;
item = &(fview->items[i]);
item->name = rt_strdup(dirent->d_name);
rt_memset(&s, 0, sizeof(struct stat));
/* get fullpath of file */
dfs_get_fullpath(fullpath, directory, dirent->d_name);
stat(fullpath, &s);
if(s.st_mode & S_IFDIR)
{
item->type = RTGUI_FITEM_DIR;
item->size = 0;
}
else
{
item->type = RTGUI_FITEM_FILE;
item->size = s.st_size;
}
}
//.........这里部分代码省略.........
开发者ID:amsl,项目名称:RTGUI,代码行数:101,代码来源:fileview.c
示例10: _block_device_test
//.........这里部分代码省略.........
}
}// step 4: speed test
/* step 6: multiple sector speed test */
{
rt_uint8_t * multiple_buffer;
rt_uint8_t * ptr;
rt_uint32_t tick_start,tick_end;
rt_uint32_t sector,i;
rt_kprintf("\r\nmultiple sector speed test\r\n");
for(sector=2; sector<256; sector=sector*2)
{
multiple_buffer = rt_malloc(geometry.bytes_per_sector * sector);
if(multiple_buffer == RT_NULL)
{
rt_kprintf("no memory for %d sector! multiple sector speed test abort!\r\n", sector);
break;
}
rt_memset(multiple_buffer, sector, geometry.bytes_per_sector * sector);
rt_kprintf("write: ");
tick_start = rt_tick_get();
for(i=0; i<10; i++)
{
rt_size_t n;
n = rt_device_write(device, 50, multiple_buffer, sector);
if(n == sector)
{
rt_kprintf("<");
}
else
{
rt_kprintf("#");
}
}
tick_end = rt_tick_get();
rt_kprintf("\r\n");
rt_kprintf("multiple write %d sector speed : ", sector);
calculate_speed_print( (geometry.bytes_per_sector * sector * 10 * RT_TICK_PER_SECOND)/(tick_end-tick_start) );
rt_kprintf("\r\n");
rt_memset(multiple_buffer, ~sector, geometry.bytes_per_sector * sector);
rt_kprintf("read : ");
tick_start = rt_tick_get();
for(i=0; i<10; i++)
{
rt_size_t n;
n = rt_device_read(device, 50, multiple_buffer, sector);
if(n == sector)
{
rt_kprintf(">");
}
else
{
rt_kprintf("#");
}
}
tick_end = rt_tick_get();
rt_kprintf("\r\n");
rt_kprintf("multiple read %d sector speed : ", sector);
calculate_speed_print( (geometry.bytes_per_sector * sector * 10 * RT_TICK_PER_SECOND)/(tick_end-tick_start) );
ptr = multiple_buffer;
for(i=0; i<geometry.bytes_per_sector * sector; i++)
{
if(*ptr != sector)
{
rt_kprintf(" but data verify fail!");
break;
}
ptr++;
}
rt_kprintf("\r\n\r\n");
rt_free(multiple_buffer);
}
} /* step 5: multiple sector speed test */
return RT_EOK;
}// device can read and write.
else
{
// device read only
return RT_EOK;
}// device read only
__return:
if( read_buffer != RT_NULL )
{
rt_free(read_buffer);
}
if( write_buffer != RT_NULL )
{
rt_free(write_buffer);
}
return RT_ERROR;
}
开发者ID:634351070,项目名称:rt-thread,代码行数:101,代码来源:device_test.c
示例11: rt_module_exec_cmd
/**
* This function will do a executable program with main function and parameters.
*
* @param path the full path of application module
* @param cmd_line the command line of program
* @param size the size of command line of program
*
* @return the module object
*/
rt_module_t rt_module_exec_cmd(const char *path, const char* cmd_line, int line_size)
{
struct dfs_filesystem *fs;
appentry_t fptr;
HINSTANCE hinstlib;
rt_module_t module;
char * winpath = RT_NULL;
char * name = RT_NULL;
char *full_path = RT_NULL;
RT_DEBUG_NOT_IN_INTERRUPT;
/* check parameters */
RT_ASSERT(path != RT_NULL);
if (*path != '/')
{
full_path = dfs_normalize_path(RT_NULL, path);
}
else
{
full_path = (const char*)path;
}
/* app module should only in DFS_WIN32 */
fs = dfs_filesystem_lookup(full_path);
if ((fs == RT_NULL) || (strcmp(fs->ops->name,"wdir") != 0))
{
rt_kprintf("invalid path: %s\n", path);
goto __exit;
}
/* change path */
// len = strlen(full_path + 1);
if ((winpath = dfs_win32_dirdup((char *)full_path)) == RT_NULL)
{
rt_kprintf("out of memory, exit", path);
goto __exit;
}
hinstlib = LoadLibrary(winpath);
if (hinstlib == NULL)
{
rt_kprintf("error: unable to open %s\n", winpath);
goto __exit;
}
fptr = (appentry_t)GetProcAddress(hinstlib, "main");
if (fptr == NULL)
{
rt_kprintf("error: unable to find function in %s\n", winpath);
FreeLibrary(hinstlib);
goto __exit;
}
/* release winpath */
rt_free(winpath);
/* get the name of the module */
name = _module_name(path);
/* allocate module */
module = (struct rt_module *)rt_object_allocate(RT_Object_Class_Module, name);
if (!module)
{
goto __exit;
}
module->nref = 0;
module->module_entry = fptr;
/* init module object container */
rt_module_init_object_container(module);
/* increase module reference count */
module->nref ++;
if (module->module_entry != 0)
{
/* set module argument */
module->module_cmd_line = (rt_uint8_t*)rt_malloc(line_size + 1);
rt_memcpy(module->module_cmd_line, cmd_line, line_size);
module->module_cmd_line[line_size] = '\0';
module->module_cmd_size = line_size;
#ifdef RT_USING_SLAB
/* init module memory allocator */
module->mem_list = RT_NULL;
/* create page array */
//.........这里部分代码省略.........
开发者ID:Cheong2K,项目名称:rt-thread,代码行数:101,代码来源:module_win32.c
示例12: _calc_line
static void _calc_line(rtgui_textview_t *textview, const char* text)
{
char* line;
const unsigned char* ptr;
rt_ubase_t line_index, line_position;
if (textview->lines != RT_NULL)
{
rt_free(textview->lines);
textview->lines = RT_NULL;
textview->line_count = 0;
}
/* get line count */
line_index = 0; line_position = 0;
ptr = (const unsigned char*)text;
if (*ptr == 0) return;
while (*ptr != '\0')
{
if (*ptr == '\n')
{
line_index ++;
line_position = 0;
}
else if (*ptr == '\r')
{
ptr ++;
continue;
}
else if (*ptr == '\t')
{
line_position += 4;
if (line_position >= textview->line_width - 1)
{
line_index ++;
line_position = 0;
}
}
else
{
if ((*ptr) >= 0x80)
{
/* fill cjk character */
if (line_position + 1 >= (textview->line_width - 1))
{
/* split to next line */
line_index ++;
line_position = 0;
}
line_position ++;
line_position ++;
}
else
{
line_position ++;
}
if (line_position >= textview->line_width - 1)
{
line_index ++;
line_position = 0;
}
}
ptr ++;
}
/* set line count */
textview->line_count = line_index + 1;
/* allocate lines */
textview->lines = rt_malloc(textview->line_count * textview->line_width);
rt_memset(textview->lines, 0, (textview->line_count * textview->line_width));
/* fill lines */
line_index = 0; line_position = 0;
ptr = (const unsigned char*)text;
line = _get_line_text(textview, line_index);
while (*ptr)
{
if (*ptr == '\n')
{
line_index ++;
line_position = 0;
line = _get_line_text(textview, line_index);
}
else if (*ptr == '\r')
{
/* ignore '\r' */
ptr ++;
continue;
}
else if (*ptr == '\t')
{
line[line_position++] = ' ';
line[line_position++] = ' ';
line[line_position++] = ' ';
line[line_position++] = ' ';
//.........这里部分代码省略.........
开发者ID:Paolo-Maffei,项目名称:rt-thread-stm32f4discovery,代码行数:101,代码来源:textview.c
示例13: _rtgui_textview_destructor
static void _rtgui_textview_destructor(rtgui_textview_t *textview)
{
/* release line memory */
rt_free(textview->lines);
textview->lines = RT_NULL;
}
开发者ID:Paolo-Maffei,项目名称:rt-thread-stm32f4discovery,代码行数:6,代码来源:textview.c
示例14: _rtgui_label_destructor
static void _rtgui_label_destructor(rtgui_label_t *label)
{
/* release text memory */
rt_free(label->text);
label->text = RT_NULL;
}
开发者ID:pengdonglin137,项目名称:iboot,代码行数:6,代码来源:label.c
示例15: wlan_cmd_802_11_snmp_mib
//.........这里部分代码省略.........
pSNMPMIB->BufSize = (sizeof(u8));
if (card->InfrastructureMode == Wlan802_11Infrastructure)
ucTemp = SNMP_MIB_VALUE_INFRA;
else
ucTemp = SNMP_MIB_VALUE_ADHOC;
rt_memmove(pSNMPMIB->Value, &ucTemp, sizeof(u8));
break;
case OID_802_11D_ENABLE:
{
u32 ulTemp;
pSNMPMIB->OID = (u16) Dot11D_i;
if (cmd_action == HostCmd_ACT_SET)
{
pSNMPMIB->QueryType = HostCmd_ACT_GEN_SET;
pSNMPMIB->BufSize = sizeof(u16);
ulTemp = *(u32 *) pdata_buf;
*((u16*) (pSNMPMIB->Value)) = ((u16) ulTemp);
}
break;
}
case OID_802_11_FRAGMENTATION_THRESHOLD:
{
WLAN_802_11_FRAGMENTATION_THRESHOLD ulTemp;
pSNMPMIB->OID = ((u16) FragThresh_i);
if (cmd_action == HostCmd_ACT_GET)
{
pSNMPMIB->QueryType = (HostCmd_ACT_GEN_GET);
}
else if (cmd_action == HostCmd_ACT_SET)
{
pSNMPMIB->QueryType = (HostCmd_ACT_GEN_SET);
pSNMPMIB->BufSize = (sizeof(u16));
ulTemp = *((WLAN_802_11_FRAGMENTATION_THRESHOLD *) pdata_buf);
*((u16*) (pSNMPMIB->Value)) = ((u16) ulTemp);
}
break;
}
case OID_802_11_RTS_THRESHOLD:
{
WLAN_802_11_RTS_THRESHOLD ulTemp;
pSNMPMIB->OID = ((u16) RtsThresh_i);
if (cmd_action == HostCmd_ACT_GET)
{
pSNMPMIB->QueryType = HostCmd_ACT_GEN_GET;
}
else if (cmd_action == HostCmd_ACT_SET)
{
pSNMPMIB->QueryType = (HostCmd_ACT_GEN_SET);
pSNMPMIB->BufSize = (sizeof(u16));
ulTemp = *((WLAN_802_11_RTS_THRESHOLD *) pdata_buf);
*(u16*) (pSNMPMIB->Value) = ((u16) ulTemp);
}
break;
}
case OID_802_11_TX_RETRYCOUNT:
pSNMPMIB->OID = ((u16) ShortRetryLim_i);
if (cmd_action == HostCmd_ACT_GET)
{
pSNMPMIB->QueryType = (HostCmd_ACT_GEN_GET);
}
else if (cmd_action == HostCmd_ACT_SET)
{
pSNMPMIB->QueryType = (HostCmd_ACT_GEN_SET);
pSNMPMIB->BufSize = (sizeof(u16));
*((u16*) (pSNMPMIB->Value)) = ((u16) card->TxRetryCount);
}
break;
default:
break;
}
WlanDebug(WlanCmd,"SNMP_CMD: Action=0x%x, OID=0x%x, OIDSize=0x%x, Value=0x%x\r\n",
pSNMPMIB->QueryType, pSNMPMIB->OID, pSNMPMIB->BufSize,
*(u16 *) pSNMPMIB->Value);
ret = WlanExecuteCommand(card, CmdPtr);
if (ret)
{
WlanDebug(WlanErr,"Failure for set SNMP\r\n");
ret = WLAN_STATUS_FAILURE;
}
rt_free(CmdPtr);
return WLAN_STATUS_SUCCESS;
}
开发者ID:lynx19890808,项目名称:LynxFlyOpen,代码行数:101,代码来源:wlan_cmd.c
示例16: mem_free_debug
void mem_free_debug(void *p)
{
rt_free(p);
}
开发者ID:heyuanjie87,项目名称:rt-thread,代码行数:4,代码来源:board.c
示例17: wlan_cmd_802_11_set_wep
//.........这里部分代码省略.........
{
case WEP_40_BIT_LEN:
wep->WEPTypeForKey1 = HostCmd_TYPE_WEP_40_BIT;
rt_memmove(wep->WEP1, card->WepKey[0].KeyMaterial,
card->WepKey[0].KeyLength);
break;
case WEP_104_BIT_LEN:
wep->WEPTypeForKey1 = HostCmd_TYPE_WEP_104_BIT;
rt_memmove(wep->WEP1, card->WepKey[0].KeyMaterial,
card->WepKey[0].KeyLength);
break;
case 0:
break;
default:
WlanDebug(WlanErr,"Set Wep key0 length %d\r\n",card->WepKey[0].KeyLength);
ret = WLAN_STATUS_FAILURE;
goto done;
}
switch (card->WepKey[1].KeyLength)
{
case WEP_40_BIT_LEN:
wep->WEPTypeForKey2 = HostCmd_TYPE_WEP_40_BIT;
rt_memmove(wep->WEP2, card->WepKey[1].KeyMaterial,
card->WepKey[1].KeyLength);
break;
case WEP_104_BIT_LEN:
wep->WEPTypeForKey2 = HostCmd_TYPE_WEP_104_BIT;
rt_memmove(wep->WEP2, card->WepKey[1].KeyMaterial,
card->WepKey[1].KeyLength);
break;
case 0:
break;
default:
WlanDebug(WlanErr,"Set Wep Key1 Length = %d \n",card->WepKey[1].KeyLength);
ret = WLAN_STATUS_FAILURE;
goto done;
}
switch (card->WepKey[2].KeyLength)
{
case WEP_40_BIT_LEN:
wep->WEPTypeForKey3 = HostCmd_TYPE_WEP_40_BIT;
rt_memmove(wep->WEP3, card->WepKey[2].KeyMaterial,
card->WepKey[2].KeyLength);
break;
case WEP_104_BIT_LEN:
wep->WEPTypeForKey3 = HostCmd_TYPE_WEP_104_BIT;
rt_memmove(wep->WEP3, card->WepKey[2].KeyMaterial,
card->WepKey[2].KeyLength);
break;
case 0:
break;
default:
WlanDebug(WlanErr,"Set Wep Key2 Length = %d \n",card->WepKey[1].KeyLength);
ret = WLAN_STATUS_FAILURE;
goto done;
}
switch (card->WepKey[3].KeyLength)
{
case WEP_40_BIT_LEN:
wep->WEPTypeForKey4 = HostCmd_TYPE_WEP_40_BIT;
rt_memmove(wep->WEP4, card->WepKey[3].KeyMaterial,
card->WepKey[3].KeyLength);
break;
case WEP_104_BIT_LEN:
wep->WEPTypeForKey4 = HostCmd_TYPE_WEP_104_BIT;
rt_memmove(wep->WEP4, card->WepKey[3].KeyMaterial,
card->WepKey[3].KeyLength);
break;
case 0:
break;
default:
WlanDebug(WlanErr,"Set Wep Key3 Length = %d \n",card->WepKey[1].KeyLength);
ret = WLAN_STATUS_FAILURE;
goto done;
}
}
else if (cmd_oid == OID_802_11_REMOVE_WEP)
{
CmdPtr->Command = (HostCmd_CMD_802_11_SET_WEP);
CmdPtr->Size = (sizeof(HostCmd_DS_802_11_SET_WEP)) + S_DS_GEN;
wep->Action = HostCmd_ACT_REMOVE;
/* default tx key index */
wep->KeyIndex = ((u16) (card->CurrentWepKeyIndex
& (u32) HostCmd_WEP_KEY_INDEX_MASK));
}
ret = WlanExecuteCommand(cardinfo, CmdPtr);
if (ret)
{
WlanDebug(WlanErr,"cmd Set Wep Key failed \n");
ret = WLAN_STATUS_FAILURE;
}
rt_free(CmdPtr);
ret = WLAN_STATUS_SUCCESS;
done: return ret;
}
开发者ID:lynx19890808,项目名称:LynxFlyOpen,代码行数:101,代码来源:wlan_cmd.c
示例18: dfs_uffs_open
static int dfs_uffs_open(struct dfs_fd* file)
{
int fd;
int oflag, mode;
char * file_path;
oflag = file->flags;
if (oflag & DFS_O_DIRECTORY) /* operations about dir */
{
uffs_DIR * dir;
if (oflag & DFS_O_CREAT) /* create a dir*/
{
if (uffs_mkdir(file->path) < 0)
return uffs_result_to_dfs(uffs_get_error());
}
/* open dir */
file_path = rt_malloc(FILE_PATH_MAX);
if(file_path == RT_NULL)
return -DFS_STATUS_ENOMEM;
if (file->path[0] == '/' && !(file->path[1] == 0))
rt_snprintf(file_path, FILE_PATH_MAX, "%s/", file->path);
else
{
file_path[0] = '/';
file_path[1] = 0;
}
dir = uffs_opendir(file_path);
if (dir == RT_NULL)
{
rt_free(file_path);
return uffs_result_to_dfs(uffs_get_error());
}
/* save this pointer,will used by dfs_uffs_getdents*/
file->data = dir;
rt_free(file_path);
return DFS_STATUS_OK;
}
/* regular file operations */
/* int uffs_open(const char *name, int oflag, ...); what is this?
* uffs_open can open dir!! **/
mode = 0;
if (oflag & DFS_O_RDONLY) mode |= UO_RDONLY;
if (oflag & DFS_O_WRONLY) mode |= UO_WRONLY;
if (oflag & DFS_O_RDWR) mode |= UO_RDWR;
/* Opens the file, if it is existing. If not, a new file is created. */
if (oflag & DFS_O_CREAT) mode |= UO_CREATE;
/* Creates a new file. If the file is existing, it is truncated and overwritten. */
if (oflag & DFS_O_TRUNC) mode |= UO_TRUNC;
/* Creates a new file. The function fails if the file is already existing. */
if (oflag & DFS_O_EXCL) mode |= UO_EXCL;
fd = uffs_open(file->path, mode);
if (fd < 0)
{
return uffs_result_to_dfs(uffs_get_error());
}
/* save this pointer, it will be used when calling read()£¬write(),
* flush(), seek(), and will be free when calling close()*/
file->data = (void *)fd;
file->pos = uffs_seek(fd, 0, USEEK_CUR);
file->size = uffs_seek(fd, 0, USEEK_END);
uffs_seek(fd, file->pos, USEEK_SET);
if (oflag & DFS_O_APPEND)
{
file->pos = uffs_seek(fd, 0, USEEK_END);
}
return 0;
}
开发者ID:bobo8909,项目名称:RTT,代码行数:75,代码来源:dfs_uffs.c
示例19: rt_malloc
/*
* Create a UDP based client handle.
* If *sockp<0, *sockp is set to a newly created UPD socket.
* If raddr->sin_port is 0 a binder on the remote machine
* is consulted for the correct port number.
* NB: It is the clients responsibility to close *sockp.
* NB: The rpch->cl_auth is initialized to null authentication.
* Caller may wish to set this something more useful.
*
* wait is the amount of time used between retransmitting a call if
* no response has been heard; retransmition occurs until the actual
* rpc call times out
|
请发表评论