Ejemplo n.º 1
0
void leds_tick(void)
{
    leds_counter++;
    if( leds_open_state == LED_ON){
        PIN_SET(LED_OPEN_PIN);
    }else if( leds_open_state == LED_OFF ){
        PIN_CLEAR(LED_OPEN_PIN);
    }else if( leds_open_state == LED_SHORT_FLASH ){
        if( (leds_counter % 1024) < 50 ){
            PIN_SET(LED_OPEN_PIN);
        }else{
            PIN_CLEAR(LED_OPEN_PIN);
        }
    }

}
Ejemplo n.º 2
0
void leds_init(void)
{
    DDR_CONFIG_OUT(LED_OPEN_PIN);
    PIN_SET(LED_OPEN_PIN);
    leds_open_state = LED_OFF;
    leds_counter = 0;
}
Ejemplo n.º 3
0
Archivo: clock.c Proyecto: ETHZ-TEC/LWB
/*---------------------------------------------------------------------------*/
ISR(UNMI, unmi_interrupt)       /* user non-maskable interrupts */
{    
  ENERGEST_ON(ENERGEST_TYPE_CPU);
    
  PIN_SET(LED_ERROR);           /* use PIN_SET instead of LED_ON */
  switch (SYSUNIV) {
    case SYSUNIV_NMIIFG:        /* non-maskable interrupt */
      while(1);
      break;
    case SYSUNIV_OFIFG:         /* oscillator fault */
      WAIT_FOR_OSC();           /* try to clear the fault flag */
      break;
    case SYSUNIV_ACCVIFG:       /* Flash Memory Access Violation */
      /* will be accidentially triggered after flash programming when using
       * a voltage between 2.4 and 2.6V (errata SYS12) */
      while(1);
      break;
    case SYSUNIV_SYSBERRIV:
      while(1);
      break;
    default:
      while(1);
      break;
  }
  PIN_CLR(LED_ERROR);
  
  ENERGEST_OFF(ENERGEST_TYPE_CPU);
}
Ejemplo n.º 4
0
void
dcf77_init(void)
{
  DCFDEBUG("init dcf77\n");
#ifdef DCF1_USE_PON_SUPPORT
  DCFDEBUG("PON\n");
  /* if module needs a peak on PON to enable dcf77 receiver
   * configure pin as output, set low */
  PIN_SET(DCF1_PON);
#endif

#if defined(DCF77_PCINT_PIN)
  DCFDEBUG("configure_pcint\n");
  /* configure */
  dcf77_configure_pcint();
#elif defined(DCF77_INT_PIN)
  DCFDEBUG("HAVE_DCF77_INT\n");
  /* Initialize "real" Interrupt */
  _EIMSK |= _BV(DCF77_INT_PIN);
  _EICRA = (_EICRA & ~DCF77_INT_ISCMASK) | DCF77_INT_ISC;
#else
  DCFDEBUG("Analog Comparator\n");
  // Analog Comparator init
  ACSR |= _BV(ACIE);
#endif

#ifdef DCF1_USE_PON_SUPPORT
  for (uint8_t i = 0; i < 100; i++)
  {
    wdt_kick();
    _delay_ms(10);
  }
  PIN_CLEAR(DCF1_PON);
#endif
}
Ejemplo n.º 5
0
void rc5_send_zero(void)
{
    PIN_SET(RC5_SEND);
    _delay_loop_2(RC5_PULSE);
    PIN_CLEAR(RC5_SEND);
    _delay_loop_2(RC5_PULSE);
}
Ejemplo n.º 6
0
static void dht22_sun5i_write_bit(u8 bit) {
    if (dht22_sun5i_gpio_direction != PIN_DIR_OUT) {
        dht22_sun5i_gpio_direction = PIN_DIR_OUT;
        PIN_DIR(PIN_DIR_OUT);
    }
    PIN_SET(bit);
}
Ejemplo n.º 7
0
void
usb_init(void)
{
#ifdef AUTOSET_USB_ENABLE_PIN_SUPPORT
  PIN_SET(USB_ENABLE);
#endif /* AUTOSET_USB_ENABLE_PIN_SUPPORT */
#ifdef USB_NET_SUPPORT
  usb_net_init();
#endif

#ifdef USB_KEYBOARD_SUPPORT
#endif

#define USB_DDR_CONFIG(pin)  DDR_CHAR( pin ## _PORT) &= ~(_BV((pin ## _PIN)) | _BV(USB_INT_PIN))
#define USB_PORT_CONFIG(pin)  PORT_CHAR( pin ## _PORT) &= ~(_BV((pin ## _PIN)) | _BV(USB_INT_PIN))
  USB_DDR_CONFIG(USB_DMINUS);
  USB_PORT_CONFIG(USB_DMINUS);
#undef USB_DDR_CONFIG
#undef USB_PORT_CONFIG

  uint8_t i;
  /* Reenummerate the device */
  usbDeviceDisconnect();
  for(i = 0; i < 20; i++){  /* 300 ms disconnect */
    _delay_ms(15);
    wdt_kick();
  }
  usbDeviceConnect();

  /* USB Initialize */
  usbInit();
}
Ejemplo n.º 8
0
static void
rfm12_txstart_hard(void)
{
  rfm12_status = RFM12_TX;

#ifdef STATUSLED_RFM12_TX_SUPPORT
  PIN_SET(STATUSLED_RFM12_TX);
#endif

  ACTIVITY_LED_RFM12_TX;

  rfm12_index = 0;

  rfm12_prologue(RFM12_MODULE_IP);
  rfm12_trans(RFM12_CMD_PWRMGT | RFM12_PWRMGT_ET | RFM12_PWRMGT_ES |
              RFM12_PWRMGT_EX);
  rfm12_epilogue();

  /* Force interrupts active no matter what.
   * 
   * If we're forwarding a packet from say Ethernet, uip_buf_unlock won't
   * unlock since there's an active RFM12 transfer, but it'd leave
   * the RFM12 interrupt disabled as well. */
  _uip_buf_lock = 8;
  rfm12_int_enable();
}
Ejemplo n.º 9
0
void buttons_init(void)
{
    DDR_CONFIG_IN(BUTTON_0);
    PIN_SET(BUTTON_0);

    DDR_CONFIG_IN(BUTTON_1);
    PIN_SET(BUTTON_1);

    DDR_CONFIG_IN(BUTTON_2);
    PIN_SET(BUTTON_2);

    buttons_0_counter = 0;
    buttons_1_counter = 0;
    buttons_2_counter = 0;
    buttons_latched_state = 0;
}
Ejemplo n.º 10
0
void leds_init(void)
{
    DDR_CONFIG_OUT(LED1); 
    DDR_CONFIG_OUT(LED2); 
    DDR_CONFIG_OUT(LED3); 
    PIN_SET(LED2);
}
Ejemplo n.º 11
0
void noinline hd44780_hw_init(void)
{
    /* init io pins */
    CTRL_OUTPUT();
#ifdef HAVE_LCDON
    PIN_SET(LCDON);
#endif

    PIN_CLEAR(HD44780_RS);
#ifndef HD44780_MULTIENSUPPORT
    PIN_CLEAR(HD44780_EN1);
#endif
#ifdef HD44780_MULTIENSUPPORT
    PIN_CLEAR(HD44780_EN1);
    PIN_CLEAR(HD44780_EN2);
#endif
#ifdef HAVE_HD44780_RW
    PIN_CLEAR(HD44780_RW);
#endif
    PIN_CLEAR(HD44780_D4);
    PIN_CLEAR(HD44780_D5);
    PIN_CLEAR(HD44780_D6);
    PIN_CLEAR(HD44780_D7);
    DATA_OUTPUT();

#ifdef HD44780_BACKLIGHT_SUPPORT
    PIN_CLEAR(HD44780_BL);
#endif
}
Ejemplo n.º 12
0
uint8_t
modbus_rxstart(uint8_t *data, uint8_t len, int16_t *recv_len) {
#ifdef MODBUS_CLIENT_SUPPORT
  if (data[0] == MODBUS_ADDRESS || data[0] == MODBUS_BROADCAST) {
    modbus_client_process(data, len, recv_len);
    if (data[0] == MODBUS_ADDRESS)
      return 1;
  }
#endif
  if (modbus_data.crc_len != 0) return 0; /* There is an packet on the way */

  /* enable the transmitter */
  PIN_SET(MODBUS_TX);

  modbus_recv_len_ptr = recv_len;

  modbus_data.crc = modbus_crc_calc(data, len);
  modbus_data.crc_len = 2;

  modbus_data.data = data;
  modbus_data.len = len;

  /* Enable the tx interrupt and send the first character */
  modbus_data.sent = 1;
  usart(UCSR,B) |= _BV(usart(TXCIE));
  usart(UDR) = data[0];

  return 1;
}
Ejemplo n.º 13
0
void resync_led_display(void) {
  //Setzt einmal Reset
  cli();
  PIN_SET(LED_RESET); //Reset high
  gzeile = 0;
  PIN_CLEAR(LED_RESET); //Reset lo
  sei();
}
Ejemplo n.º 14
0
void init_led_display(void) {
  /*Setzen der Data Direction Regiser auf Ausgang
  LED_RESET_DDR |= (1<<LED_RESET_PIN);
  LED_SELECT_DDR |= (1<<LED_SELECT_PIN);
  LED_BRIGHT_DDR |= (1<<LED_BRIGHT_PIN);
  LED_RED_DDR |= (1<<LED_RED_PIN);
  LED_GREEN_DDR |= (1<<LED_GREEN_PIN);
  LED_CLOCK_DDR |= (1<<LED_CLOCK_PIN);
  */
  TC2_COUNTER_CURRENT = 0;                    //Timer 2 Resetten
  _TIMSK_TIMER2  |= _BV(TOIE2); //Timer 2 Overflow Interrupt aktiv
  _TCCR2_PRESCALE = _BV(CS21) | _BV(CS20);  //Prescaler = 8 /32
  PIN_SET(LED_RESET);      //LED_RESET_PORT |= (1<<LED_RESET_PIN); //Reset high
  gzeile = 0;                   //beginne mit Zeile 0
  PIN_CLEAR(LED_RESET); //Reset low
  PIN_SET(LED_SELECT);     //LED_SELECT_PORT |= (1<<LED_SELECT_PIN); //Select auf high
}
Ejemplo n.º 15
0
static void switch_channel_multiplex(void)
{
#if FREQCOUNT_CHANNELS > 1
    if (freqcount_current_channel & 0x01)
        PIN_SET(FREQCOUNT_CHANNEL_MULTIPLEX_BIT1);
    else
        PIN_CLEAR(FREQCOUNT_CHANNEL_MULTIPLEX_BIT1);
#endif

#if FREQCOUNT_CHANNELS > 2
    if (freqcount_current_channel & 0x02)
        PIN_SET(FREQCOUNT_CHANNEL_MULTIPLEX_BIT2);
    else
        PIN_CLEAR(FREQCOUNT_CHANNEL_MULTIPLEX_BIT2);
#endif

#if FREQCOUNT_CHANNELS > 4
    if (freqcount_current_channel & 0x04)
        PIN_SET(FREQCOUNT_CHANNEL_MULTIPLEX_BIT3);
    else
        PIN_CLEAR(FREQCOUNT_CHANNEL_MULTIPLEX_BIT3);
#endif

#if FREQCOUNT_CHANNELS > 8
    // we have two 74xx251 multiplexers
    // they are enabled by setting the respective
    // chip select line to low
    // otherwise their output is in high-z
    if (freqcount_current_channel & 0x08)
    {
        // bit 8 set: enable multiplexer ic B
        PIN_SET(FREQCOUNT_CHANNEL_MULTIPLEX_CS_A);
        PIN_CLEAR(FREQCOUNT_CHANNEL_MULTIPLEX_CS_B);
    }
    else
    {
        // bit 8 not set: enable multiplexer ic A
        PIN_CLEAR(FREQCOUNT_CHANNEL_MULTIPLEX_CS_A);
        PIN_SET(FREQCOUNT_CHANNEL_MULTIPLEX_CS_B);
    }
#endif

#if FREQCOUNT_CHANNELS > 16
#error sorry, more than 16 frequency counter channels currently not supported
#endif
}
Ejemplo n.º 16
0
void
bulbdial_clock(uint8_t delay){
  struct clock_datetime_t date;
  clock_current_localtime(&date);
  clear();
  set(0x0001 << (date.sec/5));
  PIN_SET(BULBDIAL_MINUTES);
  for (uint8_t i = delay; i; i--)
    _delay_ms(1);
  PIN_CLEAR(BULBDIAL_MINUTES);
  clear();
  set(0x0001 << (date.min/5));
  PIN_SET(BULBDIAL_HOURS);
  for (uint8_t i = delay; i; i--)
    _delay_ms(1);
  PIN_CLEAR(BULBDIAL_HOURS);
}
Ejemplo n.º 17
0
int16_t parse_cmd_matemat_cooling(char *cmd, char *output, uint16_t len)
/* {{{ */ {
    if(cmd[1] == '1')
        PIN_SET(MATEMAT_COOLER);
    if(cmd[1] == '0')
        PIN_CLEAR(MATEMAT_COOLER);
    return 0;
} /* }}} */
Ejemplo n.º 18
0
void fs20_send_zero(void)
{
  PIN_SET(FS20_SEND);
  _delay_loop_2(FS20_DELAY_ZERO);
  PIN_CLEAR(FS20_SEND);
  _delay_loop_2(FS20_DELAY_ZERO);

}
void Stepper::setSpeed(int16_t _speed){	
	speed += constrain((_speed-speed), -(int16_t)maxAccel, (int16_t)maxAccel);
    if(speed == 0)
		period = 0;
	else
		period = MAX_SPEED/abs(speed);
	(speed>0) ? PIN_CLR(dirPin) : PIN_SET(dirPin);
}
Ejemplo n.º 20
0
void
hd44780_backlight(uint8_t state)
{
  hd44780_backlight_state = state;

#ifdef HD44780_BACKLIGHT_INV
  if (hd44780_backlight_state)
    PIN_CLEAR(HD44780_BL);
  else
    PIN_SET(HD44780_BL);
#else
  if (hd44780_backlight_state)
    PIN_SET(HD44780_BL);
  else
    PIN_CLEAR(HD44780_BL);
#endif
}
Ejemplo n.º 21
0
void ST7626_write(uint8_t mode, uint8_t data)
{
    ST7626_DATA_DDR = 0xFF;
    
    if(mode)
	PIN_SET(ST7626_A0);
    else
	PIN_CLEAR(ST7626_A0);
	
    ST7626_DATA = data;
    PIN_CLEAR(ST7626_CS);
    PIN_CLEAR(ST7626_WR);
    asm("nop");
    asm("nop");
    PIN_SET(ST7626_WR);
    PIN_SET(ST7626_CS);
}
Ejemplo n.º 22
0
void fs20_send_one(void)
{

  PIN_SET(FS20_SEND);
  _delay_loop_2(FS20_DELAY_ONE);
  PIN_CLEAR(FS20_SEND);
  _delay_loop_2(FS20_DELAY_ONE);

}
Ejemplo n.º 23
0
void analog_clock_clr(void)
{
	uint8_t ticks = 0;
	
	PIN_SET(SR74LS164_AB);
	
	ticks = analog_clock_get_ticks(60);
	analog_clock_gen_ticks(ticks);
}
Ejemplo n.º 24
0
/* Hauptroutine: Wird in der Hauptschleife abgerufen (sobald alle Interrupts und Timer abgearbeitet sind) - as fast as possible */
void rainmaster_mainloop(void) {

  // Druckabfall in Leitung erkennen und Pumpe bei Bedarf einschalten
  if(rm_status.PumpenKontakt == true) {
    setpwm('a', 255);             // Pumpe einschalten
    rm_status.PumpenFlag = true;  // Pumpenflag setzen
  } else {
    setpwm('a', 0);                // Pumpe ausschalten
    rm_status.PumpenFlag = false;  // PumpenFlag setzen
    rm_offcounter = 0;             // Pumpe läuft nicht, also counter auf 0  
  }


  uip_ipaddr_t ip_addr;


  if(my_tanklevel < TANK_MIN) {

    // TODO:
    uip_ipaddr(ip_addr, 192, 168, 1, 101);

    // Kugelhahn umstellen auf Trinkwasserbetrieb
    PIN_CLEAR(RM_KUGELHAHN);
    rm_status.Kugelhahn = 0; 

    // Eigenes Magnetventil schließen
    setpwm('c', 0);
    rm_status.Magnetventil = 0;

    // TODO:
    if(rm_001.request_state == 0) {
      // Fremdgerät kann Magnetventil öffnen u Pumpe starten, falls kein Eigenbedarf u genügend Wasser bei sich
      //ecmd_sender_send_command_P(&ip_addr, NULL, PSTR("rainmaster_request 1\n"));
      rm_001.request_state = 1;
      //rm_001.busy = 1;
    }

  }


  if(my_tanklevel > TANK_MAX) {

      if(rm_001.request_state == 1) {
        // Fremdgerät kann Magnetventil öffnen u Pumpe starten, falls kein Eigenbedarf u genügend Wasser bei sich
        //ecmd_sender_send_command_P(&ip_addr, NULL, PSTR("rainmaster_request 1\n"));
        rm_001.request_state = 0;
      }

      // Kugelhahn umstellen auf Regenwasserbetrieb
      PIN_SET(RM_KUGELHAHN);
      rm_status.Kugelhahn = 1; 

    }


} /* End rainmaster_mainloop */
Ejemplo n.º 25
0
uint8_t noinline
hd44780_clock_rw(uint8_t read, uint8_t en)
{
  uint8_t data = 0;

  /* set EN high, wait for more than 450 ns */
#ifdef HD44780_MULTIEN_SUPPORT
  if (en == 1)
    PIN_SET(HD44780_EN1);
  else if (en == 2)
    PIN_SET(HD44780_EN2);

#else
  PIN_SET(HD44780_EN1);
#endif
  /* make sure that we really wait for more than 450 ns... */
  _delay_us(1);

  /* read data, if requested.  data pins must be configured as input! */
  if (read)
  {
    if (PIN_HIGH(HD44780_D4))
      data |= _BV(0);
    if (PIN_HIGH(HD44780_D5))
      data |= _BV(1);
    if (PIN_HIGH(HD44780_D6))
      data |= _BV(2);
    if (PIN_HIGH(HD44780_D7))
      data |= _BV(3);
  }

  /* set EN low */

#ifdef HD44780_MULTIEN_SUPPORT
  if (en == 1)
    PIN_CLEAR(HD44780_EN1);
  else if (en == 2)
    PIN_CLEAR(HD44780_EN2);
#else
  PIN_CLEAR(HD44780_EN1);
#endif
  return data;
}
Ejemplo n.º 26
0
void analog_clock_set_inv(uint8_t val)
{
	analog_clock_set(59);
	
	PIN_SET(SR74LS164_AB);
	
	analog_clock_gen_ticks(analog_clock_get_ticks(val));

	analog_clock_val=0;
}
Ejemplo n.º 27
0
static void
psb2186_write(uint8_t addr, uint8_t value)
{
    PIN_CLEAR(PSB2186_CS);

    DDRA = 0xFF;
    PORTA = addr;
    PIN_SET(PSB2186_ALE);
    nop();
    PIN_CLEAR(PSB2186_ALE);

    PORTA = value;

    PIN_CLEAR(PSB2186_WR);
    nop();
    PIN_SET(PSB2186_WR);

    PIN_SET(PSB2186_CS);
}
Ejemplo n.º 28
0
void hd44780_backlight(uint8_t state)
{
    back_light = state;
#ifdef HD44780_BACKLIGHT_SUPPORT
    if (back_light)
        PIN_SET(HD44780_BL);
    else
        PIN_CLEAR(HD44780_BL);
#endif
}
Ejemplo n.º 29
0
/* Инициализация портов */
void    sys_init()
{
    port_attr_t   port_attr;
#if defined(BLINK_ON)
    PIN_SET( port_attr.dir, LED1|LED2|LED3, PIN_HI );   /* Направление на вывод */
    PIN_CLEAR( port_attr.sel, LED1|LED2|LED3 );         /* Функция ввода/вывода */
    PIN_CLEAR( port_attr.ie, LED1|LED2|LED3 );          /* Запрет прерываний */
    port_set_attr( LED_PORT, LED1|LED2|LED3, &port_attr );
    port_write( LED_PORT, LED1|LED2|LED3, PIN_LO );
#endif
#if defined(PLATFORM_FIRE_BUTTON)
    PIN_SET( port_attr.dir, CONTROL_PINS, PIN_HI );   /* Направление на вывод */
    PIN_CLEAR( port_attr.sel, CONTROL_PINS );         /* Функция ввода/вывода */
    PIN_CLEAR( port_attr.ie, CONTROL_PINS );          /* Запрет прерываний */
    port_set_attr( CONTROL_PORT, CONTROL_PINS, &port_attr );
    port_write( CONTROL_PORT, CONTROL_PINS, PINT1 );
#endif
    /* Настройка входа от геркона  */
    {   port_t  iport = 0x00;
        event_type_t    event_type = 0;
        result_t    res = ENOSYS;    

        port_reset_iflag( IPORT, IPINS );

        PIN_CLEAR( port_attr.dir, IPINS );     /* Направление на ввод */
        PIN_CLEAR( port_attr.sel, IPINS );     /* Функция ввода/вывода */ 
        PIN_SET( port_attr.ie, IPINS, PIN_HI );    /* Разрешаем прерывания от кнопки */
        PIN_SET( port_attr.ies, IPINS, PIN_LO );   /* Ловим изменение с низкого на высокий уровень */ 
        port_set_attr( IPORT, IPINS, &port_attr );

        /* Определение текущего состояния входов */
        port_read( IPORT, IPINS, &iport );
        /* У тех входов, которые уже в 1 настраиваем прерывания на спад */
        PIN_SET( port_attr.ies, iport, PIN_HI );   /* Ловим изменение с высокого на низкий уровень */ 
        port_set_attr( IPORT, iport, &port_attr );
        res = event_emit( PRIORITY, GIOP_INTERRUPT, (unidata_t)iport );
        if( IS_ERROR(res) ) {
            port_write( LED_PORT, LED1, PIN_HI );
        }
    }
    return;
}
Ejemplo n.º 30
0
Archivo: spi.c Proyecto: Floo/ethersex
void
spi_init(void)
{
  /* Input and Output configuration is done in the beginning of main(), so it
   * doesn't have to be done here
   */

  /* Set the chip-selects as high */

#ifdef ENC28J60_SUPPORT
  PIN_SET(SPI_CS_NET);
#endif

#ifdef SER_RAM_23K256_SUPPORT
    PIN_SET(SPI_CS_23K256);
#endif

#ifdef RFM12_SUPPORT
  for (int8_t modul = 0; modul < RFM12_MODULE_COUNT; modul++)
  {
    *rfm12_moduls[modul].rfm12_port |= rfm12_moduls[modul].rfm12_mask;
  }
#endif

#ifdef DATAFLASH_SUPPORT
  PIN_SET(SPI_CS_DF);
#endif

#ifdef USTREAM_SUPPORT
  PIN_SET(VS1053_CS);
#endif

#if defined(SPI_CS_SD_READER_PIN) && defined(SD_NETIO_ADDON_WORKAROUND)
  PIN_SET(SPI_CS_SD_READER);
#endif

#ifndef SOFT_SPI_SUPPORT
  /* enable spi, set master and clock modes (f/2) */
  _SPCR0 = _BV(_SPE0) | _BV(_MSTR0);
  _SPSR0 = _BV(_SPI2X0);
#endif
}