示例#1
0
文件: loras.c 项目: alexeyk13/rexos
static void loras_timer_poll_timeout(LORA* lora)
{
    int last_error;
#if (LORA_DEBUG)
    uint32_t duration_ms;
    ++lora->polls_cnt;
#endif

    if (lora->status != LORA_STATUS_TRANSFER_IN_PROGRESS)
    {
        loras_fatal(lora);
#if (LORA_DEBUG)
        printf("[loras] [fatal error] unexpected status %d => server closed\n", lora->status);
#endif
        return;
    }

    (lora->tx ? loras_hw_tx_async_wait : loras_hw_rx_async_wait)(lora);

    last_error = get_last_error();

#if (LORA_DEBUG)
    //check for internal unexpected errors (ex. ERROR_INVALID_STATE -- chip is in invalid state)
    if (!(last_error >= ERROR_OK || last_error == ERROR_TIMEOUT))
    {
        loras_fatal(lora);
        printf("[loras] [fatal error] unexpected error %d => server closed\n", last_error);
        return;
    }
#endif

    switch (lora->status)
    {
    case LORA_STATUS_TRANSFER_IN_PROGRESS:
        timer_start_ms(lora->timer_poll_timeout, LORA_POLL_TIMEOUT_MS);
        //note: do not check if last_error == ERROR_OK (should be)
        ipc_post_inline(lora->process, HAL_CMD(HAL_LORA, LORA_TRANSFER_IN_PROGRESS), 0, 0, last_error);
        break;
    case LORA_STATUS_TRANSFER_COMPLETED:
        timer_stop(lora->timer_txrx_timeout, 0, HAL_LORA);
#if (LORA_DEBUG)
        duration_ms = loras_get_uptime_ms() - lora->transfer_in_progress_ms;
        printf("[loras] [info] poll completed duration_ms:%u polls_cnt:%u\n", duration_ms, lora->polls_cnt);
#endif
        ipc_post_inline(lora->process, HAL_CMD(HAL_LORA, LORA_TRANSFER_COMPLETED), 0, 0, last_error);
        break;
    default:
        error(ERROR_NOT_SUPPORTED);
        break;
    }
}
示例#2
0
文件: loras.c 项目: alexeyk13/rexos
static void loras_timer_txrx_timeout(LORA* lora)
{
    if (lora->status != LORA_STATUS_TRANSFER_IN_PROGRESS)
    {
        loras_fatal(lora);
#if (LORA_DEBUG)
        printf("[loras] [fatal error] unexpected status %d => server closed\n", lora->status);
#endif
        return;
    }
#if (LORA_DEBUG)
    printf("[loras] [info] timer_txrx_timeout expired -> transfer completed\n");
#endif
    timer_stop(lora->timer_poll_timeout, 0, HAL_LORA);
    if (lora->tx || !LORA_CONTINUOUS_RECEPTION_ON)
        loras_hw_sleep(lora);
#if (LORA_DO_ERROR_COUNTING)
    lora->tx ? ++lora->stats_tx.timeout_num : ++lora->stats_rx.timeout_num;
#endif
    lora->status = LORA_STATUS_TRANSFER_COMPLETED;
    ipc_post_inline(lora->process, HAL_CMD(HAL_LORA, LORA_TRANSFER_COMPLETED), 0, 0, ERROR_TIMEOUT);
}
示例#3
0
static void icmps_echo_complete(TCPIPS* tcpips, int err)
{
    ipc_post_inline(tcpips->icmps.process, HAL_CMD(HAL_ICMP, ICMP_PING), tcpips->icmps.echo_ip.u32.ip, err == ERROR_OK ? 0 : INVALID_HANDLE, err);
    tcpips->icmps.process = INVALID_HANDLE;
}
示例#4
0
static inline void lpc_sdmmc_io(CORE* core, HANDLE process, HANDLE user, IO* io, unsigned int size, bool read)
{
    SHA1_CTX sha1;
    unsigned int count;
    STORAGE_STACK* stack = io_stack(io);
    io_pop(io, sizeof(STORAGE_STACK));
    if (!core->sdmmc.active)
    {
        error(ERROR_NOT_CONFIGURED);
        return;
    }
    if (core->sdmmc.state != SDMMC_STATE_IDLE)
    {
        error(ERROR_IN_PROGRESS);
        return;
    }
    if ((user != core->sdmmc.user) || (size == 0))
    {
        error(ERROR_INVALID_PARAMS);
        return;
    }
    //erase
    if (!read && ((stack->flags & STORAGE_MASK_MODE) == 0))
    {
        sdmmcs_erase(&core->sdmmc.sdmmcs, stack->sector, size);
        return;
    }
    if (size % core->sdmmc.sdmmcs.sector_size)
    {
        error(ERROR_INVALID_PARAMS);
        return;
    }
    count = size / core->sdmmc.sdmmcs.sector_size;
    core->sdmmc.total = size;
    if (core->sdmmc.total > LPC_SDMMC_TOTAL_SIZE)
    {
        error(ERROR_INVALID_PARAMS);
        return;
    }
    if ((core->sdmmc.activity != INVALID_HANDLE) && !(stack->flags & STORAGE_FLAG_IGNORE_ACTIVITY_ON_REQUEST))
    {
        ipc_post_inline(core->sdmmc.activity, HAL_CMD(HAL_SDMMC, STORAGE_NOTIFY_ACTIVITY), core->sdmmc.user, read ? 0 : STORAGE_FLAG_WRITE, 0);
        core->sdmmc.activity = INVALID_HANDLE;
    }
    core->sdmmc.io = io;
    core->sdmmc.process = process;

    lpc_sdmmc_prepare_descriptors(core);

    if (read)
    {
        io->data_size = 0;
        core->sdmmc.state = SDMMC_STATE_READ;
        if (sdmmcs_read(&core->sdmmc.sdmmcs, stack->sector, count))
            error(ERROR_SYNC);
    }
    else
    {
        switch (stack->flags & STORAGE_MASK_MODE)
        {
        case STORAGE_FLAG_WRITE:
            core->sdmmc.state = SDMMC_STATE_WRITE;
            if (sdmmcs_write(&core->sdmmc.sdmmcs, stack->sector, count))
                error(ERROR_SYNC);
            break;
        default:
            //verify/verify write
            sha1_init(&sha1);
            sha1_update(&sha1, io_data(io), core->sdmmc.total);
            sha1_final(&sha1, core->sdmmc.hash);
            core->sdmmc.sector = stack->sector;
            switch (stack->flags & STORAGE_MASK_MODE)
            {
            case STORAGE_FLAG_VERIFY:
                core->sdmmc.state = SDMMC_STATE_VERIFY;
                if (sdmmcs_read(&core->sdmmc.sdmmcs, stack->sector, count))
                    error(ERROR_SYNC);
                break;
            case (STORAGE_FLAG_VERIFY | STORAGE_FLAG_WRITE):
                core->sdmmc.state = SDMMC_STATE_WRITE_VERIFY;
                if (sdmmcs_write(&core->sdmmc.sdmmcs, stack->sector, count))
                    error(ERROR_SYNC);
                break;
            default:
                error(ERROR_NOT_SUPPORTED);
                return;
            }
        }
    }
}