예제 #1
0
static void
state_handler(hfcusb_data * hfc, __u8 state)
{
	__u8 old_state;

	old_state = hfc->l1_state;
	if (state == old_state || state < 1 || state > 8)
		return;

#ifdef CONFIG_HISAX_DEBUG
	DBG(ISDN_DBG, "HFC-S USB: new S0 state:%d old_state:%d", state,
	    old_state);
#endif
	if (state < 4 || state == 7 || state == 8) {
		if (timer_pending(&hfc->t3_timer))
			del_timer(&hfc->t3_timer);
#ifdef CONFIG_HISAX_DEBUG
		DBG(ISDN_DBG, "HFC-S USB: T3 deactivated");
#endif
	}
	if (state >= 7) {
		if (timer_pending(&hfc->t4_timer))
			del_timer(&hfc->t4_timer);
#ifdef CONFIG_HISAX_DEBUG
		DBG(ISDN_DBG, "HFC-S USB: T4 deactivated");
#endif
	}

	if (state == 7 && !hfc->l1_activated) {
		hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,
				   PH_ACTIVATE | INDICATION, NULL);
#ifdef CONFIG_HISAX_DEBUG
		DBG(ISDN_DBG, "HFC-S USB: PH_ACTIVATE | INDICATION sent");
#endif
		hfc->l1_activated = true;
		handle_led(hfc, LED_S0_ON);
	} else if (state <= 3 /* && activated */ ) {
		if (old_state == 7 || old_state == 8) {
#ifdef CONFIG_HISAX_DEBUG
			DBG(ISDN_DBG, "HFC-S USB: T4 activated");
#endif
			if (!timer_pending(&hfc->t4_timer)) {
				hfc->t4_timer.expires =
				    jiffies + (HFC_TIMER_T4 * HZ) / 1000;
				add_timer(&hfc->t4_timer);
			}
		} else {
			hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,
					   PH_DEACTIVATE | INDICATION,
					   NULL);
#ifdef CONFIG_HISAX_DEBUG
			DBG(ISDN_DBG,
			    "HFC-S USB: PH_DEACTIVATE | INDICATION sent");
#endif
			hfc->l1_activated = false;
			handle_led(hfc, LED_S0_OFF);
		}
	}
	hfc->l1_state = state;
}
예제 #2
0
static void
ph_state_nt(struct dchannel *dch)
{
	struct hfcsusb *hw = dch->hw;

	if (debug & DEBUG_HW) {
		if (dch->state <= HFC_MAX_NT_LAYER1_STATE)
			printk(KERN_DEBUG "%s: %s: %s\n",
			       hw->name, __func__,
			       HFC_NT_LAYER1_STATES[dch->state]);

		else
			printk(KERN_INFO DRIVER_NAME "%s: %s: NT G%d\n",
			       hw->name, __func__, dch->state);
	}

	switch (dch->state) {
	case (1):
		test_and_clear_bit(FLG_ACTIVE, &dch->Flags);
		test_and_clear_bit(FLG_L2_ACTIVATED, &dch->Flags);
		hw->nt_timer = 0;
		hw->timers &= ~NT_ACTIVATION_TIMER;
		handle_led(hw, LED_S0_OFF);
		break;

	case (2):
		if (hw->nt_timer < 0) {
			hw->nt_timer = 0;
			hw->timers &= ~NT_ACTIVATION_TIMER;
			hfcsusb_ph_command(dch->hw, HFC_L1_DEACTIVATE_NT);
		} else {
			hw->timers |= NT_ACTIVATION_TIMER;
			hw->nt_timer = NT_T1_COUNT;
			
			write_reg(hw, HFCUSB_STATES, 2 | HFCUSB_NT_G2_G3);
		}
		break;
	case (3):
		hw->nt_timer = 0;
		hw->timers &= ~NT_ACTIVATION_TIMER;
		test_and_set_bit(FLG_ACTIVE, &dch->Flags);
		_queue_data(&dch->dev.D, PH_ACTIVATE_IND,
			    MISDN_ID_ANY, 0, NULL, GFP_ATOMIC);
		handle_led(hw, LED_S0_ON);
		break;
	case (4):
		hw->nt_timer = 0;
		hw->timers &= ~NT_ACTIVATION_TIMER;
		break;
	default:
		break;
	}
	hfcsusb_ph_info(hw);
}
예제 #3
0
/* S0 state changed */
static void
s0_state_handler(hfcusb_data *hfc, __u8 state)
{
	__u8 old_state;

	old_state = hfc->l1_state;
	if (state == old_state || state < 1 || state > 8)
		return;

	DBG(HFCUSB_DBG_STATES, "HFC-S USB: S0 statechange(%d -> %d)",
	    old_state, state);

	if (state < 4 || state == 7 || state == 8) {
		if (timer_pending(&hfc->t3_timer))
			del_timer(&hfc->t3_timer);
		DBG(HFCUSB_DBG_STATES, "HFC-S USB: T3 deactivated");
	}
	if (state >= 7) {
		if (timer_pending(&hfc->t4_timer))
			del_timer(&hfc->t4_timer);
		DBG(HFCUSB_DBG_STATES, "HFC-S USB: T4 deactivated");
	}

	if (state == 7 && !hfc->l1_activated) {
		hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,
				   PH_ACTIVATE | INDICATION, NULL);
		DBG(HFCUSB_DBG_STATES, "HFC-S USB: PH_ACTIVATE | INDICATION sent");
		hfc->l1_activated = 1;
		handle_led(hfc, LED_S0_ON);
	} else if (state <= 3 /* && activated */) {
		if (old_state == 7 || old_state == 8) {
			DBG(HFCUSB_DBG_STATES, "HFC-S USB: T4 activated");
			if (!timer_pending(&hfc->t4_timer)) {
				hfc->t4_timer.expires =
					jiffies + (HFC_TIMER_T4 * HZ) / 1000;
				add_timer(&hfc->t4_timer);
			}
		} else {
			hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,
					   PH_DEACTIVATE | INDICATION,
					   NULL);
			DBG(HFCUSB_DBG_STATES,
			    "HFC-S USB: PH_DEACTIVATE | INDICATION sent");
			hfc->l1_activated = 0;
			handle_led(hfc, LED_S0_OFF);
		}
	}
	hfc->l1_state = state;
}
예제 #4
0
파일: main.c 프로젝트: Nazrax/Blinky-Clock
int main(void) {
  init();
  alarm_init();
  clock_init();
  display_init();

  sei();

  for(;;) {
    clock_update();
    buttons_update();

    handle_buttons();
    handle_display();
    handle_led();

    buttons_age();
    clock_ticked = false;

    // Check display timeout
    if (mode != mode_off || status != status_none || !clock_set) { // Need the main clock
      set_sleep_mode(SLEEP_MODE_IDLE);
    } else {
      set_sleep_mode(SLEEP_MODE_PWR_SAVE);
    }
    sleep_enable();
    sleep_cpu();
    sleep_disable();
  }
}
예제 #5
0
/* ISDN l1 timer T4 expires */
static void
l1_timer_expire_t4(hfcusb_data *hfc)
{
	hfc->d_if.ifc.l1l2(&hfc->d_if.ifc, PH_DEACTIVATE | INDICATION,
			   NULL);

	DBG(HFCUSB_DBG_STATES,
	    "HFC-S USB: PH_DEACTIVATE | INDICATION sent (T4 expire)");

	hfc->l1_activated = 0;
	handle_led(hfc, LED_S0_OFF);
}
예제 #6
0
static void
l1_timer_expire_t4(hfcusb_data * hfc)
{
	hfc->d_if.ifc.l1l2(&hfc->d_if.ifc, PH_DEACTIVATE | INDICATION,
			   NULL);
#ifdef CONFIG_HISAX_DEBUG
	DBG(ISDN_DBG,
	    "HFC-S USB: PH_DEACTIVATE | INDICATION sent (T4 expire)");
#endif
	hfc->l1_activated = false;
	handle_led(hfc, LED_S0_OFF);
}
예제 #7
0
static void
ph_state_te(struct dchannel *dch)
{
	struct hfcsusb *hw = dch->hw;

	if (debug & DEBUG_HW) {
		if (dch->state <= HFC_MAX_TE_LAYER1_STATE)
			printk(KERN_DEBUG "%s: %s: %s\n", hw->name, __func__,
			       HFC_TE_LAYER1_STATES[dch->state]);
		else
			printk(KERN_DEBUG "%s: %s: TE F%d\n",
			       hw->name, __func__, dch->state);
	}

	switch (dch->state) {
	case 0:
		l1_event(dch->l1, HW_RESET_IND);
		break;
	case 3:
		l1_event(dch->l1, HW_DEACT_IND);
		break;
	case 5:
	case 8:
		l1_event(dch->l1, ANYSIGNAL);
		break;
	case 6:
		l1_event(dch->l1, INFO2);
		break;
	case 7:
		l1_event(dch->l1, INFO4_P8);
		break;
	}
	if (dch->state == 7)
		handle_led(hw, LED_S0_ON);
	else
		handle_led(hw, LED_S0_OFF);
}
예제 #8
0
static int
hfc_dctrl(struct mISDNchannel *ch, u_int cmd, void *arg)
{
	struct mISDNdevice	*dev = container_of(ch, struct mISDNdevice, D);
	struct dchannel		*dch = container_of(dev, struct dchannel, dev);
	struct hfcsusb		*hw = dch->hw;
	struct channel_req	*rq;
	int			err = 0;

	if (dch->debug & DEBUG_HW)
		printk(KERN_DEBUG "%s: %s: cmd:%x %p\n",
		       hw->name, __func__, cmd, arg);
	switch (cmd) {
	case OPEN_CHANNEL:
		rq = arg;
		if ((rq->protocol == ISDN_P_TE_S0) ||
		    (rq->protocol == ISDN_P_NT_S0))
			err = open_dchannel(hw, ch, rq);
		else
			err = open_bchannel(hw, rq);
		if (!err)
			hw->open++;
		break;
	case CLOSE_CHANNEL:
		hw->open--;
		if (debug & DEBUG_HW_OPEN)
			printk(KERN_DEBUG
			       "%s: %s: dev(%d) close from %p (open %d)\n",
			       hw->name, __func__, hw->dch.dev.id,
			       __builtin_return_address(0), hw->open);
		if (!hw->open) {
			hfcsusb_stop_endpoint(hw, HFC_CHAN_D);
			if (hw->fifos[HFCUSB_PCM_RX].pipe)
				hfcsusb_stop_endpoint(hw, HFC_CHAN_E);
			handle_led(hw, LED_POWER_ON);
		}
		module_put(THIS_MODULE);
		break;
	case CONTROL_CHANNEL:
		err = channel_ctrl(hw, arg);
		break;
	default:
		if (dch->debug & DEBUG_HW)
			printk(KERN_DEBUG "%s: %s: unknown command %x\n",
			       hw->name, __func__, cmd);
		return -EINVAL;
	}
	return err;
}
예제 #9
0
/* ISDN l1 timer T3 expires */
static void
l1_timer_expire_t3(hfcusb_data *hfc)
{
	hfc->d_if.ifc.l1l2(&hfc->d_if.ifc, PH_DEACTIVATE | INDICATION,
			   NULL);

	DBG(HFCUSB_DBG_STATES,
	    "HFC-S USB: PH_DEACTIVATE | INDICATION sent (T3 expire)");

	hfc->l1_activated = 0;
	handle_led(hfc, LED_S0_OFF);
	/* deactivate : */
	queue_control_request(hfc, HFCUSB_STATES, 0x10, 1);
	queue_control_request(hfc, HFCUSB_STATES, 3, 1);
}
예제 #10
0
static void
l1_timer_expire_t3(hfcusb_data * hfc)
{
	hfc->d_if.ifc.l1l2(&hfc->d_if.ifc, PH_DEACTIVATE | INDICATION,
			   NULL);
#ifdef CONFIG_HISAX_DEBUG
	DBG(ISDN_DBG,
	    "HFC-S USB: PH_DEACTIVATE | INDICATION sent (T3 expire)");
#endif
	hfc->l1_activated = false;
	handle_led(hfc, LED_S0_OFF);
	/* deactivate : */
	queue_control_request(hfc, HFCUSB_STATES, 0x10, 1);
	queue_control_request(hfc, HFCUSB_STATES, 3, 1);
}
void status_led_timer_handler(uint32_t current_time)
{
	handle_led(&status_led_state, current_time);
	if (current_time < LED_STARTUP_TIME)
	{
		if (!status_led_state.current_pin_state)
		{
			status_led_state.current_pin_state = true;
			set_status_led_pin(true);
		}
	}
	else if (status_led_state.current_pin_state != status_led_state.is_on)
	{
		status_led_state.current_pin_state = status_led_state.is_on;
		set_status_led_pin(status_led_state.is_on);
	}

}
예제 #12
0
static int
hfcsusb_setup_bch(struct bchannel *bch, int protocol)
{
	struct hfcsusb *hw = bch->hw;
	__u8 conhdlc, sctrl, sctrl_r;

	if (debug & DEBUG_HW)
		printk(KERN_DEBUG "%s: %s: protocol %x-->%x B%d\n",
		       hw->name, __func__, bch->state, protocol,
		       bch->nr);

	
	conhdlc = 0;
	if (protocol > ISDN_P_NONE)
		conhdlc = 8;	

	switch (protocol) {
	case (-1):	
		bch->state = -1;
		
	case (ISDN_P_NONE):
		if (bch->state == ISDN_P_NONE)
			return 0; 
		bch->state = ISDN_P_NONE;
		clear_bit(FLG_HDLC, &bch->Flags);
		clear_bit(FLG_TRANSPARENT, &bch->Flags);
		break;
	case (ISDN_P_B_RAW):
		conhdlc |= 2;
		bch->state = protocol;
		set_bit(FLG_TRANSPARENT, &bch->Flags);
		break;
	case (ISDN_P_B_HDLC):
		bch->state = protocol;
		set_bit(FLG_HDLC, &bch->Flags);
		break;
	default:
		if (debug & DEBUG_HW)
			printk(KERN_DEBUG "%s: %s: prot not known %x\n",
			       hw->name, __func__, protocol);
		return -ENOPROTOOPT;
	}

	if (protocol >= ISDN_P_NONE) {
		write_reg(hw, HFCUSB_FIFO, (bch->nr == 1) ? 0 : 2);
		write_reg(hw, HFCUSB_CON_HDLC, conhdlc);
		write_reg(hw, HFCUSB_INC_RES_F, 2);
		write_reg(hw, HFCUSB_FIFO, (bch->nr == 1) ? 1 : 3);
		write_reg(hw, HFCUSB_CON_HDLC, conhdlc);
		write_reg(hw, HFCUSB_INC_RES_F, 2);

		sctrl = 0x40 + ((hw->protocol == ISDN_P_TE_S0) ? 0x00 : 0x04);
		sctrl_r = 0x0;
		if (test_bit(FLG_ACTIVE, &hw->bch[0].Flags)) {
			sctrl |= 1;
			sctrl_r |= 1;
		}
		if (test_bit(FLG_ACTIVE, &hw->bch[1].Flags)) {
			sctrl |= 2;
			sctrl_r |= 2;
		}
		write_reg(hw, HFCUSB_SCTRL, sctrl);
		write_reg(hw, HFCUSB_SCTRL_R, sctrl_r);

		if (protocol > ISDN_P_NONE)
			handle_led(hw, (bch->nr == 1) ? LED_B1_ON : LED_B2_ON);
		else
			handle_led(hw, (bch->nr == 1) ? LED_B1_OFF :
				   LED_B2_OFF);
	}
	hfcsusb_ph_info(hw);
	return 0;
}