Сделана заготовка структуры и функций для измерения датчиков с модуля пч
This commit is contained in:
@@ -19,123 +19,7 @@
|
||||
|
||||
/* Declarations and definitions --------------------------------------------*/
|
||||
|
||||
struct
|
||||
{
|
||||
DALLAS_HandleTypeDef outdoor;
|
||||
DALLAS_HandleTypeDef indoor;
|
||||
DALLAS_HandleTypeDef bathroom;
|
||||
DALLAS_HandleTypeDef kitchen;
|
||||
DALLAS_HandleTypeDef big_room;
|
||||
DALLAS_HandleTypeDef small_room;
|
||||
DALLAS_HandleTypeDef living_room;
|
||||
DALLAS_HandleTypeDef basement;
|
||||
}AllSens;
|
||||
|
||||
/* Functions ---------------------------------------------------------------*/
|
||||
|
||||
void Dallas_ReadAll(void)
|
||||
{
|
||||
HAL_StatusTypeDef result;
|
||||
|
||||
result = Dallas_StartConvertTAll(&OW, DALLAS_WAIT_BUS, 0);
|
||||
|
||||
if(Dallas_ReadTemperature(&AllSens.outdoor) == HAL_BUSY)
|
||||
Dallas_ReplaceLostedSensor(&AllSens.outdoor);
|
||||
|
||||
if(Dallas_ReadTemperature(&AllSens.indoor) == HAL_BUSY)
|
||||
Dallas_ReplaceLostedSensor(&AllSens.indoor);
|
||||
|
||||
if(Dallas_ReadTemperature(&AllSens.bathroom) == HAL_BUSY)
|
||||
Dallas_ReplaceLostedSensor(&AllSens.bathroom);
|
||||
|
||||
if(Dallas_ReadTemperature(&AllSens.kitchen) == HAL_BUSY)
|
||||
Dallas_ReplaceLostedSensor(&AllSens.kitchen);
|
||||
|
||||
if(Dallas_ReadTemperature(&AllSens.big_room) == HAL_BUSY)
|
||||
Dallas_ReplaceLostedSensor(&AllSens.big_room);
|
||||
|
||||
if(Dallas_ReadTemperature(&AllSens.small_room) == HAL_BUSY)
|
||||
Dallas_ReplaceLostedSensor(&AllSens.small_room);
|
||||
|
||||
if(Dallas_ReadTemperature(&AllSens.living_room) == HAL_BUSY)
|
||||
Dallas_ReplaceLostedSensor(&AllSens.living_room);
|
||||
|
||||
if(Dallas_ReadTemperature(&AllSens.basement) == HAL_BUSY)
|
||||
Dallas_ReplaceLostedSensor(&AllSens.basement);
|
||||
|
||||
}
|
||||
|
||||
void Dallas_FirstInit(void)
|
||||
{
|
||||
OW.DataPin = DS_Pin;
|
||||
OW.DataPort = DS_GPIO_Port;
|
||||
DS.Resolution = DS18B20_RESOLUTION_9BITS;
|
||||
|
||||
OneWire_Init(&OW);
|
||||
DS18B20_Search(&DS, &OW);
|
||||
AllSens.outdoor.Init.ROM = 0x28C60C61060000DC;
|
||||
AllSens.indoor.Init.ROM = 0x283E4861060000F9;
|
||||
AllSens.bathroom.Init.ROM = 0x28876D60060000CD;
|
||||
|
||||
AllSens.outdoor.Init.SensInd = 0;
|
||||
AllSens.indoor.Init.SensInd = 1;
|
||||
AllSens.bathroom.Init.SensInd = 2;
|
||||
AllSens.kitchen.Init.SensInd = 3;
|
||||
AllSens.big_room.Init.SensInd = 4;
|
||||
AllSens.small_room.Init.SensInd = 5;
|
||||
AllSens.living_room.Init.SensInd = 6;
|
||||
AllSens.basement.Init.SensInd = 7;
|
||||
|
||||
AllSens.outdoor.Init.UserBytes12 = 1;
|
||||
AllSens.indoor.Init.UserBytes12 = 2;
|
||||
AllSens.bathroom.Init.UserBytes12 = 3;
|
||||
AllSens.kitchen.Init.UserBytes12 = 4;
|
||||
AllSens.big_room.Init.UserBytes12 = 5;
|
||||
AllSens.small_room.Init.UserBytes12 = 6;
|
||||
AllSens.living_room.Init.UserBytes12 = 7;
|
||||
AllSens.basement.Init.UserBytes12 = 8;
|
||||
|
||||
|
||||
|
||||
AllSens.outdoor.Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByUserBytes;
|
||||
AllSens.indoor.Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByUserBytes;
|
||||
AllSens.bathroom.Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByUserBytes;
|
||||
AllSens.kitchen.Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByUserBytes;
|
||||
AllSens.big_room.Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByUserBytes;
|
||||
AllSens.small_room.Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByUserBytes;
|
||||
AllSens.living_room.Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByUserBytes;
|
||||
AllSens.basement.Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByUserBytes;
|
||||
|
||||
Dallas_AddNewSensors(&OW, &AllSens.outdoor);
|
||||
Dallas_AddNewSensors(&OW, &AllSens.indoor);
|
||||
Dallas_AddNewSensors(&OW, &AllSens.bathroom);
|
||||
|
||||
//
|
||||
// Dallas_SensorInitByInd(&OW, &AllSens.outdoor, 0);
|
||||
// Dallas_SensorInitByInd(&OW, &AllSens.indoor, 2);
|
||||
// Dallas_SensorInitByInd(&OW, &AllSens.bathroom, 1);
|
||||
// Dallas_SensorInitByInd(&OW, &AllSens.kitchen, 3);
|
||||
// Dallas_SensorInitByInd(&OW, &AllSens.big_room, 4);
|
||||
// Dallas_SensorInitByInd(&OW, &AllSens.small_room, 5);
|
||||
// Dallas_SensorInitByInd(&OW, &AllSens.living_room, 6);
|
||||
// Dallas_SensorInitByInd(&OW, &AllSens.basement, 7);
|
||||
//
|
||||
// uint8_t mask = DALLAS_USER_BYTE_ALL;
|
||||
// Dallas_WriteUserBytes(&AllSens.outdoor, 1, NULL, mask);
|
||||
// Dallas_WriteUserBytes(&AllSens.indoor, 2, NULL, mask);
|
||||
// Dallas_WriteUserBytes(&AllSens.bathroom, 3, NULL, mask);
|
||||
// Dallas_WriteUserBytes(&AllSens.kitchen, 4, NULL, mask);
|
||||
// Dallas_WriteUserBytes(&AllSens.big_room, 5, NULL, mask);
|
||||
// Dallas_WriteUserBytes(&AllSens.small_room, 6, NULL, mask);
|
||||
// Dallas_WriteUserBytes(&AllSens.living_room, 7, NULL, mask);
|
||||
// Dallas_WriteUserBytes(&AllSens.basement, 8, NULL, mask);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Ôóíêöèÿ äëÿ íàõîæäåíèÿ íîâîãî äàò÷èêà íà ìåñòî ïîòåðÿííîãî
|
||||
* @param sensor Óêàçàòåëü íà ñòðóêòóðó äàò÷èêà
|
||||
@@ -276,52 +160,47 @@ HAL_StatusTypeDef Dallas_SensorInitByUserBytes(OneWire_t *onewire, DALLAS_Handle
|
||||
|
||||
DALLAS_ScratchpadTypeDef scratchpad;
|
||||
for(int i = 0; i < onewire->RomCnt; i++)
|
||||
{
|
||||
{
|
||||
/* Проверка присутствует ли выбранный датчик на линии */
|
||||
result = DS18B20_ReadScratchpad(onewire, (uint8_t *)&DS.DevAddr[i], (uint8_t *)&scratchpad);
|
||||
if (result != HAL_OK)
|
||||
return result;
|
||||
|
||||
for(int rom_ind = 0; rom_ind < DALLAS_ROM_SIZE; rom_ind++)
|
||||
/* Сравнение UserByte1 и UserByte2, если они не равны нулю */
|
||||
if(sensor->Init.UserBytes12 != NULL)
|
||||
{
|
||||
/* Ïðîâåðêà ïðèñóòñòâóåò ëè âûáðàííûé äàò÷èê íà ëèíèè */
|
||||
result = DS18B20_ReadScratchpad(onewire, (uint8_t *)&DS.DevAddr[i], (uint8_t *)&scratchpad);
|
||||
if (result != HAL_OK)
|
||||
return result;
|
||||
|
||||
/* Ñðàâíåíèå UserByte1 è UserByte2, åñëè îíè íå ðàâíû íóëþ */
|
||||
if(sensor->Init.UserBytes12 != NULL)
|
||||
{
|
||||
if( (scratchpad.tHighRegister == UserByte1) &&
|
||||
(scratchpad.tLowRegister == UserByte2))
|
||||
{
|
||||
UserByte12Cmp = 1;
|
||||
}
|
||||
}/* Åñëè ñðàâíåíèå UserByte1 è UserByte2 íå âûáðàíî, òî ñ÷èòàåì ÷òî îíè ñîâïàäàþò */
|
||||
else
|
||||
if( (scratchpad.tHighRegister == UserByte1) &&
|
||||
(scratchpad.tLowRegister == UserByte2))
|
||||
{
|
||||
UserByte12Cmp = 1;
|
||||
}
|
||||
/* Ñðàâíåíèå UserByte3 è UserByte4, åñëè îíè íå ðàâíû íóëþ */
|
||||
if(sensor->Init.UserBytes34 != NULL)
|
||||
{
|
||||
if( (scratchpad.UserByte3 == UserByte3) &&
|
||||
(scratchpad.UserByte4 == UserByte4))
|
||||
{
|
||||
UserByte34Cmp = 1;
|
||||
}
|
||||
}/* Åñëè ñðàâíåíèå UserByte3 è UserByte4 íå âûáðàíî, òî ñ÷èòàåì ÷òî îíè îäèíàêîâûå */
|
||||
else
|
||||
}/* Если сравнение UserByte1 и UserByte2 не выбрано, то считаем что они совпадают */
|
||||
else
|
||||
{
|
||||
UserByte12Cmp = 1;
|
||||
}
|
||||
/* Сравнение UserByte3 и UserByte4, если они не равны нулю */
|
||||
if(sensor->Init.UserBytes34 != NULL)
|
||||
{
|
||||
if( (scratchpad.UserByte3 == UserByte3) &&
|
||||
(scratchpad.UserByte4 == UserByte4))
|
||||
{
|
||||
UserByte34Cmp = 1;
|
||||
}
|
||||
/* Åñëè íàøëè íóæíûé äàò÷èê - çàâåðøàåì ïîèñê */
|
||||
if(UserByte12Cmp && UserByte34Cmp)
|
||||
{
|
||||
// sensor->isInitialized = 1;
|
||||
// sensor->Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByUserBytes;
|
||||
result = Dallas_SensorInit(onewire, sensor, &DS.DevAddr[i]);
|
||||
return result;
|
||||
}
|
||||
}/* Если сравнение UserByte3 и UserByte4 не выбрано, то считаем что они одинаковые */
|
||||
else
|
||||
{
|
||||
UserByte34Cmp = 1;
|
||||
}
|
||||
/* Если нашли нужный датчик - завершаем поиск */
|
||||
if(UserByte12Cmp && UserByte34Cmp)
|
||||
{
|
||||
// sensor->isInitialized = 1;
|
||||
// sensor->Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByUserBytes;
|
||||
result = Dallas_SensorInit(onewire, sensor, &DS.DevAddr[i]);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Dallas_SensorDeInit(sensor);
|
||||
/* Âîçâðàùàåì îøèáêó åñëè íå íàøëè */
|
||||
return HAL_ERROR;
|
||||
}
|
||||
@@ -368,8 +247,6 @@ HAL_StatusTypeDef Dallas_SensorInit(OneWire_t *onewire, DALLAS_HandleTypeDef *se
|
||||
if(onewire == 0)
|
||||
return HAL_ERROR;
|
||||
|
||||
|
||||
|
||||
sensor->onewire = onewire;
|
||||
|
||||
for(int i = 0; i < DALLAS_ROM_SIZE; i++)
|
||||
@@ -389,14 +266,12 @@ HAL_StatusTypeDef Dallas_SensorInit(OneWire_t *onewire, DALLAS_HandleTypeDef *se
|
||||
else
|
||||
{
|
||||
sensor->isInitialized = 0;
|
||||
Dallas_SensorDeInit(sensor);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sensor->isInitialized = 0;
|
||||
Dallas_SensorDeInit(sensor);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -414,12 +289,10 @@ HAL_StatusTypeDef Dallas_SensorDeInit(DALLAS_HandleTypeDef *sensor)
|
||||
return HAL_ERROR;
|
||||
|
||||
DALLAS_InitStructTypeDef initbuff = sensor->Init;
|
||||
DALLAS_ControlTypeDef ctrlbuff = sensor->Control;
|
||||
|
||||
memset(sensor, 0, sizeof(DALLAS_HandleTypeDef));
|
||||
|
||||
sensor->Init = initbuff;
|
||||
sensor->Control = ctrlbuff;
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
@@ -111,9 +111,7 @@ typedef enum
|
||||
|
||||
|
||||
/* Functions ---------------------------------------------------------------*/
|
||||
void Dallas_Init(DALLAS_HandleTypeDef *sensor, UART_HandleTypeDef *huart);
|
||||
void Dallas_ReadAll(void);
|
||||
void Dallas_FirstInit(void);
|
||||
|
||||
/* Функция для нахождения нового датчика на место потерянного */
|
||||
HAL_StatusTypeDef Dallas_ReplaceLostedSensor(DALLAS_HandleTypeDef *sensor);
|
||||
/* Функция для иниицализации нового датчика в структуре */
|
||||
|
||||
173
DS18B20/pch_sensors.c
Normal file
173
DS18B20/pch_sensors.c
Normal file
@@ -0,0 +1,173 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file pch_sensors.c
|
||||
* @brief Ðàáîòà ñ äàò÷èêàìè òåìïåðàòóðû DS18B20 â Ï×
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
/* Includes ----------------------------------------------------------------*/
|
||||
|
||||
#include "pch_sensors.h"
|
||||
|
||||
|
||||
/* Declarations and definitions --------------------------------------------*/
|
||||
|
||||
PCHSens_ModuleTypeDef module1;
|
||||
/* Functions ---------------------------------------------------------------*/
|
||||
|
||||
HAL_StatusTypeDef PCHSens_InitNewSensor(OneWire_t *onewire, PCH_SensorTypeDef* sensor, uint64_t ROM, PCHSens_LocationTypeDef *location)
|
||||
{
|
||||
DALLAS_HandleTypeDef tempsens;
|
||||
HAL_StatusTypeDef result;
|
||||
if(onewire == NULL)
|
||||
return HAL_ERROR;
|
||||
if(sensor == NULL)
|
||||
return HAL_ERROR;
|
||||
if(location == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
PCHSens_LocationTypeDef initlocation = *location;
|
||||
|
||||
sensor->Location = (PCHSens_LocationTypeDef *)&sensor->sens.scratchpad.tHighRegister;
|
||||
|
||||
sensor->sens.Init.ROM = ROM;
|
||||
|
||||
sensor->sens.Init.UserBytes12 = initlocation.all;
|
||||
|
||||
sensor->sens.Init.init_func = &Dallas_SensorInitByROM;
|
||||
|
||||
result = Dallas_AddNewSensors(onewire, &sensor->sens);
|
||||
if(result != HAL_OK)
|
||||
return result;
|
||||
|
||||
result = Dallas_WriteUserBytes(&sensor->sens, initlocation.all, 0, DALLAS_USER_BYTE_12);
|
||||
if(result != HAL_OK)
|
||||
return result;
|
||||
|
||||
sensor->sens.Init.init_func = &Dallas_SensorInitByUserBytes;
|
||||
|
||||
return Dallas_AddNewSensors(onewire, &sensor->sens);
|
||||
}
|
||||
|
||||
|
||||
HAL_StatusTypeDef PCHSens_FindSensor(OneWire_t *onewire, PCH_SensorTypeDef* sensor, PCHSens_LocationTypeDef *location)
|
||||
{
|
||||
if(onewire == NULL)
|
||||
return HAL_ERROR;
|
||||
if(sensor == NULL)
|
||||
return HAL_ERROR;
|
||||
if(location == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
PCHSens_LocationTypeDef initlocation = *location;
|
||||
|
||||
sensor->Location = (PCHSens_LocationTypeDef *)&sensor->sens.scratchpad.tHighRegister;
|
||||
|
||||
sensor->sens.Init.UserBytes12 = initlocation.all;
|
||||
|
||||
sensor->sens.Init.init_func = &Dallas_SensorInitByUserBytes;
|
||||
|
||||
return Dallas_AddNewSensors(onewire, &sensor->sens);
|
||||
}
|
||||
|
||||
HAL_StatusTypeDef PCHSens_FindModule(OneWire_t *onewire, PCHSens_ModuleTypeDef* module, PCHSens_LocationTypeDef *location, uint8_t init)
|
||||
{
|
||||
if(onewire == NULL)
|
||||
return HAL_ERROR;
|
||||
if(module == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
PCHSens_LocationTypeDef initlocation = *location;
|
||||
|
||||
module->onewire = onewire;
|
||||
module->refLocation = initlocation;
|
||||
|
||||
if(init == 0)
|
||||
{
|
||||
initlocation.location.Location = 0;
|
||||
PCHSens_FindSensor(onewire, &module->sens1, &initlocation);
|
||||
|
||||
initlocation.location.Location = 1;
|
||||
PCHSens_FindSensor(onewire, &module->sens2, &initlocation);
|
||||
|
||||
initlocation.location.Location = 2;
|
||||
PCHSens_FindSensor(onewire, &module->sens3, &initlocation);
|
||||
|
||||
initlocation.location.Location = 3;
|
||||
PCHSens_FindSensor(onewire, &module->sens4, &initlocation);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint64_t ROM = 0x28366a48f6563c8d;
|
||||
initlocation.location.Location = 0;
|
||||
PCHSens_InitNewSensor(onewire, &module->sens1, ROM, &initlocation);
|
||||
|
||||
ROM = 0x28CF5248F6BB3C2F;
|
||||
initlocation.location.Location = 1;
|
||||
PCHSens_InitNewSensor(onewire, &module->sens2, ROM, &initlocation);
|
||||
|
||||
ROM = 0x28876D60060000CD;
|
||||
initlocation.location.Location = 2;
|
||||
PCHSens_InitNewSensor(onewire, &module->sens3, ROM, &initlocation);
|
||||
|
||||
ROM = 0;
|
||||
initlocation.location.Location = 3;
|
||||
PCHSens_InitNewSensor(onewire, &module->sens4, ROM, &initlocation);
|
||||
}
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
|
||||
HAL_StatusTypeDef PCHSens_ReadModuleTemperature(PCHSens_ModuleTypeDef *module)
|
||||
{
|
||||
HAL_StatusTypeDef result;
|
||||
|
||||
result = Dallas_StartConvertTAll(module->onewire, DALLAS_WAIT_BUS, 0);
|
||||
|
||||
result = Dallas_ReadTemperature(&module->sens1.sens);
|
||||
result = Dallas_ReadTemperature(&module->sens2.sens);
|
||||
result = Dallas_ReadTemperature(&module->sens3.sens);
|
||||
result = Dallas_ReadTemperature(&module->sens4.sens);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void Dallas_FirstInit(void)
|
||||
{
|
||||
int init_find = 0;
|
||||
OW.DataPin = DS_Pin;
|
||||
OW.DataPort = DS_GPIO_Port;
|
||||
DS.Resolution = DS18B20_RESOLUTION_9BITS;
|
||||
|
||||
OneWire_Init(&OW);
|
||||
DS18B20_Search(&DS, &OW);
|
||||
|
||||
|
||||
PCHSens_LocationTypeDef location;
|
||||
location.all = REG_PCH_NUMB_11|REG_PCH_DIODE_NUMB_1;
|
||||
PCHSens_FindModule(&OW, &module1, &location, init_find);
|
||||
|
||||
|
||||
// Dallas_SensorInitByInd(&OW, &AllSens.outdoor, 0);
|
||||
// Dallas_SensorInitByInd(&OW, &AllSens.indoor, 2);
|
||||
// Dallas_SensorInitByInd(&OW, &AllSens.bathroom, 1);
|
||||
// Dallas_SensorInitByInd(&OW, &AllSens.kitchen, 3);
|
||||
// Dallas_SensorInitByInd(&OW, &AllSens.big_room, 4);
|
||||
// Dallas_SensorInitByInd(&OW, &AllSens.small_room, 5);
|
||||
// Dallas_SensorInitByInd(&OW, &AllSens.living_room, 6);
|
||||
// Dallas_SensorInitByInd(&OW, &AllSens.basement, 7);
|
||||
//
|
||||
// uint8_t mask = DALLAS_USER_BYTE_ALL;
|
||||
// Dallas_WriteUserBytes(&AllSens.outdoor, 1, NULL, mask);
|
||||
// Dallas_WriteUserBytes(&AllSens.indoor, 2, NULL, mask);
|
||||
// Dallas_WriteUserBytes(&AllSens.bathroom, 3, NULL, mask);
|
||||
// Dallas_WriteUserBytes(&AllSens.kitchen, 4, NULL, mask);
|
||||
// Dallas_WriteUserBytes(&AllSens.big_room, 5, NULL, mask);
|
||||
// Dallas_WriteUserBytes(&AllSens.small_room, 6, NULL, mask);
|
||||
// Dallas_WriteUserBytes(&AllSens.living_room, 7, NULL, mask);
|
||||
// Dallas_WriteUserBytes(&AllSens.basement, 8, NULL, mask);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
117
DS18B20/pch_sensors.h
Normal file
117
DS18B20/pch_sensors.h
Normal file
@@ -0,0 +1,117 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file pch_sensors.h
|
||||
* @brief Ðàáîòà ñ äàò÷èêàìè òåìïåðàòóðû DS18B20 â Ï×
|
||||
******************************************************************************
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef PCH_SENSORS_H
|
||||
#define PCH_SENSORS_H
|
||||
|
||||
|
||||
|
||||
/* Includes -----------------------------------------------------------------*/
|
||||
#include "stm32f1xx_hal.h"
|
||||
#include "dallas_tools.h"
|
||||
|
||||
/* Declarations and definitions ---------------------------------------------*/
|
||||
|
||||
/* Ïîçèöèè ïàðàìåòðîâ â ROM */
|
||||
#define REG_SENS_LOCATION_Pos (0) /*!< @brief Ïîçèöèÿ ïàðàìåòðà "Ëîêàöèÿ âíóòðè ìîäóëÿ" */
|
||||
|
||||
#define REG_PCH_LOCATION_Pos (8) /*!< @brief Ïîçèöèÿ ïàðàìåòðà "Ðàñïîëîæåíèå â Ï×" */
|
||||
#define REG_PCH_DIOD_PHASE_Pos (10) /*!< @brief Ïîçèöèÿ ïàðàìåòðà "Äèîäíûé èëè ôàçíûé ìîäóëü" */
|
||||
#define REG_PCH_MODULE_NUMB_Pos (8) /*!< @brief Ïîçèöèÿ ïàðàìåòðà "Ïîðÿäêîâûé íîìåð äèîäíîãî/ôàçíîãî ìîäóëÿ" */
|
||||
|
||||
#define REG_PCH_NUMB_Pos (11) /*!< @brief Ïîçèöèÿ ïàðàìåòðà "Ïðåîáðàçîâàòåëü ÷àñòîòû" */
|
||||
#define REG_PCH_NUMB_DIGIT_1_Pos (13) /*!< @brief Ïîçèöèÿ ïàðàìåòðà "Ïåðâàÿ öèôðà íîìåðà ïðåîáðàçîâàòåëÿ ÷àñòîòû" */
|
||||
#define REG_PCH_NUMB_DIGIT_2_Pos (11) /*!< @brief Ïîçèöèÿ ïàðàìåòðà "Âòîðàÿ öèôðà íîìåðà ïðåîáðàçîâàòåëÿ ÷àñòîòû" */
|
||||
|
||||
#define REG_ZIP_Pos (15) /*!< @brief Ïîçèöèÿ ïàðàìåòðà "ÇÈÏ/íå ÇÈÏ" */
|
||||
|
||||
/* Ìàñêè ïàðàìåòðîâ â ROM */
|
||||
#define REG_SENS_LOCATION_Mask ((uint16_t)0x3 << REG_SENS_LOCATION_Pos) /*!< @brief Ìàñêà ïàðàìåòðà "Ëîêàöèÿ âíóòðè ìîäóëÿ" */
|
||||
|
||||
#define REG_PCH_LOCATION_Mask ((uint16_t)0x7 << REG_PCH_LOCATION_Pos) /*!< @brief Ìàñêà ïàðàìåòðà "Ðàñïîëîæåíèå â Ï×" */
|
||||
#define REG_PCH_DIOD_PHASE_Mask ((uint16_t)0x1 << REG_PCH_DIOD_PHASE_Pos) /*!< @brief Ìàñêà ïàðàìåòðà "Äèîäíûé èëè ôàçíûé ìîäóëü" */
|
||||
#define REG_PCH_MODULE_NUMB_Mask ((uint16_t)0x3 << REG_PCH_MODULE_NUMB_Pos) /*!< @brief Ìàñêà ïàðàìåòðà "Ïîðÿäêîâûé íîìåð äèîäíîãî/ôàçíîãî ìîäóëÿ" */
|
||||
|
||||
#define REG_PCH_NUMB_Mask ((uint16_t)0xF << REG_PCH_NUMB_Pos) /*!< @brief Ìàñêà ïàðàìåòðà "Ïðåîáðàçîâàòåëü ÷àñòîòû" */
|
||||
#define REG_PCH_NUMB_DIGIT_1_Mask ((uint16_t)0x3 << REG_PCH_NUMB_DIGIT_1_Pos) /*!< @brief Ìàñêà ïàðàìåòðà "Ïåðâàÿ öèôðà íîìåðà ïðåîáðàçîâàòåëÿ ÷àñòîòû" */
|
||||
#define REG_PCH_NUMB_DIGIT_2_Mask ((uint16_t)0x3 << REG_PCH_NUMB_DIGIT_2_Pos) /*!< @brief Ìàñêà ïàðàìåòðà "Âòîðàÿ öèôðà íîìåðà ïðåîáðàçîâàòåëÿ ÷àñòîòû" */
|
||||
|
||||
#define REG_ZIP_Mask ((uint16_t)0x1 << REG_ZIP_Pos) /*!< @brief Ìàñêà ïàðàìåòðà "ÇÈÏ/íå ÇÈÏ" */
|
||||
|
||||
/* Âàðèàíòû ïàðàìåòðîâ â ROM */
|
||||
#define REG_PCH_NUMB_11 ((1 << REG_PCH_NUMB_DIGIT_1_Pos) | (1 << REG_PCH_NUMB_DIGIT_2_Pos))
|
||||
#define REG_PCH_NUMB_12 ((1 << REG_PCH_NUMB_DIGIT_1_Pos) | (2 << REG_PCH_NUMB_DIGIT_2_Pos))
|
||||
#define REG_PCH_NUMB_13 ((1 << REG_PCH_NUMB_DIGIT_1_Pos) | (3 << REG_PCH_NUMB_DIGIT_2_Pos))
|
||||
#define REG_PCH_NUMB_21 ((2 << REG_PCH_NUMB_DIGIT_1_Pos) | (1 << REG_PCH_NUMB_DIGIT_2_Pos))
|
||||
#define REG_PCH_NUMB_22 ((2 << REG_PCH_NUMB_DIGIT_1_Pos) | (2 << REG_PCH_NUMB_DIGIT_2_Pos))
|
||||
#define REG_PCH_NUMB_23 ((2 << REG_PCH_NUMB_DIGIT_1_Pos) | (3 << REG_PCH_NUMB_DIGIT_2_Pos))
|
||||
|
||||
#define REG_PCH_DIODE_NUMB_1 ((0 << REG_PCH_DIOD_PHASE_Pos) | (1 << REG_PCH_MODULE_NUMB_Pos))
|
||||
#define REG_PCH_DIODE_NUMB_2 ((0 << REG_PCH_DIOD_PHASE_Pos) | (2 << REG_PCH_MODULE_NUMB_Pos))
|
||||
#define REG_PCH_DIODE_NUMB_3 ((0 << REG_PCH_DIOD_PHASE_Pos) | (3 << REG_PCH_MODULE_NUMB_Pos))
|
||||
#define REG_PCH_PHASE_NUMB_1 ((1 << REG_PCH_DIOD_PHASE_Pos) | (1 << REG_PCH_MODULE_NUMB_Pos))
|
||||
#define REG_PCH_PHASE_NUMB_2 ((1 << REG_PCH_DIOD_PHASE_Pos) | (2 << REG_PCH_MODULE_NUMB_Pos))
|
||||
#define REG_PCH_PHASE_NUMB_3 ((1 << REG_PCH_DIOD_PHASE_Pos) | (3 << REG_PCH_MODULE_NUMB_Pos))
|
||||
|
||||
/* Ïîëó÷èòü ïàðàìåòð èç ROM */
|
||||
#define GET_REG_SENS_LOCATION(_REG_) ((_REG_) & REG_SENS_LOCATION_Mask) /*!< @brief Ìàñêà ïàðàìåòðà "Ëîêàöèÿ âíóòðè ìîäóëÿ" */
|
||||
|
||||
#define GET_REG_PCH_LOCATION(_REG_) ((_REG_) & REG_PCH_LOCATION_Mask) /*!< @brief Ìàñêà ïàðàìåòðà "Ðàñïîëîæåíèå â Ï×" */
|
||||
#define GET_REG_PCH_DIOD_PHASE(_REG_) ((_REG_) & REG_PCH_DIOD_PHASE_Mask) /*!< @brief Ìàñêà ïàðàìåòðà "Äèîäíûé èëè ôàçíûé ìîäóëü" */
|
||||
#define GET_REG_PCH_MODULE_NUMB(_REG_) ((_REG_) & REG_PCH_MODULE_NUMB_Mask) /*!< @brief Ìàñêà ïàðàìåòðà "Ïîðÿäêîâûé íîìåð äèîäíîãî/ôàçíîãî ìîäóëÿ" */
|
||||
|
||||
#define GET_REG_PCH_NUMB(_REG_) ((_REG_) & REG_PCH_NUMB_Mask) /*!< @brief Ìàñêà ïàðàìåòðà "Ïðåîáðàçîâàòåëü ÷àñòîòû" */
|
||||
#define GET_REG_PCH_NUMB_DIGIT_1(_REG_) ((_REG_) & REG_PCH_NUMB_DIGIT_1_Mask) /*!< @brief Ìàñêà ïàðàìåòðà "Ïåðâàÿ öèôðà íîìåðà ïðåîáðàçîâàòåëÿ ÷àñòîòû" */
|
||||
#define GET_REG_PCH_NUMB_DIGIT_2(_REG_) ((_REG_) & REG_PCH_NUMB_DIGIT_2_Mask) /*!< @brief Ìàñêà ïàðàìåòðà "Âòîðàÿ öèôðà íîìåðà ïðåîáðàçîâàòåëÿ ÷àñòîòû" */
|
||||
|
||||
#define GET_REG_ZIP(_REG_) ((_REG_) & REG_ZIP_Mask) /*!< @brief Ìàñêà ïàðàìåòðà "ÇÈÏ/íå ÇÈÏ" */
|
||||
|
||||
|
||||
typedef union
|
||||
{
|
||||
uint16_t all;
|
||||
struct
|
||||
{
|
||||
unsigned Location:2;
|
||||
unsigned reserved:6;
|
||||
unsigned ModuleNumb:2;
|
||||
unsigned DiodeOrPhase:1;
|
||||
unsigned PCHdig2:2;
|
||||
unsigned PCHdig1:2;
|
||||
unsigned ZIP:1;
|
||||
}location;
|
||||
}PCHSens_LocationTypeDef;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
DALLAS_HandleTypeDef sens;
|
||||
PCHSens_LocationTypeDef *Location;
|
||||
}PCH_SensorTypeDef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
OneWire_t *onewire;
|
||||
|
||||
PCH_SensorTypeDef sens1;
|
||||
PCH_SensorTypeDef sens2;
|
||||
PCH_SensorTypeDef sens3;
|
||||
PCH_SensorTypeDef sens4;
|
||||
|
||||
PCHSens_LocationTypeDef refLocation;
|
||||
}PCHSens_ModuleTypeDef;
|
||||
extern PCHSens_ModuleTypeDef module1;
|
||||
|
||||
|
||||
/* Functions ---------------------------------------------------------------*/
|
||||
HAL_StatusTypeDef PCHSens_InitNewSensor(OneWire_t *onewire, PCH_SensorTypeDef* sensor, uint64_t ROM, PCHSens_LocationTypeDef *location);
|
||||
HAL_StatusTypeDef PCHSens_FindSensor(OneWire_t *onewire, PCH_SensorTypeDef* sensor, PCHSens_LocationTypeDef *location);
|
||||
HAL_StatusTypeDef PCHSens_FindModule(OneWire_t *onewire, PCHSens_ModuleTypeDef* module, PCHSens_LocationTypeDef *location, uint8_t init);
|
||||
HAL_StatusTypeDef PCHSens_ReadModuleTemperature(PCHSens_ModuleTypeDef *module);
|
||||
|
||||
void Dallas_FirstInit(void);
|
||||
#endif // #ifndef PCH_SENSORS_H
|
||||
Reference in New Issue
Block a user