コード例 #1
0
ファイル: write.c プロジェクト: emilk/bon
void bon_w_footer(bon_w_doc* B)
{
	if (B->flags & BON_W_FLAG_CRC)
	{
		// Add contribution of buffered data:
		B->crc_inv = crc_update(B->crc_inv, B->buff, B->buff_ix);
		
		uint32_t crc = B->crc_inv ^ 0xffffffff;
		uint32_t crc_le = uint32_to_le(crc);
		
		bon_w_raw_uint8 (B, BON_CTRL_FOOTER_CRC);
		bon_w_raw_uint32(B, crc_le);
		bon_w_raw_uint8 (B, BON_CTRL_FOOTER_CRC);
	}
	else
	{
		bon_w_raw_uint8 (B, BON_CTRL_FOOTER);
	}
}
コード例 #2
0
ファイル: main.c プロジェクト: Drooids/nrf
static void handle_get_msg(snrf_msg_t* msg)
{
  /* capture before modifying */
  const uint8_t key = msg->u.set.key;

  /* completion sent back, assume success */
  MAKE_COMPL_ERROR(msg, SNRF_ERR_SUCCESS);

  switch (key)
  {
  case SNRF_KEY_STATE:
    msg->u.compl.val = uint32_to_le(snrf_state);
    break ;

  case SNRF_KEY_CRC:
    msg->u.compl.val = uint32_to_le(nrf_get_crc());
    break ;

  case SNRF_KEY_RATE:
    {
#if (NRF_CONFIG_NRF24L01P == 1)
      const uint8_t x = nrf24l01p_read_reg8(NRF24L01P_REG_RF_SETUP);
      static const uint8_t map[] =
      {
	NRF24L01P_RATE_1MBPS,
	NRF24L01P_RATE_2MBPS,
	NRF24L01P_RATE_250KBPS,
	NRF24L01P_RATE_250KBPS,
	NRF24L01P_RATE_250KBPS
      };
      msg->u.compl.val = uint32_to_le(map[(x >> 3) & 5]);
#elif (NRF_CONFIG_NRF905 == 1)
      msg->u.compl.val = uint32_to_le(SNRF_RATE_50KBPS);
#endif
      break ;
    }

#if (NRF_CONFIG_NRF24L01P == 1)
  case SNRF_KEY_CHAN:
    {
      const uint8_t x = nrf24l01p_read_reg8(NRF24L01P_REG_RF_CH);
      msg->u.compl.val = uint32_to_le(x);
      break ;
    }
#endif

  case SNRF_KEY_ADDR_WIDTH:
    msg->u.compl.val = uint32_to_le(nrf_get_addr_width());
    break ;

  case SNRF_KEY_RX_ADDR:
    nrf_get_rx_addr((uint8_t*)&msg->u.compl.val);
    break ;

  case SNRF_KEY_TX_ADDR:
    nrf_get_tx_addr((uint8_t*)&msg->u.compl.val);
    break ;

  case SNRF_KEY_TX_ACK:
    msg->u.compl.val = uint32_to_le(nrf_get_tx_ack());
    break ;

  case SNRF_KEY_PAYLOAD_WIDTH:
    msg->u.compl.val = uint32_to_le(nrf_get_payload_width());
    break ;

  case SNRF_KEY_UART_FLAGS:
    msg->u.compl.val = uint32_to_le((uint32_t)uart_flags);
    break ;

  case SNRF_KEY_NRF_CHIPSET:
#if (NRF_CONFIG_NRF24L01P == 1)
    msg->u.compl.val = uint32_to_le(SNRF_CHIPSET_NRF24L01P);
#else
    msg->u.compl.val = uint32_to_le(SNRF_CHIPSET_NRF905);
#endif
    break ;

  default:
    MAKE_COMPL_ERROR(msg, SNRF_ERR_KEY);
    break ;
  }
}