Esempio n. 1
0
/***********************************************************************************************************************
* Function Name: R_MTU_Close
* Description  : Removes power to the MTU channel designated by the handle and disables the associated interrupts.
* Arguments    : : channel-
*                   The channel number
* Return Value : MTU_SUCCESS-
*                    Successful; channel closed
*                MTU_TIMERS_ERR_CH_NOT_OPEN-
*                    The channel has not been opened so closing has no effect.
*                MTU_TIMERS_ERR_BAD_CHAN-
*                    Channel number is invalid for part
***********************************************************************************************************************/
mtu_err_t  R_MTU_Close(mtu_channel_t  channel)
{
    #if MTU_CFG_PARAM_CHECKING_ENABLE == 1
    if (MTU_CHANNEL_MAX <= channel)           // First check for channel number out of range
    {
        return MTU_ERR_BAD_CHAN;
    }
    #endif

    /* Check to see if the channel is currently initialized. */
    if (!g_mtu_channel_mode[channel])
    {
        /* This channel is not open so need not be closed. */
        return MTU_ERR_CH_NOT_OPENED;
    }

    /* Stop any current operation. */
    R_MTU_Control((mtu_channel_t)channel, MTU_CMD_STOP, FIT_NO_PTR);

    mtu_interrupts_disable(channel);

    g_mtu_channel_mode[channel] = MTU_MODE_CLOSED;
    g_num_channels_in_use--;

    /* Shut down the MTU unit if this was the last channel in use. */
    if (0 == g_num_channels_in_use)
    {
            power_on_off(MTU_POWER_OFF);
    }

    /* Clear all control flags arrays for this channel. */
    g_mtu_channel_repeats[channel] = 0;
    g_mtu_channel_clr_src[channel] = 0;

    g_mtu_tgi_icu_en_flags[channel][MTU_TIMER_A] = 0;
    g_mtu_tgi_icu_en_flags[channel][MTU_TIMER_B] = 0;
    g_mtu_tgi_icu_en_flags[channel][MTU_TIMER_C] = 0;
    g_mtu_tgi_icu_en_flags[channel][MTU_TIMER_D] = 0;

    g_mtu_tgr_callbacks[channel][MTU_TIMER_A] = 0;
    g_mtu_tgr_callbacks[channel][MTU_TIMER_B] = 0;
    g_mtu_tgr_callbacks[channel][MTU_TIMER_C] = 0;
    g_mtu_tgr_callbacks[channel][MTU_TIMER_D] = 0;

    return MTU_SUCCESS;
}
Esempio n. 2
0
File: mtk.c Progetto: semafor/ofono
static void mtk_set_online(struct ofono_modem *modem, ofono_bool_t online,
				ofono_modem_online_cb_t callback, void *data)
{
	struct mtk_data *md = ofono_modem_get_data(modem);
	struct cb_data *cbd = cb_data_new(callback, data, modem);
	ofono_modem_online_cb_t cb = cbd->cb;
	int current_state, next_state;

	/*
	 * Serialize online requests to avoid incoherent states. When changing
	 * the online state of *one* of the modems, we need to send a
	 * DUAL_SIM_MODE_SWITCH request, which affects *both* modems. Also, when
	 * we want to online one modem and at that time both modems are
	 * offline a RADIO_POWERON needs to be sent before DUAL_SIM_MODE_SWITCH,
	 * with the additional complexity of being disconnected from the rild
	 * socket while doing the sequence. This can take some time, and we
	 * cannot change the state of the other modem while the sequence is
	 * happenig, as DUAL_SIM_MODE_SWITCH affects both states. Therefore, we
	 * need to do this serialization, which is different from the one done
	 * per modem by ofono core.
	 */
	if (mtk_data_0->pending_cb != NULL) {
		md->pending_online_cbd = cbd;
		md->pending_online = online;
		return;
	}

	current_state = sim_state();

	md->ofono_online = online;

	/* Changes as md points to either mtk_data_0 or mtk_data_1 variables */
	next_state = sim_state();

	DBG("setting md_%d->ofono_online to: %d (from %d to %d)",
		md->slot, online, current_state, next_state);

	if (current_state == next_state) {
		CALLBACK_WITH_SUCCESS(cb, cbd->data);
		g_free(cbd);
		return;
	}

	/* Reset mtk_data variables */
	if (online == FALSE)
		md->sim_status_retries = 0;

	if (current_state == NO_SIM_ACTIVE) {
		/* Old state was off, need to power on the modem */
		if (power_on_off(mtk_data_0->ril, TRUE, cbd)) {
			/* Socket might disconnect... failsafe */
			mtk_data_0->pending_cb = poweron_disconnect;
			mtk_data_0->pending_cbd = cbd;
		}
	} else if (next_state == NO_SIM_ACTIVE) {
		/* Disconnection expected for dual SIM only */
		if (power_on_off(mtk_data_0->ril, FALSE, cbd)
				&& mtk_data_1 != NULL)
			disconnect_expected = TRUE;
	} else {
		mtk_send_sim_mode(mtk_sim_mode_cb, cbd);
	}
}