какая-то заготовка которую я не помню...

This commit is contained in:
2025-02-28 14:18:27 +03:00
parent d73b65a286
commit 39c495410b
5 changed files with 137 additions and 139 deletions

View File

@@ -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)

View File

@@ -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);
module->sens1.Location.all = module->refLocation.all;
module->sens1.Location.param.Location = 0;
PCHSens_AddSensor(onewire, &module->sens1);
initlocation.location.Location = 1;
PCHSens_AddSensor(onewire, &module->sens2, initlocation.all);
module->sens2.Location.all = module->refLocation.all;
module->sens2.Location.param.Location = 1;
PCHSens_AddSensor(onewire, &module->sens2);
initlocation.location.Location = 2;
PCHSens_AddSensor(onewire, &module->sens3, initlocation.all);
module->sens3.Location.all = module->refLocation.all;
module->sens3.Location.param.Location = 2;
PCHSens_AddSensor(onewire, &module->sens3);
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->sens4.Location.all = module->refLocation.all;
module->sens4.Location.param.Location = 3;
PCHSens_AddSensor(onewire, &module->sens4);
return HAL_OK;
}
@@ -176,21 +121,10 @@ 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);
@@ -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);

View File

@@ -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

Binary file not shown.

View File

@@ -152,9 +152,9 @@
<Bp>
<Number>0</Number>
<Type>0</Type>
<LineNumber>236</LineNumber>
<LineNumber>264</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>134229812</Address>
<Address>134230484</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
@@ -163,23 +163,7 @@
<BreakIfRCount>1</BreakIfRCount>
<Filename>..\..\DS18B20\pch_sensors.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\ds18b20\../../DS18B20/pch_sensors.c\236</Expression>
</Bp>
<Bp>
<Number>1</Number>
<Type>0</Type>
<LineNumber>70</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>134231004</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>..\..\DS18B20\pch_sensors.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\ds18b20\../../DS18B20/pch_sensors.c\70</Expression>
<Expression>\\ds18b20\../../DS18B20/pch_sensors.c\264</Expression>
</Bp>
</Breakpoint>
<WatchWindow1>
@@ -375,7 +359,7 @@
<Group>
<GroupName>Drivers/STM32F1xx_HAL_Driver</GroupName>
<tvExp>0</tvExp>
<tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel>
<RteFlg>0</RteFlg>