diff --git a/DS18B20/dallas_tools.c b/DS18B20/dallas_tools.c
index 42264a7..61c21aa 100644
--- a/DS18B20/dallas_tools.c
+++ b/DS18B20/dallas_tools.c
@@ -33,6 +33,8 @@ HAL_StatusTypeDef Dallas_ReplaceLostedSensor(DALLAS_HandleTypeDef *sensor)
if(sensor == NULL)
return HAL_ERROR;
+ result = Dallas_IsConnected(sensor);
+
if(sensor->isLost)
{
if(DS18B20_Search(&DS, &OW) != HAL_OK)
diff --git a/DS18B20/pch_sensors.c b/DS18B20/pch_sensors.c
index 5754832..b3581ff 100644
--- a/DS18B20/pch_sensors.c
+++ b/DS18B20/pch_sensors.c
@@ -14,41 +14,7 @@ PCHSens_UnknownSensorsTypeDef UnknownSensors;
PCHSens_ModuleTypeDef module1;
/* Functions ---------------------------------------------------------------*/
-HAL_StatusTypeDef PCHSens_FindUnknownSensors(OneWire_t *onewire, PCHSens_UnknownSensorsTypeDef *unknowns)
-{
- HAL_StatusTypeDef result;
- if(onewire == NULL)
- return HAL_ERROR;
- if(unknowns == NULL)
- return HAL_ERROR;
-
- unknowns->onewire = onewire;
- unknowns->UnknownCnt = 0;
- DALLAS_ScratchpadTypeDef scratchpad;
-
- PCHSens_LocationTypeDef *location = (PCHSens_LocationTypeDef *)&scratchpad.tHighRegister;
- for(int i = 0; i < onewire->RomCnt; i++)
- {
- /* Проверка присутствует ли выбранный датчик на линии */
- result = DS18B20_ReadScratchpad(onewire, (uint8_t *)&DS.DevAddr[i], (uint8_t *)&scratchpad);
- if(result != HAL_OK)
- __NOP();
-
- if((IS_REG_SENS_LOCATION(location) == 0) ||
- (IS_REG_PCH_LOCATION(location) == 0) ||
- (IS_REG_PCH_NUMB(location) == 0) )
- {
- unknowns->unknown_sensors[unknowns->UnknownCnt].Init.SensInd = i;
- unknowns->unknown_sensors[unknowns->UnknownCnt].Init.init_func = &Dallas_SensorInitByInd;
- result = Dallas_AddNewSensors(onewire, &unknowns->unknown_sensors[unknowns->UnknownCnt++]);
- if(result != HAL_OK)
- __NOP();
- }
- }
- return HAL_OK;
-}
-
-HAL_StatusTypeDef PCHSens_InitNewSensor(OneWire_t *onewire, PCHSens_SensorTypeDef* sensor, uint64_t ROM, uint16_t location)
+HAL_StatusTypeDef PCHSens_InitNewSensor(OneWire_t *onewire, PCHSens_SensorTypeDef* sensor, uint64_t ROM)
{
DALLAS_HandleTypeDef tempsens;
HAL_StatusTypeDef result;
@@ -56,14 +22,12 @@ HAL_StatusTypeDef PCHSens_InitNewSensor(OneWire_t *onewire, PCHSens_SensorTypeDe
return HAL_ERROR;
if(sensor == NULL)
return HAL_ERROR;
- if(location == NULL)
- return HAL_ERROR;
- sensor->Location = (PCHSens_LocationTypeDef *)&sensor->sens.scratchpad.tHighRegister;
+// sensor->UserBytes = (PCHSens_LocationTypeDef *)&sensor->sens.scratchpad.tHighRegister;
sensor->sens.Init.ROM = ROM;
- sensor->sens.Init.UserBytes12 = location;
+ sensor->sens.Init.UserBytes12 = sensor->Location.all;
sensor->sens.Init.init_func = &Dallas_SensorInitByROM;
@@ -74,7 +38,7 @@ HAL_StatusTypeDef PCHSens_InitNewSensor(OneWire_t *onewire, PCHSens_SensorTypeDe
return result;
}
- result = Dallas_WriteUserBytes(&sensor->sens, location, 0, DALLAS_USER_BYTE_12);
+ result = Dallas_WriteUserBytes(&sensor->sens, sensor->Location.all, sensor->Location.all, USED_USER_BYTES);
if(result != HAL_OK)
return result;
@@ -92,19 +56,17 @@ HAL_StatusTypeDef PCHSens_InitNewSensor(OneWire_t *onewire, PCHSens_SensorTypeDe
-HAL_StatusTypeDef PCHSens_AddSensor(OneWire_t *onewire, PCHSens_SensorTypeDef* sensor, uint16_t location)
+HAL_StatusTypeDef PCHSens_AddSensor(OneWire_t *onewire, PCHSens_SensorTypeDef* sensor)
{
HAL_StatusTypeDef result;
if(onewire == NULL)
return HAL_ERROR;
if(sensor == NULL)
return HAL_ERROR;
- if(location == NULL)
- return HAL_ERROR;
- sensor->Location = (PCHSens_LocationTypeDef *)&sensor->sens.scratchpad.tHighRegister;
+// sensor->UserBytes = (PCHSens_LocationTypeDef *)&sensor->sens.scratchpad.tHighRegister;
- sensor->sens.Init.UserBytes12 = location;
+ sensor->sens.Init.UserBytes12 = sensor->Location.all;
sensor->sens.Init.init_func = &Dallas_SensorInitByUserBytes;
@@ -118,7 +80,7 @@ HAL_StatusTypeDef PCHSens_AddSensor(OneWire_t *onewire, PCHSens_SensorTypeDef* s
return result;
}
-HAL_StatusTypeDef PCHSens_InitModule(OneWire_t *onewire, PCHSens_ModuleTypeDef* module, uint16_t location, uint8_t init)
+HAL_StatusTypeDef PCHSens_InitModule(OneWire_t *onewire, PCHSens_ModuleTypeDef* module, uint16_t param)
{
if(onewire == NULL)
return HAL_ERROR;
@@ -126,43 +88,26 @@ HAL_StatusTypeDef PCHSens_InitModule(OneWire_t *onewire, PCHSens_ModuleTypeDef*
return HAL_ERROR;
PCHSens_LocationTypeDef initlocation;
- initlocation.all = location;
+ initlocation.all = param;
module->onewire = onewire;
module->refLocation = initlocation;
- if(init == 0)
- {
- initlocation.location.Location = 0;
- PCHSens_AddSensor(onewire, &module->sens1, initlocation.all);
-
- initlocation.location.Location = 1;
- PCHSens_AddSensor(onewire, &module->sens2, initlocation.all);
-
- initlocation.location.Location = 2;
- PCHSens_AddSensor(onewire, &module->sens3, initlocation.all);
-
- initlocation.location.Location = 3;
- PCHSens_AddSensor(onewire, &module->sens4, initlocation.all);
- }
- else
- {
- uint64_t ROM = 0x28366a48f6563c8d;
- initlocation.location.Location = 0;
- PCHSens_InitNewSensor(onewire, &module->sens1, ROM, initlocation.all);
-
- ROM = 0x28CF5248F6BB3C2F;
- initlocation.location.Location = 1;
- PCHSens_InitNewSensor(onewire, &module->sens2, ROM, initlocation.all);
-
- ROM = 0x28876D60060000CD;
- initlocation.location.Location = 2;
- PCHSens_InitNewSensor(onewire, &module->sens3, ROM, initlocation.all);
-
- ROM = 0;
- initlocation.location.Location = 3;
- PCHSens_InitNewSensor(onewire, &module->sens4, ROM, initlocation.all);
- }
+ module->sens1.Location.all = module->refLocation.all;
+ module->sens1.Location.param.Location = 0;
+ PCHSens_AddSensor(onewire, &module->sens1);
+
+ module->sens2.Location.all = module->refLocation.all;
+ module->sens2.Location.param.Location = 1;
+ PCHSens_AddSensor(onewire, &module->sens2);
+
+ module->sens3.Location.all = module->refLocation.all;
+ module->sens3.Location.param.Location = 2;
+ PCHSens_AddSensor(onewire, &module->sens3);
+
+ module->sens4.Location.all = module->refLocation.all;
+ module->sens4.Location.param.Location = 3;
+ PCHSens_AddSensor(onewire, &module->sens4);
return HAL_OK;
}
@@ -176,22 +121,11 @@ HAL_StatusTypeDef PCHSens_ReadTemperature(PCHSens_ModuleTypeDef *module)
result = Dallas_StartConvertTAll(module->onewire, DALLAS_WAIT_BUS, 0);
- result = Dallas_ReadTemperature(&module->sens1.sens);
- if(result != HAL_OK)
- PCHSens_CheckSensor(module->onewire, &module->sens1);
-
- result = Dallas_ReadTemperature(&module->sens2.sens);
- if(result != HAL_OK)
- PCHSens_CheckSensor(module->onewire, &module->sens2);
-
- result = Dallas_ReadTemperature(&module->sens3.sens);
- if(result != HAL_OK)
- PCHSens_CheckSensor(module->onewire, &module->sens3);
-
- result = Dallas_ReadTemperature(&module->sens4.sens);
- if(result != HAL_OK)
- PCHSens_CheckSensor(module->onewire, &module->sens4);
-
+ result = PCHSens_SensorHandleActions(module->onewire, &module->sens1);
+ result = PCHSens_SensorHandleActions(module->onewire, &module->sens2);
+ result = PCHSens_SensorHandleActions(module->onewire, &module->sens3);
+ result = PCHSens_SensorHandleActions(module->onewire, &module->sens4);
+
PCHSens_DefineUnknownSensor(&UnknownSensors, NULL);
return result;
@@ -211,7 +145,7 @@ HAL_StatusTypeDef PCHSens_CheckSensor(OneWire_t *onewire, PCHSens_SensorTypeDef*
if((sensor->sens.isLost == 1))
{
- initlocation.location.Location = 0;
+ initlocation.param.Location = 0;
if(Dallas_ReplaceLostedSensor(&sensor->sens) != HAL_OK)
{
sensor->not_found = 1;
@@ -225,15 +159,48 @@ HAL_StatusTypeDef PCHSens_CheckSensor(OneWire_t *onewire, PCHSens_SensorTypeDef*
}
+HAL_StatusTypeDef PCHSens_FindUnknownSensors(OneWire_t *onewire, PCHSens_UnknownSensorsTypeDef *unknowns)
+{
+ HAL_StatusTypeDef result;
+ if(onewire == NULL)
+ return HAL_ERROR;
+ if(unknowns == NULL)
+ return HAL_ERROR;
+
+ unknowns->onewire = onewire;
+ unknowns->UnknownCnt = 0;
+ DALLAS_ScratchpadTypeDef scratchpad;
+
+ PCHSens_LocationTypeDef *param = (PCHSens_LocationTypeDef *)&scratchpad.tHighRegister;
+ for(int i = 0; i < onewire->RomCnt; i++)
+ {
+ /* Проверка присутствует ли выбранный датчик на линии */
+ result = DS18B20_ReadScratchpad(onewire, (uint8_t *)&DS.DevAddr[i], (uint8_t *)&scratchpad);
+ if(result != HAL_OK)
+ __NOP();
+
+ if((IS_REG_SENS_LOCATION(param) == 0) ||
+ (IS_REG_PCH_LOCATION(param) == 0) ||
+ (IS_REG_PCH_NUMB(param) == 0) )
+ {
+ unknowns->unknown_sensors[unknowns->UnknownCnt].Init.SensInd = i;
+ unknowns->unknown_sensors[unknowns->UnknownCnt].Init.init_func = &Dallas_SensorInitByInd;
+ result = Dallas_AddNewSensors(onewire, &unknowns->unknown_sensors[unknowns->UnknownCnt++]);
+ if(result != HAL_OK)
+ __NOP();
+ }
+ }
+ return HAL_OK;
+}
HAL_StatusTypeDef PCHSens_DefineUnknownSensor(PCHSens_UnknownSensorsTypeDef *unknowns, PCHSens_SensorTypeDef *sensor)
{
HAL_StatusTypeDef result;
-// if(unknowns->UnknownCnt == 0)
-// return HAL_OK;
+ if(sensor == NULL)
+ return HAL_ERROR;
if((unknowns->ROMtoDefine != NULL) && (unknowns->LocationtoDefine.all != NULL) && (unknowns->senstoDefine != NULL))
{
- result = PCHSens_InitNewSensor(unknowns->onewire, unknowns->senstoDefine, unknowns->ROMtoDefine, unknowns->LocationtoDefine.all);
+ result = PCHSens_InitNewSensor(unknowns->onewire, unknowns->senstoDefine, unknowns->ROMtoDefine);
unknowns->ROMtoDefine = 0;
unknowns->LocationtoDefine.all = 0;
unknowns->senstoDefine = 0;
@@ -242,13 +209,48 @@ HAL_StatusTypeDef PCHSens_DefineUnknownSensor(PCHSens_UnknownSensorsTypeDef *unk
return HAL_OK;
}
-HAL_StatusTypeDef PCHSens_FullDeInitSensor(PCHSens_SensorTypeDef *sensor)
+HAL_StatusTypeDef PCHSens_UndefineSensor(PCHSens_SensorTypeDef *sensor)
{
HAL_StatusTypeDef result;
-// if(unknowns->UnknownCnt == 0)
-// return HAL_OK;
+ if(sensor == NULL)
+ return HAL_ERROR;
+
+ result = Dallas_WriteUserBytes(&sensor->sens, 0, 0, USED_USER_BYTES);
+ if(result != HAL_OK)
+ {
+ return result;
+ }
+
+ result = Dallas_SensorDeInit(&sensor->sens);
+ return result;
+}
+
+HAL_StatusTypeDef PCHSens_SensorHandleActions(OneWire_t *onewire, PCHSens_SensorTypeDef *sensor)
+{
+ HAL_StatusTypeDef result;
+ if(sensor == NULL)
+ return HAL_ERROR;
+
+ if(sensor->action.connectROM != NULL)
+ {
+ result = PCHSens_InitNewSensor(onewire, sensor, sensor->action.connectROM);
+ sensor->action.connectROM = 0;
+ }
+
+ if(sensor->action.read != NULL)
+ {
+// sensor->action.read = 0;
+ result = Dallas_ReadTemperature(&sensor->sens);
+ if(result != HAL_OK)
+ PCHSens_CheckSensor(onewire, sensor);
+ }
+
+ if(sensor->action.deinit != NULL)
+ {
+ sensor->action.deinit = 0;
+ result = PCHSens_UndefineSensor(sensor);
+ }
- result = PCHSens_InitNewSensor(sensor->onewire, sensor, unknowns->ROMtoDefine, unknowns->LocationtoDefine.all);
return result;
}
@@ -262,7 +264,7 @@ void PCHSens_FirstInit(void)
OneWire_Init(&OW);
DS18B20_Search(&DS, &OW);
- PCHSens_InitModule(&OW, &module1, REG_PCH_NUMB_11|REG_PCH_DIODE_NUMB_1, init_find);
+ PCHSens_InitModule(&OW, &module1, REG_PCH_NUMB_11|REG_PCH_DIODE_NUMB_1);
PCHSens_FindUnknownSensors(&OW, &UnknownSensors);
PCHSens_DefineUnknownSensor(&UnknownSensors, NULL);
diff --git a/DS18B20/pch_sensors.h b/DS18B20/pch_sensors.h
index b413d46..f7ed078 100644
--- a/DS18B20/pch_sensors.h
+++ b/DS18B20/pch_sensors.h
@@ -15,6 +15,7 @@
#include "dallas_tools.h"
/* Declarations and definitions ---------------------------------------------*/
+#define USED_USER_BYTES DALLAS_USER_BYTE_12
/* Позиции параметров в UserBytes */
#define REG_SENS_LOCATION_Pos (0) /*!< @brief Позиция параметра "Локация внутри модуля" */
@@ -71,8 +72,8 @@
#define GET_REG_ZIP(_REG_) ((_REG_) & REG_ZIP_Mask) /*!< @brief Получить параметр "ЗИП/не ЗИП" */
/* Диапазоны параметров из UserBytes */
-#define REG_SENS_LOCATION_MAX 4
-#define REG_SENS_LOCATION_MIN 1
+#define REG_SENS_LOCATION_MAX 3
+#define REG_SENS_LOCATION_MIN 0
#define REG_PCH_DIOD_PHASE_MAX 1
#define REG_PCH_DIOD_PHASE_MIN 0
#define REG_PCH_MODULE_NUMB_MAX 3
@@ -84,21 +85,21 @@
/** @brief Получить параметр "Локация внутри модуля" */
-#define IS_REG_SENS_LOCATION(_REG_) (((_REG_)->location.Location <= REG_SENS_LOCATION_MAX) && ((_REG_)->location.Location >= REG_SENS_LOCATION_MIN))
+#define IS_REG_SENS_LOCATION(_REG_) (((_REG_)->param.Location <= REG_SENS_LOCATION_MAX) && ((_REG_)->param.Location >= REG_SENS_LOCATION_MIN))
/*!< @brief Получить параметр "Расположение в ПЧ" */
#define IS_REG_PCH_LOCATION(_REG_) (IS_REG_PCH_DIOD_PHASE(_REG_) && IS_REG_PCH_MODULE_NUMB(_REG_))
/*!< @brief Получить параметр "Диодный или фазный модуль" */
-#define IS_REG_PCH_DIOD_PHASE(_REG_) (((_REG_)->location.DiodeOrPhase <= REG_PCH_DIOD_PHASE_MAX) && ((_REG_)->location.DiodeOrPhase >= REG_PCH_DIOD_PHASE_MIN))
+#define IS_REG_PCH_DIOD_PHASE(_REG_) (((_REG_)->param.DiodeOrPhase <= REG_PCH_DIOD_PHASE_MAX) && ((_REG_)->param.DiodeOrPhase >= REG_PCH_DIOD_PHASE_MIN))
/*!< @brief Получить параметр "Порядковый номер диодного/фазного модуля" */
-#define IS_REG_PCH_MODULE_NUMB(_REG_) (((_REG_)->location.ModuleNumb <= REG_PCH_MODULE_NUMB_MAX) && ((_REG_)->location.ModuleNumb >= REG_PCH_MODULE_NUMB_MIN))
+#define IS_REG_PCH_MODULE_NUMB(_REG_) (((_REG_)->param.ModuleNumb <= REG_PCH_MODULE_NUMB_MAX) && ((_REG_)->param.ModuleNumb >= REG_PCH_MODULE_NUMB_MIN))
/*!< @brief Получить параметр "Преобразователь частоты" */
#define IS_REG_PCH_NUMB(_REG_) (IS_REG_PCH_NUMB_DIGIT_1(_REG_) && IS_REG_PCH_NUMB_DIGIT_2(_REG_))
/*!< @brief Получить параметр "Первая цифра номера преобразователя частоты" */
-#define IS_REG_PCH_NUMB_DIGIT_1(_REG_) (((_REG_)->location.PCHdig1 <= REG_PCH_NUMB_DIGIT_1_MAX) && ((_REG_)->location.PCHdig1 >= REG_PCH_NUMB_DIGIT_1_MIN))
+#define IS_REG_PCH_NUMB_DIGIT_1(_REG_) (((_REG_)->param.PCHdig1 <= REG_PCH_NUMB_DIGIT_1_MAX) && ((_REG_)->param.PCHdig1 >= REG_PCH_NUMB_DIGIT_1_MIN))
/*!< @brief Получить параметр "Вторая цифра номера преобразователя частоты" s*/
-#define IS_REG_PCH_NUMB_DIGIT_2(_REG_) (((_REG_)->location.PCHdig2 <= REG_PCH_NUMB_DIGIT_2_MAX) && ((_REG_)->location.PCHdig2 >= REG_PCH_NUMB_DIGIT_2_MIN))
+#define IS_REG_PCH_NUMB_DIGIT_2(_REG_) (((_REG_)->param.PCHdig2 <= REG_PCH_NUMB_DIGIT_2_MAX) && ((_REG_)->param.PCHdig2 >= REG_PCH_NUMB_DIGIT_2_MIN))
/*!< @brief Получить параметр "ЗИП/не ЗИП" */
#define IS_REG_ZIP(_REG_) (GET_REG_ZIP(_REG_))
@@ -114,15 +115,24 @@ typedef union
unsigned PCHdig2:2;
unsigned PCHdig1:2;
unsigned ZIP:1;
- }location;
+ }param;
}PCHSens_LocationTypeDef;
typedef struct
{
- DALLAS_HandleTypeDef sens;
- PCHSens_LocationTypeDef *Location;
- unsigned not_found:1;
+ unsigned connectROM;
+ unsigned read;
+ unsigned deinit;
+}PCHSens_SensorActionsTypeDef;
+
+typedef struct
+{
+ DALLAS_HandleTypeDef sens;
+// PCHSens_LocationTypeDef *UserBytes;
+ PCHSens_LocationTypeDef Location;
+ PCHSens_SensorActionsTypeDef action;
+ unsigned not_found:1;
}PCHSens_SensorTypeDef;
typedef struct
@@ -153,12 +163,12 @@ typedef struct
/* Functions ---------------------------------------------------------------*/
HAL_StatusTypeDef PCHSens_FindUnknownSensors(OneWire_t *onewire, PCHSens_UnknownSensorsTypeDef *unknowns);
-HAL_StatusTypeDef PCHSens_InitNewSensor(OneWire_t *onewire, PCHSens_SensorTypeDef* sensor, uint64_t ROM, uint16_t location);
-HAL_StatusTypeDef PCHSens_AddSensor(OneWire_t *onewire, PCHSens_SensorTypeDef* sensor, uint16_t location);
-HAL_StatusTypeDef PCHSens_InitModule(OneWire_t *onewire, PCHSens_ModuleTypeDef* module, uint16_t location, uint8_t init);
+HAL_StatusTypeDef PCHSens_InitNewSensor(OneWire_t *onewire, PCHSens_SensorTypeDef* sensor, uint64_t ROM);
+HAL_StatusTypeDef PCHSens_AddSensor(OneWire_t *onewire, PCHSens_SensorTypeDef* sensor);
+HAL_StatusTypeDef PCHSens_InitModule(OneWire_t *onewire, PCHSens_ModuleTypeDef* module, uint16_t param);
HAL_StatusTypeDef PCHSens_ReadTemperature(PCHSens_ModuleTypeDef *module);
HAL_StatusTypeDef PCHSens_CheckSensor(OneWire_t *onewire, PCHSens_SensorTypeDef* sensor);
HAL_StatusTypeDef PCHSens_DefineUnknownSensor(PCHSens_UnknownSensorsTypeDef *unknowns, PCHSens_SensorTypeDef *sensor);
-
+HAL_StatusTypeDef PCHSens_SensorHandleActions(OneWire_t *onewire, PCHSens_SensorTypeDef *sensor);
void PCHSens_FirstInit(void);
#endif // #ifndef PCH_SENSORS_H
\ No newline at end of file
diff --git a/ds18b20_locations.xlsx b/ds18b20_locations.xlsx
index 293a8f8..6b591fa 100644
Binary files a/ds18b20_locations.xlsx and b/ds18b20_locations.xlsx differ
diff --git a/test_project/MDK-ARM/ds18b20.uvoptx b/test_project/MDK-ARM/ds18b20.uvoptx
index 6908c8d..abacbc7 100644
--- a/test_project/MDK-ARM/ds18b20.uvoptx
+++ b/test_project/MDK-ARM/ds18b20.uvoptx
@@ -152,9 +152,9 @@
0
0
- 236
+ 264
1
- 134229812
+ 134230484
0
0
0
@@ -163,23 +163,7 @@
1
..\..\DS18B20\pch_sensors.c
- \\ds18b20\../../DS18B20/pch_sensors.c\236
-
-
- 1
- 0
- 70
- 1
- 134231004
- 0
- 0
- 0
- 0
- 0
- 1
- ..\..\DS18B20\pch_sensors.c
-
- \\ds18b20\../../DS18B20/pch_sensors.c\70
+ \\ds18b20\../../DS18B20/pch_sensors.c\264
@@ -375,7 +359,7 @@
Drivers/STM32F1xx_HAL_Driver
- 0
+ 1
0
0
0