示例#1
0
// ============================================================================================
void _getReading(void)

{
    uint32_t temperature, output;

    // See if we have got a valid temperature
    temperature = sensorReturnReading();

    // Only turn the LED off if we've got legal data, otherwise flash it
    if (temperature == TEMP_INVALID)
        {
            ledSetState(LEDFLASH_ERROR);
            heaterSetLevel(0, CYCLE_LEN);
            isErrored=TRUE;
            sensorRequestCallback();    // Get another reading as soon as we can
            return;
        }

    ledSetState(LEDFLASH_NORMAL);
    // ...otherwise we've got a valid temp, so do the business with it
    if (pidGetSetpoint(&pidInstance) == SETPOINT_IDLE)
        output = 0;
    else
        output=pidCalc(&pidInstance,temperature);

    heaterSetLevel(output, CYCLE_LEN);
    contribute_log_entry(temperature, heaterGetPercentage(), pidGetSetpoint(&pidInstance), CYCLE_LEN);

    // Now wait for a while before doing it all again
    timerAdd(&tstate, TIMER_ORIGIN_STATEMACHINE, 0, CYCLE_LEN);
}
// set output if output = 1, otherwise input
static void gpio_set_mode_escs(int8_t escIndex, uint8_t mode) {
  int i = 0;
  ledSetState(LED_ESC_MODE_TX, mode != Mode_IPU);
  ledSetState(LED_ESC_MODE_RX, mode == Mode_IPU);
  if (escIndex == -1) {
    escIndex = 0;
    // only configure all escs if going into Mode_Out_PP
    if (mode == Mode_Out_PP) {
      for (i = 0; i < ESC_COUNT; i++) {
        gpio_set_mode(escHardware[i].gpio, escHardware[i].pin, mode);
      }
      return;
    }
  }
  gpio_set_mode(escHardware[escIndex].gpio, escHardware[escIndex].pin, mode);
}
示例#3
0
void loadUtcOffsetFromFlash()
{
	utcOffset = *(int8_t *)IMG_START_SECTOR;
	if ((utcOffset < -12) || (utcOffset > 12))
	{
		utcOffset = 0;
		ledSetState(TASK_LED, LedBlink);
	}
}
示例#4
0
void net_task (void const *arg)
{
	uint8_t count;
	bool ntpSuccess;
	
	netTaskErr resultGetTime;
	
	netTaskId = osThreadGetId();
	
	while (1)
	{
		osSignalWait(FLAG_NTP_REQ_START, osWaitForever);
	
		ntpSuccess = false;
		ledSetState(TASK_LED, LedOn);
		for (count = 0; count < DHCP_WAIT_TRIES; count++)
		{
			if ((localm[NETIF_ETH].IpAddr[0] != 0) ||
				(localm[NETIF_ETH].IpAddr[1] != 0) ||
				(localm[NETIF_ETH].IpAddr[2] != 0) ||
				(localm[NETIF_ETH].IpAddr[3] != 0))
			{
				resultGetTime = getEpochTime();
				if (resultGetTime == errOK)
				{
					updateRtcTime();
					ntpSuccess = true;
					break;
				}
			}
			else
				osDelay(DHCP_WAIT_DELAY_MS);
		}
		if (ntpSuccess == true)
			ledSetState(TASK_LED, LedOff);
		else
		{
			ledSetState(TASK_LED, LedBlink);
			//rerequest NTP time after delay
			scheldueNTPRequest();
		}
	}
}
static void ledInitDebug(void)
{
#if defined(STM32F3DISCOVERY)
  GPIO_DeInit(GPIOE);
  gpio_enable_clock(RCC_AHBPeriph_GPIOE);
  gpio_set_mode(GPIOE, GPIO_Pin_8|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_14|GPIO_Pin_15, Mode_Out_PP);
  // Inverted LEDs
  ledSetState(GPIOE, GPIO_Pin_8|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_14|GPIO_Pin_15, Bit_RESET);
#endif
  return;
}
static uint8_t escHi(int8_t escIndex) {
  uint16_t val = 0;
  // we can only read / passthrough 1 escs, lets pass the first one in "all" mode
  if (escIndex == -1) { escIndex = 1; }
  // inverted schmitt trigger on the input vs. the non-inverted schmitt trigger on the avr
  // invert the input to get the true edge direction
  // bit reset (0) indicates a true rising edge
  val = (GPIO_ReadInputDataBit(escHardware[escIndex].gpio, escHardware[escIndex].pin));
  ledSetState(LED_ESC_RX, val == Bit_RESET);
  return val;
}
示例#7
0
void saveUtcOffsetToFlash()
{
	flashImage[0] = utcOffset;

	__disable_irq();
	if(u32IAP_PrepareSectors(16, 16) == IAP_STA_CMD_SUCCESS)
	{
		u32IAP_EraseSectors(16, 16);
		u32IAP_PrepareSectors(16, 16);
		if(u32IAP_CopyRAMToFlash(IMG_START_SECTOR, (uint32_t)flashImage, IAP_FLASH_PAGE_SIZE_BYTES) == IAP_STA_CMD_SUCCESS)
		{
			if(u32IAP_Compare(IMG_START_SECTOR, (uint32_t)flashImage, IAP_FLASH_PAGE_SIZE_BYTES, 0) == IAP_STA_CMD_SUCCESS)
			{
				__enable_irq();
				ledSetState(TASK_LED, LedOn);
				return;
			}
		}
	}
	__enable_irq();
	ledSetState(TASK_LED, LedBlink);
}
void escSet(int8_t escIndex, BitAction val) {
  int i = 0;
  // Write all esc pins
  if (escIndex == -1) {
    for (i = 0; i < ESC_COUNT; i++) {
      GPIO_WriteBit(escHardware[i].gpio, escHardware[i].pin, val);
    }
  }
  // Write the specified pin
  else {
    GPIO_WriteBit(escHardware[escIndex].gpio, escHardware[i].pin, val);
  }
  // low == data
  ledSetState(LED_ESC_TX, val == Bit_RESET);
}
static void txSet(BitAction val) {
  GPIO_WriteBit(S1W_TX_GPIO, S1W_TX_PIN, val);
  // low == data
  ledSetState(LED_PRGMR_TX, val == Bit_RESET);
}
static uint8_t rxHi() {
  uint16_t val = 0;
  val = (GPIO_ReadInputDataBit(S1W_RX_GPIO, S1W_RX_PIN));
  ledSetState(LED_PRGMR_RX, val == Bit_RESET);
  return val;
}