Exemple #1
0
uint8_t
adc_vref_reaction(uint8_t * ptr, struct snmp_varbinding * bind,
                  void *userdata)
{
  if (bind->len != 1 || bind->data[0] >= ADC_CHANNELS)
  {
    return 0;
  }
  return encode_short(ptr, SNMP_TYPE_INTEGER, adc_get_vref());
}
Exemple #2
0
int16_t
parse_cmd_adc_vref(char *cmd, char *output, uint16_t len)
{
  while (*cmd == ' ')
    cmd++;

  if (*cmd == 0)
  {
    return ECMD_FINAL(snprintf(output, len, "%d", adc_get_vref()));
  }

  uint16_t vref = atoi(cmd);
  if (vref < 100 || vref > 6000)
  {
    return ECMD_ERR_PARSE_ERROR;
  }
  adc_set_vref(vref);

  return ECMD_FINAL_OK;
}
Exemple #3
0
//We don't want to transmit status while we are updating the buffer
/// \brief
/// This is a main loop routine. Gathers the various status information across
/// the msp430 and stores it into the status buffer. This information is sent
/// back to the i2c master when it requests the msp's status.
void msp_status_update(void)
{
#ifdef TIME_PROFILING
	statusTime.past = get_highres_timer();
#endif

	uint8_t* adc_state_ptr;
	uint8_t* adc_vref_ptr;
	uint8_t temp;

//BYTE 0
	temp = 0;
	/* RELAY STATES */
	temp |= RELAY1 << 7;
	temp |= RELAY2 << 6;
	/* IR STATUS */
	temp |= ir_busy() << 5;
	/* I2C STATUS */
	temp |= i2c_slave_overflow() << 4;
	/* UART1 TX BUSY */
	temp |= uart1_tx_busy() << 3;
	/* UART1 RX OVERFLOW */
	temp |= uart1_get_rx_overflow() << 2;
	/* UART2 TX BUSY */
	temp |= uart2_tx_busy() << 1;
	/* UART2 RX OVERFLOW */
	temp |= uart2_get_rx_overflow();
	status_buffer[0] = temp;

//BYTE 1
	temp = 0;
	/* DI/DO DIRECTION */
	/* DI/DO States */
	adc_state_ptr = adc_get_states();
	if(adc_get_active(0))
	{
		temp |= (*(adc_state_ptr+2) & 0x1);
	}
	else
	{
		temp |= 0x01 << 7;
		temp |= D1OUT << 3;
	}
	//++adc_state_ptr;
	if(adc_get_active(1))
	{
		temp |= (*(adc_state_ptr+3) & 0x1) << 1;
	}
	else
	{
		temp |= 0x01 << 6;
		temp |= D2OUT << 2;
	}
	//++adc_state_ptr;
	if(adc_get_active(2))
	{
		temp |= (*(adc_state_ptr) & 0x1) << 2;
	}
	else
	{
		temp |= 0x01 << 5;
		temp |= D3OUT << 1;
	}
	//++adc_state_ptr;
	if(adc_get_active(3))
	{
		temp |= (*(adc_state_ptr+1) & 0x1) << 3;
	}
	else
	{
		temp |= 0x01 << 4;
		temp |= D4OUT;
	}
	status_buffer[1] = temp;

//BYTE 2
	temp = 0;
	/* ADC VREF */
	adc_vref_ptr = adc_get_vref();
	temp |= (*adc_vref_ptr & 0x3) << 6;
	++adc_vref_ptr;
	temp |= (*adc_vref_ptr & 0x3) << 4;
	++adc_vref_ptr;
	temp |= (*adc_vref_ptr & 0x3) << 2;
	++adc_vref_ptr;
	temp |= (*adc_vref_ptr & 0x3);
	status_buffer[2] = temp;

//BYTE 3
	temp = uart1_get_rx_count();
	status_buffer[3] = temp;
//BYTE 4
	temp = uart2_get_rx_count();
	status_buffer[4] = temp;
//BYTE 5 UART1 Settings
	status_buffer[5] = uart1_get_settings();
//BYTE 6 UART2 Settings
	status_buffer[6] = uart2_get_settings();
//BYTE 7
	temp = ir_get_activeport();
	temp |= uart1_get_rx_miss() << 3;
	temp |= uart1_get_bad_read() << 4;
	status_buffer[7] = temp;

#ifdef TIME_PROFILING
	statusTime.present = get_highres_timer();
	statusTime.total = statusTime.present - statusTime.past;
#endif
}