protocol for uart communication

pull/112/head
Robert Gawron 2019-08-05 17:57:09 +03:00
rodzic a1a7e0147c
commit 45b25a8e8b
8 zmienionych plików z 86 dodań i 10 usunięć

Wyświetl plik

@ -10,7 +10,7 @@
#include "CommonDataTypes.h"
typedef uint16_t Logger_DataFormat_t;
typedef uint8_t Logger_DataFormat_t;
void Logger_Init();

Wyświetl plik

@ -0,0 +1,18 @@
/*
* MeassurementFrame.h
*
* Created on: 06.07.2019
* Author: robert
*/
#ifndef INC_MEASSUREMENTFRAME_H_
#define INC_MEASSUREMENTFRAME_H_
#include "CommonDataTypes.h"
void MeassurementFrame_Create(uint8_t configuration, uint16_t data);
/* Dependency injection. This module require a function that take character as an argument and print it somewhere. */
bool MeassurementFrame_Send(void (*sendFunction)(uint8_t));
#endif /* INC_MEASSUREMENTFRAME_H_ */

Wyświetl plik

@ -16,5 +16,6 @@ void VoltageSensorActualValue_Init();
bool VoltageSensorActualValue_MeasureValue(VoltageSensorActualValue_MeasurementData_t *measurementData);
uint8_t VoltageSensorActualValue_GetConfiguration();
#endif /* SRC_VOLTAGESENSORACTUALVALUE_H_ */

Wyświetl plik

@ -8,7 +8,7 @@
#include "Logger.h"
#include "stm8s_uart1.h"
#include "PinoutConfiguration.h"
#include "BitHandler.h"
//#define USE_PRINTF
#if defined USE_PRINTF
@ -47,8 +47,7 @@ void Logger_Print(Logger_DataFormat_t data)
#if defined USE_PRINTF
printf("%d\n\r", data);
#else
putchar(GET_MSB(data));
putchar(GET_LSB(data));
putchar(data);
#endif
}

Wyświetl plik

@ -0,0 +1,45 @@
/*
* MeassurementFrame.c
*
* Created on: 06.07.2019
* Author: robert
*/
#include "MeassurementFrame.h"
#include "BitHandler.h"
#define MAX_FRAME_LENGTH 5
#define FRAME_SEND_MEASSUREMENT_ID 1
#define GET_CRC(configuration, data) (configuration ^ GET_MSB(data) ^ GET_LSB(data))
enum Frameffsets { FRAME_PREAMBLE=0,
FRAME_CONFIGURATION=1,
FRAME_DATA_MSB=2,
FRAME_DATA_LSB=3,
FRAME_CRC=4 };
static uint8_t buffer[MAX_FRAME_LENGTH];
void MeassurementFrame_Create(uint8_t configuration, uint16_t data)
{
buffer[FRAME_PREAMBLE] = (FRAME_SEND_MEASSUREMENT_ID << 4) | MAX_FRAME_LENGTH;
buffer[FRAME_CONFIGURATION] = configuration;
buffer[FRAME_DATA_MSB] = GET_MSB(data);
buffer[FRAME_DATA_LSB] = GET_LSB(data);
buffer[FRAME_CRC] = GET_CRC(configuration, data);
}
bool MeassurementFrame_Send(void (*sendFunction)(uint8_t))
{
for(uint8_t i=0; i< MAX_FRAME_LENGTH; i++)
{
sendFunction(buffer[i]);
}
// TODO this should return status of sending data
return TRUE;
}

Wyświetl plik

@ -7,6 +7,7 @@
#include "MeasurementCollector.h"
#include "VoltageSensorActualValue.h"
#include "MeassurementFrame.h"
#include "Logger.h"
@ -17,9 +18,12 @@ void MeasurementCollector_Init()
void MeasurementCollector_Tick()
{
uint8_t configuration = VoltageSensorActualValue_GetConfiguration();
VoltageSensorActualValue_MeasurementData_t sample;
VoltageSensorActualValue_MeasureValue(&sample);
Logger_Print(sample);
MeassurementFrame_Create(configuration, sample);
MeassurementFrame_Send(&Logger_Print);
}

Wyświetl plik

@ -51,6 +51,11 @@ bool VoltageSensorActualValue_MeasureValue(VoltageSensorActualValue_MeasurementD
return TRUE;
}
uint8_t VoltageSensorActualValue_GetConfiguration()
{
return MCP3425_CONFIGURATION;
}
void GPIO_setup(void)
{

Wyświetl plik

@ -31,11 +31,11 @@ IHX = $(BUILD_DIR)/$(TARGET).ihx
################### BUILD PROCESS ###################
.PHONY: all build clean flash
all: make_build_dir build flash
all: build flash
make_build_dir:
mkdir -p $(BUILD_DIR)
mkdir $(BUILD_DIR)
build: $(IHX)
@ -86,8 +86,10 @@ $(BUILD_DIR)/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)/MeassurementFrame.rel: $(SRCS)/MeassurementFrame.c
$(CC) -c $(CFLAGS) $(LDFLAGS) -o $(BUILD_DIR)/ $(SRCS)/MeassurementFrame.rel $(SRCS)/MeassurementFrame.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)/MeasurementCollector.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 $(BUILD_DIR)/MeassurementFrame.rel
$(CC) -c $(CFLAGS) $(LDFLAGS) -o $(BUILD_DIR)/ $(SRCS)/ApplicationBuilder.rel $(SRCS)/ApplicationBuilder.c
@ -103,7 +105,8 @@ $(IHX): $(SRCS)/$(TARGET).c \
$(BUILD_DIR)/stm8s_it.rel \
$(BUILD_DIR)/Logger.rel \
$(BUILD_DIR)/VoltageSensorPeakValue.rel \
$(BUILD_DIR)/MeasurementCollector.rel
$(BUILD_DIR)/MeasurementCollector.rel \
$(BUILD_DIR)/MeassurementFrame.rel
$(CC) $(CFLAGS) $(LDFLAGS) -o $(BUILD_DIR)/ $< \
$(BUILD_DIR)/stm8s_gpio.rel \
@ -120,7 +123,8 @@ $(IHX): $(SRCS)/$(TARGET).c \
$(BUILD_DIR)/TimerConfigurator.rel \
$(BUILD_DIR)/stm8s_tim1.rel \
$(BUILD_DIR)/VoltageSensorPeakValue.rel \
$(BUILD_DIR)/MeasurementCollector.rel
$(BUILD_DIR)/MeasurementCollector.rel \
$(BUILD_DIR)/MeassurementFrame.rel
$(SIZE) $@