static int at_init(uart_dev_t *u, const char *recv_delimiter, const char *send_delimiter, int timeout) { if (!u || !recv_delimiter || !send_delimiter || (timeout < 0)) { LOGE(MODULE_NAME, "%s: invalid argument", __func__); return -1; } if (at_init_uart(u) != 0) return -1; at_set_timeout(timeout); at_set_recv_delimiter(recv_delimiter); at_set_send_delimiter(send_delimiter); if (at._mode == ASYN) { at_init_mutex(); slist_init(&at.task_l); aos_task_new("at_worker", at_worker, NULL, 4096); } return 0; }
static int at_init(const char *recv_prefix, const char *recv_success_postfix, const char *recv_fail_postfix, const char *send_delimiter, int timeout) { if (!recv_prefix || !recv_success_postfix || !recv_fail_postfix || !send_delimiter || (timeout < 0)) { LOGE(MODULE_NAME, "%s: invalid argument", __func__); return -1; } if (inited == 1) { LOGI(MODULE_NAME, "have already inited ,it will init again\r\n"); inited = 0; } if (at_init_uart() != 0) { LOGE(MODULE_NAME, "at uart init fail \r\n"); return -1; } memset(at._oobs, 0, sizeof(oob_t) * OOB_MAX); at_set_timeout(timeout); at_set_recv_delimiter(recv_prefix, recv_success_postfix, recv_fail_postfix); at_set_send_delimiter(send_delimiter); LOGD(MODULE_NAME, "at worker rcv prefix is %s success postfix is %s fail postfix is %s " "\r\n", recv_prefix, recv_success_postfix, recv_fail_postfix); if (at_init_at_mutex() != 0) { LOGE(MODULE_NAME, "at uart mutex init fail \r\n"); return -1; } if (at_init_task_mutex() != 0) { at_uinit_at_mutex(); LOGE(MODULE_NAME, "at mutex init fail \r\n"); return -1; } slist_init(&at.task_l); if (at_worker_uart_send_mutex_init() != 0) { at_uinit_at_mutex(); at_uinit_task_mutex(); LOGE(MODULE_NAME, "fail to creat at worker sem\r\n"); } if (aos_task_new("at_worker", at_worker, NULL, at_worker_stacksize)) { at_uinit_at_mutex(); at_uinit_task_mutex(); at_worker_uart_send_mutex_uinit(); LOGE(MODULE_NAME, "fail to creat at task\r\n"); return -1; } inited = 1; return 0; }