Exemplo n.º 1
0
void
NEXA::Transmitter::send_code(code_t cmd, int8_t onoff)
{
    // Send the code four times with a pause between each
    for (uint8_t i = 0; i < SEND_CODE_MAX; i++) {
        const uint8_t BITS_MAX = 32;
        const uint8_t ONOFF_POS = 27;
        int32_t bits = cmd;
        // Send start pulse with extended delay, code bits and stop pulse
        send_pulse(0);
        DELAY(START_PULSE);
        for (uint8_t j = 0; j < BITS_MAX; j++) {
            // Check for dim level (-1..-15)
            if ((j == ONOFF_POS) && (onoff < 0)) {
                send_pulse(0);
                send_pulse(0);
            }
            else send_bit(bits < 0);
            bits <<= 1;
        }
        // Check for dim level transmission; level encoded as -1..-15
        if (onoff < 0) {
            int8_t level = (-onoff) << 4;
            for (uint8_t j = 0; j < 4; j++) {
                send_bit(level < 0);
                level <<= 1;
            }
        }
        send_pulse(0);
        RTC::delay(PAUSE);
    }
}
Exemplo n.º 2
0
inline void send_manchester_symbol(u8 tx_bit)
{
  //Send the first bit
  send_bit(tx_bit);

  //The second bit in a manchester symbol is the inverse of the first bit
  send_bit(tx_bit ^ 1);
}
Exemplo n.º 3
0
/*!
	Send positive acknowledge afterwards if <acknowledge> is true,
	else send negative one
*/
static status_t
receive_byte(const i2c_bus *bus, uint8 *resultByte, bool acknowledge)
{
	uint8 byte = 0;
	int i;

	// pull clock low to let slave wait for us
	bus->set_signals(bus->cookie, 0, 1);

	for (i = 7; i >= 0; i--) {
		bool bit;

		status_t status = receive_bit(bus, &bit,
			i == 7 ? bus->timing.byte_timeout : bus->timing.bit_timeout);
		if (status != B_OK)
			return status;

		byte = (byte << 1) | bit;
	}

	//SHOW_FLOW(3, "%x ", byte);

	*resultByte = byte;

	return send_bit(bus, acknowledge ? 0 : 1, bus->timing.bit_timeout);
}
Exemplo n.º 4
0
static void send_byte_part(uint8_t byte, uint8_t length) {
	int8_t i;

	for(i = length - 1; i >= 0; --i) {
		send_bit(byte & (1 << i));
	}
}
Exemplo n.º 5
0
void RTTY::send_byte(char c) {
  uint8_t i;

  send_bit(0); // Start bit

  // Send bits for for char LSB first	
  for (i=0; i<7; i++) { // Change this here 7 or 8 for ASCII-7 / ASCII-8
    if (c & 1)
      send_bit(1);
    else
      send_bit(0);	
    c = c >> 1;
  }

  send_bit(1); // Stop bit
  send_bit(1); // Stop bit
}
Exemplo n.º 6
0
inline void tx_send_preamble(void)
{
  int i = 0;
  for(i = 0;i < 32;i++){
    send_bit(mask_bit((int) VLC_PREAMBLE, i));
  }

  tx_packet->state = TX_SENDING_SEQUENCE;
}
Exemplo n.º 7
0
irom static inline i2c_error_t send_ack(bool_t ack)
{
	i2c_error_t error;

	if(state != i2c_state_data_receive_ack_send)
		return(i2c_error_invalid_state_not_send_ack);

	if((error = send_bit(!ack)) != i2c_error_ok)
		return(error);

	return(i2c_error_ok);
}
Exemplo n.º 8
0
bool I2C<CL_t, DA_t>::send_byte(uint8_t data)
{
	for (uint8_t i = 0; i < 8; ++i) {
		send_bit(data & 0x80);

		data += data;
	}

	DA::set();

	return recv_bit() == false;
}
Exemplo n.º 9
0
void tx_handler(void *arg)
{
  while(tx_packet){ 

    //If the current packet isn't ready, step to the next one
    if(tx_packet->state == PACKET_COMPLETE ||
       tx_packet->state == PACKET_EMPTY ||
       tx_packet->state == PACKET_CORRUPTED){

      tx_packet = tx_packet->next;      
      if(rx_packet->state == RX_SENDING_ACK) tx_send_ack();
      else send_bit(1);
    }

    else if(tx_packet->state == TX_WAITING_ACK){
      if(rx_packet->state == RX_SENDING_ACK) tx_send_ack();
      else send_bit(1);
    }

    else if(tx_packet->state == PACKET_READY){
      if(rx_packet->state == RX_SENDING_ACK) tx_send_ack();

      tx_send_preamble();
      debug("VLC TX: Preamble sent!\n");
      if(tx_packet->state == TX_SENDING_SEQUENCE) tx_send_sequence();
      debug("VLC TX: Sequence sent!\n");
      if(tx_packet->state == TX_SENDING_PACKET_LEN) tx_send_len();
      debug("VLC TX: Length sent!\n");
      if(tx_packet->state == TX_SENDING_PACKET_DATA) tx_send_data();
      debug("VLC TX: Data sent!\n");
      if(tx_packet->state == TX_SENDING_CHECKSUM) tx_send_checksum();
      debug("VLC TX: Checksum sent!\n");

      if(tx_packet->state == TX_WAITING_ACK) tx_wait_ack();
    }
  }
  return;
}
Exemplo n.º 10
0
void send_byte(unsigned char bytedat)
{
    int k;
    unsigned char bt;
    
    //8ビット分行う
    for(k = 0 ; k < 8 ; k++)
    {
		//下位ビットから送信するため、byteの一番右側のbitから送信処理を行う。
    	
        bt = bytedat & 0x01;
        
		if((fcsflag_send_fm == 0)&&(flag_send_fm == 0))
            crcbit(bt);
        if(bt == 0)
            send_bit(0);
        else
        {
            send_bit(1);
            stuff++;
            
            // stuff : ビットスタッフィング用のカウンタ
            // プリアンブル・ポストアンブル以外で1が5回以上続いた場合に"0"を1bit挿入する。
            // flag:プリアンブル送信中か判定。プリアンブル送信時はビットスタッフィングを行わない。
            if((flag_send_fm == 0) && (stuff == 5))
            {
                delay_modem();
                send_bit(0);
            }
        }
		
        bytedat = bytedat >> 1;		//次のbitに移る
		
		//delay_ms(1);
        delay_modem();
		
    }
}
Exemplo n.º 11
0
void send_ir_data(unsigned char* data, int len)
{
	int i  = 0;
	
	output_38k(NEC_HDR_MARK);
	output_38k_off(NEC_HDR_MARK);

	for (i = 0; i < len; i++)
		send_byte(data[i]);

	send_bit(1);
	delay_us(NEC_HDR_MARK- PWM_OFF_DELAY);

}
Exemplo n.º 12
0
void LegoIr::send()
{
    uint8_t i, j;
    uint16_t message = _nib1 << 12 | _nib2 << 8 | _nib3 << 4 | CHECKSUM();
    for(i = 0; i < 6; i++)
    {
        pause(i);
        start_stop_bit();
        for(j = 0; j < 16; j++) {
            send_bit();
            delayMicroseconds((0x8000 & (message << j)) != 0 ? HIGH_PAUSE : LOW_PAUSE);
        }
        start_stop_bit();
    }
}
Exemplo n.º 13
0
uint8_t I2C<CL_t, DA_t>::recv_byte(bool nack)
{
	uint8_t data;

	DA::set();

	for (uint8_t i = 0; i < 8; ++i) {
		data += data;

		if (recv_bit())
			data |= 1;
	}

	send_bit(nack);

	return data;
}
Exemplo n.º 14
0
irom static i2c_error_t send_byte(int byte)
{
	i2c_error_t error;
	int current;

	if((state != i2c_state_address_send) && (state != i2c_state_data_send_data))
		return(i2c_error_invalid_state_not_send_address_or_data);

	for(current = 8; current > 0; current--)
	{
		if((error = send_bit(byte & 0x80)) != i2c_error_ok)
			return(error);
		byte <<= 1;
	}

	return(i2c_error_ok);
}
Exemplo n.º 15
0
inline void tx_send_ack(void)
{
  int i = 0;
  for(i = 0;i < 32;i++){
    send_bit(mask_bit((int) VLC_ACK, i));
  }
  if(rx_packet->state == RX_SENDING_ACK){

    rx_packet->state = PACKET_COMPLETE;

    /*
    //Check if this packet is a DUP
    if(rx_packet->sequence == rx_sequence_num){
      rx_packet->state = PACKET_COMPLETE;
      rx_sequence_num++;
    }
    
    //If it is, set it to corrupted
    else rx_packet->state == PACKET_CORRUPTED;
    */
  }
}
Exemplo n.º 16
0
unsigned char RX_byte(unsigned char ack_nack)
{
	unsigned char 	RX_buffer;
	unsigned char	Bit_Counter;
	
	for(Bit_Counter=8; Bit_Counter; Bit_Counter--)
	{
		if(Receive_bit())						
		{
			RX_buffer <<= 1;					
			RX_buffer |=0x01;
		}
		else
		{
			RX_buffer <<= 1;					
			RX_buffer &=0xfe;	
		}

	}
	send_bit(ack_nack);							
	return RX_buffer;
}
Exemplo n.º 17
0
static void send_ack(void)
{
	send_bit(0);
}
Exemplo n.º 18
0
void
send_belfox(char *msg)
{

  uint8_t repeat=BELFOX_REPEAT;
  uint8_t len=strnlen(msg,BELFOX_LEN+2)-1;
  
  // assert if length incorrect
  if (len != BELFOX_LEN) return;
  
  LED_ON();

#if defined (HAS_IRRX) || defined (HAS_IRTX) // Block IR_Reception
  cli();
#endif

#ifdef USE_RF_MODE
  change_RF_mode(RF_mode_slow);
#else

#ifdef HAS_MORITZ
  uint8_t restore_moritz = 0;
  if(moritz_on) {
    restore_moritz = 1;
    moritz_on = 0;
    set_txreport("21");
  }
#endif

  if(!cc_on)
    set_ccon();
#endif
  ccTX();                                       // Enable TX 
  do {
    send_sync();                                // sync

    for(int i = 1; i <= BELFOX_LEN; i++)        // loop input, for example 'L111001100110'
      send_bit(msg[i] == '1');

    CC1100_OUT_PORT &= ~_BV(CC1100_OUT_PIN);    // final low to complete last bit
        
    my_delay_ms(BELFOX_PAUSE);                  // pause

  } while(--repeat > 0);

  if(TX_REPORT) {                               // Enable RX
    ccRX();
  } else {
    ccStrobe(CC1100_SIDLE);
  }

#if defined (HAS_IRRX) || defined (HAS_IRTX) // Activate IR_Reception
  sei(); 
#endif

#ifdef USE_RF_MODE
  restore_RF_mode();
#else
#ifdef HAS_MORITZ
  if(restore_moritz)
    rf_moritz_init();
#endif
#endif
  LED_OFF();
}
Exemplo n.º 19
0
// Send the start/stop bit
void PowerFunctions::start_stop_bit()
{
  send_bit();
  delayMicroseconds(START_STOP); // Extra pause for start_stop_bit
}
Exemplo n.º 20
0
// Send the start/stop bit
void LegoIr::start_stop_bit()
{
    send_bit();
    delayMicroseconds(START_STOP); // Extra pause for start_stop_bit
}