Exemplo n.º 1
0
static void storaged_release() {
    DEBUG_FUNCTION;

    if (storaged_storages) {
        storage_t *st = storaged_storages;
        while (st != storaged_storages + storaged_nrstorages)
            storage_release(st++);
        free(storaged_storages);
        storaged_nrstorages = 0;
        storaged_storages = 0;
    }
}
Exemplo n.º 2
0
int main(int argc, char **argv) {
    storage_t st;
    sid_t sid = 0;
    sstat_t sst;
    fid_t fid;
    //bin_t *bins;

    rozofs_initialize(LAYOUT_2_3_4);
    storage_initialize(&st, sid, "/tmp");

    if (storage_stat(&st, &sst) != 0) {
        perror("failed to stat storage");
        exit(-1);
    }
    printf("size: %" PRIu64 ", free: %" PRIu64 "\n", sst.size, sst.free);

    uuid_generate(fid);
    // Write some bins (15 prj)
    //bins = xmalloc(rozofs_psizes[0] * 15);
/*
    if (storage_write(&st, fid, 0, 10, 15, bins) != 0) {
        perror("failed to write bins");
        exit(-1);
    }
*/

    if (storage_truncate(&st, fid, 0, 10) != 0) {
        perror("failed to truncate pfile");
        exit(-1);
    }

    if (storage_rm_file(&st, fid) != 0) {
        perror("failed to remove pfile");
        exit(-1);
    }

    storage_release(&st);
    exit(0);
}
Exemplo n.º 3
0
/**
 * \brief BLE manager task
 */
static void ble_mgr_task(void *pvParameters)
{
        ad_ble_hdr_t *msg_rx;
        uint32_t ulNotifiedValue;
        OS_BASE_TYPE xResult;
        int8_t wdog_id;

        /* Register task to be monitored by watch dog. */
        wdog_id = sys_watchdog_register(false);

        for (;;) {
                /* Notify watch dog on each loop since there's no other trigger for this. */
                sys_watchdog_notify(wdog_id);

                /* Suspend monitoring while task is blocked on OS_TASK_NOTIFY_WAIT(). */
                sys_watchdog_suspend(wdog_id);

                /*
                 * Wait on any of the event group bits, then clear them all.
                 */
                xResult = OS_TASK_NOTIFY_WAIT(0x0, OS_TASK_NOTIFY_ALL_BITS, &ulNotifiedValue,
                                                                            OS_TASK_NOTIFY_FOREVER);
                OS_ASSERT(xResult == OS_OK);

                /* Resume watch dog monitoring. */
                sys_watchdog_notify_and_resume(wdog_id);

                if (ulNotifiedValue & mainBIT_ADAPTER_EVENT_QUEUE) {
                        /* Make sure there are messages waiting on the queue. */
                        if (!uxQueueMessagesWaiting(adapter_if->evt_q)) {
                                goto no_event;
                        }

                        /* Check if there is free space on BLE manager's event queue. */
                        if (uxQueueSpacesAvailable(mgr_if.evt_q)) {
                                /* Get message from queue. */
                                OS_QUEUE_GET(adapter_if->evt_q, &msg_rx, 0);
                                OS_ASSERT(msg_rx->op_code < AD_BLE_OP_CODE_LAST);

#ifdef BLE_STACK_PASSTHROUGH_MODE
                                {
                                        OS_IRB new_irb;

                                        /* Fill-in new IRB fields. */
                                        new_irb.status   = IRB_PENDING;
                                        new_irb.class_id = IRB_BLE;
                                        new_irb.ptr_buf  = msg_rx;

                                        /* Send directly to BLE manager's event queue. */
                                        ble_mgr_event_queue_send(&new_irb, OS_QUEUE_FOREVER);
                                }
#else

                                if (msg_rx->op_code == AD_BLE_OP_CODE_STACK_MSG) {
                                        irb_ble_stack_msg_t *stack_msg =
                                                                      (irb_ble_stack_msg_t*) msg_rx;

                                        /* In non-passthrough we only expect GTL messages. */
                                        OS_ASSERT(stack_msg->msg_type == GTL_MSG);

                                        /*
                                         * during reset we ignore messages other than GAPM_CMP_EVT
                                         * and GAPM_RESET operation
                                         */
                                        if (reset) {
                                                struct gapm_cmp_evt *evt;

                                                if (stack_msg->msg.gtl.msg_id != GAPM_CMP_EVT) {
                                                        goto rx_done;
                                                }

                                                evt = (void *) stack_msg->msg.gtl.param;

                                                if (evt->operation != GAPM_RESET) {
                                                        goto rx_done;
                                                }
                                        }

                                        /*
                                         * Check if someone is waiting for this message.
                                         * if not, try to handle message as an event.
                                         */
                                        if (!ble_gtl_waitqueue_match(&stack_msg->msg.gtl)) {
                                                if (!ble_gtl_handle_event(&stack_msg->msg.gtl)) {
                                                        /* Stack message is not handled by the manager. */
#ifdef DEBUG
                                                        configASSERT(0);
#endif
                                                }
                                        }
                                }
                                else if (msg_rx->op_code == AD_BLE_OP_CODE_ADAPTER_MSG) {
                                        ad_ble_msg_t *ad_msg = (ad_ble_msg_t *) msg_rx;

                                        /* In non-passthrough we only expect GTL messages. */
                                        OS_ASSERT(ad_msg->operation < AD_BLE_OP_LAST);

                                        /* Check if someone is waiting for this message. */
                                        ble_ad_msg_waitqueue_match(ad_msg);

                                }

rx_done:
                                OS_FREE(msg_rx);
#endif
                                /*
                                 * Check if there are more messages waiting in the BLE adapter's
                                 * event queue.
                                 */
                                if (uxQueueMessagesWaiting(adapter_if->evt_q)) {
                                        OS_TASK_NOTIFY(mgr_if.task,
                                                mainBIT_ADAPTER_EVENT_QUEUE, OS_NOTIFY_SET_BITS);
                                }
                        }
                        else {
                                /* Set blocked flag to true. */
                                ble_mgr_blocked = true;
                        }
                }
no_event:
                if (ulNotifiedValue & mainBIT_MANAGER_COMMAND_QUEUE) {
                        if (uxQueueMessagesWaiting(mgr_if.cmd_q)) {
                                OS_IRB irb_rx;

                                /* Get IRB from the queue. */
                                OS_QUEUE_GET(mgr_if.cmd_q, &irb_rx, 0);

                                if (irb_rx.status == IRB_COMPLETED) {
                                        /* Free message buffer if it was not freed by application. */
                                        irb_ble_free_msg(&irb_rx);
                                }
                                else if (irb_rx.status == IRB_ERROR) {
                                        ble_mgr_event_queue_send(&irb_rx, OS_QUEUE_FOREVER);
                                }
                                else if (irb_rx.status == IRB_PENDING) {
                                        /* New IRB from application. */
                                        if (!ble_irb_handle_msg(&irb_rx)) {
                                                /*
                                                 * No handler found for IRB - free command buffer
                                                 * because nothing else will free it.
                                                 */
                                                OS_FREE(irb_rx.ptr_buf);
                                                irb_rx.ptr_buf = NULL;
                                        }
                                }

                                /* Check if blocked and if there is space on the event queue. */
                                if (ble_mgr_blocked && uxQueueSpacesAvailable(mgr_if.evt_q)) {
                                        /* Set flag to false. */
                                        ble_mgr_blocked = false;

                                        /* Notify task to resume getting BLE adapter events. */
                                        OS_TASK_NOTIFY(mgr_if.task, mainBIT_ADAPTER_EVENT_QUEUE,
                                                OS_NOTIFY_SET_BITS);
                                }

                                /* Check if there are messages waiting in the command queue. */
                                if (uxQueueMessagesWaiting(mgr_if.cmd_q)) {
                                        OS_TASK_NOTIFY(mgr_if.task,
                                                mainBIT_MANAGER_COMMAND_QUEUE, OS_NOTIFY_SET_BITS);
                                }
                        }
                }

                /*
                 * Check this bit as last one since previous commands may also update storage. In
                 * such case changes will be written to flash already and there's no need to execute
                 * this twice in a row.
                 */
                if (ulNotifiedValue & mainBIT_COMMIT_STORAGE) {
                        /*
                         * To commit anything modified in storage it's enough to acquire and then
                         * immediately release lock - if dirty flag was set, contents of storage
                         * will be written to flash automatically.
                         */
                        storage_acquire();
                        storage_release();
                }

                /* Check if BLE adapter is blocked and if there is free space on its event queue. */
                if (ble_mgr_adapter_is_blocked() && uxQueueSpacesAvailable(adapter_if->evt_q)) {
                        /* Notify BLE adapter that there is free space on its event queue. */
                        ad_ble_notify_event_queue_avail();
                }
        }
}