Exemplo n.º 1
0
/**
 * This API is used, usually by athost, to send stream content without response
 * required. The content is usually status event, such as
 * YEVENT:MONITOR_UP/MONITOR_DOWN, etc.
 */
static int at_send_raw_no_rsp(const char *content)
{
    int ret;

    aos_mutex_lock(&at.at_uart_send_mutex, AOS_WAIT_FOREVER);

    if (content) {
#ifdef HDLC_UART
        if ((ret =
               hdlc_uart_send(&hdlc_encode_ctx, at._pstuart, (void *)content,
                              strlen(content), at._timeout, true)) != 0)
#else
        if ((ret = hal_uart_send(at._pstuart, (void *)content, strlen(content),
                                 at._timeout)) != 0)
#endif
        {
            LOGE(MODULE_NAME, "uart send raw content (%s) failed", content);
            aos_mutex_unlock(&at.at_uart_send_mutex);
            assert(0);
            return -1;
        }

        LOGD(MODULE_NAME, "Raw content (%s) with no response required sent.",
             content);
    }

    aos_mutex_unlock(&at.at_uart_send_mutex);

    return 0;
}
Exemplo n.º 2
0
static int at_putc(char c)
{
    int ret = 0;
    if (inited == 0) {
        LOGE(MODULE_NAME, "at have not init yet\r\n");
        return -1;
    }

    if (at._mode != ASYN) {
        LOGE(MODULE_NAME, "AT mode is normal, can no use at_putc \r\n");
        return -1;
    }

    LOGD(MODULE_NAME, "uart sending %c(0x%02x)\r\n", c, c);
    aos_mutex_lock(&at.at_uart_send_mutex, AOS_WAIT_FOREVER);
#ifdef HDLC_UART
    ret = hdlc_uart_send(&hdlc_encode_ctx, at._pstuart, (void *)&c, 1,
                         at._timeout, false);
#else
    ret = hal_uart_send(at._pstuart, (void *)&c, 1, at._timeout);
#endif
    aos_mutex_unlock(&at.at_uart_send_mutex);

    return ret;
}
Exemplo n.º 3
0
// Write data
e_MQTTSN_RETURNS_t serWriteOD(subidx_t * pSubidx, uint8_t Len, uint8_t *pBuf)
{
    uint8_t port = pSubidx->Base/10;

    assert(extSerV[port] != NULL);

    if(Len > 0)
    {
        if((extSerV[port]->pTxBuf == NULL) && hal_uart_free(port))
        {
            MQ_t * pTxBuf = mqAlloc(sizeof(MQ_t));
            if(pTxBuf == NULL)
                return MQTTSN_RET_REJ_CONG;

            memcpy(pTxBuf->raw, pBuf, Len);
            hal_uart_send(port, Len, pTxBuf->raw);

            extSerV[port]->pTxBuf = pTxBuf;
        }
        else
            return MQTTSN_RET_REJ_CONG;
    }

    return MQTTSN_RET_ACCEPTED;
}
Exemplo n.º 4
0
static void uart_tx_task(void)
{
    static MQ_t   * pTx_buf = NULL;

    if(pTx_buf != NULL)
    {
        if(hal_uart_free(UART_PHY_PORT))
        {
            mqFree(pTx_buf);
            pTx_buf = NULL;
        }
    }

    if(uart_tx_queue.Size != 0)
    {
#ifdef LED_On
        LED_On();
#endif  //  LED_On
        if(hal_uart_free(UART_PHY_PORT))
        {
            pTx_buf = mqDequeue(&uart_tx_queue);
            // Paranoid check
            if(pTx_buf != NULL)
            {
                hal_uart_send(UART_PHY_PORT, (pTx_buf->Length + 1), &pTx_buf->Length);
            }
        }
    }
}
Exemplo n.º 5
0
static be_jse_symbol_t * uart_write(void){
	int8_t ret = -1;
	int8_t result = -1;
	char * data = NULL;
	uint32_t len = 0;
	item_handle_t uart_handle;
	be_jse_symbol_t * arg0 = NULL;
	be_jse_symbol_t * arg1 = NULL;
	uart_dev_t * uart_device = NULL;
	
	be_jse_handle_function(0,&arg0,&arg1,NULL,NULL);
	if(!arg0 || !symbol_is_int(arg0)){
		goto out;
	}
	uart_handle.handle = get_symbol_value_int(arg0);
	uart_device = board_get_node_by_handle(MODULE_UART,&uart_handle);
	if(NULL == uart_device){
		be_error("uart","board_get_node_by_handle fail!\n");
		goto out;
	}
	if(!arg1 || !symbol_is_string(arg1)){
		goto out;
	}
	len = symbol_str_len(arg1);
	data = calloc(1,sizeof(char)*(len+1));
	if(NULL==data){
		goto out;
	}
	symbol_to_str(arg1,data,len);
	ret = hal_uart_send(uart_device,data,len,0);
	if(-1 == ret){
		be_error("uart","hal_uart_send fail!\n");
		goto out;
	}
	result = 0;
out:
	symbol_unlock(arg0);
	symbol_unlock(arg1);
	if(NULL != data){
		free(data);
		data = NULL;
	}
	
	return new_int_symbol(len);
}
Exemplo n.º 6
0
static void uart_tx_task(void)
{
    static MQ_t   * pTx_buf = NULL;

    if(hal_uart_free(UART_PHY_PORT))
    {
        if(pTx_buf != NULL)
        {
            mqFree(pTx_buf);
            pTx_buf = NULL;
        }

        if(uart_tx_queue.Size != 0)
        {
            pTx_buf = mqDequeue(&uart_tx_queue);
            assert(pTx_buf != NULL);
            Activity(UART_PHY);
            hal_uart_send(UART_PHY_PORT, (pTx_buf->Length + 1), &pTx_buf->Length);
        }
    }
}
Exemplo n.º 7
0
static int at_write(const char *data, int size)
{
    int ret = 0;

    if (inited == 0) {
        LOGE(MODULE_NAME, "at have not init yet\r\n");
        return -1;
    }

    aos_mutex_lock(&at.at_uart_send_mutex, AOS_WAIT_FOREVER);
#ifdef HDLC_UART
    ret = hdlc_uart_send(&hdlc_encode_ctx, at._pstuart, (void *)data, size,
                         AOS_WAIT_FOREVER, true);
#else
    ret = hal_uart_send(at._pstuart, (void *)data, size, AOS_WAIT_FOREVER);
#endif
    aos_mutex_unlock(&at.at_uart_send_mutex);

    if (ret != 0) {
        return -1;
    }

    return size;
}
Exemplo n.º 8
0
static int at_reset()
{
    int ret = 0;
    char response[64] = {0};
    char *commond = AT_RESET_CMD;
    
    if (at._mode != ASYN) {
        LOGE(MODULE_NAME, "Operation not supported in non asyn mode");
        return -1;
    }

    at_task_t *tsk = (at_task_t *)aos_malloc(sizeof(at_task_t));
    if (NULL == tsk) {
        LOGE(MODULE_NAME, "tsk buffer allocating failed");
        return -1;
    }

    if ((ret = aos_sem_new(&tsk->smpr, 0)) != 0) {
        LOGE(MODULE_NAME, "failed to allocate semaphore");
        goto end;
    }

    LOGD(MODULE_NAME, "at task created: %d, smpr: %d",
         (uint32_t)tsk, (uint32_t)&tsk->smpr);

    tsk->rsp = response;
    tsk->rsp_offset = 0;
    tsk->rsp_len = sizeof(response);

    aos_mutex_lock(&at._mutex, AOS_WAIT_FOREVER);
    slist_add_tail(&tsk->next, &at.task_l);

    // uart operation should be inside mutex lock
    if ((ret = hal_uart_send(&at._uart, (void *)commond,
                             strlen(commond), at._timeout)) != 0) {
        aos_mutex_unlock(&at._mutex);
        LOGE(MODULE_NAME, "uart send command failed");
        goto end;
    }
    LOGD(MODULE_NAME, "Sending command %s", commond);
    if ((ret = hal_uart_send(&at._uart, (void *)at._send_delimiter,
        strlen(at._send_delimiter), at._timeout)) != 0) {
        aos_mutex_unlock(&at._mutex);
        LOGE(MODULE_NAME, "uart send delimiter failed");
        goto end;
    }
    LOGD(MODULE_NAME, "Sending delimiter %s", at._send_delimiter);

    aos_mutex_unlock(&at._mutex);

    if ((ret = aos_sem_wait(&tsk->smpr, AOS_WAIT_FOREVER)) != 0) {
        LOGE(MODULE_NAME, "sem_wait failed");
        goto end;
    }

    LOGD(MODULE_NAME, "sem_wait succeed.");

end:
    aos_mutex_lock(&at._mutex, AOS_WAIT_FOREVER);
    slist_del(&tsk->next, &at.task_l);
    aos_mutex_unlock(&at._mutex);
    if (aos_sem_is_valid(&tsk->smpr)) {
        aos_sem_free(&tsk->smpr);
    }
    if (tsk) {
        aos_free(tsk);
    }
    
    return  ret;
}
Exemplo n.º 9
0
/**
 * Example:
 *          AT+ENETRAWSEND=<len>
 *          ><data>
 *          OK
 *
 * Send data in 2 stages. These 2 stages must be finished inside 
 * one mutex lock.
 *   1. Send 'fst' string (first stage);
 *   2. Receving prompt, usually "<" character;
 *   3. Send data (second stage) in 'len' length.
 */
static int at_send_data_2stage(const char *fst, const char *data, 
                               uint32_t len, char *rsp, uint32_t rsplen/*, at_send_t t*/)
{
    int ret = 0;

    if (at._mode != ASYN) {
        LOGE(MODULE_NAME, "Operation not supported in non asyn mode");
        return -1;
    }

    if ((ret = at_reset()) != 0){
        LOGE(MODULE_NAME, "There is something wrong with atparser and reset fail\n");
        return -1;
    }
    
    at_task_t *tsk = (at_task_t *)aos_malloc(sizeof(at_task_t));
    if (NULL == tsk) {
        LOGE(MODULE_NAME, "tsk buffer allocating failed");
        return -1;
    }

    if ((ret = aos_sem_new(&tsk->smpr, 0)) != 0) {
        LOGE(MODULE_NAME, "failed to allocate semaphore");
        goto end;
    }

    LOGD(MODULE_NAME, "at 2stage task created: %d, smpr: %d",
      (uint32_t)tsk, (uint32_t)&tsk->smpr);

    tsk->rsp = rsp;
    tsk->rsp_offset = 0;
    tsk->rsp_len = rsplen;
    /* The 2 stages should be inside one mutex lock*/
    /* Mutex context begin*/
    aos_mutex_lock(&at._mutex, AOS_WAIT_FOREVER);
    LOGD(MODULE_NAME, "%s: at lock got", __func__);
    slist_add_tail(&tsk->next, &at.task_l);

    // uart operation should be inside mutex lock
    if ((ret = hal_uart_send(&at._uart, (void *)fst, 
      strlen(fst), at._timeout)) != 0) {
        aos_mutex_unlock(&at._mutex);
        LOGE(MODULE_NAME, "uart send 2stage prefix failed");
        goto end;
    }
    LOGD(MODULE_NAME, "Sending 2stage prefix %s", fst);

    if ((ret = hal_uart_send(&at._uart, (void *)at._send_delimiter, 
      strlen(at._send_delimiter), at._timeout)) != 0) {
        aos_mutex_unlock(&at._mutex);
        LOGE(MODULE_NAME, "uart send delimiter failed");
        goto end;
    }
    LOGD(MODULE_NAME, "Sending delimiter %s", at._send_delimiter);

    if ((ret = hal_uart_send(&at._uart, (void *)data, 
      len, at._timeout)) != 0) {
        aos_mutex_unlock(&at._mutex);
        LOGE(MODULE_NAME, "uart send 2stage data failed");
        goto end;
    }
    LOGD(MODULE_NAME, "Sending 2stage data %s", data);

    if ((ret = hal_uart_send(&at._uart, (void *)at._send_delimiter,
      strlen(at._send_delimiter), at._timeout)) != 0) {
        aos_mutex_unlock(&at._mutex);
        LOGE(MODULE_NAME, "uart send delimiter failed");
        goto end;
    }
    LOGD(MODULE_NAME, "Sending delimiter %s", at._send_delimiter);

    aos_mutex_unlock(&at._mutex);
    LOGD(MODULE_NAME, "%s: at lock released", __func__);
    /* Mutex context end*/

    if ((ret = aos_sem_wait(&tsk->smpr, AOS_WAIT_FOREVER)) != 0) {
        LOGE(MODULE_NAME, "sem_wait failed");
        goto end;
    }

    LOGD(MODULE_NAME, "sem_wait succeed.");

end:
    aos_mutex_lock(&at._mutex, AOS_WAIT_FOREVER);
    slist_del(&tsk->next, &at.task_l);
    aos_mutex_unlock(&at._mutex);
    if (aos_sem_is_valid(&tsk->smpr)) aos_sem_free(&tsk->smpr);
    if (tsk) aos_free(tsk);
    return  ret;
}
Exemplo n.º 10
0
static int at_putc(char c)
{
    LOGD(MODULE_NAME, "uart sending %c(0x%02x)", c, c);
    return hal_uart_send(&at._uart, (void *)&c, 1, at._timeout);
}
Exemplo n.º 11
0
/**
 * Example:
 *          AT+ENETRAWSEND=<len>
 *          ><data>
 *          OK
 *
 * Send data in 2 stages. These 2 stages must be finished inside
 * one mutex lock.
 *   1. Send 'fst' string (first stage);
 *   2. Receving prompt, usually ">" character;
 *   3. Send data (second stage) in 'len' length.
 */
static int at_send_data_2stage(const char *fst, const char *data, uint32_t len,
                               char *rsp, uint32_t rsplen)
{
    int ret = 0;

    if (inited == 0) {
        LOGE(MODULE_NAME, "at have not init yet\r\n");
        return -1;
    }

    if (at._mode != ASYN) {
        LOGE(MODULE_NAME, "Operation not supported in non asyn mode \r\n");
        return -1;
    }

    if (NULL == fst) {
        LOGE(MODULE_NAME, "%s invalid input \r\n", __FUNCTION__);
        return -1;
    }

    if (NULL == rsp || 0 == rsplen) {
        LOGE(MODULE_NAME, "%s invalid input \r\n", __FUNCTION__);
        return -1;
    }

    at_task_t *tsk = (at_task_t *)aos_malloc(sizeof(at_task_t));
    if (NULL == tsk) {
        LOGE(MODULE_NAME, "tsk buffer allocating failed");
        return -1;
    }
    memset(tsk, 0, sizeof(at_task_t));

    if ((ret = aos_sem_new(&tsk->smpr, 0)) != 0) {
        LOGE(MODULE_NAME, "failed to allocate semaphore");
        goto end;
    }

    LOGD(MODULE_NAME, "at task created: %d, smpr: %d", (uint32_t)tsk,
         (uint32_t)&tsk->smpr);

    tsk->command = (char *)fst;
    tsk->rsp     = rsp;
    tsk->rsp_len = rsplen;

    aos_mutex_lock(&at.at_uart_send_mutex, AOS_WAIT_FOREVER);

    at_worker_task_add(tsk);

    // uart operation should be inside mutex lock
#ifdef HDLC_UART
    if ((ret = hdlc_uart_send(&hdlc_encode_ctx, at._pstuart, (void *)fst,
                              strlen(fst), at._timeout, true)) != 0)
#else
    if ((ret = hal_uart_send(at._pstuart, (void *)fst, strlen(fst),
                             at._timeout)) != 0)
#endif
    {
        LOGE(MODULE_NAME, "uart send command failed");
        goto end;
    }
    LOGD(MODULE_NAME, "Sending command %s", fst);

#ifdef HDLC_UART
    if ((ret = hdlc_uart_send(
           &hdlc_encode_ctx, at._pstuart, (void *)at._send_delimiter,
           strlen(at._send_delimiter), at._timeout, false)) != 0)
#else
    if ((ret = hal_uart_send(at._pstuart, (void *)at._send_delimiter,
                             strlen(at._send_delimiter), at._timeout)) != 0)
#endif
    {
        LOGE(MODULE_NAME, "uart send delimiter failed");
        goto end;
    }
    LOGD(MODULE_NAME, "Sending delimiter %s", at._send_delimiter);

#ifdef AT_PARSER_DELAY_FLAG
    aos_msleep(20);
#endif

#ifdef HDLC_UART
    if ((ret = hdlc_uart_send(&hdlc_encode_ctx, at._pstuart, (void *)data, len,
                              at._timeout, true)) != 0)
#else
    if ((ret = hal_uart_send(at._pstuart, (void *)data, len, at._timeout)) != 0)
#endif
    {
        LOGE(MODULE_NAME, "uart send 2stage data failed");
        goto end;
    }

    LOGD(MODULE_NAME, "Sending 2stage data %s", data);

    if ((ret = aos_sem_wait(&tsk->smpr, TASK_DEFAULT_WAIT_TIME)) != 0) {
        LOGE(MODULE_NAME, "sem_wait failed");
        goto end;
    }

    LOGD(MODULE_NAME, "sem_wait succeed.");
end:
    at_worker_task_del(tsk);
    aos_mutex_unlock(&at.at_uart_send_mutex);
    return ret;
}
Exemplo n.º 12
0
/**
 * This API can be used to send packet, without response required.
 *
 * AT stream format as below:
 *     [<header>,]data[,<tailer>]
 *
 * In which, header and tailer is optional.
 */
static int at_send_data_3stage_no_rsp(const char *header, const uint8_t *data,
                                      uint32_t len, const char *tailer)
{
    int ret;

    if (inited == 0) {
        LOGE(MODULE_NAME, "at have not init yet\r\n");
        return -1;
    }

    if (at._mode != ASYN) {
        LOGE(MODULE_NAME, "Operation not supported in non asyn mode");
        return -1;
    }

    if (!data || !len) {
        return 0;
    }

#ifdef DEBUG
    dump_payload(data, len);
#endif

    aos_mutex_lock(&at.at_uart_send_mutex, AOS_WAIT_FOREVER);

    if (header) {
#ifdef HDLC_UART
        if ((ret = hdlc_uart_send(&hdlc_encode_ctx, at._pstuart, (void *)header,
                                  strlen(header), at._timeout, true)) != 0)
#else
        if ((ret = hal_uart_send(at._pstuart, (void *)header, strlen(header),
                                 at._timeout)) != 0)
#endif
        {
            LOGE(MODULE_NAME, "uart send packet header failed");
            aos_mutex_unlock(&at.at_uart_send_mutex);
            assert(0);
            return -1;
        }

        LOGD(MODULE_NAME, "Packet header sent: %s", header);
    }

#ifdef HDLC_UART
    if ((ret = hdlc_uart_send(&hdlc_encode_ctx, at._pstuart, (void *)data, len,
                              at._timeout, true)) != 0)
#else
    if ((ret = hal_uart_send(at._pstuart, (void *)data, len, at._timeout)) != 0)
#endif
    {
        LOGE(MODULE_NAME, "uart send packet failed");
        aos_mutex_unlock(&at.at_uart_send_mutex);
        assert(0);
        return -1;
    }
    LOGD(MODULE_NAME, "Packet sent, len: %d", len);

    if (tailer) {
#ifdef HDLC_UART
        if ((ret = hdlc_uart_send(&hdlc_encode_ctx, at._pstuart, (void *)tailer,
                                  strlen(tailer), at._timeout, false)) != 0)
#else
        if ((ret = hal_uart_send(at._pstuart, (void *)tailer, strlen(tailer),
                                 at._timeout)) != 0)
#endif
        {
            LOGE(MODULE_NAME, "uart send packet tailer failed");
            aos_mutex_unlock(&at.at_uart_send_mutex);
            assert(0);
            return -1;
        }

        LOGD(MODULE_NAME, "Packet tailer sent: %s", tailer);
    }

    aos_mutex_unlock(&at.at_uart_send_mutex);

    return 0;
}
Exemplo n.º 13
0
static int at_send_raw_self_define_respone_formate_internal(
  const char *command, uint32_t cmdlen, char *rsp, uint32_t rsplen,
  char *rsp_prefix, char *rsp_success_postfix, char *rsp_fail_postfix)
{
    int ret = 0;

    if (inited == 0) {
        LOGE(MODULE_NAME, "at have not init yet\r\n");
        return -1;
    }

    if (at._mode != ASYN) {
        LOGE(MODULE_NAME, "Operation not supported in non asyn mode \r\n");
        return -1;
    }

    if (NULL == command) {
        LOGE(MODULE_NAME, "%s invalid input \r\n", __FUNCTION__);
        return -1;
    }

    if (NULL == rsp || 0 == rsplen) {
        LOGE(MODULE_NAME, "%s invalid input \r\n", __FUNCTION__);
        return -1;
    }

    at_task_t *tsk = (at_task_t *)aos_malloc(sizeof(at_task_t));
    if (NULL == tsk) {
        LOGE(MODULE_NAME, "tsk buffer allocating failed");
        return -1;
    }
    memset(tsk, 0, sizeof(at_task_t));

    if ((ret = aos_sem_new(&tsk->smpr, 0)) != 0) {
        LOGE(MODULE_NAME, "failed to allocate semaphore");
        goto end;
    }

    LOGD(MODULE_NAME, "at task created: %d, smpr: %d", (uint32_t)tsk,
         (uint32_t)&tsk->smpr);

    if (NULL != rsp_prefix) {
        tsk->rsp_prefix     = rsp_prefix;
        tsk->rsp_prefix_len = strlen(rsp_prefix);
    }

    if (NULL != rsp_success_postfix) {
        tsk->rsp_success_postfix     = rsp_success_postfix;
        tsk->rsp_success_postfix_len = strlen(rsp_success_postfix);
    }

    if (NULL != rsp_fail_postfix) {
        tsk->rsp_fail_postfix     = rsp_fail_postfix;
        tsk->rsp_fail_postfix_len = strlen(rsp_fail_postfix);
    }

    tsk->command = (char *)command;
    tsk->rsp     = rsp;
    tsk->rsp_len = rsplen;

    at_worker_task_add(tsk);

    // uart operation should be inside mutex lock
#ifdef HDLC_UART
    if ((ret = hdlc_uart_send(&hdlc_encode_ctx, at._pstuart, (void *)command,
                              cmdlen, at._timeout, true)) != 0)
#else
    if ((ret = hal_uart_send(at._pstuart, (void *)command, cmdlen,
                             at._timeout)) != 0)
#endif
    {
        LOGE(MODULE_NAME, "uart send command failed");
        goto end;
    }
    LOGD(MODULE_NAME, "Sending command %s", command);

#ifdef HDLC_UART
    if ((ret = hdlc_uart_send(
           &hdlc_encode_ctx, at._pstuart, (void *)at._send_delimiter,
           strlen(at._send_delimiter), at._timeout, false)) != 0)
#else
    if ((ret = hal_uart_send(at._pstuart, (void *)at._send_delimiter,
                             strlen(at._send_delimiter), at._timeout)) != 0)
#endif
    {
        LOGE(MODULE_NAME, "uart send delimiter failed");
        goto end;
    }
    LOGD(MODULE_NAME, "Sending delimiter %s", at._send_delimiter);

    if ((ret = aos_sem_wait(&tsk->smpr, TASK_DEFAULT_WAIT_TIME)) != 0) {
        LOGD(MODULE_NAME, "sem_wait failed");
        goto end;
    }

    LOGD(MODULE_NAME, "sem_wait succeed.");

end:
    at_worker_task_del(tsk);
    return ret;
}
Exemplo n.º 14
0
int _write( int file, char *ptr, int len )
{
  hal_uart_send(&uart_0, ptr, len, 0xFFFFFFFF);
  return len;
}
Exemplo n.º 15
0
int stdio_hardfault( char* data, uint32_t size )
{
  hal_uart_send(&uart_0, data, size, 1000);
  return 0;
}
Exemplo n.º 16
0
int32_t aos_uart_send(void *data, uint32_t size, uint32_t timeout)
{
    return hal_uart_send(&uart_0, data, size, timeout);
}