Ejemplo n.º 1
0
void GetConnection(void) {
	typedef enum {
		GetCon1, Passed, Error
	} GetConState_Type;
	GetConState_Type GetConState = GetCon1;

	while (GetConState != Passed) {
		switch (GetConState) {

		case GetCon1:
			SendSim900("AT+GetConnection\r\n");

			if (CompareString(buffer, "ok", 2)) {	//are the same
				FRTOS1_xSemaphoreGive(SuccessLedMutex);
				GetConState = Passed;
			}
			break;

		default:
			GetConState = Error;
			break;

		}
		FRTOS1_vTaskDelay(
				GET_CONNECTION_STATEMACHINE_DELAY_MS/portTICK_PERIOD_MS);
	}
}
Ejemplo n.º 2
0
void SendSim900(uint8_t* msg) {
	if (FRTOS1_xSemaphoreTake(DataSendMutex,SHELL_SEND_MUTEX_WAIT_MS) == pdTRUE) {
		UTIL1_strcpy(buf_send, BUFFER_SIZE, msg);
		flag_send = TRUE;
		FRTOS1_xSemaphoreGive(DataSendMutex);
	}
}
Ejemplo n.º 3
0
void BootUpModule(void) {
	typedef enum {
		Bootup1, Passed, Error
	} BootUpState_Type;
	BootUpState_Type BootUpState = Bootup1;

	while (BootUpState != Passed) {
		switch (BootUpState) {

		case Bootup1:
			SendSim900("AT+Bootup\r\n");

			if (CompareString(buffer, "OK", 2)) {	//are the same
				FRTOS1_xSemaphoreGive(SuccessLedMutex);
				BootUpState = Passed;
			}
			break;

		default:
			BootUpState = Error;
			break;

		}
		FRTOS1_vTaskDelay(BOOTUP_STATEMACHINE_DELAY_MS/portTICK_PERIOD_MS);
	}
}
Ejemplo n.º 4
0
/* measure and return the microseconds */
uint16_t US_Measure_us(void) {
  int timeout;
  
  FRTOS1_xSemaphoreTake(mutexHandle, portMAX_DELAY);
  usDevice.signalState = US_SIGNAL_OK; /* default state */
  /* send 10us pulse on TRIG line. */
  TRIG_SetVal(usDevice.trigDevice);
  WAIT1_Waitus(10);
  usDevice.state = ECHO_TRIGGERED;
  TU_US_Enable(usDevice.echoDevice);
  TRIG_ClrVal(usDevice.trigDevice);
  timeout = 30; /* timout in ms */
  while(usDevice.state!=ECHO_FINISHED) {
    /* measure echo pulse */
    if (usDevice.state==ECHO_OVERFLOW) { /* measurement took too long? */
      usDevice.signalState =  US_SIGNAL_NO_ECHO;
      break; /* no echo, error case */
    }
    WAIT1_WaitOSms(1);
    timeout--;
    if (timeout==0) {
      usDevice.signalState = US_SIGNAL_TIMEOUT;
      break;
    }
  } /* while */
  if (usDevice.state==ECHO_FINISHED) {
    usDevice.lastValue_us = (usDevice.capture*1000UL)/(TU_US_CNT_INP_FREQ_U_0/1000);
    usDevice.signalState = US_SIGNAL_OK;
  } else {
    usDevice.lastValue_us = 0; /* error case */
  }
  usDevice.state = ECHO_IDLE;
  FRTOS1_xSemaphoreGive(mutexHandle);
  return usDevice.lastValue_us;
}
Ejemplo n.º 5
0
/* measure and return the microseconds */
uint16_t US_Measure_us(void) {
  int timeout;
  
  FRTOS1_xSemaphoreTake(mutexHandle, portMAX_DELAY);
  /* send 10us pulse on TRIG line. */
  TRIG_SetVal(usDevice.trigDevice);
  WAIT1_Waitus(10);
  usDevice.state = ECHO_TRIGGERED;
  TRIG_ClrVal(usDevice.trigDevice);
  timeout = 30;
  while(usDevice.state!=ECHO_FINISHED && timeout>0) {
    /* measure echo pulse */
    if (usDevice.state==ECHO_OVERFLOW) { /* measurement took too long? */
      usDevice.state = ECHO_IDLE; /* go back to idle */
      break; /* no echo, error case */
    }
    WAIT1_WaitOSms(1);
    timeout--;
  } /* while */
  if (usDevice.state==ECHO_FINISHED) {
    usDevice.lastValue_us = (usDevice.capture*1000UL)/(TU_US_CNT_INP_FREQ_U_0/1000);
  } else {
    usDevice.lastValue_us = 0; /* error case */
  }
  usDevice.state = ECHO_IDLE;
  FRTOS1_xSemaphoreGive(mutexHandle);
  return usDevice.lastValue_us;
}
Ejemplo n.º 6
0
bool ReadSim900(uint8_t* bfr) {
	bool res;
	if (FRTOS1_xSemaphoreTake(DataReceivedMutex,
			SHELL_RECEIVE_MUTEX_WAIT_MS) == pdTRUE) {
		res = flag_rcv;
		flag_rcv = FALSE;
		if (res) {
			UTIL1_strcpy(bfr, BUFFER_SIZE, buf_rcv);
		}
		FRTOS1_xSemaphoreGive(DataReceivedMutex);
	}
	return res;
}
Ejemplo n.º 7
0
void InitModule(void) {
	typedef enum {
		Init1, Init2, Passed, Error
	} InitState_Type;
	InitState_Type InitState = Init1;

	while (InitState != Passed) {
		switch (InitState) {

		case Init1:
			SendSim900("AT+Init1\r\n");
			if (CompareString(buffer, "init1", 5)) {	//are the same
				FRTOS1_xSemaphoreGive(SuccessLedMutex);
				InitState = Init2;
			}
			break;

		case Init2:
			SendSim900("AT+Init2\r\n");
			if (CompareString(buffer, "init2", 5)) {	//are the same
				FRTOS1_xSemaphoreGive(SuccessLedMutex);
				InitState = Passed;
			}
			break;

		case Error:
			for (;;) {
				FRTOS1_xSemaphoreGive(ErrorLedMutex);
			}
			break;

		default:
			InitState = Error;

		}	//end switch case
		FRTOS1_vTaskDelay(INIT_STATEMACHINE_DELAY_MS/portTICK_PERIOD_MS);
	} //end while loop
}
Ejemplo n.º 8
0
static void REF_MeasureRaw(SensorTimeType raw[NOF_SENSORS]) {
  uint8_t cnt; /* number of sensor */
  uint8_t i;
  TMOUT1_CounterHandle timeout;

  FRTOS1_xSemaphoreTake(mutexHandle, portMAX_DELAY);
  if (ledON) {
    LED_IR_On(); /* IR LED's on */
    WAIT1_Waitus(200);
  }
  for(i=0;i<NOF_SENSORS;i++) {
    SensorFctArray[i].SetOutput(); /* turn I/O line as output */
    SensorFctArray[i].SetVal(); /* put high */
    raw[i] = MAX_SENSOR_VALUE;
  }
  WAIT1_Waitus(20); /* give at least 10 us to charge the capacitor */
  timeout = TMOUT1_GetCounter(20/TMOUT1_TICK_PERIOD_MS); /* set up timeout counter */
  FRTOS1_vTaskSuspendAll();
  
  (void)TU1_ResetCounter(timerHandle); /* reset timer counter */
  for(i=0;i<NOF_SENSORS;i++) {
    SensorFctArray[i].SetInput(); /* turn I/O line as input */
  }
  do {
    cnt = 0;
    if (TMOUT1_CounterExpired(timeout)) {
      break; /* get out of wile loop */
    }
    for(i=0;i<NOF_SENSORS;i++) {
      if (raw[i]==MAX_SENSOR_VALUE) { /* not measured yet? */
        if (SensorFctArray[i].GetVal()==0) {
          raw[i] = TU1_GetCounterValue(timerHandle);
        }
      } else { /* have value */
        cnt++;
      }
    }
  } while(cnt!=NOF_SENSORS);
  TMOUT1_LeaveCounter(timeout);
  FRTOS1_xTaskResumeAll();
  if (ledON) {
    LED_IR_Off(); /* IR LED's off */
    WAIT1_Waitus(200);
  }
  FRTOS1_xSemaphoreGive(mutexHandle);
}