Ejemplo n.º 1
0
__interrupt void PORT1(void)
{
	if (P1IFG & TASTE_LINKS) {
		BIT_CLR(P1IFG, TASTE_LINKS);
		LED_ON(LED_ROT);
		
		SHT11_Read_Sensor();
		sprintf(uart_buffer, "%s %s\r\n", temp_char, humi_char);

		// USART konfigurieren		
		BIT_CLR(IFG2, UTXIFG1);	// interrupt flag loeschen
		BIT_CLR(IE2, UTXIE1);	// interrupt ausschaulten
		
		// DMA konfigurieren
		DMA2SZ = strlen(uart_buffer);
		DMA2DA = (unsigned int)&U1TXBUF; // speichere die Addresse des TX Buffers
		DMA2SA = (unsigned int)uart_buffer; // und die von unserem String
		DMACTL0 = DMA2TSEL3 + DMA2TSEL1; // Trigger wenn TX IFG gestezt ist
		// kopiere 1 Byte vom String ins TX Buffer bei jedem Transfer und erhoehe src um eins
		DMA2CTL = DMAEN + DMASRCINCR0 + DMASRCINCR1 + DMADSTBYTE + DMASRCBYTE;

		// Bescheid sagen, wenn der Transfer fertig ist
		BIT_CLR(DMA2CTL, DMAIFG);
		DMA2CTL += DMAIE;
		//Port 1.2 fuer die Messung anschalten
		BIT_SET(P1OUT, BIT2);
		BIT_SET(IFG2, UTXIFG1); // starte den ersten Transfer
	}
}
Ejemplo n.º 2
0
/* ---------- 受光モジュールからの信号 ---------- */
IR_RCV_INT()
{
  if (ctx.state == IDLE) {
    DM_SIG_INT_DISABLE();
    OUTPUT_MODE(DM_SIG_PIN);
    BIT_SET(RE_LED_PIN);
    ctx.state = RECV;
  }
  if (BIT_READ(IR_RCV_PIN) != 0) {
    BIT_SET(DM_SIG_PIN);
  } else {
    BIT_CLR(DM_SIG_PIN);
  }
  ctx.count++;
  if (ctx.count >= 36) {
    ctx.count = 0;
    BIT_SET(DM_SIG_PIN);
    INPUT_MODE(DM_SIG_PIN);
    BIT_CLR(RE_LED_PIN);
    ctx.state = IDLE;
    _delay_us(500);
    DM_SIG_INT_FLG_CLR();
    DM_SIG_INT_ENABLE();
  }
}
Ejemplo n.º 3
0
__interrupt void DMA(void)
{
	// ISR aufgerufen, wenn der Transfer fertig ist
	if (DMA2CTL & DMAIFG) {
		//Der Port wird nach der Messung ausgeschaltet
		BIT_CLR(P1OUT, BIT2);
		BIT_CLR(DMA2CTL, DMAIFG);
		// Lampe ausmachen, wir sind fertig
		LED_OFF(LED_ROT);		
	}
}
Ejemplo n.º 4
0
static int do_sethook(xpd_t *xpd, int pos, bool to_offhook)
{
	unsigned long		flags;
	xbus_t			*xbus;
	struct FXO_priv_data	*priv;
	int			ret = 0;
	byte			value;

	BUG_ON(!xpd);
	BUG_ON(xpd->direction == TO_PHONE);		// We can SETHOOK state only on PSTN
	xbus = xpd->xbus;
	priv = xpd->priv;
	BUG_ON(!priv);
	if(priv->battery[pos] != BATTERY_ON && to_offhook) {
		LINE_NOTICE(xpd, pos, "Cannot take offhook while battery is off!\n");
		return -EINVAL;
	}
	spin_lock_irqsave(&xpd->lock, flags);
	mark_ring(xpd, pos, 0, 0);				// No more rings
	value = REG_DAA_CONTROL1_ONHM;				/* Bit 3 is for CID */
	if(to_offhook)
		value |= REG_DAA_CONTROL1_OH;
	LINE_DBG(SIGNAL, xpd, pos, "SETHOOK: value=0x%02X %s\n", value, (to_offhook)?"OFFHOOK":"ONHOOK");
	if(to_offhook)
		MARK_ON(priv, pos, LED_GREEN);
	else
		MARK_OFF(priv, pos, LED_GREEN);
	ret = DAA_DIRECT_REQUEST(xbus, xpd, pos, DAA_WRITE, REG_DAA_CONTROL1, value);
	if(to_offhook) {
		BIT_SET(xpd->offhook, pos);
	} else {
		BIT_CLR(xpd->offhook, pos);
	}
	if(caller_id_style != CID_STYLE_PASS_ALWAYS) {
		LINE_DBG(SIGNAL, xpd, pos, "Caller-ID PCM: off\n");
		BIT_CLR(xpd->cid_on, pos);
	}
#ifdef	WITH_METERING
	priv->metering_count[pos] = 0;
	priv->metering_tone_state = 0L;
	DAA_DIRECT_REQUEST(xbus, xpd, pos, DAA_WRITE, DAA_REG_METERING, 0x2D);
#endif
	reset_battery_readings(xpd, pos);	/* unstable during hook changes */
	priv->power_denial_safezone[pos] = (to_offhook) ? POWER_DENIAL_SAFEZONE : 0;
	if(!to_offhook)
		priv->power[pos] = POWER_UNKNOWN;
	spin_unlock_irqrestore(&xpd->lock, flags);
	return ret;
}
Ejemplo n.º 5
0
static void shift_byte(u8 byte)
{
  for (u8 i = 0; i < 8; i++) {
    // Decide whether to shift high or low.
    (byte & (1 << 7)) ? BIT_SET(SHIFT_PORT, SHIFT_SER)
                      : BIT_CLR(SHIFT_PORT, SHIFT_SER);

    // Now shift out that bit with a pulse on SCK.
    BIT_CLR(SHIFT_PORT, SHIFT_SCK);
    BIT_SET(SHIFT_PORT, SHIFT_SCK);

    // Move on the next bit.
    byte <<= 1;
  }
}
Ejemplo n.º 6
0
AJ_Status AJS_TargetIO_PinEnableTrigger(void* pinCtx, AJS_IO_PinTriggerMode trigger, int32_t* trigId, uint8_t debounce)
{
    GPIO* gpio = (GPIO*)pinCtx;

    if ((trigger != AJS_IO_PIN_TRIGGER_ON_RISE) && (trigger != AJS_IO_PIN_TRIGGER_ON_FALL)) {
        /*
         * Disable triggers for this pin
         */
        if (gpio->trigId != AJS_IO_PIN_NO_TRIGGER) {
            SendCmd('i', gpio, 0, 0);
            *trigId = gpio->trigId;
            BIT_CLR(trigSet, gpio->trigId);
            gpio->trigId = AJS_IO_PIN_NO_TRIGGER;
        } else {
            *trigId = AJS_IO_PIN_NO_TRIGGER;
        }
        return AJ_OK;
    }
    SendCmd('i', gpio, (trigger == AJS_IO_PIN_TRIGGER_ON_RISE) ? 1 : 2, 0);
    gpio->trigId = gpio->pinId;
    *trigId = gpio->trigId;

    AJ_ErrPrintf(("AJS_TargetIO_PinEnableTrigger pinId %d\n", gpio->pinId));
    return AJ_OK;
}
Ejemplo n.º 7
0
/*
 * LED control is done via DAA register 0x20
 */
static int do_led(xpd_t *xpd, lineno_t chan, __u8 which, bool on)
{
	int ret = 0;
	struct FXO_priv_data *priv;
	xbus_t *xbus;
	__u8 value;

	BUG_ON(!xpd);
	xbus = xpd->xbus;
	priv = xpd->priv;
	which = which % NUM_LEDS;
	if (IS_SET(PHONEDEV(xpd).digital_outputs, chan)
	    || IS_SET(PHONEDEV(xpd).digital_inputs, chan))
		goto out;
	if (chan == PORT_BROADCAST) {
		priv->ledstate[which] = (on) ? ~0 : 0;
	} else {
		if (on)
			BIT_SET(priv->ledstate[which], chan);
		else
			BIT_CLR(priv->ledstate[which], chan);
	}
	value = 0;
	value |= ((BIT(5) | BIT(6) | BIT(7)) & ~led_register_mask[which]);
	value |= (on) ? BIT(0) : 0;
	value |= (on) ? BIT(1) : 0;
	LINE_DBG(LEDS, xpd, chan, "LED: which=%d -- %s\n", which,
		 (on) ? "on" : "off");
	ret = DAA_DIRECT_REQUEST(xbus, xpd, chan, DAA_WRITE, 0x20, value);
out:
	return ret;
}
Ejemplo n.º 8
0
__interrupt void PORT1(void)
{
	if (P1IFG & TASTE_LINKS) {
		BIT_CLR(P1IFG, TASTE_LINKS);
		print_buf("Hallo World\r\n");		
	}
}
Ejemplo n.º 9
0
static void update_dahdi_ring(xpd_t *xpd, int pos, bool on)
{
	dahdi_rxsig_t	rxsig;

	BUG_ON(!xpd);
	if(on) {
		if(caller_id_style == CID_STYLE_BELL) {
			LINE_DBG(SIGNAL, xpd, pos, "Caller-ID PCM: off\n");
			BIT_CLR(xpd->cid_on, pos);
		}
		rxsig = DAHDI_RXSIG_RING;
	} else {
		if(caller_id_style == CID_STYLE_BELL) {
			LINE_DBG(SIGNAL, xpd, pos, "Caller-ID PCM: on\n");
			BIT_SET(xpd->cid_on, pos);
		}
		rxsig = DAHDI_RXSIG_OFFHOOK;
	}
	pcm_recompute(xpd, 0);
	/*
	 * We should not spinlock before calling dahdi_hooksig() as
	 * it may call back into our xpp_hooksig() and cause
	 * a nested spinlock scenario
	 */
	if(SPAN_REGISTERED(xpd))
		dahdi_hooksig(&xpd->chans[pos], rxsig);
}
Ejemplo n.º 10
0
void _ISR_NOPSV _T1Interrupt(void)
{
    BIT_CLR(IFS0, TMR1_INT);        // Clear Timer1 interrupt flag

    BIT_SET(_sysTick, SYSTICK_1MS); // 1 ms

    if (++_tick[SYSTICK_10MS] > 10U)
    {
        BIT_SET(_sysTick, SYSTICK_10MS);    // 10 ms
        _tick[SYSTICK_10MS] = 0;

        if (++_tick[SYSTICK_100MS] > 10U)
        {
            BIT_SET(_sysTick, SYSTICK_100MS);   // 100 ms
            _tick[SYSTICK_100MS] = 0;

            if (++_tick[SYSTICK_1000MS] > 10U)
            {
                BIT_SET(_sysTick, SYSTICK_1000MS);  // 1000 ms
                BIT_TGL(LATA, 4);
                _tick[SYSTICK_1000MS] = 0;
            }
        }
    }
}
Ejemplo n.º 11
0
Archivo: chattr.c Proyecto: lufb/code
static void
judge_ttr(struct chattr_opt *op, unsigned int *attr)
{
#define I_OFFSET   4
#define A_OFFSET   5
    if(op->a == ADD_OPTION)
        BIT_SET(*attr, A_OFFSET);
    if(op->i == ADD_OPTION)
        BIT_SET(*attr, I_OFFSET);

    if(op->a == DEL_OPTION)
        BIT_CLR(*attr, A_OFFSET);
    if(op->i == DEL_OPTION)
        BIT_CLR(*attr, I_OFFSET);
#undef A_OFFSET
#undef I_OFFSET
}
Ejemplo n.º 12
0
void hp98x5_io_sys_device::set_irq(uint8_t sc , int state)
{
	if (state) {
		BIT_SET(m_irq_pending, sc);
	} else {
		BIT_CLR(m_irq_pending, sc);
	}
	update_irq();
}
Ejemplo n.º 13
0
/* stop the stopwatch, and return the time */
u32 timer_stop(void)
{
	/* stop the timer */
	BIT_CLR(TIMER32(TMRCONTROL), RUN);
	/* get access to counter */
	BIT_SET(TIMER32(TMRCONTROL), LDCNT);

	return TIMER32(TMRCOUNT);
}
Ejemplo n.º 14
0
void hp98x5_io_sys_device::set_dmar(uint8_t sc , int state)
{
	if (state) {
		BIT_SET(m_dmar_status, sc);
	} else {
		BIT_CLR(m_dmar_status, sc);
	}
	update_dmar();
}
Ejemplo n.º 15
0
static void reset_battery_readings(xpd_t *xpd, lineno_t pos)
{
	struct FXO_priv_data	*priv = xpd->priv;

	priv->nobattery_debounce[pos] = 0;
	priv->power_denial_debounce[pos] = 0;
	priv->power_denial_delay[pos] = 0;
	BIT_CLR(priv->maybe_power_denial, pos);
}
Ejemplo n.º 16
0
void hp_nanoprocessor_device::execute_set_input(int linenum, int state)
{
	if (linenum == 0) {
		if (state) {
			BIT_SET(m_flags, NANO_I_BIT);
		} else {
			BIT_CLR(m_flags, NANO_I_BIT);
		}
	}
}
Ejemplo n.º 17
0
static void lh7a40xuart_break_ctl (struct uart_port* port, int break_state)
{
	unsigned long flags;

	spin_lock_irqsave(&port->lock, flags);
	if (break_state == -1)
		BIT_SET (port, UART_R_FCON, BRK); /* Assert break */
	else
		BIT_CLR (port, UART_R_FCON, BRK); /* Deassert break */
	spin_unlock_irqrestore(&port->lock, flags);
}
Ejemplo n.º 18
0
/* start the stopwatch */
void timer_start(void)
{
	/* make sure the timer is stopped */
	BIT_CLR(TIMER32(TMRCONTROL), RUN);

	/* zero out the timer */
	TIMER32(TMRCOUNT) = 0;

	/* run the timer */
	BIT_SET(TIMER32(TMRCONTROL), RUN);
}
Ejemplo n.º 19
0
void hp98x5_io_sys_device::set_sts(uint8_t sc , int state)
{
	if (state) {
		BIT_SET(m_sts_status, sc);
	} else {
		BIT_CLR(m_sts_status, sc);
	}
	if (sc == m_pa) {
		update_flg_sts();
	}
}
Ejemplo n.º 20
0
/* ---------- main ---------- */
int main(void)
{
  ctx.state = IDLE;
  ctx.count = 0;
  ctx.timeout = 0;
  DDRB  = (1<<GR_LED_PIN) | (1<<RE_LED_PIN);
  PORTB = (1<<DM_SIG_PIN) | (1<<IR_RCV_PIN); // プルアップ
  MCUCR = (1<<ISC00); // 論理変化割り込み
  PCMSK = (1<<DM_SIG_PIN);
  GIMSK = (1<<INT0) | (1<<PCIE);
  TCCR0A = (1<<COM0A0) | (1<<WGM01) | (1<<WGM00);
  TCCR0B = (1<<WGM02) | (1<<CS00);
  OCR0A = 126; // 38kHz
  _delay_ms(500); // 受光モジュールが安定するまで待機
  sei();

  while (1) {
    _delay_us(1000);
    if (ctx.state == IDLE) {
      ctx.timeout = 200;
    } else {
      ctx.timeout--;
    }
    if (ctx.timeout == 0) {
      cli();
      ctx.state = IDLE;
      ctx.count = 0;
      BIT_CLR(GR_LED_PIN);
      BIT_CLR(RE_LED_PIN);
      BIT_SET(DM_SIG_PIN);
      INPUT_MODE(DM_SIG_PIN);
      IR_LED_OFF();
      IR_RCV_INT_FLG_CLR();
      DM_SIG_INT_FLG_CLR();
      IR_RCV_INT_ENABLE();
      DM_SIG_INT_ENABLE();
      sei();
    }
  }
  return 0;
}
Ejemplo n.º 21
0
__interrupt void USART1RX(void)
{
    char c = U1RXBUF;
    BIT_CLR(IFG2, URXIFG1);

    if (c == 'E')
        LED_ON(LED_GELB);
    else if (c == 'A')
        LED_OFF(LED_GELB);
    else if (c == '\r')
        LED_TOGGLE(LED_GRUEN);
}
Ejemplo n.º 22
0
void tmr_poll_start(u16 val)
{
	/* make sure the timer is stopped */
	BIT_CLR(TIMER32(TMRCONTROL), RUN);

	/* zero out the timer */
	TIMER32(TMRCOUNT) = 0;

	/* run the timer */
	BIT_SET(TIMER32(TMRCONTROL), RUN);
	
	value = val;
}
Ejemplo n.º 23
0
int32_t AJS_TargetIO_PinTrigId(uint32_t* level)
{
    if (trigSet == 0) {
        return AJS_IO_PIN_NO_TRIGGER;
    } else {
        static uint32_t id = 0;
        while (!BIT_IS_SET(trigSet, id % MAX_TRIGGERS)) {
            ++id;
        }
        BIT_CLR(trigSet, id % MAX_TRIGGERS);
        return (id % MAX_TRIGGERS);
    }
}
Ejemplo n.º 24
0
int moloch_http_curl_close_callback(void *serverV, curl_socket_t fd)
{
    MolochHttpServer_t        *server = serverV;

    if (! BIT_ISSET(fd, connectionsSet)) {
        LOG("Couldn't connect %s defaultPort: %d", server->names[0], server->defaultPort);
        return 0;
    }

    struct sockaddr_in localAddress, remoteAddress;
    memset(&localAddress, 0, sizeof(localAddress));
    memset(&remoteAddress, 0, sizeof(localAddress));

    socklen_t addressLength = sizeof(localAddress);
    getsockname(fd, (struct sockaddr*)&localAddress, &addressLength);
    addressLength = sizeof(remoteAddress);
    getpeername(fd, (struct sockaddr*)&remoteAddress, &addressLength);

    char sessionId[MOLOCH_SESSIONID_LEN];

    moloch_session_id(sessionId, localAddress.sin_addr.s_addr, localAddress.sin_port,
                      remoteAddress.sin_addr.s_addr, remoteAddress.sin_port);

    MolochHttpConn_t *conn;
    BIT_CLR(fd, connectionsSet);

    MOLOCH_LOCK(connections);
    HASH_FIND(h_, connections, sessionId, conn);
    if (conn) {
        HASH_REMOVE(h_, connections, conn);
        MOLOCH_TYPE_FREE(MolochHttpConn_t, conn);
    }
    MOLOCH_UNLOCK(connections);

    server->connections--;

    LOG("Close %d/%d - %s   %d->%s:%d fd:%d", 
            server->outstanding,
            server->connections,
            server->names[0],
            ntohs(localAddress.sin_port),
            inet_ntoa(remoteAddress.sin_addr),
            ntohs(remoteAddress.sin_port),
            fd);

    close (fd);
    return 0;
}
Ejemplo n.º 25
0
static void refresh_display(void)
{
  static u8 i;

  // First shift enables only one column.
  shift_byte(~(0b00000001 << i));
  // Second shift for column data.
  shift_byte(matrix[i]);

  // Pulse to move everything to output.
  BIT_CLR(SHIFT_PORT, SHIFT_RCK);
  BIT_SET(SHIFT_PORT, SHIFT_RCK);

  // Increase i with each cycle, but don't let it get bigger than 7.
  i = (i + 1) % 7;
}
Ejemplo n.º 26
0
/*
 * Die in case of unrecoverable error.  On LF1000, we pull the power off. 
 * Otherwise just lock up. 
 */
static void die(void)
{
	db_puts("die()\n");
#ifdef CPU_LF1000
	/* enable access to Alive GPIO */
	REG32(LF1000_ALIVE_BASE+ALIVEPWRGATEREG) = 1;
	/* pull VDDPWRON low by resetting the flip-flop */
	BIT_CLR(REG32(LF1000_ALIVE_BASE+ALIVEGPIOSETREG), VDDPWRONSET);
	BIT_SET(REG32(LF1000_ALIVE_BASE+ALIVEGPIORSTREG), VDDPWRONSET);
	/* reset flip-flop to latch in */
	REG32(LF1000_ALIVE_BASE+ALIVEGPIOSETREG) = 0;
	REG32(LF1000_ALIVE_BASE+ALIVEGPIORSTREG) = 0;
	/* power should be off now... */
#endif
	while(1);
}
Ejemplo n.º 27
0
int32_t AJS_TargetIO_PinTrigId(uint32_t* level)
{
    if (trigSet == 0) {
        return AJS_IO_PIN_NO_TRIGGER;
    } else {
        /*
         * This is static so triggers are returned round-robin to ensure fairness
         */
        static uint32_t id = 0;
        while (!BIT_IS_SET(trigSet, id % MAX_TRIGGERS)) {
            ++id;
        }
        BIT_CLR(trigSet, id % MAX_TRIGGERS);
        return (id % MAX_TRIGGERS);
    }
}
Ejemplo n.º 28
0
u8 tmr_poll_has_expired(void)
{
   BIT_CLR(TIMER32(TMRCONTROL), RUN);
   BIT_SET(TIMER32(TMRCONTROL), LDCNT);
   u32 timer = TIMER32(TMRCOUNT);
   //db_puts("TIMER:");db_int (timer);db_puts(" ");
   //db_puts("VALUE:");db_int (value * 8197);db_puts("\n");
   BIT_SET(TIMER32(TMRCONTROL), RUN);
   
	if (timer >= (value * 8197))
		return 1;
		
	else
		return 0;
		
}
Ejemplo n.º 29
0
void ReportKeycodeAction(u8 keycode, bool add) {
  u8 index;

  if (IsModifier(keycode)) {
    index = 0;
  } else {
    // Add one to skip the modifier byte.
    index = 1 + (keycode / 8);
  }

  u8 nth_bit = (keycode % 8);

  if (add)
    BIT_SET(report_data[index], nth_bit);
  else
    BIT_CLR(report_data[index], nth_bit);

  changed = true;
}
Ejemplo n.º 30
0
__interrupt void PORT1(void)
{
	if (P1IFG & BIT6) {
		// linker Taster gedrueckt -> wert erniedrigen
		if (P1IN & TASTE_LINKS) {
			wert--;
		// rechter Taster gedrueckt -> wert erhoen
		} else if (P1IN & TASTE_RECHTS) {
			wert++;
		// keiner gedrueckt -> gelb aus, solange gedrueckt ist
		} else {
			LED_TOGGLE(LED_GELB);
			while (!(P1IN & BIT_YM)) {
			}
		}

		print_value();
		BIT_CLR(P1IFG, BIT6);
	}
}