Example #1
0
/**
 * @brief Protocol exit function.
 *
 * This function can be called when protocol terminated.
 *
 * @param operation The pointer to structure of gb_operation.
 * @return None.
 */
static void gb_uart_exit(unsigned int cport)
{
    device_uart_attach_ls_callback(info->dev, NULL);

    device_uart_attach_ms_callback(info->dev, NULL);

    device_close(info->dev);

    uart_receiver_cb_deinit();

    uart_status_cb_deinit();

    free(info);
}
Example #2
0
/**
 * @brief Protocol exit function.
 *
 * This function can be called when protocol terminated.
 *
 * @param cport CPort number
 * @param bundle Greybus bundle handle
 * @return None.
 */
static void gb_uart_exit(unsigned int cport, struct gb_bundle *bundle)
{
    struct gb_uart_info *info;

    DEBUGASSERT(bundle);
    info = bundle->priv;

    if (!info)
        return;

    device_uart_attach_ls_callback(bundle->dev, NULL, NULL);

    device_uart_attach_ms_callback(bundle->dev, NULL, NULL);

    uart_receiver_cb_deinit(info);

    uart_status_cb_deinit(info);

    device_close(bundle->dev);
    bundle->dev = NULL;

    free(info);
}
Example #3
0
/**
 * @brief Protocol initialization function.
 *
 * This function perform the protocto initialization function, such as open
 * the cooperation device driver, launch threads, create buffers etc.
 *
 * @param cport CPort number
 * @param bundle Greybus bundle handle
 * @return GB_OP_SUCCESS on success, error code on failure.
 */
static int gb_uart_init(unsigned int cport, struct gb_bundle *bundle)
{
    struct gb_uart_info *info;
    int ret;
    uint8_t ms = 0, ls = 0;

    info = zalloc(sizeof(*info));
    if (info == NULL) {
        return -ENOMEM;
    }

    bundle->priv = info;

    gb_debug("%s(): GB uart info struct: 0x%p \n", __func__, info);

    info->cport = cport;

    bundle->dev = device_open(DEVICE_TYPE_UART_HW, 0);
    if (!bundle->dev) {
        ret = -ENODEV;
        goto err_device_close;
    }

    ret = uart_status_cb_init(info);
     if (ret) {
        goto err_device_close;
     }

    ret = uart_receiver_cb_init(bundle);
    if (ret) {
        goto err_status_cb_deinit;
     }

    /* update serial status */
    ret = device_uart_get_modem_status(bundle->dev, &ms);
    if (ret) {
        goto err_receiver_cb_deinit;
    }

    ret = device_uart_get_line_status(bundle->dev, &ls);
    if (ret) {
        goto err_receiver_cb_deinit;
    }

    info->last_serial_state = parse_ms_ls_registers(ms, ls);

    ret = device_uart_attach_ms_callback(bundle->dev, uart_ms_callback, info);
    if (ret) {
        goto err_receiver_cb_deinit;
    }

    ret = device_uart_attach_ls_callback(bundle->dev, uart_ls_callback, info);
    if (ret) {
        goto err_clr_ms_callback;
    }

    /* trigger the first receiving */
    info->require_node = 1;
    sem_post(&info->rx_sem);

    return 0;

err_clr_ms_callback:
    device_uart_attach_ms_callback(bundle->dev, NULL, info);
err_receiver_cb_deinit:
    uart_receiver_cb_deinit(info);
err_status_cb_deinit:
    uart_status_cb_deinit(info);
err_device_close:
    device_close(bundle->dev);
    bundle->priv = NULL;
    bundle->dev = NULL;
    free(info);
    return ret;
}