Browse Source

first move/implementation

Juraj Ďuďák 2 years ago
parent
commit
bcf9b4fc07
5 changed files with 1429 additions and 87 deletions
  1. 55 0
      Inc/memory_ec20.h
  2. 401 0
      Inc/one_wire.h
  3. 1 87
      README.md
  4. 135 0
      Src/memory_ec20.c
  5. 837 0
      Src/one_wire.c

+ 55 - 0
Inc/memory_ec20.h

@@ -0,0 +1,55 @@
+#ifndef __1W_EC20
+#define __1W_EC20
+
+#include "one_wire.h"
+
+#define DS28EC20_FAMILY_CODE            0x43
+#define CMD_WRITE_SCRATCHPAD            0x0F
+#define CMD_READ_SCRATCHPAD             0xAA
+#define CMD_COPY_SCRATCHPAD             0x55
+#define CMD_READ_MEMORY                 0xF0
+#define CMD_EXTENDED_READ_MEMORY        0xA5
+#define REG_MEMORY_BLOCK_LOCK           0xA1E
+#define REG_REGISTER_PAGE_LOCK          0xA1F
+
+#define WRITE_PROTECTION                0x55
+#define EPROM_MODE                      0xAA
+
+#define PAGE_SIZE                       0x20
+#define NUM_OF_PAGES                    0x50
+#define MEM_SIZE                        (PAGE_SIZE * NUM_OF_PAGES)
+
+
+typedef struct _onewire_ec20_{
+    uint8_t buffer_rx[32];
+    uint8_t buffer_tx[32];
+    uint8_t real_size;
+    uint8_t ROM[8];
+}OneWire_EC20_typeDef;
+
+typedef struct{
+	uint8_t (*init)(GPIO_TypeDef*, uint16_t);
+	void (*read)(uint16_t,uint8_t);
+	uint8_t (*write)(uint16_t ,uint8_t);
+	uint32_t (*read_word)(uint16_t);
+	uint16_t (*read_half_word)(uint16_t);
+	uint8_t (*write_word)(uint32_t, uint16_t);
+	uint8_t (*write_half_word)(uint16_t, uint16_t);
+}Ec20_MemoryDriver;
+
+
+Ec20_MemoryDriver *getEc20MemoryDriver();
+
+uint8_t DS28EC20_init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
+void DS28EC20_readMem(uint16_t,uint8_t);
+uint8_t DS28EC20_writeMem(uint16_t ,uint8_t);
+
+uint32_t DS28EC20_readData4B(uint16_t);
+uint16_t DS28EC20_readData2B(uint16_t address);
+
+uint8_t DS28EC20_writeData4B(uint32_t, uint16_t );
+uint8_t DS28EC20_writeData2B(uint16_t data, uint16_t  adr);
+
+uint8_t DS28EC20_writeData4char(uint8_t *data, uint16_t  adr);
+
+#endif

+ 401 - 0
Inc/one_wire.h

@@ -0,0 +1,401 @@
+/** @addtogroup Firmware
+  * @{
+  */
+
+/** @addtogroup Implementácia_MultiSlave
+  * @{
+  */
+
+/** @defgroup OneWire_modul
+ * @brief Implementácia komunikácie na zbernici 1-wire
+ * @{
+ */
+
+#ifndef ONE_WIRE_LIB_H
+#define ONE_WIRE_LIB_H
+
+
+//#include "stdint.h"
+#include "mcu_platform.h"
+
+//#define OW_MODULE_USE_TIMER
+
+
+#define TRUE  0x01					// konstanty v kniznici 1-wire
+#define FALSE 0x00
+
+
+#define OW_USE_2_WIRE   FALSE
+#define MCU_FREQUENCY	32000		//4194
+#define USE_STRONG		0
+
+
+#define OW_WRITE_ZERO		60
+#define OW_WRITE_ONE		6
+#define OW_WRITE_ONE_DELAY	54
+#define OW_WRITE_DELAY		10
+#define OW_READ_PULSE		6
+#define OW_READ_PRESENCE	9
+#define OW_READ_DELAY		45
+#define OW_RESET_MEASTER    500
+#define OW_RESET_PRESENCE   80
+#define OW_RESET_DELAY      400
+#define OW_CONVERT_DELAY	750
+#define OW_BOOSTER	        25		// od 5 do 1000 usec
+
+#define OW_CMD_READ_ROM             0x33
+#define OW_CMD_MATCH_ROM            0x55
+#define OW_CMD_SEARCH_ROM           0xF0
+#define OW_CMD_ALARM_SEARCH         0xEC
+#define OW_CMD_SKIP_ROM             0xCC
+#define OW_CMD_CONVERT_VALUE        0x44
+#define OW_CMD_COPY_SCRATCHPAD      0x48
+#define OW_CMD_READ_POWER_SUPPLY    0xB4
+#define OW_CMD_RECALL_E2            0xB8
+#define OW_CMD_READ_SCRATCHPAD      0xBE
+#define OW_CMD_WRITE_SCRATCHPAD     0x4E
+
+
+#define  OW_SETTING_NORMAL          1
+#define  OW_SETTING_LONG            2
+#define  OW_SETTING_USER            3
+
+
+#define OW_SET_HI		(oneWirePins.port->BSRR = (uint32_t)oneWirePins.pin_ow)
+#define OW_SET_LO		(oneWirePins.port->BRR = (uint32_t)oneWirePins.pin_ow)
+
+#define OW_UP_SET		(oneWirePins.port->BSRR = oneWirePins.pin_ow_up)
+#define OW_UP_CLEAR		(oneWirePins.port->BRR  = oneWirePins.pin_ow_up)
+
+#define OW_DOWN_SET		(oneWirePins.port->BSRR= oneWirePins.pin_ow_down)
+#define OW_DOWN_CLEAR	(oneWirePins.port->BRR = oneWirePins.pin_ow_down)
+
+//#define OW_STRONG_SET	(oneWirePins.port->BSRR = oneWirePins.pin_ow_strong)
+//#define OW_STRONG_CLEAR	(oneWirePins.port->BRR  = oneWirePins.pin_ow_strong)
+
+//#define OW_NO_INTERRUPTS_ONLY_SYSTICK
+#ifdef OW_NO_INTERRUPTS_ONLY_SYSTICK
+//Only systick will be disabled when calling OW_DIS_INTERRUPTS
+#define OW_DIS_INTERRUPTS 	DISABLE_sysTick_IRQ
+#define OW_ENA_INTERRUPTS   ENABLE_sysTick_IRQ
+#else
+//All interrupts will be disabled when calling OW_DIS_INTERRUPTS
+#define OW_DIS_INTERRUPTS 	uint32_t primSpec55511 = __get_PRIMASK(); \
+							do{ \
+								__disable_irq(); \
+							}while(0)
+
+#define OW_ENA_INTERRUPTS   do{ \
+								if (!primSpec55511) {__enable_irq();} \
+							}while(0)
+#endif // OW_NO_INTERRUPTS_ONLY_SYSTICK
+
+
+#define OW_USE_TICKS
+#ifdef OW_USE_TICKS
+
+/**
+ * @brief Delay ticks helper.
+ * @param ticks Count of ticks to wait divided by 3.
+ * @see delay_ticks_c
+ */
+#define delay_ticks_0(ticks) { uint32_t tcks = (ticks); \
+							__ASM volatile( ".syntax unified;" \
+											 "0: SUBS %[count], 1;" \
+											 "BNE 0b;" :[count]"+r"(tcks) );}
+
+//This works only with constant numbers - ifs are evaluated at compile time
+/**
+ * @brief Delays specified amount of ticks.
+ * @param ticks Count of ticks to wait. This has to be constant value, because
+ * this macro contains ifs, which has to be evaluated at compilation time.
+ * @note Always disable interrupts when using this macro to achieve accurate result.
+ */
+#define delay_ticks_c(ticks) do{ \
+								if((ticks) > 2){delay_ticks_0((ticks)/3);} \
+								if((ticks) % 3 == 1) __ASM volatile( ".syntax unified; nop;"); \
+								else if((ticks) % 3 == 2) __ASM volatile( ".syntax unified; nop; nop;"); \
+							}while(0);
+
+/**
+ * @brief Calculates number of ticks (MCU cycles) from frequency and time.
+ * @param us Time in microseconds.
+ * @param freq MCU frequency in kHz.
+ */
+#define OW_US_FREQ_TO_TICKS(us, freq) (((us)*(freq))/1000UL)
+
+#define OW_DELAY_US(us, freq, tick_offs) if(OW_US_FREQ_TO_TICKS((us), (freq)) >= (tick_offs)) {delay_ticks_c(OW_US_FREQ_TO_TICKS((us), (freq)) - (tick_offs));}
+#define delay_us(us) OW_DELAY_US((us), MCU_FREQUENCY, 0)
+
+/**
+ * @brief Creates pulse with specified duration on selected GPIO pin. At first, new pin value is set and
+ * after that delay is applied.
+ * @param us Duration of pulse in microseconds.
+ * @param hi 1 for high pulse, 0 for low pulse.
+ * @param freq MCU frequency in kHz.
+ * @param tick_offs Count of ticks, that are wait outside of this macro. It's value has to be at least 1,
+ * because GPIO pin setting takes 1 tick. It can be used to fine tune pulse width, which can be affected
+ * by instructions called after this macro.
+ * @param GPIO_port GPIO port to be used.
+ * @param GPIO_pin Pin on specified GPIO port.
+ * @note Always disable interrupts when using this macro to achieve accurate result.
+ */
+#define OW_GPIO_PULSE(us, hi, freq, tick_offs, GPIO_port, GPIO_pin) do{ \
+										if(hi){(GPIO_port)->BSRR = (GPIO_pin);} \
+										else {(GPIO_port)->BRR = (GPIO_pin);} \
+										OW_DELAY_US((us),(freq),(tick_offs)); \
+									}while(0);
+
+#else
+
+#ifdef OW_MODULE_USE_TIMER
+
+void delay_us_long(uint16_t time);
+void delay_us(uint16_t time);
+
+#else
+#define delay_us_0(time) {    \
+                __ASM volatile ( \
+                "mov r0, %0 \n"     \
+                "5: \n"             \
+                "sub r0, #1 \n"     \
+                "bhi 5b \n":  : "i"(time) :);    \
+                }
+
+/* ------------------------------------------------------------------*/
+/* ----------------------------  STM32 L0  --------------------------*/
+/* ------------------------------------------------------------------*/
+#ifdef STM32L0
+/* ------------------------- LSI = 8000  kHz -------------------------*/
+#if MCU_FREQUENCY == 8000
+#define delay_us(time){ \
+    delay_us_0(time) \
+    delay_us_0(time) \
+    delay_us_0(time-2) \
+    }
+
+#define delay_us_long(time) {    \
+    delay_us(time)  \
+    delay_us(time)  \
+    delay_us(time)  \
+    delay_us(time-50)  \
+}
+#endif // MCU_FREQUENCY
+
+/* -------------------------- MSI =  4194 kHz ---------------------------*/
+/**
+ * time in code  |  measured time [us]
+ *   	6		 |  5
+ *   	10		 |	9.5
+ *   	20       |  20.25
+ *   	50		 |  52
+ */
+#if MCU_FREQUENCY == 4194
+#define delay_us(time){ \
+    delay_us_0(time-3) \
+    delay_us_0((time-1)/2) \
+    }
+
+#define delay_us_long(time) {    \
+    delay_us(time)  \
+    delay_us(time)  \
+    delay_us(time)  \
+    delay_us(time-10)  \
+}
+#endif // MCU_FREQUENCY
+
+/* --------------------------- MSI = 2097 kHz ---------------------------*/
+#if MCU_FREQUENCY == 2097
+#define delay_us(time){ \
+	delay_us_0( ((time-2)*2/3) ) \
+    }
+
+
+#define delay_us_long(time) {    \
+    delay_us(time)  \
+    delay_us(time-10)  \
+    delay_us(time-10)  \
+    delay_us(time-10)  \
+}
+
+#endif // MCU_FREQUENCY
+
+#endif // STM32L0
+
+/* ------------------------------------------------------------------*/
+/* ----------------------------  STM32 F0  --------------------------*/
+/* ------------------------------------------------------------------*/
+#ifdef STM32F0
+
+/* --------------------------- LSI = 48 MHz ---------------------------*/
+#if MCU_FREQUENCY == 48
+#define delay_us(time){ \
+    owSetDelayUs_0(time) \
+    owSetDelayUs_0(time) \
+    owSetDelayUs_0(time) \
+    owSetDelayUs_0(time) \
+    owSetDelayUs_0(time) \
+    owSetDelayUs_0(time) \
+    owSetDelayUs_0(time) \
+    owSetDelayUs_0(time) \
+    owSetDelayUs_0(time) \
+    owSetDelayUs_0(time) \
+    owSetDelayUs_0(time) \
+    owSetDelayUs_0(time-1) \
+    }
+
+#define delay_us_long(time) {    \
+    owSetDelayUs(time);    \
+    owSetDelayUs(time);    \
+    owSetDelayUs(time);    \
+    owSetDelayUs(time);    \
+}
+#endif // FREQUENCY
+
+#endif // STM32F0
+
+#endif // OW_MODULE_USE_TIMER
+
+#endif // OW_USE_TICKS
+
+
+/**
+* Dátová štruktúra pre komunikáciu so zbernicou 1-wire. Obsahuje:
+* - časové konštanty
+* - príznaky komunikácie
+* - komunikačný buffer
+* - inštanciu časovača knižnice STM32 HAL
+*/
+typedef struct {
+    /** Globalne nastavenie casovania zvernice 1w */
+    volatile uint8_t one_wire_timing_settings;
+
+    /** lokalny buffer pre ID zariadenia */
+    uint8_t ROM_NO[8];
+    /** priznak konfliktu na zbernici pri vyhladavani ID */
+    __IO uint32_t LastDiscrepancy;
+    __IO uint32_t LastFamilyDiscrepancy;
+    __IO uint32_t LastDeviceFlag;
+    /** Priznak timeru ze aktualne je v stave cakania na udalost pri ktorej sa zmenia jeho parametre. */
+    __IO uint8_t flag_timer_inUse;
+    /** Stav zbernice: OW_STATE_READY, OW_STATE_WAITING. */
+    __IO uint8_t ow_state;
+    /** Priznak pripravenosti dat. Hodnoty môžu nadobúdať zo štruktúry oneWireDataReady_typeDef. */
+    __IO uint8_t ow_data_ready;
+#ifdef OW_MODULE_USE_TIMER
+    /** Inštancia časovača knižnice HAL. Časovač je použitý pre časovanie komunikácie */
+    TIM_HandleTypeDef *owTimer;
+#endif
+} oneWireDriver_typeDef;
+
+/**
+* Definícia pinov pre ovládanie zbernice 1-wire. Aktuálne nepoužité.
+*/
+typedef struct oneWirePins_struct {
+    /** Pin pre signál, ktorý zdvihne zbernicu na hodnotu 1 */
+    volatile uint16_t pin_ow_up;
+    /** Pin pre signál, ktorý zloží zbernicu na hodnotu 0 */
+    volatile uint16_t pin_ow_down;
+    /** Pin pre signál, ktorý zdvihne zbernicu na tvrdú hodnotu 1 */
+    volatile uint16_t pin_ow_strong;
+    /** Pin pre vstupný signál */
+    volatile uint16_t pin_ow_in;
+    /** Port, na ktorom sú piny */
+    GPIO_TypeDef* port;
+} oneWirePins_typeDef;
+
+typedef struct oneWirePin_struct {
+    __IO uint16_t pin_ow;
+    __IO uint16_t pin_ow_moder_bit;
+#if OW_USE_2_WIRE == 1
+    volatile uint16_t pin_ow_in;
+#endif // OW_USE_2_WIRE
+    GPIO_TypeDef* port;
+} oneWirePin_typeDef;
+
+
+/**
+* Príznak pripravenosti dát zo senzorov zbernice 1-wire.
+*/
+typedef enum OW_DATA_enum {
+    /** Dáta nie sú pripravené, práve sa merajú */
+    OW_DATA_BUSY=0,
+    /** Dáta sú pripravené */
+    OW_DATA_READY=1,
+} oneWireDataReady_typeDef;
+
+/**
+* Príznak stavu zbernice v stave STRONG.
+*/
+typedef enum OW_STRONG_STATE_enum {
+    /** Zbernica nie je v stave STRONG */
+    OW_STRONG_OFF = 0,
+    /** Zbernica je v stave STRONG */
+    OW_STRONG_ON = 1,
+} oneWireStrongState_typeDef;
+
+/**
+* Príznak pre stav časovača.
+*/
+typedef enum {
+    /** Časovač je spustený, prebieha meranie */
+    TIMER_STATE_RUN = 0,
+    /** Časovač je vypnutý */
+    TIMER_STATE_IDLE = 1,
+} oneWireTimerState_typeDef;
+
+
+#ifdef OW_MODULE_USE_TIMER
+void oneWire_init(TIM_HandleTypeDef *timer, GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
+#else
+#if OW_USE_2_WIRE == 1
+void oneWire_init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint16_t GPIO_Pin_i );				// konfiguracia portu pre 1-wire
+#else
+void oneWire_init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin );				// konfiguracia portu pre 1-wire
+#endif // OW_USE_2_WIRE
+#endif
+
+uint8_t owReset(void);				// reset zbernice a kontrola pritomnosti zariadeni
+uint8_t owFirst();				// nacitanie ID prveho zariadenia
+uint8_t owNext();				// iteracia zoznamu zariadeni
+uint8_t owVerify(void);			// kontrola existencia ID zariadenia
+void owTargetSetup(uint8_t fcode);	// nastavenie podmnoziny vyhladavanych zariadeni
+void owFamilySkipSetup(void);	// zrusenie selektivneho vyhladavania
+void owSetRom(uint8_t *array);		// nastavenie ID konkretneho zariadenia
+uint8_t owSearch();
+uint8_t owCrc8(uint8_t);
+uint8_t owReadBit(void);
+void owWriteByte(uint8_t, uint8_t);
+uint8_t owReadByte(void);
+#ifdef OW_USE_TICKS
+void owWriteBit(uint8_t*);
+#else
+void owWriteBit(uint8_t);
+#endif
+
+void owWriteBitStrong(uint8_t);
+
+void owSetDelayMs(uint16_t time);
+void ow_stop_ms_timer(void);
+uint8_t *oneWire_getROM();
+
+void owGetROM(uint8_t *mem_page);
+void owSelect_ROM(const uint8_t rom[8]);
+void owSelect();
+void ow_ClearStrong(void);
+void ow_SetStrong(void);
+
+
+#endif //ONE_WIRE_LIB_H
+
+/**
+  * @}
+  */
+
+/**
+  * @}
+  */
+
+/**
+  * @}
+  */

+ 1 - 87
README.md

@@ -2,91 +2,5 @@
 
 
 
-## Getting started
+## DS28EC20
 
-To make it easy for you to get started with GitLab, here's a list of recommended next steps.
-
-Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
-
-## Add your files
-
-- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
-- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
-
-```
-cd existing_repo
-git remote add origin https://gitlab.nsoric.com/mtf/stm32/librararies/one-wire-memory.git
-git branch -M main
-git push -uf origin main
-```
-
-## Integrate with your tools
-
-- [ ] [Set up project integrations](https://gitlab.nsoric.com/mtf/stm32/librararies/one-wire-memory/-/settings/integrations)
-
-## Collaborate with your team
-
-- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
-- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
-- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
-- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
-- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
-
-## Test and Deploy
-
-Use the built-in continuous integration in GitLab.
-
-- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
-- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
-- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
-- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
-- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
-
-***
-
-# Editing this README
-
-When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
-
-## Suggestions for a good README
-Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
-
-## Name
-Choose a self-explaining name for your project.
-
-## Description
-Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
-
-## Badges
-On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
-
-## Visuals
-Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
-
-## Installation
-Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
-
-## Usage
-Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
-
-## Support
-Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
-
-## Roadmap
-If you have ideas for releases in the future, it is a good idea to list them in the README.
-
-## Contributing
-State if you are open to contributions and what your requirements are for accepting them.
-
-For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
-
-You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
-
-## Authors and acknowledgment
-Show your appreciation to those who have contributed to the project.
-
-## License
-For open source projects, say how it is licensed.
-
-## Project status
-If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.

+ 135 - 0
Src/memory_ec20.c

@@ -0,0 +1,135 @@
+#include "memory_ec20.h"
+
+OneWire_EC20_typeDef mem_page;
+
+Ec20_MemoryDriver memory_ec20 = {
+		DS28EC20_init,
+		DS28EC20_readMem,
+		DS28EC20_writeMem,
+		DS28EC20_readData4B,
+		DS28EC20_readData2B,
+		DS28EC20_writeData4B,
+		DS28EC20_writeData2B
+};
+
+Ec20_MemoryDriver *getEc20MemoryDriver() {
+	return &memory_ec20;
+}
+
+uint8_t DS28EC20_init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) {
+	oneWire_init(GPIOx, GPIO_Pin);
+    mem_page.real_size=0;
+    HAL_Delay(2);
+    owFirst();
+    owGetROM(mem_page.ROM);
+    if (mem_page.ROM[0] != DS28EC20_FAMILY_CODE) {
+    	return 0;
+    }
+    return 1;
+}
+
+void DS28EC20_readMem(uint16_t address, uint8_t size) {
+
+    owReset();
+    owSelect(mem_page.ROM);
+
+    owWriteByte(CMD_READ_MEMORY, OW_STRONG_OFF);
+    owWriteByte(address & 0xFF, OW_STRONG_OFF);
+    owWriteByte(address >> 8, OW_STRONG_OFF);
+
+    uint8_t i;
+    for(i=0; i < size ; i++) {
+        mem_page.buffer_rx[i] = owReadByte();
+    }
+
+}
+
+
+uint8_t DS28EC20_writeMem(uint16_t addr, uint8_t size) {
+    uint8_t TA1 = (uint8_t) (addr & 0xFF);
+    uint8_t TA2 = (uint8_t) ((addr >> 8) & 0xFF);
+
+    uint8_t i;
+
+	owReset();
+	owSelect(mem_page.ROM);
+
+	owWriteByte(CMD_WRITE_SCRATCHPAD, OW_STRONG_OFF);      // 0x0F
+	owWriteByte(TA1,OW_STRONG_OFF);
+	owWriteByte(TA2, OW_STRONG_OFF);
+	for (i = 0 ; i < size; i++) {
+		owWriteByte(mem_page.buffer_tx[i], OW_STRONG_OFF);
+	}
+
+	owReset();
+	owSelect(mem_page.ROM);
+
+	owWriteByte(CMD_READ_SCRATCHPAD, OW_STRONG_OFF);    //0xAA
+	uint8_t tempVal = owReadByte();
+	if (tempVal != TA1) return 1;
+
+	tempVal = owReadByte();
+	if (tempVal != TA2) return 2;
+
+	uint8_t ES = owReadByte();
+
+	for (i = 0 ; i < size; i++) {
+		tempVal = owReadByte();
+		if (tempVal != mem_page.buffer_tx[i]) return i+10;
+	}
+
+	HAL_Delay(10);
+    owReset();
+	owSelect(mem_page.ROM);
+
+	owWriteByte(CMD_COPY_SCRATCHPAD, OW_STRONG_OFF);  //0x55
+	owWriteByte(TA1, OW_STRONG_OFF);
+	owWriteByte(TA2, OW_STRONG_OFF);
+	owWriteByte(ES, OW_STRONG_OFF);
+	HAL_Delay(10);
+
+	owReset();
+	return 0;
+}
+
+
+uint32_t DS28EC20_readData4B(uint16_t address) {
+    mem_page.buffer_rx[3] = mem_page.buffer_rx[2] = mem_page.buffer_rx[1] = mem_page.buffer_rx[0] = 0;
+    DS28EC20_readMem(address, 4);
+    uint32_t data32 = mem_page.buffer_rx[3];
+    data32 |= mem_page.buffer_rx[2]<<8;
+    data32 |= mem_page.buffer_rx[1]<<16;
+    data32 |= mem_page.buffer_rx[0]<<24;
+    return data32;
+}
+
+uint16_t DS28EC20_readData2B(uint16_t address) {
+    mem_page.buffer_rx[1] = mem_page.buffer_rx[0] = 0;
+    DS28EC20_readMem(address, 2);
+    uint16_t data16 = mem_page.buffer_rx[1];
+    data16 |= mem_page.buffer_rx[0]<<8;
+    return data16;
+}
+
+
+uint8_t DS28EC20_writeData4B(uint32_t data, uint16_t adr) {
+    mem_page.buffer_tx[0] = data>>24;
+    mem_page.buffer_tx[1] = (data>>16) & 0xFF;
+    mem_page.buffer_tx[2] = (data>>8) & 0xFF;
+    mem_page.buffer_tx[3] = (data) & 0xFF;
+    return DS28EC20_writeMem(adr,4);
+}
+
+uint8_t DS28EC20_writeData2B(uint16_t data, uint16_t adr) {
+    mem_page.buffer_tx[0] = (data>>8) & 0xFF;
+    mem_page.buffer_tx[1] = (data) & 0xFF;
+    return DS28EC20_writeMem(adr,2);
+}
+
+uint8_t DS28EC20_writeData4char(uint8_t *data, uint16_t adr) {
+    mem_page.buffer_tx[0] = data[0];
+    mem_page.buffer_tx[1] = data[1];
+    mem_page.buffer_tx[2] = data[2];
+    mem_page.buffer_tx[3] = data[3];
+    return DS28EC20_writeMem(adr,4);
+}

+ 837 - 0
Src/one_wire.c

@@ -0,0 +1,837 @@
+/**
+ * @file     module_one_wire.c
+ * @author   Juraj Dudak
+ * @date     16 January, 2015
+ * @version  1.0
+ *
+ * @brief Implementacia funkcii pre 1-Wire zbernicu.
+ *
+ */
+
+//----------------------------------------------------------------------
+// Include & define
+//----------------------------------------------------------------------
+#include "one_wire.h"
+
+
+#define TRUE  0x01					// konstanty v kniznici 1-wire
+#define FALSE 0x00
+
+
+/** @addtogroup Firmware
+  * @{
+  */
+
+/** @addtogroup Implementácia_MultiSlave
+  * @{
+  */
+
+/** @defgroup OneWire_modul
+ * @brief Implementácia komunikácie na zbernici 1-wire
+ * @{
+ */
+
+//----------------------------------------------------------------------
+// Lokalne premenne
+//----------------------------------------------------------------------
+/**
+* SW driver pre zbernicu 1-wire. Obsahuje dátový buffer, časové konštanty,
+* príznaky komunikácie a stavové premenné.
+*/
+oneWireDriver_typeDef oneWireDrv;
+
+/** Definícia pinov pre ovládanie zbernice 1-wire*/
+oneWirePin_typeDef oneWirePins;
+
+
+/** globalna hodnota CRC */
+uint8_t crc8_ow;
+
+/** Tabuľka pre výpočet súčtu CRC8 */
+static const uint8_t dscrc_table[] = {
+    0, 94, 188, 226, 97, 63, 221, 131, 194, 156, 126, 32, 163, 253, 31, 65,
+    157, 195, 33, 127, 252, 162, 64, 30, 95, 1, 227, 189, 62, 96, 130, 220,
+    35, 125, 159, 193, 66, 28, 254, 160, 225, 191, 93, 3, 128, 222, 60, 98,
+    190, 224, 2, 92, 223, 129, 99, 61, 124, 34, 192, 158, 29, 67, 161, 255,
+    70, 24, 250, 164, 39, 121, 155, 197, 132, 218, 56, 102, 229, 187, 89, 7,
+    219, 133, 103, 57, 186, 228, 6, 88, 25, 71, 165, 251, 120, 38, 196, 154,
+    101, 59, 217, 135, 4, 90, 184, 230, 167, 249, 27, 69, 198, 152, 122, 36,
+    248, 166, 68, 26, 153, 199, 37, 123, 58, 100, 134, 216, 91, 5, 231, 185,
+    140, 210, 48, 110, 237, 179, 81, 15, 78, 16, 242, 172, 47, 113, 147, 205,
+    17, 79, 173, 243, 112, 46, 204, 146, 211, 141, 111, 49, 178, 236, 14, 80,
+    175, 241, 19, 77, 206, 144, 114, 44, 109, 51, 209, 143, 12, 82, 176, 238,
+    50, 108, 142, 208, 83, 13, 239, 177, 240, 174, 76, 18, 145, 207, 45, 115,
+    202, 148, 118, 40, 171, 245, 23, 73, 8, 86, 180, 234, 105, 55, 213, 139,
+    87, 9, 235, 181, 54, 104, 138, 212, 149, 203, 41, 119, 244, 170, 72, 22,
+    233, 183, 85, 11, 136, 214, 52, 106, 43, 117, 151, 201, 74, 20, 246, 168,
+    116, 42, 200, 150, 21, 75, 169, 247, 182, 232, 10, 84, 215, 137, 107, 53
+};
+
+
+//--------------------------------------------------------------------------
+// Implementacia low-level funkcii pre STM32
+//--------------------------------------------------------------------------
+#ifdef OW_MODULE_USE_TIMER
+void delay_us(uint16_t time) {
+
+    time -= 3;
+    oneWireDrv.owTimer->Instance->CNT=0;
+    HAL_TIM_Base_Start(oneWireDrv.owTimer);
+    while(oneWireDrv.owTimer->Instance->CNT < time);
+    HAL_TIM_Base_Stop(oneWireDrv.owTimer);
+}
+
+void delay_us_long(uint16_t time){
+	delay_us(time);
+}
+#endif
+
+/**
+* Zruší stav STRONG na zbernici 1-wire.
+*/
+inline void ow_ClearStrong(){
+//    OW_STRONG_CLEAR;
+}
+
+/**
+* Zbenicu 1-wire nastaví do stavu STRONG (silná hodtnota "1").
+*/
+inline void ow_SetStrong(void) {
+//    OW_STRONG_SET;
+}
+
+
+/**
+* Zbenicu 1-wire nastaví do stavu, kedy je možné zo zbenice čítať hodnoty.
+*/
+static inline void ow_SetReadState(void) {
+//    OW_UP_CLEAR;
+//    OW_DOWN_CLEAR;
+}
+
+/**
+* Nastavi pin pre 1W ako vstupný.
+* Aktuálne je podporovaná rýchla zmena len pre STM32F0x
+* Opis registrov: http://www.hertaville.com/stm32f0-gpio-tutorial-part-1.html
+*/
+__attribute__((optimize("O1")))  static void setPinIn(){
+#if OW_USE_2_WIRE == 0
+
+#ifdef STM32F0
+    #define PIN_IN_USE_IN
+    uint32_t temp = oneWirePins.port->MODER;
+    CLEAR_BIT(temp, GPIO_MODER_MODER0 << (oneWirePins.pin_ow_moder_bit));
+    SET_BIT(temp, (0) << (oneWirePins.pin_ow_moder_bit));
+    oneWirePins.port->MODER = temp;
+#endif // STM32F0
+
+#ifdef STM32L0
+    #define PIN_IN_USE_IN
+    uint32_t temp = oneWirePins.port->MODER;
+    CLEAR_BIT(temp, GPIO_MODER_MODE0 << (oneWirePins.pin_ow_moder_bit));
+    SET_BIT(temp, (0) << (oneWirePins.pin_ow_moder_bit));
+    oneWirePins.port->MODER = temp;
+#endif // STM32L0
+
+#ifndef PIN_IN_USE_IN
+    #error MUSITE POUZIT VERIZU 1-WIRE PRE 2 PINY PROCESORA
+    //GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
+    //HAL_GPIO_Init(oneWirePins.port, &GPIO_InitStructure);
+#endif // PIN_IN_USE_IN
+
+#endif // OW_USE_2_WIRE
+}
+
+/**
+* Nastavi pin pre 1W ako výstupný.
+* Aktuálne je podporovaná rýchla zmena len pre STM32F0x
+* Opis registrov: http://www.hertaville.com/stm32f0-gpio-tutorial-part-1.html
+*/
+__attribute__((optimize("O1"))) static void setPinOut() {
+#if OW_USE_2_WIRE == 0
+
+#ifdef STM32F0
+    #define PIN_IN_USE_IN
+    uint32_t temp = oneWirePins.port->MODER;
+    CLEAR_BIT(temp, GPIO_MODER_MODER0 << (oneWirePins.pin_ow_moder_bit));
+    SET_BIT(temp, (1) << (oneWirePins.pin_ow_moder_bit));
+    oneWirePins.port->MODER = temp;
+#endif // STM32F0
+
+#ifdef STM32L0
+    #define PIN_IN_USE_IN
+    uint32_t temp = oneWirePins.port->MODER;
+    CLEAR_BIT(temp, GPIO_MODER_MODE0 << (oneWirePins.pin_ow_moder_bit));
+    SET_BIT(temp, (1) << (oneWirePins.pin_ow_moder_bit));
+    oneWirePins.port->MODER = temp;
+#endif // STM32L0
+
+#ifndef PIN_IN_USE_IN
+    //GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
+    //HAL_GPIO_Init(oneWirePins.port, &GPIO_InitStructure);
+    #error MUSITE POUZIT VERIZU 1-WIRE PRE 2 PINY PROCESORA
+#endif // STM32F0
+
+#endif // OW_USE_2_WIRE
+}
+
+
+//----------------------------------------------------------------------
+// Implementacia high-level funkcii podla Maxim, AN187
+//----------------------------------------------------------------------
+
+/**
+ * @brief   Inicializacia drivera zbernice 1-wire
+ * Driver podporuje komunikáciu na 1-wire zbenici v implementácii 2 pinov (1xvstup, 1xvystup pin),
+ * alebo 1 pinu (pin je podľa potreby zmenený). V aktuálnej verzii nie je podpora boostera zbernice.
+ * Toto nastavenie je dané v súbore module_one_wire.h konštantou OW_USE_2_WIRE
+ * - Nastavia sa časové konštanty na preddefinované hodnoty.
+ * - Nastavia sa piny pre zbernicu One-wire
+ *
+ * @param   timer časovač použirý an generovanie:
+ *          - blokujúcej pauzy v ráde us
+ * @param GPIOx port pre piny
+ * @param GPIO_Pin pin pre zápis na zbernicu (defined OW_USE_2_WIRE), alebo zápis/čítanie (NOT defined OW_USE_2_WIRE)
+ * @param GPIO_Pin_in pin pre čítanie na zbernicu (defined OW_USE_2_WIRE)
+ * @return none
+ */
+#ifdef OW_MODULE_USE_TIMER
+void oneWire_init(TIM_HandleTypeDef *timer, GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) {
+    oneWireDrv.owTimer = timer;
+#else
+#if OW_USE_2_WIRE == 1
+void oneWire_init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint16_t GPIO_Pin_in ) {
+#else
+void oneWire_init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin ) {
+#endif
+#endif
+	oneWireDrv.one_wire_timing_settings = OW_SETTING_NORMAL;
+    oneWirePins.port = GPIOx;
+    oneWirePins.pin_ow = GPIO_Pin;
+
+    uint16_t tmp = oneWirePins.pin_ow;
+    oneWirePins.pin_ow_moder_bit = 0;
+    while(tmp){
+        oneWirePins.pin_ow_moder_bit++;
+        tmp>>=1;
+    }
+    oneWirePins.pin_ow_moder_bit--;
+    oneWirePins.pin_ow_moder_bit*=2;
+
+#if OW_USE_2_WIRE == 1
+    oneWirePins.pin_ow_in = GPIO_Pin_in;
+#endif // OW_USE_2_WIRE
+
+    setPinOut();
+    OW_SET_HI;
+    *(oneWireDrv.ROM_NO) = (uint32_t)0;
+    *(oneWireDrv.ROM_NO+4) = (uint32_t)0;
+   // delay_us_long(120);
+}
+
+
+/**
+* Vráti pointer na ROM_NO.
+* @retval pointer na ROM_NO
+*/
+uint8_t *oneWire_getROM() {
+    return oneWireDrv.ROM_NO;
+}
+
+
+/**
+ * @brief    Find the 'first' devices on the 1-Wire bus
+ * @param    none
+ * @retval   TRUE  - device found, ROM number in ROM_NO buffer
+ *           FALSE - no device present
+ */
+uint8_t owFirst() {
+    // reset the search state
+    oneWireDrv.LastDiscrepancy = 0;
+    oneWireDrv.LastDeviceFlag = FALSE;
+    oneWireDrv.LastFamilyDiscrepancy = 0;
+    return owSearch();
+}
+
+/**
+ * @brief    Find the 'next' devices on the 1-Wire bus
+ * @param    none
+ * @retval : TRUE  - device found, ROM number in ROM_NO buffer
+ *           FALSE : device not found, end of search
+ */
+uint8_t owNext() {
+    return owSearch();
+}
+
+
+void owSelect_ROM(const uint8_t rom[8]) {
+    uint8_t i;
+    owWriteByte(OW_CMD_MATCH_ROM, OW_STRONG_OFF);           // Choose ROM
+    for (i = 0; i < 8; i++) {
+        owWriteByte(rom[i], OW_STRONG_OFF);
+    }
+}
+
+void owSelect() {
+	OW_DIS_INTERRUPTS;
+	uint8_t i;
+    if (owReset()) {
+        owWriteByte(OW_CMD_MATCH_ROM, OW_STRONG_OFF);
+        for(i=0; i<8; i++) {
+            owWriteByte(oneWireDrv.ROM_NO[i], OW_STRONG_OFF);
+        }
+    }
+    OW_ENA_INTERRUPTS;
+}
+
+/**
+* Odovzdá ako odkaz obsah ROM.
+* @param mem_page pole bytov[8], kre bude uložený obsah ROM_NO
+*/
+void owGetROM(uint8_t *mem_page) {
+    *mem_page = *oneWireDrv.ROM_NO;
+    *(mem_page +4)= *(oneWireDrv.ROM_NO+4);
+}
+
+
+/**
+ * @brief    Perform the 1-Wire Search Algorithm on the 1-Wire bus
+ *           using the existing search state.
+ * @param    none
+ * @retval : TRUE  - device found, ROM number in ROM_NO buffer
+ *           FALSE : device not found, end of search
+ */
+uint8_t owSearch() {
+	OW_DIS_INTERRUPTS;
+	uint32_t id_bit_number;
+    uint32_t last_zero, rom_byte_number, search_result;
+    uint32_t id_bit, cmp_id_bit;
+    uint8_t rom_byte_mask, search_direction;
+    // initialize for search
+    id_bit_number = 1;
+    last_zero = 0;
+    rom_byte_number = 0;
+    rom_byte_mask = 1;
+    search_result = 0;
+    crc8_ow = 0;
+
+    // if the last call was not the last one
+    if (oneWireDrv.LastDeviceFlag == FALSE) {
+        // 1-Wire reset
+        if (!owReset()) {
+            // reset the search
+            oneWireDrv.LastDiscrepancy = 0;
+            oneWireDrv.LastDeviceFlag = FALSE;
+            oneWireDrv.LastFamilyDiscrepancy = 0;
+            OW_ENA_INTERRUPTS;
+            return FALSE;
+        }
+        // issue the search command
+        owWriteByte(OW_CMD_SEARCH_ROM, OW_STRONG_OFF);
+
+        // loop to do the search
+        do {
+            // read a bit and its complement
+            id_bit = owReadBit();
+            cmp_id_bit = owReadBit();
+            // check for no devices on 1-wire
+            if ((id_bit == 1) && (cmp_id_bit == 1)) {
+                break;
+            } else {
+                // all devices coupled have 0 or 1
+                if (id_bit != cmp_id_bit) {
+                    search_direction = id_bit; // bit write value for search
+                } else {
+                    // if this discrepancy if before the Last Discrepancy
+                    // on a previous next then pick the same as last time
+                    if (id_bit_number < oneWireDrv.LastDiscrepancy)
+                        search_direction = ((oneWireDrv.ROM_NO[rom_byte_number] & rom_byte_mask) > 0);
+                    else
+                        // if equal to last pick 1, if not then pick 0
+                        search_direction = (id_bit_number == oneWireDrv.LastDiscrepancy);
+
+                    // if 0 was picked then record its position in LastZero
+                    if (search_direction == 0) {
+                        last_zero = id_bit_number;
+
+                        // check for Last discrepancy in family
+                        if (last_zero < 9)
+                            oneWireDrv.LastFamilyDiscrepancy = last_zero;
+                    }
+                }
+
+                // set or clear the bit in the ROM byte rom_byte_number
+                // with mask rom_byte_mask
+                if (search_direction == 1)
+                    oneWireDrv.ROM_NO[rom_byte_number] |= rom_byte_mask;
+                else
+                    oneWireDrv.ROM_NO[rom_byte_number] &= ~rom_byte_mask;
+
+                // serial number search direction write bit
+#ifdef OW_USE_TICKS
+                owWriteBit(&search_direction);
+#else
+                owWriteBit(search_direction);
+#endif
+                // increment the byte counter id_bit_number
+                // and shift the mask rom_byte_mask
+                id_bit_number++;
+                rom_byte_mask <<= 1;
+
+                // if the mask is 0 then go to new SerialNum byte rom_byte_number and reset mask
+                if (rom_byte_mask == 0) {
+                    owCrc8(oneWireDrv.ROM_NO[rom_byte_number]); // accumulate the CRC
+                    rom_byte_number++;
+                    rom_byte_mask = 1;
+                }
+            }
+        } while (rom_byte_number < 8); // loop until through all ROM bytes 0-7
+
+        // if the search was successful then
+        if (!((id_bit_number < 65) || (crc8_ow != 0))) {
+            // search successful so set LastDiscrepancy,LastDeviceFlag,search_result
+            oneWireDrv.LastDiscrepancy = last_zero;
+
+            // check for last device
+            if (oneWireDrv.LastDiscrepancy == 0)
+                oneWireDrv.LastDeviceFlag = TRUE;
+            search_result = TRUE;
+        }
+    }
+    // if no device found then reset counters so next 'search' will be like a first
+    if (!search_result || !oneWireDrv.ROM_NO[0]) {
+        oneWireDrv.LastDiscrepancy = 0;
+        oneWireDrv.LastDeviceFlag = FALSE;
+        oneWireDrv.LastFamilyDiscrepancy = 0;
+        search_result = FALSE;
+    }
+    if(search_result){
+       // owSelect();
+    }
+    OW_ENA_INTERRUPTS;
+    return search_result;
+}
+
+/**
+ * @brief    Verify the device with the ROM number in ROM_NO buffer is present.
+ * @param    none
+ * @return : TRUE  : device verified present
+ *           FALSE : device not present
+ */
+uint8_t owVerify() {
+	OW_DIS_INTERRUPTS;
+	unsigned char rom_backup[8];
+    int i, rslt, ld_backup, ldf_backup, lfd_backup;
+
+    // keep a backup copy of the current state
+    for (i = 0; i < 8; i++)
+        rom_backup[i] = oneWireDrv.ROM_NO[i];
+    ld_backup = oneWireDrv.LastDiscrepancy;
+    ldf_backup = oneWireDrv.LastDeviceFlag;
+    lfd_backup = oneWireDrv.LastFamilyDiscrepancy;
+
+    // set search to find the same device
+    oneWireDrv.LastDiscrepancy = 64;
+    oneWireDrv.LastDeviceFlag = FALSE;
+
+    if (owSearch()) {
+        // check if same device found
+        rslt = TRUE;
+        for (i = 0; i < 8; i++) {
+            if (rom_backup[i] != oneWireDrv.ROM_NO[i]) {
+                rslt = FALSE;
+                break;
+            }
+        }
+    } else
+        rslt = FALSE;
+
+    // restore the search state
+    for (i = 0; i < 8; i++){
+        oneWireDrv.ROM_NO[i] = rom_backup[i];
+    }
+    oneWireDrv.LastDiscrepancy = ld_backup;
+    oneWireDrv.LastDeviceFlag = ldf_backup;
+    oneWireDrv.LastFamilyDiscrepancy = lfd_backup;
+
+    if(rslt == TRUE) {
+        owSelect();
+    }
+    OW_ENA_INTERRUPTS;
+    // return the result of the verify
+    return rslt;
+}
+
+/**
+ * @brief    Setup the search to find the device type 'family_code' on the next call
+ *           to owNext() if it is present.
+ * @param    none
+ * @retval : none
+ */
+void owTargetSetup(uint8_t family_code) {
+    // set the search state to find SearchFamily type devices
+    oneWireDrv.ROM_NO[0] = family_code;
+    oneWireDrv.ROM_NO[1] = 0;
+    oneWireDrv.ROM_NO[2] = 0;
+    oneWireDrv.ROM_NO[3] = 0;
+    oneWireDrv.ROM_NO[4] = 0;
+    oneWireDrv.ROM_NO[5] = 0;
+    oneWireDrv.ROM_NO[6] = 0;
+    oneWireDrv.ROM_NO[7] = 0;
+    oneWireDrv.LastDiscrepancy = 64;
+    oneWireDrv.LastFamilyDiscrepancy = 0;
+    oneWireDrv.LastDeviceFlag = FALSE;
+}
+
+/**
+ * @brief    Setup the search to skip the current device type on the next call
+ *           to owNeOW_LOWxt().
+ * @param    none
+ * @retval : none
+ */
+void owFamilySkipSetup(void) {
+    // set the Last discrepancy to last family discrepancy
+    oneWireDrv.LastDiscrepancy = oneWireDrv.LastFamilyDiscrepancy;
+    oneWireDrv.LastFamilyDiscrepancy = 0;
+
+    // check for end of list
+    if (oneWireDrv.LastDiscrepancy == 0)
+        oneWireDrv.LastDeviceFlag = TRUE;
+}
+
+/**
+ * @brief    Setup new ROM number
+ * @param    array with new ROM number
+ * @retval : none
+ */
+void owSetRom(uint8_t *array) {
+    *oneWireDrv.ROM_NO = *array;
+    *(oneWireDrv.ROM_NO +4 )= *(array+4);
+}
+
+/**
+ * @brief    Calculate the CRC8 of the byte value provided with the
+ *           current global 'crc8' value.
+ * @param    byte value
+ * @retval : current global crc8 value
+ */
+uint8_t owCrc8(uint8_t value) {
+    crc8_ow = dscrc_table[crc8_ow ^ value];
+    return crc8_ow;
+}
+
+
+/**
+  * @brief    Reset 1-wire zbernice s detekciou pritomnosti zariadenia
+  * @param    none
+  * @retval : TRUE  - device present
+  *           FALSE - no device present
+  */
+uint8_t __attribute__((optimize("O3"))) owReset(void) {
+    uint8_t state;
+#ifdef OW_USE_TICKS
+    OW_GPIO_PULSE(OW_RESET_MEASTER, 0, MCU_FREQUENCY, 1,  oneWirePins.port, oneWirePins.pin_ow);
+
+    OW_SET_HI;
+	setPinIn();
+	OW_DELAY_US(OW_RESET_PRESENCE, MCU_FREQUENCY, 1); //TODO set offset
+
+#if OW_USE_2_WIRE == 1
+	state = (oneWirePins.port->IDR & oneWirePins.pin_ow_in ) != 0;
+#else
+	state = (oneWirePins.port->IDR & oneWirePins.pin_ow ) != 0;
+#endif //OW_USE_2_WIRE
+
+	//setPinOut();
+	OW_DELAY_US(OW_RESET_DELAY, MCU_FREQUENCY, 40); //TODO set offset
+	setPinOut(); //Toto som presunul až za oneskorenie, pretože to spôsobovalo nechcené pulzy
+
+	return !state;
+#else
+    OW_SET_LO;
+	delay_us_long(OW_RESET_MEASTER/4);
+	OW_SET_HI;
+
+	setPinIn();
+	delay_us(OW_RESET_PRESENCE);
+
+#if OW_USE_2_WIRE == 1
+	state = (oneWirePins.port->IDR & oneWirePins.pin_ow_in ) != 0 ? 1:0;
+#else
+	state = (oneWirePins.port->IDR & oneWirePins.pin_ow ) != 0 ? 1:0;
+#endif //OW_USE_2_WIRE
+
+	setPinOut();
+	delay_us_long(OW_RESET_DELAY/4);
+
+	if(state == GPIO_PIN_SET)
+		return FALSE;
+	else
+		return TRUE;
+#endif
+}
+
+/**
+  * @brief    Vyslanie 8-bitov na zbernicu 1-wire
+  * @param    byte_value 1W príkaz
+  * @param    strong príznak, či sa má po poslednom bite dať zbernica do stavu STRONG.
+  * povolené hodnoty: @arg OW_STRONG_OFF - zbernica bude v stave RESISTIVE,
+  * @arg OW_STRONG_ON zbernica bude v stave STRONG
+  * @retval : none
+  */
+#ifdef OW_USE_TICKS
+void __attribute__((optimize("O1"))) owWriteByte(uint8_t byte_value, uint8_t strong) {
+	owWriteBit(&byte_value);
+	owWriteBit(&byte_value);
+	owWriteBit(&byte_value);
+	owWriteBit(&byte_value);
+	owWriteBit(&byte_value);
+	owWriteBit(&byte_value);
+	owWriteBit(&byte_value);
+	//owWriteBit(&byte_value);
+#if USE_STRONG == 1
+	    if(strong == OW_STRONG_ON){
+	    	owWriteBitStrong(byte_value>>7);
+	    }else{
+	    	if(byte_value & 0x01){
+				// zapis bit=1
+				OW_GPIO_PULSE(OW_WRITE_ONE, 0, MCU_FREQUENCY, 1,  oneWirePins.port, oneWirePins.pin_ow);
+				OW_GPIO_PULSE(OW_WRITE_ONE_DELAY + OW_WRITE_DELAY, 1, MCU_FREQUENCY, 29,  oneWirePins.port, oneWirePins.pin_ow);
+				//Offset je nastavený na 19, pretože zohľadňuje volanie aj obsluhu funkcie
+			}
+			else{
+				// zapis bit=0
+				OW_GPIO_PULSE(OW_WRITE_ZERO, 0, MCU_FREQUENCY, 1,  oneWirePins.port, oneWirePins.pin_ow);
+				OW_GPIO_PULSE(OW_WRITE_DELAY, 1, MCU_FREQUENCY, 30,  oneWirePins.port, oneWirePins.pin_ow);
+				//Offset je nastavený na 21, pretože zohľadňuje volanie aj obsluhu funkcie
+			}
+	    }
+#else
+	if(byte_value & 0x01){
+		// zapis bit=1
+		OW_GPIO_PULSE(OW_WRITE_ONE, 0, MCU_FREQUENCY, 1,  oneWirePins.port, oneWirePins.pin_ow);
+		OW_GPIO_PULSE(OW_WRITE_ONE_DELAY + OW_WRITE_DELAY, 1, MCU_FREQUENCY, 29,  oneWirePins.port, oneWirePins.pin_ow);
+		//Offset je nastavený na 19, pretože zohľadňuje volanie aj obsluhu funkcie
+	}
+	else{
+		// zapis bit=0
+		OW_GPIO_PULSE(OW_WRITE_ZERO, 0, MCU_FREQUENCY, 1,  oneWirePins.port, oneWirePins.pin_ow);
+		OW_GPIO_PULSE(OW_WRITE_DELAY, 1, MCU_FREQUENCY, 30,  oneWirePins.port, oneWirePins.pin_ow);
+		//Offset je nastavený na 21, pretože zohľadňuje volanie aj obsluhu funkcie
+	}
+#endif
+}
+#else
+void owWriteByte(uint8_t byte_value, uint8_t strong) {
+	//    HAL_SuspendTick();
+		owWriteBit(byte_value);
+	    owWriteBit(byte_value>>1);
+	    owWriteBit(byte_value>>2);
+	    owWriteBit(byte_value>>3);
+	    owWriteBit(byte_value>>4);
+	    owWriteBit(byte_value>>5);
+	    owWriteBit(byte_value>>6);
+	#if USE_STRONG == 1
+	    if(strong == OW_STRONG_ON){
+	    	owWriteBitStrong(byte_value>>7);
+	    }else{
+	    	owWriteBit(byte_value>>7);
+	    }
+	#else
+	    owWriteBit(byte_value>>7);
+	//    HAL_ResumeTick();
+	#endif
+}
+#endif
+
+/**
+* Na zbernicu 1-wire zapíše 1 bit. Po zápise nastaví zbernicu
+* do stavu STRONG.
+* @param bit_value - bit, ktorý sa bude zapisovať.
+*/
+#ifdef OW_USE_TICKS
+void owWriteBitStrong(uint8_t bit_value) {
+	if(bit_value & 0x01){
+		// zapis bit=1
+		OW_GPIO_PULSE(OW_WRITE_ONE, 1, MCU_FREQUENCY, 15, oneWirePins.port, oneWirePins.pin_ow);
+		//TODO offset je stanovený od oka v tomto prípade
+	}
+	else{
+		// zapis bit=0
+		OW_GPIO_PULSE(OW_WRITE_ZERO, 0, MCU_FREQUENCY, 17,  oneWirePins.port, oneWirePins.pin_ow);
+		//TODO offset je stanovený od oka v tomto prípade
+	}
+}
+#else
+void owWriteBitStrong(uint8_t bit_value) {
+	OW_SET_LO;
+	switch(bit_value & 0x01) {
+	case 0x00:
+		// zapis bit=0
+		delay_us(OW_WRITE_ZERO);
+		break;
+
+	case 0x01:
+		// zapis bit=1
+		delay_us(OW_WRITE_ONE);
+		break;
+	}
+	ow_SetReadState();
+	//    OW_STRONG_SET;
+}
+#endif
+
+
+/**
+  * @brief    Vyslanie 1 bitu na zbernicu 1-wire
+  * @param    data, akceptovany je LSB
+  * @retval : none
+  */
+#ifdef OW_USE_TICKS
+void __attribute__((optimize("Ofast"))) owWriteBit(uint8_t* bit_value) {
+	if(*bit_value & 0x01){
+		// zapis bit=1
+		OW_GPIO_PULSE(OW_WRITE_ONE, 0, MCU_FREQUENCY, 1,  oneWirePins.port, oneWirePins.pin_ow);
+		OW_GPIO_PULSE(OW_WRITE_ONE_DELAY + OW_WRITE_DELAY, 1, MCU_FREQUENCY, 19,  oneWirePins.port, oneWirePins.pin_ow);
+		//Offset je nastavený na 19, pretože zohľadňuje volanie aj obsluhu funkcie
+	}
+	else{
+		// zapis bit=0
+		OW_GPIO_PULSE(OW_WRITE_ZERO, 0, MCU_FREQUENCY, 1,  oneWirePins.port, oneWirePins.pin_ow);
+		OW_GPIO_PULSE(OW_WRITE_DELAY, 1, MCU_FREQUENCY, 21,  oneWirePins.port, oneWirePins.pin_ow);
+		//Offset je nastavený na 21, pretože zohľadňuje volanie aj obsluhu funkcie
+	}
+	*bit_value >>= 1;
+}
+#else
+void owWriteBit(uint8_t bit_value) {
+    OW_SET_LO;
+    //uint32_t prim = __get_PRIMASK();
+    //__disable_irq();
+
+    if(bit_value & 0x01) {
+        // zapis bit=1
+        delay_us(OW_WRITE_ONE);
+        OW_SET_HI;
+        delay_us(OW_WRITE_ONE_DELAY);
+    }else{
+        // zapis bit=0
+        delay_us(OW_WRITE_ZERO);
+        OW_SET_HI;
+    }
+
+
+    delay_us(OW_WRITE_DELAY);
+    //    if (!prim) {
+    //    __enable_irq();
+    //}
+}
+#endif
+
+
+
+/**
+  * @brief    Nacitanie 1 bitu zo zbernicu 1-wire
+  * @param    none
+  * @retval : nacitana hodnota 0/1
+  */
+uint8_t owReadBit(void) {
+#ifdef OW_USE_TICKS
+	//uint32_t prim = __get_PRIMASK();
+	//__disable_irq();
+	//HAL_SuspendTick();
+	uint8_t state=0x00;
+
+	OW_GPIO_PULSE(OW_READ_PULSE, 0, MCU_FREQUENCY, 7,  oneWirePins.port, oneWirePins.pin_ow); //TODO set offset
+
+	//OW_SET_HI;
+	setPinIn();
+	OW_SET_HI; //Toto som presunul až za oneskorenie, pretože to spôsobovalo nechcené pulzy
+	OW_DELAY_US(OW_READ_PRESENCE, MCU_FREQUENCY, 1); //TODO set offset
+
+#if OW_USE_2_WIRE == 1
+	state = (oneWirePins.port->IDR & oneWirePins.pin_ow_in ) != 0;
+#else
+	state = (oneWirePins.port->IDR & oneWirePins.pin_ow ) != 0;
+#endif //OW_USE_2_WIRE
+
+	//setPinOut();
+	//OW_SET_HI;
+	OW_DELAY_US(OW_READ_DELAY, MCU_FREQUENCY, 1); //TODO set offset
+	setPinOut(); //Toto som presunul až za oneskorenie, pretože to spôsobovalo nechcené pulzy
+	OW_DELAY_US(OW_BOOSTER, MCU_FREQUENCY, 36); //TODO set offset
+	/*
+	if (!prim) {
+		__enable_irq();
+	}
+	*/
+//    HAL_ResumeTick();
+	return state;
+
+#else
+	//uint32_t prim = __get_PRIMASK();
+	//__disable_irq();
+	//HAL_SuspendTick();
+	uint8_t state=0x00;
+
+
+	OW_SET_LO;
+	delay_us(OW_READ_PULSE);
+
+	OW_SET_HI;
+	setPinIn();
+	delay_us(OW_READ_PRESENCE);
+
+#if OW_USE_2_WIRE == 1
+	state = (oneWirePins.port->IDR & oneWirePins.pin_ow_in ) != 0 ? 1:0;
+#else
+	state = (oneWirePins.port->IDR & oneWirePins.pin_ow ) != 0 ? 1:0;
+#endif //OW_USE_2_WIRE
+
+	setPinOut();
+	OW_SET_HI;
+	delay_us(OW_READ_DELAY);
+	delay_us(OW_BOOSTER);
+	/*
+	if (!prim) {
+		__enable_irq();
+	}
+	*/
+//    HAL_ResumeTick();
+	return state;
+#endif
+
+}
+
+/**
+  * @brief    Nacitanie 1 byte zo zbernice 1-wire
+  * @param    none
+  * @retval   nacitana hodnota 8-bit hodnota
+  */
+uint8_t owReadByte(void) {
+    uint8_t value;
+    value  = (owReadBit()); // LSB first
+	value |= (owReadBit()<<1);
+	value |= (owReadBit()<<2);
+	value |= (owReadBit()<<3);
+	value |= (owReadBit()<<4);
+	value |= (owReadBit()<<5);
+	value |= (owReadBit()<<6);
+	value |= (owReadBit()<<7);
+    return value;
+}
+
+
+
+
+/**
+  * @}
+  */
+
+/**
+  * @}
+  */
+
+/**
+  * @}
+  */