Exemplo n.º 1
0
static void delay_ms(uint32_t ms)
{
	int timeout = get_uptime_32k() + 32 * ms;

	while (get_uptime_32k() < timeout)
		;
}
Exemplo n.º 2
0
static void delay_us(uint32_t us)
{
	int timeout = get_uptime_32k() + (us + 30) / 30;

	while (get_uptime_32k() < timeout)
		;
}
Exemplo n.º 3
0
void qrk_aonpt_start(void)
{
	MMIO_REG_VAL_FROM_BASE(SCSS_REGISTER_BASE, SCSS_AONPT_CTRL) =
		(AONPT_CLR | AONPT_RST);
	volatile uint32_t time = get_uptime_32k();
	while(get_uptime_32k() - time < 5);
	MMIO_REG_VAL_FROM_BASE(SCSS_REGISTER_BASE, SCSS_AONPT_STAT);
}
Exemplo n.º 4
0
void qrk_aonpt_stop(void)
{
	uint32_t flags = interrupt_lock();
	MMIO_REG_VAL_FROM_BASE(SCSS_REGISTER_BASE, SCSS_AONPT_CFG) = 0;
	MMIO_REG_VAL_FROM_BASE(SCSS_REGISTER_BASE, SCSS_AONPT_CTRL) = (AONPT_CLR | AONPT_RST);
	volatile uint32_t time = get_uptime_32k();
	while(get_uptime_32k() - time < 5);
	interrupt_unlock(flags);
}
Exemplo n.º 5
0
BleStatus ble_client_init(ble_client_gap_event_cb_t gap_event_cb, void *gap_event_param,
                          ble_client_gatts_event_cb_t gatts_event_cb, void *gatts_event_param)
{
    BleStatus status;
    uint32_t delay_until;

    cfw_platform_nordic_init();

    client_handle = cfw_init(cfw_get_service_queue(),
                             ble_core_client_handle_message,
                             NULL);

    sync.response = 0;
    if (cfw_register_svc_available(client_handle,
                                   BLE_CORE_SERVICE_ID,
                                   NULL))
        return BLE_STATUS_ERROR;

    /* Wait for response messages */
    wait_for_condition(sync.response, status);
    if (status != BLE_STATUS_SUCCESS)
        return status;

    /* We need to wait for ~1 ms before continuing */
    delay_until = get_uptime_32k() + TIMEOUT_TICKS_1MS;
    while (get_uptime_32k() < delay_until);

    sync.response = 0;
    cfw_open_service(client_handle,
                     BLE_CORE_SERVICE_ID,
                     NULL);

    /* Wait for response messages */
    wait_for_condition(sync.response, status);
    if (status != BLE_STATUS_SUCCESS)
        return status;

    ble_client_gap_event_cb = gap_event_cb;
    ble_client_gap_event_param = gap_event_param;

    ble_client_gatts_event_cb = gatts_event_cb;
    ble_client_gatts_event_param = gatts_event_param;

    return sync.status;
}
Exemplo n.º 6
0
void poll_usb(void)
{
	static uint32_t date = 0;
	uint32_t new_date;
	uint32_t elapsed;

	new_date = get_uptime_32k();
	if (new_date > date) {
		elapsed = new_date - date;
	} else {
		elapsed = new_date + (INT32_MAX - date);
	}
	if (elapsed > 32) {
		usb_ISR();
		date = new_date;
	}
}
Exemplo n.º 7
0
static void wait_ticks(uint32_t ticks)
{
	uint32_t start = get_uptime_32k();

	while ((get_uptime_32k() - start) < ticks) ;
}