long version(void) { struct m3_sys_info_st sys_info; //char datestr[12]; char datestr_1[12]; int i; //rt_show_version(); read_syscfgdata_tbl(SYSCFGDATA_TBL_SYS_INFO, 0, &sys_info); printf_syn("HW ver:%d.%d.%d\n", M3_HW_VERSION, M3_HW_SUBVERSION, M3_HW_REVISION); printf_syn("OS ver:%d.%d.%d\n", RT_VERSION, RT_SUBVERSION, RT_REVISION); printf_syn("DB ver:%d.%d.%d\n", (sys_info.db_ver>>16)&0xff, (sys_info.db_ver>>8)&0xff, (sys_info.db_ver)&0xff); printf_syn("App ver:%d.%d.%d build %s %s\n", RT_APP_VERSION, RT_APP_SUBVERSION, RT_APP_REVISION, __DATE__, __TIME__); /* Aug 22 2012 */ rt_strncpy(datestr_1, __DATE__, sizeof(datestr_1)); datestr_1[3] = '\0'; if (' '==datestr_1[4]) datestr_1[4] = '0'; datestr_1[6] = '\0'; //datestr_1[11] = '\0'; for (i=0; i<12; ++i) if (0==rt_strncmp(months_str[i], datestr_1, 3)) break; rt_sprintf(datestr_1, "%02d", i+1); printf_syn("Standard ver:SCC_%d.%d.%d.%s%s%s_%s_%d\n", (sys_info.sw_ver>>16)&0xff, (sys_info.sw_ver>>8)&0xff, (sys_info.sw_ver)&0xff, &datestr_1[7], &datestr_1[0], &datestr_1[4], RT_APP_VER_TYPE, RT_APP_MODIFY_VERSION); return 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; }
int dfs_elm_mkfs(const char *device_name) { BYTE drv; rt_device_t dev; FRESULT result; /* find device name */ for (drv = 0; drv < _VOLUMES; drv ++) { dev = disk[drv]; if (rt_strncmp(dev->parent.name, device_name, RT_NAME_MAX) == 0) { /* 1: no partition table */ /* 0: auto selection of cluster size */ result = f_mkfs(drv, 1, 0); if (result != FR_OK) { rt_kprintf("format error\n"); return elm_result_to_dfs(result); } return DFS_STATUS_OK; } } /* can't find device driver */ rt_kprintf("can not find device driver: %s\n", device_name); return -DFS_STATUS_EIO; }
int main() { char s[20] = "123abc"; char t[20] = "123456"; printf("%d\n", rt_strncmp(s, t, 4)); return 0; }
static void finsh_wait_auth(void) { char ch; rt_bool_t input_finish = RT_FALSE; char password[FINSH_PASSWORD_MAX] = { 0 }; rt_size_t cur_pos = 0; /* password not set */ if (rt_strlen(finsh_get_password()) == 0) return; while (1) { rt_kprintf("Password for login: "******"*"); password[cur_pos++] = ch; } else if (ch == '\b' && cur_pos > 0) { /* backspace */ password[cur_pos] = '\0'; cur_pos--; rt_kprintf("\b \b"); } else if (ch == '\r' || ch == '\n') { rt_kprintf("\n"); input_finish = RT_TRUE; break; } } } if (!rt_strncmp(shell->password, password, FINSH_PASSWORD_MAX)) return; else { /* authentication failed, delay 2S for retry */ rt_thread_delay(2 * RT_TICK_PER_SECOND); rt_kprintf("Sorry, try again.\n"); cur_pos = 0; input_finish = RT_FALSE; rt_memset(password, '\0', FINSH_PASSWORD_MAX); } } }
void list_irq(void) { int irq; rt_kprintf("number\tcount\tname\n"); for (irq = 0; irq < MAX_HANDLERS; irq++) { if (rt_strncmp(irq_desc[irq].name, "default", sizeof("default"))) { rt_kprintf("%02ld: %10ld %s\n", irq, irq_desc[irq].counter, irq_desc[irq].name); } } }
static int dfs_uffs_mkfs(const char* device_name) { rt_base_t index; rt_uint32_t block; struct rt_mtd_nand_device * mtd; /*1. find the device index */ for (index = 0; index < UFFS_DEVICE_MAX; index++) { if (rt_strncmp(nand_part[index].dev->parent.parent.name, device_name, RT_NAME_MAX) == 0) break; } if (index == UFFS_DEVICE_MAX) { /* can't find device driver */ rt_kprintf("can not find device driver: %s\n", device_name); return -DFS_STATUS_ENOENT; } /*2. then unmount the partition */ uffs_Mount(nand_part[index].mount_path); mtd = nand_part[index].dev; /*3. erase all blocks on the partition */ block = mtd->block_start; for (; block <= mtd->block_end; block++) { rt_mtd_nand_erase_block(mtd, block); if (rt_mtd_nand_check_block(mtd, block) != RT_EOK) { rt_kprintf("found bad block %d\n", block); rt_mtd_nand_mark_badblock(mtd, block); } } /*4. remount it */ if (init_uffs_fs(&nand_part[index]) < 0) { return uffs_result_to_dfs(uffs_get_error()); } return DFS_STATUS_OK; }
void rtgui_label_set_text(rtgui_label_t* label, const char* text) { RT_ASSERT(label != RT_NULL); if (label->text != RT_NULL) { /* it's a same text string */ if (rt_strncmp(text, label->text, rt_strlen(text)) == 0) return; /* release old text memory */ rtgui_free(label->text); } if (text != RT_NULL) label->text = (char*)rt_strdup((const char*)text); else label->text = RT_NULL; /* update widget */ rtgui_theme_draw_label(label); }
/** * This fucntion will find the object id by specified object name * * @param type the type of object * @param name the specified object name * * @return object id for successful */ rt_object_t rt_object_find(enum rt_object_class_type type, const char* name) { struct rt_object_information *information; struct rt_object* object; struct rt_list_node* node; 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) { return object; } } /* not found */ return RT_NULL; }
void rt_init_thread_entry(void* parameter) { int ch; rt_thread_delay(RT_TICK_PER_SECOND); { extern void rt_platform_init(void); rt_platform_init(); } #ifdef RT_USING_FINSH /* initialize finsh */ finsh_system_init(); finsh_set_device(RT_CONSOLE_DEVICE_NAME); rt_thread_delay(10); /* wait finsh thread init OK */ if(rt_strncmp(RT_CONSOLE_DEVICE_NAME, "bridge", sizeof("bridge")) == 0) finsh_set_echo(0); #endif rt_console_set_device(RT_CONSOLE_DEVICE_NAME); rt_show_version(); }
/* 查找指定sn的设备数据是否已缓存 */ static struct sinkinfo_wl_data_item_st *si_lookup_item_in_wl_data(char *sn) { int i; struct sinkinfo_wl_data_item_st *p; /* 查找是否已存储到缓冲区 */ p = sink_wl_collect_data; for (i=0; i<SINKINFO_WL_DATA_ITEM_MAX_NO; ++i) { if (0 == rt_strncmp(p->pt_ct_sn, sn, sizeof(p->pt_ct_sn))) break; ++p; } sinki_debug_data(("func:%s(), line:%d, sn:%s\n", __FUNCTION__, __LINE__, sn)); if (i < SINKINFO_WL_DATA_ITEM_MAX_NO) return p; else return NULL; }
/** * 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; }
struct romfs_dirent *dfs_romfs_lookup(struct romfs_dirent *root_dirent, const char *path, rt_size_t *size) { rt_size_t index, found; const char *subpath, *subpath_end; struct romfs_dirent *dirent; rt_size_t dirent_size; if (path[0] == '/' && path[1] == '\0') { *size = root_dirent->size; return root_dirent; } /* goto root directy entries */ dirent = (struct romfs_dirent *)root_dirent->data; dirent_size = root_dirent->size; /* get the end position of this subpath */ subpath_end = path; /* skip /// */ while (*subpath_end && *subpath_end == '/') subpath_end ++; subpath = subpath_end; while ((*subpath_end != '/') && *subpath_end) subpath_end ++; while (dirent != RT_NULL) { found = 0; /* search in folder */ for (index = 0; index < dirent_size; index ++) { if (rt_strncmp(dirent[index].name, subpath, (subpath_end - subpath)) == 0) { dirent_size = dirent[index].size; /* skip /// */ while (*subpath_end && *subpath_end == '/') subpath_end ++; subpath = subpath_end; while ((*subpath_end != '/') && *subpath_end) subpath_end ++; if (!(*subpath)) { *size = dirent_size; return &dirent[index]; } if (dirent[index].type == ROMFS_DIRENT_DIR) { /* enter directory */ dirent = (struct romfs_dirent*)dirent[index].data; found = 1; break; } else { /* return file dirent */ if (subpath != RT_NULL) break; /* not the end of path */ return &dirent[index]; } } } if (!found) break; /* not found */ } /* not found */ return RT_NULL; }