draft of buisness logic to handle meassurements

pull/96/head
RobertGawron 2019-07-28 13:01:31 +01:00
rodzic 4fc4f766f8
commit 5986315169
6 zmienionych plików z 81 dodań i 52 usunięć

Wyświetl plik

@ -0,0 +1,15 @@
/*
* MeasurementCollector.h
*
* Created on: 15 cze 2019
* Author: robert
*/
#ifndef INC_MEASUREMENTCOLLECTOR_H_
#define INC_MEASUREMENTCOLLECTOR_H_
void MeasurementCollector_Init();
void MeasurementCollector_Tick();
#endif /* INC_MEASUREMENTCOLLECTOR_H_ */

Wyświetl plik

@ -13,14 +13,13 @@
#define VoltageSensorActualValue_MeasurementData_t uint8_t
typedef struct MCP3425A0TConfig_t {
int pinId;
int i2cAddress;
} MCP3425A0TConfig_t;
void VoltageSensorActualValue_Init();
bool VoltageSensorActualValue_GeMeasurementData(VoltageSensorActualValue_MeasurementData_t *measurementData);
bool VoltageSensorActualValue_GetMeasurementData(VoltageSensorActualValue_MeasurementData_t *measurementData);
#endif /* SRC_VOLTAGESENSORACTUALVALUE_H_ */

Wyświetl plik

@ -14,6 +14,7 @@
#include "UserInterface.h"
#include "VoltageSensorActualValue.h"
#include "VoltageSensorPeakValue.h"
#include "MeasurementCollector.h"
void ApplicationBuilder_Init()
{
@ -24,7 +25,8 @@ void ApplicationBuilder_Init()
PulseCounter_Init();
UserInterface_Init();
VoltageSensorActualValue_Init();
MeasurementCollector_Init();
enableInterrupts();
// UserInterface_ShowMessage(USER_INTERFAE_STATE_OK_MSG);
@ -42,6 +44,7 @@ void ApplicationBuilder_Run()
void ApplicationBuilder_Tick()
{
//Logger_Tick();
VoltageSensorActualValue_GeMeasurementData(0);
MeasurementCollector_Tick();
UserInterface_Tick();
}

Wyświetl plik

@ -0,0 +1,20 @@
/*
* MeasurementCollector.c
*
* Created on: 15 cze 2019
* Author: robert
*/
#include "MeasurementCollector.h"
#include "VoltageSensorActualValue.h"
#
void MeasurementCollector_Init()
{
}
void MeasurementCollector_Tick()
{
VoltageSensorActualValue_GetMeasurementData(0);
}

Wyświetl plik

@ -17,67 +17,28 @@
static void GPIO_setup(void);
static void I2C_setup(void);
static uint8_t getRegisterValue(uint8_t registerId);
void VoltageSensorActualValue_Init()
{
#if 0
CLK_DeInit();
CLK_HSECmd(DISABLE);
CLK_LSICmd(DISABLE);
CLK_HSICmd(ENABLE);
while(CLK_GetFlagStatus(CLK_FLAG_HSIRDY) == FALSE);
CLK_ClockSwitchCmd(ENABLE);
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV8);
CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV2);
CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSI,
DISABLE, CLK_CURRENTCLOCKSTATE_ENABLE);
CLK_PeripheralClockConfig(CLK_PERIPHERAL_SPI, DISABLE);
CLK_PeripheralClockConfig(CLK_PERIPHERAL_I2C, ENABLE);
CLK_PeripheralClockConfig(CLK_PERIPHERAL_ADC, DISABLE);
CLK_PeripheralClockConfig(CLK_PERIPHERAL_AWU, DISABLE);
CLK_PeripheralClockConfig(CLK_PERIPHERAL_UART1, ENABLE);
CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER1, ENABLE);
CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER2, DISABLE);
CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER4, DISABLE);
#endif
GPIO_setup();
I2C_setup();
}
bool VoltageSensorActualValue_GeMeasurementData(VoltageSensorActualValue_MeasurementData_t *measurementData)
bool VoltageSensorActualValue_GetMeasurementData(VoltageSensorActualValue_MeasurementData_t *measurementData)
{
/////////// send dummy data //////////////////////////////////////////////
measurementData = getRegisterValue(0x00);
I2C_GenerateSTART(ENABLE);
while(!I2C_CheckEvent(I2C_EVENT_MASTER_MODE_SELECT));
I2C_Send7bitAddress((I2C_SLAVE_ADDRESS << 1), I2C_DIRECTION_TX);
while(!I2C_CheckEvent(I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
I2C_SendData(0x0);
while(!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTED));
if (0 == I2C_ReceiveData())
if (measurementData == 0)
{
// for temporary debug only
UserInterface_ShowMessage(USER_INTERFACE_COLLECTING_DATA_MSG);
}
I2C_GenerateSTOP(ENABLE);
while(I2C_GetFlagStatus(I2C_FLAG_BUSBUSY));
// for temporary debug only
UserInterface_ShowMessage(USER_INTERFACE_COLLECTING_DATA_MSG);
// getRegisterValue should return false on timeout and this should be later propagated to GUI component.
return TRUE;
}
@ -102,3 +63,26 @@ void I2C_setup(void)
I2C_Cmd(ENABLE);
}
uint8_t getRegisterValue(uint8_t registerId)
{
uint8_t registerValue = 0xFF;
I2C_GenerateSTART(ENABLE);
while(!I2C_CheckEvent(I2C_EVENT_MASTER_MODE_SELECT));
I2C_Send7bitAddress((I2C_SLAVE_ADDRESS << 1), I2C_DIRECTION_TX);
while(!I2C_CheckEvent(I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
I2C_SendData(registerId);
while(!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTED));
//while(!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_RECEIVED));
registerValue = I2C_ReceiveData();
I2C_GenerateSTOP(ENABLE);
while(I2C_GetFlagStatus(I2C_FLAG_BUSBUSY));
return registerValue;
}

Wyświetl plik

@ -83,8 +83,11 @@ $(BUILD_DIR)/UserInterface.rel: $(SRCS)/UserInterface.c
$(BUILD_DIR)/Logger.rel: $(SRCS)/Logger.c
$(CC) -c $(CFLAGS) $(LDFLAGS) -o $(BUILD_DIR)/ $(SRCS)/Logger.rel $(SRCS)/Logger.c
$(BUILD_DIR)/MeasurementCollector.rel: $(SRCS)/MeasurementCollector.c
$(CC) -c $(CFLAGS) $(LDFLAGS) -o $(BUILD_DIR)/ $(SRCS)/MeasurementCollector.rel $(SRCS)/MeasurementCollector.c
$(BUILD_DIR)/ApplicationBuilder.rel: $(SRCS)/ApplicationBuilder.c $(BUILD_DIR)/VoltageSensorActualValue.rel $(BUILD_DIR)/PulseCounter.rel $(BUILD_DIR)/Logger.rel $(BUILD_DIR)/UserInterface.rel $(BUILD_DIR)/stm8s_uart1.rel $(BUILD_DIR)/TimerConfigurator.rel $(BUILD_DIR)/stm8s_i2c.rel
$(BUILD_DIR)/ApplicationBuilder.rel: $(SRCS)/ApplicationBuilder.c $(BUILD_DIR)/VoltageSensorActualValue.rel $(BUILD_DIR)/PulseCounter.rel $(BUILD_DIR)/Logger.rel $(BUILD_DIR)/UserInterface.rel $(BUILD_DIR)/stm8s_uart1.rel $(BUILD_DIR)/TimerConfigurator.rel $(BUILD_DIR)/stm8s_i2c.rel $(BUILD_DIR)/MeasurementCollector.rel
$(CC) -c $(CFLAGS) $(LDFLAGS) -o $(BUILD_DIR)/ $(SRCS)/ApplicationBuilder.rel $(SRCS)/ApplicationBuilder.c
@ -98,7 +101,10 @@ $(IHX): $(SRCS)/$(TARGET).c \
$(BUILD_DIR)/ClockConfigurator.rel \
$(BUILD_DIR)/stm8s_tim1.rel \
$(BUILD_DIR)/stm8s_it.rel \
$(BUILD_DIR)/Logger.rel \
$(BUILD_DIR)/VoltageSensorPeakValue.rel
$(BUILD_DIR)/MeasurementCollector.rel
$(CC) $(CFLAGS) $(LDFLAGS) -o $(BUILD_DIR)/ $< \
$(BUILD_DIR)/stm8s_gpio.rel \
$(BUILD_DIR)/stm8s_it.rel \
@ -114,6 +120,8 @@ $(IHX): $(SRCS)/$(TARGET).c \
$(BUILD_DIR)/TimerConfigurator.rel \
$(BUILD_DIR)/stm8s_tim1.rel \
$(BUILD_DIR)/VoltageSensorPeakValue.rel
$(BUILD_DIR)/MeasurementCollector.rel
$(SIZE) $@