Exemple #1
0
void mutex_buf_queue_coopr_test(void)
{
    kstat_t ret;

    krhino_mutex_dyn_create(&test_mutex, "mutextest");
    krhino_buf_queue_create(&test_buf_queue, "bugqueue", (void *)buf_queue_test_buf,
                            8, 1);

    ret = krhino_task_dyn_create(&task_mutex, MODULE_NAME, 0, TASK_COMB_PRI,
                                 0, TASK_TEST_STACK_SIZE, task_mutex_opr_entry, 1);
    if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
        test_case_fail++;
        PRINT_RESULT(MODULE_NAME, FAIL);
    }

    ret = krhino_task_dyn_create(&task_buf_queue, MODULE_NAME, 0, TASK_COMB_PRI + 1,
                                 0, TASK_TEST_STACK_SIZE, task_buf_queue_entry, 1);
    if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
        test_case_fail++;
        PRINT_RESULT(MODULE_NAME, FAIL);
    }

    ret = krhino_task_dyn_create(&task_buf_queue_trigger, MODULE_NAME, 0,
                                 TASK_COMB_PRI + 2,
                                 0, TASK_TEST_STACK_SIZE, task_buf_queue_trigger_entry, 1);
    if ((ret != RHINO_SUCCESS) && (ret != RHINO_STOPPED)) {
        test_case_fail++;
        PRINT_RESULT(MODULE_NAME, FAIL);
    }
}
Exemple #2
0
static void task_queue0_entry(void *arg)
{
    kstat_t ret;

    while (1) {
        ret = krhino_buf_queue_create(&g_test_bufqueue0, "test_bufqueue0",
                                      g_test_bufqueue_buf0,
                                      TEST_BUFQUEUE_BUF0_SIZE, TEST_BUFQUEUE_MSG_MAX);
        BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);

        /* check krhino_buf_queue_flush param */
        buf_queue_flush_param_test();

        ret = krhino_buf_queue_send(&g_test_bufqueue0, g_test_send_msg0,
                                    TEST_BUFQUEUE_MSG_MAX);
        BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);

        ret = krhino_buf_queue_send(&g_test_bufqueue0, g_test_send_msg0,
                                    TEST_BUFQUEUE_MSG_MAX);
        BUFQUEUE_VAL_CHK(ret == RHINO_BUF_QUEUE_FULL);

        ret = krhino_buf_queue_flush(&g_test_bufqueue0);
        BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);

        ret = krhino_buf_queue_send(&g_test_bufqueue0, g_test_send_msg0,
                                    TEST_BUFQUEUE_MSG_MAX);
        BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);

        ret = krhino_buf_queue_del(&g_test_bufqueue0);
        BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);

        if (test_case_check_err == 0) {
            test_case_success++;
            PRINT_RESULT("buf queue flush", PASS);
        } else {
            test_case_check_err = 0;
            test_case_fail++;
            PRINT_RESULT("buf queue flush", FAIL);
        }

        next_test_case_notify();
        krhino_task_dyn_del(task_0_test);
    }
}
Exemple #3
0
int aos_queue_new(aos_queue_t *queue, void *buf, unsigned int size, int max_msg)
{
    kstat_t       ret;
    kbuf_queue_t *q;

    if ((queue == NULL) || (buf == NULL)) {
        return -EINVAL;
    }

    q = aos_malloc(sizeof(kbuf_queue_t));
    if (q == NULL) {
        return -ENOMEM;
    }

    ret = krhino_buf_queue_create(q, "AOS", buf, size, max_msg);
    if (ret != RHINO_SUCCESS) {
        aos_free(q);
        ERRNO_MAPPING(ret);
    }

    queue->hdl = q;

    return 0;
}
Exemple #4
0
static void task_queue0_entry(void *arg)
{
    kstat_t ret;
    size_t  size;
    int     count = 0;
    size_t  msg;

    /* err param test */
    ret = krhino_buf_queue_create(&g_test_bufqueue0, "test_bufqueue0",
                                  (void *)g_test_bufqueue_buf0,
                                  TEST_BUFQUEUE_BUF0_SIZE, 0);

    BUFQUEUE_VAL_CHK(ret == RHINO_INV_PARAM);

    ret = krhino_buf_queue_create(&g_test_bufqueue0, "test_bufqueue0",
                                  (void *)g_test_bufqueue_buf0,
                                  TEST_BUFQUEUE_BUF0_SIZE, TEST_BUFQUEUE_MSG_MAX);

    BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);

    ret = krhino_fix_buf_queue_create(&g_test_bufqueue1, "test_bufqueue1",
                                      (void *)g_test_bufqueue_buf1, sizeof(size_t), 2);

    BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);

    msg = 0x11;
    ret = krhino_buf_queue_send(&g_test_bufqueue1, &msg, sizeof(size_t));
    BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);

    ret = krhino_buf_queue_send(&g_test_bufqueue1, &msg, sizeof(size_t));
    BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);

    ret = krhino_buf_queue_send(&g_test_bufqueue1, &msg, sizeof(size_t));
    BUFQUEUE_VAL_CHK(ret == RHINO_BUF_QUEUE_FULL);

    (void)krhino_buf_queue_recv(&g_test_bufqueue1, RHINO_NO_WAIT, &msg, &size);
    (void)krhino_buf_queue_recv(&g_test_bufqueue1, RHINO_NO_WAIT, &msg, &size);

    ret = krhino_buf_queue_recv(&g_test_bufqueue1, 1, &msg, &size);
    BUFQUEUE_VAL_CHK(ret == RHINO_BLK_TIMEOUT);

    /* check krhino_buf_queue_recv */
    buf_queue_recv_param_test();

    buf_queue_send_param_test();

    /* check RHINO_NO_WAIT */
    ret = krhino_buf_queue_recv(&g_test_bufqueue0, RHINO_NO_WAIT, &g_test_recv_msg0,
                                &size);
    BUFQUEUE_VAL_CHK(ret == RHINO_NO_PEND_WAIT);

    /* check sched disalbe */
    ret = krhino_sched_disable();
    BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);
    ret = krhino_buf_queue_recv(&g_test_bufqueue0, RHINO_WAIT_FOREVER,
                                &g_test_recv_msg0, &size);
    BUFQUEUE_VAL_CHK(ret == RHINO_SCHED_DISABLE);
    ret = krhino_sched_enable();
    BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);

    ret = krhino_task_dyn_create(&task_1_test, "task_bufqueue1_test", 0,
                                 TEST_BUFQUEUE_SND_TASK_LOW_RPI,
                                 0, TASK_TEST_STACK_SIZE, task_queue1_entry, 1);

    BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);

    do {
        ret = krhino_buf_queue_recv(&g_test_bufqueue0, RHINO_WAIT_FOREVER,
                                    g_test_recv_msg0, &size);
        BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);

        memset(g_test_send_msg0, send_char[count], TEST_BUFQUEUE_MSG_MAX);
        ret = memcmp(g_test_send_msg0, g_test_recv_msg0, size);
        count ++;
    } while (count <  TEST_BUFQUEUE_MSG_NUM);


    ret = krhino_task_dyn_create(&task_2_test, "task_bufqueue2_test", 0,
                                 TEST_BUFQUEUE_SND_TASK_HIGH_RPI,
                                 0, TASK_TEST_STACK_SIZE, task_queue2_entry, 1);

    BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);

    krhino_task_sleep(RHINO_CONFIG_TICKS_PER_SECOND / 10);

    count = 0;

    do {
        ret = krhino_buf_queue_recv(&g_test_bufqueue0, RHINO_WAIT_FOREVER,
                                    g_test_recv_msg0, &size);
        BUFQUEUE_VAL_CHK(ret == RHINO_SUCCESS);

        memset(g_test_send_msg1, send_char[count], TEST_BUFQUEUE_MSG_MAX);
        ret = memcmp(g_test_send_msg1, g_test_recv_msg0, size);
        count ++;
    } while (count <  TEST_BUFQUEUE_MSG_NUM);


    if (test_case_check_err == 0) {
        test_case_success++;
        PRINT_RESULT("buf queue recv", PASS);
    } else {
        test_case_check_err = 0;
        test_case_fail++;
        PRINT_RESULT("buf queue recv", FAIL);
    }

    next_test_case_notify();
    krhino_task_dyn_del(task_0_test);
}
Exemple #5
0
/**
 * \brief Initialize usart interface
 */
int32_t usart_os_init(struct usart_os_descriptor *const descr, void *const hw, uint8_t *rx_buffer,
                      uint16_t rx_buffer_length, void *const func)
{
	int32_t rc;
	ASSERT(descr && hw && rx_buffer && rx_buffer_length);

	if (ERR_NONE != ringbuffer_init(&descr->rx, rx_buffer, rx_buffer_length)) {
		return ERR_INVALID_ARG;
	}

	descr->kbuf_data = aos_malloc(MAX_BUF_UART_BYTES);
	if (descr->kbuf_data == NULL) {
		return -1;
	}
	memset(descr->kbuf_data, 0, MAX_BUF_UART_BYTES);
	rc = krhino_buf_queue_create(&descr->kbuf, "buf_queue_uart", descr->kbuf_data, MAX_BUF_UART_BYTES, 1);
        
	rc = sem_init(&descr->rx_sem, 0);
	if (rc < 0) {
		return rc;
	}
	rc = sem_init(&descr->tx_sem, 0);
	if (rc < 0) {
		sem_deinit(&descr->rx_sem);
		return rc;
	}
	rc = aos_mutex_new(&descr->rx_mutex);
	if (rc < 0) {
		sem_deinit(&descr->rx_sem);
		sem_deinit(&descr->tx_sem);
		return rc;
	}
	rc = aos_mutex_new(&descr->tx_mutex);
	if (rc < 0) {
		sem_deinit(&descr->rx_sem);
		sem_deinit(&descr->tx_sem);
		aos_mutex_free(&descr->rx_mutex);
		return rc;
	}
	descr->sync_device.hw = hw;
	rc = _usart_async_init(&descr->device, hw);

	if (rc) {
		sem_deinit(&descr->tx_sem);
		sem_deinit(&descr->rx_sem);
		aos_mutex_free(&descr->rx_mutex);
		aos_mutex_free(&descr->tx_mutex);
		return rc;
	}

	descr->rx_buffer = NULL;
	descr->rx_size   = 0;
	descr->rx_length = 0;

	descr->io.read  = usart_async_read;
	descr->io.write = usart_sync_write;

	descr->device.usart_cb.tx_byte_sent = usart_os_process_byte_sent;
	descr->device.usart_cb.rx_done_cb   = usart_fill_rx_buffer;
	descr->device.usart_cb.tx_done_cb   = usart_os_transmission_complete;
	descr->device.usart_cb.error_cb     = usart_os_error;
	_usart_async_set_irq_state(&descr->device, USART_ASYNC_RX_DONE, true);
	_usart_async_set_irq_state(&descr->device, USART_ASYNC_ERROR, true);

	return ERR_NONE;
}