├── .gitignore ├── Network Module Manual - Code Rev 20240612 0226.doc ├── Network Module Manual - Code Rev 20240612 0226.odt ├── Network Module Manual - Code Rev 20240612 0226.pdf ├── NetworkModule ├── .Idea_Groups │ └── Vector_File.grp ├── .Idea_Temp │ ├── COBJ.TMP │ ├── IDEA.ERR │ ├── IDEABLD.BAT │ ├── microwebserver__lkf__.p │ ├── microwebserver__lkf__.tmp │ ├── microwebserver_vector.sbx │ ├── networkmodule_vector.sbx │ └── uip_split.sbx ├── .gitattributes ├── .gitignore ├── DS18B20.c ├── DS18B20.h ├── Enc28j60.c ├── Enc28j60.h ├── Gpio.c ├── Gpio.h ├── I2C.c ├── I2C.h ├── Main.c ├── NetworkModule.lkf ├── NetworkModule.prjsm8 ├── STM8S_StdPeriph_Driver │ ├── Release_Notes.html │ ├── inc │ │ ├── stm8s.h │ │ ├── stm8s_adc1.h │ │ ├── stm8s_adc2.h │ │ ├── stm8s_awu.h │ │ ├── stm8s_beep.h │ │ ├── stm8s_can.h │ │ ├── stm8s_clk.h │ │ ├── stm8s_exti.h │ │ ├── stm8s_flash.h │ │ ├── stm8s_gpio.h │ │ ├── stm8s_i2c.h │ │ ├── stm8s_itc.h │ │ ├── stm8s_iwdg.h │ │ ├── stm8s_rst.h │ │ ├── stm8s_spi.h │ │ ├── stm8s_tim1.h │ │ ├── stm8s_tim2.h │ │ ├── stm8s_tim3.h │ │ ├── stm8s_tim4.h │ │ ├── stm8s_tim5.h │ │ ├── stm8s_tim6.h │ │ ├── stm8s_uart1.h │ │ ├── stm8s_uart2.h │ │ ├── stm8s_uart3.h │ │ ├── stm8s_uart4.h │ │ └── stm8s_wwdg.h │ ├── src │ │ ├── stm8s_adc1.c │ │ ├── stm8s_adc2.c │ │ ├── stm8s_awu.c │ │ ├── stm8s_beep.c │ │ ├── stm8s_can.c │ │ ├── stm8s_clk.c │ │ ├── stm8s_exti.c │ │ ├── stm8s_flash.c │ │ ├── stm8s_gpio.c │ │ ├── stm8s_i2c.c │ │ ├── stm8s_itc.c │ │ ├── stm8s_iwdg.c │ │ ├── stm8s_rst.c │ │ ├── stm8s_spi.c │ │ ├── stm8s_tim1.c │ │ ├── stm8s_tim2.c │ │ ├── stm8s_tim3.c │ │ ├── stm8s_tim4.c │ │ ├── stm8s_tim5.c │ │ ├── stm8s_tim6.c │ │ ├── stm8s_uart1.c │ │ ├── stm8s_uart2.c │ │ ├── stm8s_uart3.c │ │ ├── stm8s_uart4.c │ │ └── stm8s_wwdg.c │ └── stm8s-a_stdperiph_drivers_um.chm ├── Spi.c ├── Spi.h ├── UART.c ├── UART.h ├── bme280.c ├── bme280.h ├── bme280_defs.h ├── httpd.c ├── httpd.h ├── ina226.c ├── ina226.h ├── main.h ├── mqtt.c ├── mqtt.h ├── mqtt_pal.c ├── mqtt_pal.h ├── networkmodule_vector.c ├── pcf8574.c ├── pcf8574.h ├── stm8s-005.h ├── sync.ffs_db ├── timer.c ├── timer.h ├── uip.c ├── uip.h ├── uip_TcpAppHub.c ├── uip_TcpAppHub.h ├── uip_arch.h ├── uip_arp.c ├── uip_arp.h ├── uip_types.h └── uipopt.h └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | ~$twork Module Manual - Code Rev 20221217 1925.doc 3 | -------------------------------------------------------------------------------- /Network Module Manual - Code Rev 20240612 0226.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nielsonm236/NetMod-ServerApp/1700e7a9aa5b377ca4deb89e6a47fe72e026d3f7/Network Module Manual - Code Rev 20240612 0226.doc -------------------------------------------------------------------------------- /Network Module Manual - Code Rev 20240612 0226.odt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nielsonm236/NetMod-ServerApp/1700e7a9aa5b377ca4deb89e6a47fe72e026d3f7/Network Module Manual - Code Rev 20240612 0226.odt -------------------------------------------------------------------------------- /Network Module Manual - Code Rev 20240612 0226.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nielsonm236/NetMod-ServerApp/1700e7a9aa5b377ca4deb89e6a47fe72e026d3f7/Network Module Manual - Code Rev 20240612 0226.pdf -------------------------------------------------------------------------------- /NetworkModule/.Idea_Groups/Vector_File.grp: -------------------------------------------------------------------------------- 1 | # Group File Created by IDEA 2 | # Project: 3 | # Tue Jul 02 18:27:15 2024 4 | # 5 | "networkmodule_vector.o" 6 | -------------------------------------------------------------------------------- /NetworkModule/.Idea_Temp/IDEA.ERR: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nielsonm236/NetMod-ServerApp/1700e7a9aa5b377ca4deb89e6a47fe72e026d3f7/NetworkModule/.Idea_Temp/IDEA.ERR -------------------------------------------------------------------------------- /NetworkModule/.Idea_Temp/IDEABLD.BAT: -------------------------------------------------------------------------------- 1 | REM COMMAND FILE BUILT BY IDEA 2 | REM Tue Jul 02 18:27:08 2024 3 | REM 4 | cxstm8 -v -l +strict +debug +modsl0 +split +warn "networkmodule_vector.c" 5 | cxstm8 -v -l +strict +debug +modsl0 +split +warn "bme280.c" "ds18b20.c" "enc28j60.c" "gpio.c" "httpd.c" "i2c.c" "ina226.c" "main.c" "mqtt.c" "mqtt_pal.c" "pcf8574.c" "spi.c" "timer.c" "uart.c" "uip.c" "uip_arp.c" "uip_tcpapphub.c" 6 | clnk -v -sa -o "NetworkModule.sm8" -m "NetworkModule.map" "networkmodule.lkf" 7 | chex -f3 -o "NetworkModule.sx" "NetworkModule.sm8" 8 | clabs "NetworkModule.sm8" 9 | -------------------------------------------------------------------------------- /NetworkModule/.Idea_Temp/microwebserver__lkf__.p: -------------------------------------------------------------------------------- 1 | ## link command file for STM8S005C6 2 | ## Copyright (c) 2008 by COSMIC Software 3 | ## 4 | +seg .vector -b 0x8000 -m 0x8000 -n .vector # vectors start address 5 | +seg .const -a .vector -n .const # constants follow vectors 6 | +seg .text -a .const -n .text # code follow constants 7 | +seg .eeprom -b 0x4000 -m 128 # internal eeprom 8 | +seg .bsct -b 0 -m 0x100 -n .bsct # internal ram 9 | +seg .ubsct -a .bsct -n .ubsct 10 | +seg .bit -a .ubsct -n .bit -id 11 | +seg .data -a .bit -m 0x800 -n .data 12 | +seg .bss -a .data -n .bss 13 | 14 | ## interrupt vectors 15 | __STP_VECTORFILE__ 16 | 17 | ## startup file 18 | "crts0.sm8" 19 | 20 | ## application files 21 | __STP_FILES__ 22 | 23 | ## libraries 24 | "libisl0.sm8" # C library (if needed) 25 | "libm0.sm8" # machine library 26 | 27 | ## symbols 28 | +def __endzp=@.ubsct # end of zero page 29 | +def __memory=@.bss # symbol used by library 30 | +def __stack=0x7ff # stack pointer initial value 31 | -------------------------------------------------------------------------------- /NetworkModule/.Idea_Temp/microwebserver__lkf__.tmp: -------------------------------------------------------------------------------- 1 | ## link command file for STM8S005C6 2 | ## Copyright (c) 2008 by COSMIC Software 3 | ## 4 | +seg .vector -b 0x8000 -m 0x8000 -n .vector # vectors start address 5 | #if defined(__OPT_PSPLIT__) 6 | -k 7 | #endif 8 | +seg .const -a .vector -n .const # constants follow vectors 9 | +seg .text -a .const -n .text # code follow constants 10 | +seg .eeprom -b 0x4000 -m 128 # internal eeprom 11 | +seg .bsct -b 0 -m 0x100 -n .bsct # internal ram 12 | +seg .ubsct -a .bsct -n .ubsct 13 | +seg .bit -a .ubsct -n .bit -id 14 | +seg .data -a .bit -m 0x800 -n .data 15 | +seg .bss -a .data -n .bss 16 | 17 | ## interrupt vectors 18 | #if defined(__STP_VECTOR__) 19 | __STP_VECTORFILE__ 20 | #endif 21 | 22 | ## startup file 23 | #if defined(__OPT_PMODS0__) || defined(__OPT_PMODSL0__) 24 | #if defined(__STP_CRTS__) 25 | "crts0.sm8" 26 | #elif defined(__STP_CRTSI__) 27 | "crtsi0.sm8" 28 | #endif 29 | #else 30 | #if defined(__STP_CRTS__) 31 | "crts.sm8" 32 | #elif defined(__STP_CRTSI__) 33 | "crtsi.sm8" 34 | #endif 35 | #endif 36 | 37 | ## application files 38 | __STP_FILES__ 39 | 40 | ## libraries 41 | #if defined(__OPT_PMODS0__) 42 | #if defined(__STP_FLOAT__) 43 | "libfs0.sm8" 44 | #endif 45 | "libis0.sm8" # C library (if needed) 46 | "libm0.sm8" # machine library 47 | #elif defined(__OPT_PMODS__) 48 | #if defined(__STP_FLOAT__) 49 | "libfs.sm8" 50 | #endif 51 | "libis.sm8" # C library (if needed) 52 | "libm.sm8" # machine library 53 | #elif defined(__OPT_PMODSL0__) 54 | #if defined(__STP_FLOAT__) 55 | "libfsl0.sm8" 56 | #endif 57 | "libisl0.sm8" # C library (if needed) 58 | "libm0.sm8" # machine library 59 | #else 60 | #if defined(__STP_FLOAT__) 61 | "libfsl.sm8" 62 | #endif 63 | "libisl.sm8" # C library (if needed) 64 | "libm.sm8" # machine library 65 | #endif 66 | 67 | ## symbols 68 | +def __endzp=@.ubsct # end of zero page 69 | +def __memory=@.bss # symbol used by library 70 | +def __stack=0x7ff # stack pointer initial value 71 | -------------------------------------------------------------------------------- /NetworkModule/.Idea_Temp/microwebserver_vector.sbx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nielsonm236/NetMod-ServerApp/1700e7a9aa5b377ca4deb89e6a47fe72e026d3f7/NetworkModule/.Idea_Temp/microwebserver_vector.sbx -------------------------------------------------------------------------------- /NetworkModule/.Idea_Temp/networkmodule_vector.sbx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nielsonm236/NetMod-ServerApp/1700e7a9aa5b377ca4deb89e6a47fe72e026d3f7/NetworkModule/.Idea_Temp/networkmodule_vector.sbx -------------------------------------------------------------------------------- /NetworkModule/.Idea_Temp/uip_split.sbx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nielsonm236/NetMod-ServerApp/1700e7a9aa5b377ca4deb89e6a47fe72e026d3f7/NetworkModule/.Idea_Temp/uip_split.sbx -------------------------------------------------------------------------------- /NetworkModule/.gitattributes: -------------------------------------------------------------------------------- 1 | * -crlf 2 | -------------------------------------------------------------------------------- /NetworkModule/.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | 34 | # Compiled STM8 35 | *.sbx 36 | *.ls 37 | *.obl 38 | *.sm8 39 | *.map 40 | *.sx 41 | *.stp 42 | -------------------------------------------------------------------------------- /NetworkModule/DS18B20.h: -------------------------------------------------------------------------------- 1 | /* 2021 Michael Nielson 2 | * Adapted for STM8S005 processor, ENC28J60 Ethernet Controller, 3 | * Web_Relay_Con V2.0 HW-584, and compilation with Cosmic tool set. 4 | * Author: Michael Nielson 5 | * Email: nielsonm.projects@gmail.com 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, but 12 | WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | General Public License for more details. 15 | 16 | See GNU General Public License at . 17 | 18 | Copyright 2021 Michael Nielson 19 | */ 20 | 21 | 22 | #ifndef __DS18B20_H__ 23 | #define __DS18B20_H__ 24 | 25 | void get_temperature(void); 26 | void convert_temperature(uint8_t device_num, uint8_t degCorF, uint8_t method); 27 | int reset_pulse(void); 28 | uint8_t check_CRC(void); 29 | void transmit_byte(uint8_t transmit_value); 30 | int read_bit(void); 31 | void write_bit(uint8_t transmit_bit); 32 | void one_wire_low(int wait); 33 | // void check_temperature_sensor_changes(void); 34 | void init_DS18B20(void); 35 | 36 | 37 | void FindDevices(void); 38 | uint8_t First(void); 39 | uint8_t Next(void); 40 | uint8_t dallas_crc8(uint8_t *data, uint8_t size); 41 | 42 | 43 | 44 | 45 | #endif /* __DS18B20_H__ */ 46 | -------------------------------------------------------------------------------- /NetworkModule/Enc28j60.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nielsonm236/NetMod-ServerApp/1700e7a9aa5b377ca4deb89e6a47fe72e026d3f7/NetworkModule/Enc28j60.c -------------------------------------------------------------------------------- /NetworkModule/Enc28j60.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File including all necessary settings regarding the Enc28j60 3 | * Ethernet Chip. 4 | * PS: You shouldn't care about Enc28j60's memory settings unless 5 | * you really know what you are doing. 6 | * 7 | * Author: Simon Kueppers 8 | * Email: simon.kueppers@web.de 9 | * Homepage: http://klinkerstein.m-faq.de 10 | * 11 | This program is free software: you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with this program. If not, see . 23 | 24 | Copyright 2008 Simon Kueppers 25 | * 26 | */ 27 | 28 | /* Modifications 2020-2022 Michael Nielson 29 | * Adapted for STM8S005 processor, ENC28J60 Ethernet Controller, 30 | * Web_Relay_Con V2.0 HW-584, and compilation with Cosmic tool set. 31 | * Author: Michael Nielson 32 | * Email: nielsonm.projects@gmail.com 33 | This program is free software: you can redistribute it and/or modify 34 | it under the terms of the GNU General Public License as published by 35 | the Free Software Foundation, either version 3 of the License, or 36 | (at your option) any later version. 37 | 38 | This program is distributed in the hope that it will be useful, but 39 | WITHOUT ANY WARRANTY; without even the implied warranty of 40 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 41 | General Public License for more details. 42 | 43 | See GNU General Public License at . 44 | 45 | Copyright 2022 Michael Nielson 46 | */ 47 | 48 | 49 | 50 | 51 | #ifndef ENC28J60_H_ 52 | #define ENC28J60_H_ 53 | 54 | #include 55 | #include "Spi.h" 56 | 57 | /* Physical connection */ 58 | #define ENC28J60_DDR DDRB 59 | #define ENC28J60_PORT PORTB 60 | #define ENC28J60_INT PB1 61 | #define ENC28J60_CS PB2 62 | #define ENC28J60_MOSI PB3 63 | #define ENC28J60_MISO PB4 64 | #define ENC28J60_SCK PB5 65 | 66 | // OnChip Buffer locations 67 | // Errata Workaround: RX Buffer should start at 0x0000 68 | // Errata Workaround: RXEND should not be even! 69 | #define ENC28J60_RXSTART 0x0000 //6kb 70 | #define ENC28J60_RXEND 0x17FF 71 | #define ENC28J60_TXSTART 0x1800 //2kb 72 | #define ENC28J60_TXEND 0x1FFF 73 | 74 | // LED configuration bits: 75 | // LEDA: Transmit 76 | // LEDB: Link & receive 77 | #define ENC28J60_LEDA 1 78 | #define ENC28J60_LEDB 12 79 | 80 | // Maximum frame length in bytes to prevent possible buffer overflows. 81 | // The factors pushing the MAXFRAME size are: 82 | // a) The size of the largest Home Assistant Config message plus headers 83 | // b) The copy_I2C_EEPROM_to_Flash() function which requires the uip_buf to be 84 | // at least 512 bytes. The uip_buf size is based on MAXFRAME. 85 | // #define ENC28J60_MAXFRAME 500 86 | #define ENC28J60_MAXFRAME 550 87 | 88 | // Use this for function inlining within the ENC28J60 module 89 | #define ENC28J60_INLINE static inline __attribute__ ((always_inline)) 90 | 91 | // Initialize Chip (Initialize used SPI module before!) 92 | void Enc28j60Init(void); 93 | 94 | // Receives an Ethernet-frame. If non available it returns zero 95 | // This function will never receive more than ENC28J60_MAXFRAME bytes 96 | uint16_t Enc28j60Receive(uint8_t* pBuffer); 97 | 98 | // Copies a packet into ENC28J60's buffer and sends the ethernet frame 99 | void Enc28j60Send(uint8_t* pBuffer, uint16_t nBytes); 100 | 101 | // Resets the transmit logic in the ENC28J60 102 | void reset_transmit_logic(void); 103 | 104 | // Wait for transmission complete ... or collision error ... or timeout. 105 | uint8_t wait_for_xmit_complete(void); 106 | 107 | // Reads the Transmit Status Vector 108 | // void read_TSV(void); 109 | 110 | // Use this function to control onchip clock-prescaling 111 | // provided by the ENC28J60 for using as the host processor's main clock 112 | // Startup default is ENC28J60's clock divided by 4 (6.25MHz) 113 | // Valid Prescalers are 1, 2, 3, 4, 8 114 | // void Enc28j60SetClockPrescaler(uint8_t nPrescaler); 115 | 116 | // Generates a checksum over a given range in ENC28J60's TX buffer 117 | // using ENC28J60's own checksum generation function. 118 | // uint16_t Enc28j60ChecksumTx(uint16_t Offset, uint16_t Length); 119 | 120 | // Copies data into ENC28J60's TX buffer at Offset 121 | // void Enc28j60CopyChecksum(uint16_t Offset, uint16_t Checksum); 122 | 123 | #endif /*ENC28J60_H_*/ 124 | -------------------------------------------------------------------------------- /NetworkModule/Gpio.h: -------------------------------------------------------------------------------- 1 | /* Modifications 2020-2022 Michael Nielson 2 | * Adapted for STM8S005 processor, ENC28J60 Ethernet Controller, 3 | * Web_Relay_Con V2.0 HW-584, and compilation with Cosmic tool set. 4 | * Author: Michael Nielson 5 | * Email: nielsonm.projects@gmail.com 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, but 12 | WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | General Public License for more details. 15 | 16 | See GNU General Public License at . 17 | 18 | Copyright 2022 Michael Nielson 19 | */ 20 | 21 | 22 | #ifndef __GPIO_H__ 23 | #define __GPIO_H__ 24 | 25 | // The following enum PORTS, struct io_registers, struct io_mapping, and 26 | // struct io_mapping io_map are used to direct the read_input_pins() and 27 | // write_output_pins functions to the correct registers and bits for each 28 | // physical pin that is being read or written. This significantly reduces 29 | // the code size for these functions. Credit to Carlos Ladeira for this 30 | // clever implementation. 31 | 32 | enum PORTS { PA, PB, PC, PD, PE, PF, PG, NUM_PORTS }; 33 | 34 | struct io_registers { 35 | volatile uint8_t odr; // Data Output Latch reg 36 | volatile uint8_t idr; // Input Pin Value reg 37 | volatile uint8_t ddr; // Data Direction 38 | volatile uint8_t cr1; // Control register 1 39 | volatile uint8_t cr2; // Control register 2 40 | }; 41 | 42 | struct io_mapping { 43 | uint8_t port; // port 44 | uint8_t bit; // port bit 45 | }; 46 | 47 | extern volatile struct io_registers io_reg[ NUM_PORTS ]; 48 | extern const struct io_mapping io_map[16]; 49 | 50 | void gpio_init(void); 51 | uint8_t calc_PORT_BIT_index(uint8_t IO_index); 52 | 53 | void LEDcontrol(uint8_t state); 54 | 55 | 56 | #endif /* __GPIO_H__ */ 57 | -------------------------------------------------------------------------------- /NetworkModule/I2C.h: -------------------------------------------------------------------------------- 1 | /* 2021 Michael Nielson 2 | * Adapted for STM8S005 processor, ENC28J60 Ethernet Controller, 3 | * Web_Relay_Con V2.0 HW-584, and compilation with Cosmic tool set. 4 | * Author: Michael Nielson 5 | * Email: nielsonm.projects@gmail.com 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, but 12 | WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | General Public License for more details. 15 | 16 | See GNU General Public License at . 17 | 18 | Copyright 2021 Michael Nielson 19 | */ 20 | 21 | 22 | #ifndef __I2C_H__ 23 | #define __I2C_H__ 24 | 25 | 26 | #define I2C_FAIL_NULL 0 27 | #define I2C_FAIL_NACK_CONTROL_BYTE 1 28 | #define I2C_FAIL_NACK_BYTE_ADDRESS1 2 29 | #define I2C_FAIL_NACK_BYTE_ADDRESS2 3 30 | #define I2C_FAIL_NACK_WRITE_BYTE 4 31 | 32 | #define I2C_EEPROM_R0_READ 0xa1 // 1010 0001 33 | #define I2C_EEPROM_R0_WRITE 0xa0 // 1010 0000 34 | #define I2C_EEPROM_R1_READ 0xa1 // 1010 0001 35 | #define I2C_EEPROM_R1_WRITE 0xa0 // 1010 0000 36 | #define I2C_EEPROM_R2_READ 0xa9 // 1010 1001 37 | #define I2C_EEPROM_R2_WRITE 0xa8 // 1010 1000 38 | #define I2C_EEPROM_R3_READ 0xa9 // 1010 1001 39 | #define I2C_EEPROM_R3_WRITE 0xa8 // 1010 1000 40 | 41 | #define I2C_EEPROM_R0_BASE 0x0000 // Base addr of I2C EEPROM Region 0 42 | #define I2C_EEPROM_R1_BASE 0x8000 // Base addr of I2C EEPROM Region 1 43 | #define I2C_EEPROM_R2_BASE 0x0000 // Base addr of I2C EEPROM Region 2 44 | #define I2C_EEPROM_R3_BASE 0x8000 // Base addr of I2C EEPROM Region 3 45 | 46 | 47 | #define I2C_COPY_EEPROM_R0_REQUEST 1 48 | #define I2C_COPY_EEPROM_R0_WAIT 2 49 | #define I2C_COPY_EEPROM_R1_REQUEST 3 50 | #define I2C_COPY_EEPROM_R1_WAIT 4 51 | #define I2C_COPY_EEPROM_IDLE 5 52 | 53 | uint8_t I2C_control(uint8_t control_byte); 54 | void I2C_byte_address(uint16_t byte_address, uint8_t addr_size); 55 | void I2C_write_byte(uint8_t I2C_write_data); 56 | uint8_t I2C_read_byte(uint8_t I2C_last_flag); 57 | void SCL_pulse(void); 58 | void SCL_high(void); 59 | void SCL_low(void); 60 | void SDA_high(void); 61 | void SDA_low(void); 62 | void I2C_transmit_byte(uint8_t I2C_transmit_data); 63 | uint8_t Read_Slave_NACKACK(void); 64 | void I2C_stop(void); 65 | void I2C_reset(void); 66 | void copy_I2C_EEPROM_to_Flash(uint8_t maxblocks); 67 | void copy_RAM_to_Flash(void); 68 | void copy_I2C_EEPROM_bytes_to_RAM(uint8_t *destination, 69 | uint8_t num_bytes, 70 | uint8_t control_write, 71 | uint8_t control_read, 72 | uint16_t start_address, 73 | uint8_t addr_size); 74 | //void copy_I2C_EEPROM_words_to_RAM(uint16_t *destination, 75 | // uint8_t num_words, 76 | // uint8_t control_write, 77 | // uint8_t control_read, 78 | // uint16_t start_address, 79 | // uint8_t addr_size); 80 | void copy_STM8_bytes_to_I2C_EEPROM(uint8_t *source, 81 | uint8_t num_bytes, 82 | uint8_t control_write, 83 | uint16_t start_address, 84 | uint8_t addr_size); 85 | // void copy_RAM_words_to_I2C(uint16_t *source, 86 | // uint8_t num_bytes, 87 | // uint8_t control_write, 88 | // uint16_t start_address, 89 | // uint8_t addr_size); 90 | #endif /* __I2C_H__ */ 91 | -------------------------------------------------------------------------------- /NetworkModule/NetworkModule.lkf: -------------------------------------------------------------------------------- 1 | ## link command file for STM8S005C6 2 | ## Copyright (c) 2008 by COSMIC Software 3 | ## 4 | +seg .vector -b 0x8000 -m 0x8000 -n .vector # vectors start address 5 | -k 6 | +seg .const -a .vector -n .const # constants follow vectors 7 | +seg .text -a .const -n .text # code follow constants 8 | +seg .eeprom -b 0x4000 -m 128 # internal eeprom 9 | +seg .bsct -b 0 -m 0x100 -n .bsct # internal ram 10 | +seg .ubsct -a .bsct -n .ubsct 11 | +seg .bit -a .ubsct -n .bit -id 12 | +seg .data -a .bit -m 0x800 -n .data 13 | +seg .memcpy_update -a .data -n memcpy_update -ic 14 | +seg .bss -a memcpy_update -n .bss 15 | +seg .flash_update -b 0xfc80 16 | +seg .iconst -b 0x5fe -n .iconst 17 | 18 | ## interrupt vectors 19 | "NetworkModule_vector.o" 20 | 21 | ## startup file 22 | "crts0.sm8" 23 | 24 | ## application files 25 | +inc "NetworkModule.obl" 26 | 27 | ## libraries 28 | "libisl0.sm8" # C library (if needed) 29 | "libm0.sm8" # machine library 30 | 31 | ## symbols 32 | +def __endzp=@.ubsct # end of zero page 33 | +def __memory=@.bss # symbol used by library 34 | +def __stack=0x7ff # stack pointer initial value 35 | -------------------------------------------------------------------------------- /NetworkModule/NetworkModule.prjsm8: -------------------------------------------------------------------------------- 1 | [Project] 2 | Type=APPLICATION 3 | ASM_PREPROCESS=NO 4 | DirectoryFilter= 5 | IDEAREV=4 6 | IncPath= 7 | IncPathFilter= 8 | ObjDir= 9 | LstDir= 10 | ObjPath= 11 | Name= 12 | Description= 13 | ExecName=NetworkModule.sm8 14 | DefsChanged=0 15 | TabWidth=8 16 | IndentGuides=YES 17 | LineNumbers=YES 18 | Folding=YES 19 | [Target] 20 | Derivative=STM8S005C6 21 | Directory=devices_sm8\STM8S\S005 22 | Generic=NO 23 | LinkFileAutomatic=NO 24 | VectorsAutomatic=YES 25 | UseFloat=NO 26 | Startup=Std 27 | [castm8] 28 | Cmd=castm8 29 | UserFlags= 30 | Extensions=.s 31 | [cxstm8] 32 | Cmd=cxstm8 -v -l +strict +debug +modsl0 +split +warn 33 | UserFlags= 34 | Extensions=.c 35 | [Librarian] 36 | Verbose=NO 37 | Create=YES 38 | NOPATH=NO 39 | [Linker] 40 | Cmd=-v -sa 41 | Verbose=NO 42 | SymbOnly=NO 43 | Physmap=NO 44 | BankSpec=NO 45 | OutputFile=NetworkModule.sm8 46 | InCmd=networkmodule.lkf 47 | MapFile=NetworkModule.map 48 | [Debug] 49 | Cmd= 50 | [Debug1] 51 | Cmd= 52 | [EXTTOOL] 53 | Cmd= 54 | PARSER= 55 | STDOUT=NO 56 | STDERR=NO 57 | ERRPARSE=NO 58 | [Cobj] 59 | Cmd=cobj 60 | OutputFile= 61 | [Cprd] 62 | Cmd=cprd 63 | SPECIFICS=NO 64 | [Chex] 65 | SPECIFICS=YES 66 | Format=3 67 | Noheader=NO 68 | Paginated=OFF 69 | Increasing=NO 70 | AbsAddr= 71 | Bias= 72 | Entry= 73 | MaxBytes= 74 | HeaderString= 75 | OutputFile=NetworkModule.sx 76 | [Builder.Cobj] 77 | Exec=NO 78 | Cmd=cobj 79 | OutputFile= 80 | [Builder.Cprd] 81 | Exec=NO 82 | Cmd=cprd 83 | SPECIFICS=NO 84 | [Builder.Chex] 85 | Exec=YES 86 | SPECIFICS=YES 87 | Format=3 88 | Noheader=NO 89 | Paginated=OFF 90 | Increasing=NO 91 | AbsAddr= 92 | Bias= 93 | Entry= 94 | MaxBytes= 95 | HeaderString= 96 | OutputFile=NetworkModule.sx 97 | [Builder.Clabs] 98 | Exec=YES 99 | SPECIFICS=NO 100 | [Builder.Cv695] 101 | Exec=NO 102 | SPECIFICS=NO 103 | [Builder.CvDwf] 104 | Exec=NO 105 | SPECIFICS=NO 106 | [Builder.PreUser1] 107 | Exec=NO 108 | Cmd= 109 | [Builder.User1] 110 | Exec=NO 111 | Cmd= 112 | [Builder.PreUser2] 113 | Exec=NO 114 | Cmd= 115 | [Builder.User2] 116 | Exec=NO 117 | Cmd= 118 | [Groups] 119 | 1=Vector_File 120 | [GROUP1:cxstm8] 121 | Cmd= 122 | Flags= 123 | [GROUP1:castm8] 124 | Cmd= 125 | Flags= 126 | [GROUP1FILES] 127 | 1=networkmodule_vector.c 128 | [GROUP1FILE1OPTS] 129 | FileName=networkmodule_vector.c 130 | IGNORE=NO 131 | TOOL=cxstm8 132 | DefsChanged=0 133 | [GROUP1DEFINES] 134 | DefsChanged=0 135 | [Files] 136 | 1=bme280.c 137 | 2=ds18b20.c 138 | 3=enc28j60.c 139 | 4=gpio.c 140 | 5=httpd.c 141 | 6=i2c.c 142 | 7=ina226.c 143 | 8=main.c 144 | 9=mqtt.c 145 | 10=mqtt_pal.c 146 | 11=pcf8574.c 147 | 12=spi.c 148 | 13=timer.c 149 | 14=uart.c 150 | 15=uip.c 151 | 16=uip_arp.c 152 | 17=uip_tcpapphub.c 153 | [FILE1OPTS] 154 | FileName=bme280.c 155 | TOOL=cxstm8 156 | IGNORE=NO 157 | DefsChanged=0 158 | [FILE2OPTS] 159 | FileName=ds18b20.c 160 | TOOL=cxstm8 161 | IGNORE=NO 162 | DefsChanged=0 163 | [FILE3OPTS] 164 | FileName=enc28j60.c 165 | TOOL=cxstm8 166 | IGNORE=NO 167 | DefsChanged=0 168 | [FILE4OPTS] 169 | FileName=gpio.c 170 | TOOL=cxstm8 171 | IGNORE=NO 172 | DefsChanged=0 173 | [FILE5OPTS] 174 | FileName=httpd.c 175 | TOOL=cxstm8 176 | IGNORE=NO 177 | DefsChanged=0 178 | [FILE6OPTS] 179 | FileName=i2c.c 180 | TOOL=cxstm8 181 | IGNORE=NO 182 | DefsChanged=0 183 | [FILE7OPTS] 184 | FileName=ina226.c 185 | TOOL=cxstm8 186 | IGNORE=NO 187 | DefsChanged=0 188 | [FILE8OPTS] 189 | FileName=main.c 190 | TOOL=cxstm8 191 | IGNORE=NO 192 | DefsChanged=0 193 | [FILE9OPTS] 194 | FileName=mqtt.c 195 | TOOL=cxstm8 196 | IGNORE=NO 197 | DefsChanged=0 198 | [FILE10OPTS] 199 | FileName=mqtt_pal.c 200 | TOOL=cxstm8 201 | IGNORE=NO 202 | DefsChanged=0 203 | [FILE11OPTS] 204 | FileName=pcf8574.c 205 | TOOL=cxstm8 206 | IGNORE=NO 207 | DefsChanged=0 208 | [FILE12OPTS] 209 | FileName=spi.c 210 | TOOL=cxstm8 211 | IGNORE=NO 212 | DefsChanged=0 213 | [FILE13OPTS] 214 | FileName=timer.c 215 | TOOL=cxstm8 216 | IGNORE=NO 217 | DefsChanged=0 218 | [FILE14OPTS] 219 | FileName=uart.c 220 | TOOL=cxstm8 221 | IGNORE=NO 222 | DefsChanged=0 223 | [FILE15OPTS] 224 | FileName=uip.c 225 | TOOL=cxstm8 226 | IGNORE=NO 227 | DefsChanged=0 228 | [FILE16OPTS] 229 | FileName=uip_arp.c 230 | TOOL=cxstm8 231 | IGNORE=NO 232 | DefsChanged=0 233 | [FILE17OPTS] 234 | FileName=uip_tcpapphub.c 235 | TOOL=cxstm8 236 | IGNORE=NO 237 | DefsChanged=0 238 | -------------------------------------------------------------------------------- /NetworkModule/STM8S_StdPeriph_Driver/Release_Notes.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nielsonm236/NetMod-ServerApp/1700e7a9aa5b377ca4deb89e6a47fe72e026d3f7/NetworkModule/STM8S_StdPeriph_Driver/Release_Notes.html -------------------------------------------------------------------------------- /NetworkModule/STM8S_StdPeriph_Driver/inc/stm8s_adc2.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8s_adc2.h 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all the prototypes/macros for the ADC2 peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM8S_ADC2_H 31 | #define __STM8S_ADC2_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | #include "stm8s.h" 35 | 36 | /* Exported types ------------------------------------------------------------*/ 37 | 38 | /** @addtogroup ADC2_Exported_Types 39 | * @{ 40 | */ 41 | 42 | /** 43 | * @brief ADC2 clock prescaler selection 44 | */ 45 | 46 | typedef enum { 47 | ADC2_PRESSEL_FCPU_D2 = (uint8_t)0x00, /**< Prescaler selection fADC2 = fcpu/2 */ 48 | ADC2_PRESSEL_FCPU_D3 = (uint8_t)0x10, /**< Prescaler selection fADC2 = fcpu/3 */ 49 | ADC2_PRESSEL_FCPU_D4 = (uint8_t)0x20, /**< Prescaler selection fADC2 = fcpu/4 */ 50 | ADC2_PRESSEL_FCPU_D6 = (uint8_t)0x30, /**< Prescaler selection fADC2 = fcpu/6 */ 51 | ADC2_PRESSEL_FCPU_D8 = (uint8_t)0x40, /**< Prescaler selection fADC2 = fcpu/8 */ 52 | ADC2_PRESSEL_FCPU_D10 = (uint8_t)0x50, /**< Prescaler selection fADC2 = fcpu/10 */ 53 | ADC2_PRESSEL_FCPU_D12 = (uint8_t)0x60, /**< Prescaler selection fADC2 = fcpu/12 */ 54 | ADC2_PRESSEL_FCPU_D18 = (uint8_t)0x70 /**< Prescaler selection fADC2 = fcpu/18 */ 55 | } ADC2_PresSel_TypeDef; 56 | 57 | /** 58 | * @brief ADC2 External conversion trigger event selection 59 | */ 60 | typedef enum { 61 | ADC2_EXTTRIG_TIM = (uint8_t)0x00, /**< Conversion from Internal TIM TRGO event */ 62 | ADC2_EXTTRIG_GPIO = (uint8_t)0x01 /**< Conversion from External interrupt on ADC_ETR pin*/ 63 | } ADC2_ExtTrig_TypeDef; 64 | 65 | /** 66 | * @brief ADC2 data alignment 67 | */ 68 | typedef enum { 69 | ADC2_ALIGN_LEFT = (uint8_t)0x00, /**< Data alignment left */ 70 | ADC2_ALIGN_RIGHT = (uint8_t)0x08 /**< Data alignment right */ 71 | } ADC2_Align_TypeDef; 72 | 73 | /** 74 | * @brief ADC2 schmitt Trigger 75 | */ 76 | typedef enum { 77 | ADC2_SCHMITTTRIG_CHANNEL0 = (uint8_t)0x00, /**< Schmitt trigger disable on AIN0 */ 78 | ADC2_SCHMITTTRIG_CHANNEL1 = (uint8_t)0x01, /**< Schmitt trigger disable on AIN1 */ 79 | ADC2_SCHMITTTRIG_CHANNEL2 = (uint8_t)0x02, /**< Schmitt trigger disable on AIN2 */ 80 | ADC2_SCHMITTTRIG_CHANNEL3 = (uint8_t)0x03, /**< Schmitt trigger disable on AIN3 */ 81 | ADC2_SCHMITTTRIG_CHANNEL4 = (uint8_t)0x04, /**< Schmitt trigger disable on AIN4 */ 82 | ADC2_SCHMITTTRIG_CHANNEL5 = (uint8_t)0x05, /**< Schmitt trigger disable on AIN5 */ 83 | ADC2_SCHMITTTRIG_CHANNEL6 = (uint8_t)0x06, /**< Schmitt trigger disable on AIN6 */ 84 | ADC2_SCHMITTTRIG_CHANNEL7 = (uint8_t)0x07, /**< Schmitt trigger disable on AIN7 */ 85 | ADC2_SCHMITTTRIG_CHANNEL8 = (uint8_t)0x08, /**< Schmitt trigger disable on AIN8 */ 86 | ADC2_SCHMITTTRIG_CHANNEL9 = (uint8_t)0x09, /**< Schmitt trigger disable on AIN9 */ 87 | ADC2_SCHMITTTRIG_CHANNEL10 = (uint8_t)0x0A, /**< Schmitt trigger disable on AIN10 */ 88 | ADC2_SCHMITTTRIG_CHANNEL11 = (uint8_t)0x0B, /**< Schmitt trigger disable on AIN11 */ 89 | ADC2_SCHMITTTRIG_CHANNEL12 = (uint8_t)0x0C, /**< Schmitt trigger disable on AIN12 */ 90 | ADC2_SCHMITTTRIG_CHANNEL13 = (uint8_t)0x0D, /**< Schmitt trigger disable on AIN13 */ 91 | ADC2_SCHMITTTRIG_CHANNEL14 = (uint8_t)0x0E, /**< Schmitt trigger disable on AIN14 */ 92 | ADC2_SCHMITTTRIG_CHANNEL15 = (uint8_t)0x0F, /**< Schmitt trigger disable on AIN15 */ 93 | ADC2_SCHMITTTRIG_ALL = (uint8_t)0x1F /**< Schmitt trigger disable on all channels */ 94 | 95 | } ADC2_SchmittTrigg_TypeDef; 96 | 97 | /** 98 | * @brief ADC2 conversion mode selection 99 | */ 100 | 101 | typedef enum { 102 | ADC2_CONVERSIONMODE_SINGLE = (uint8_t)0x00, /**< Single conversion mode */ 103 | ADC2_CONVERSIONMODE_CONTINUOUS = (uint8_t)0x01 /**< Continuous conversion mode */ 104 | } ADC2_ConvMode_TypeDef; 105 | 106 | /** 107 | * @brief ADC2 analog channel selection 108 | */ 109 | 110 | typedef enum { 111 | ADC2_CHANNEL_0 = (uint8_t)0x00, /**< Analog channel 0 */ 112 | ADC2_CHANNEL_1 = (uint8_t)0x01, /**< Analog channel 1 */ 113 | ADC2_CHANNEL_2 = (uint8_t)0x02, /**< Analog channel 2 */ 114 | ADC2_CHANNEL_3 = (uint8_t)0x03, /**< Analog channel 3 */ 115 | ADC2_CHANNEL_4 = (uint8_t)0x04, /**< Analog channel 4 */ 116 | ADC2_CHANNEL_5 = (uint8_t)0x05, /**< Analog channel 5 */ 117 | ADC2_CHANNEL_6 = (uint8_t)0x06, /**< Analog channel 6 */ 118 | ADC2_CHANNEL_7 = (uint8_t)0x07, /**< Analog channel 7 */ 119 | ADC2_CHANNEL_8 = (uint8_t)0x08, /**< Analog channel 8 */ 120 | ADC2_CHANNEL_9 = (uint8_t)0x09, /**< Analog channel 9 */ 121 | ADC2_CHANNEL_10 = (uint8_t)0x0A, /**< Analog channel 10 */ 122 | ADC2_CHANNEL_11 = (uint8_t)0x0B, /**< Analog channel 11 */ 123 | ADC2_CHANNEL_12 = (uint8_t)0x0C, /**< Analog channel 12 */ 124 | ADC2_CHANNEL_13 = (uint8_t)0x0D, /**< Analog channel 13 */ 125 | ADC2_CHANNEL_14 = (uint8_t)0x0E, /**< Analog channel 14 */ 126 | ADC2_CHANNEL_15 = (uint8_t)0x0F /**< Analog channel 15 */ 127 | } ADC2_Channel_TypeDef; 128 | 129 | /** 130 | * @} 131 | */ 132 | 133 | /* Exported constants --------------------------------------------------------*/ 134 | 135 | /* Exported macros ------------------------------------------------------------*/ 136 | 137 | /* Private macros ------------------------------------------------------------*/ 138 | 139 | /** @addtogroup ADC2_Private_Macros 140 | * @brief Macros used by the assert function to check the different functions parameters. 141 | * @{ 142 | */ 143 | 144 | /** 145 | * @brief Macro used by the assert function to check the different prescaler's values. 146 | */ 147 | #define IS_ADC2_PRESSEL_OK(PRESCALER) (((PRESCALER) == ADC2_PRESSEL_FCPU_D2) || \ 148 | ((PRESCALER) == ADC2_PRESSEL_FCPU_D3) || \ 149 | ((PRESCALER) == ADC2_PRESSEL_FCPU_D4) || \ 150 | ((PRESCALER) == ADC2_PRESSEL_FCPU_D6) || \ 151 | ((PRESCALER) == ADC2_PRESSEL_FCPU_D8) || \ 152 | ((PRESCALER) == ADC2_PRESSEL_FCPU_D10) || \ 153 | ((PRESCALER) == ADC2_PRESSEL_FCPU_D12) || \ 154 | ((PRESCALER) == ADC2_PRESSEL_FCPU_D18)) 155 | 156 | /** 157 | * @brief Macro used by the assert function to check the different external trigger values. 158 | */ 159 | #define IS_ADC2_EXTTRIG_OK(EXTRIG) (((EXTRIG) == ADC2_EXTTRIG_TIM) || \ 160 | ((EXTRIG) == ADC2_EXTTRIG_GPIO)) 161 | 162 | /** 163 | * @brief Macro used by the assert function to check the different alignment modes. 164 | */ 165 | #define IS_ADC2_ALIGN_OK(ALIGN) (((ALIGN) == ADC2_ALIGN_LEFT) || \ 166 | ((ALIGN) == ADC2_ALIGN_RIGHT)) 167 | 168 | 169 | /** 170 | * @brief Macro used by the assert function to check the different schmitt trigger values. 171 | */ 172 | #define IS_ADC2_SCHMITTTRIG_OK(SCHMITTTRIG) (((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL0) || \ 173 | ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL1) || \ 174 | ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL2) || \ 175 | ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL3) || \ 176 | ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL4) || \ 177 | ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL5) || \ 178 | ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL6) || \ 179 | ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL7) || \ 180 | ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL8) || \ 181 | ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL9) || \ 182 | ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL10) || \ 183 | ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL11) || \ 184 | ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL12) || \ 185 | ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL13) || \ 186 | ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL14) || \ 187 | ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL15) || \ 188 | ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_ALL)) 189 | 190 | /** 191 | * @brief Macro used by the assert function to check the different conversion modes. 192 | */ 193 | #define IS_ADC2_CONVERSIONMODE_OK(MODE) (((MODE) == ADC2_CONVERSIONMODE_SINGLE) || \ 194 | ((MODE) == ADC2_CONVERSIONMODE_CONTINUOUS)) 195 | 196 | /** 197 | * @brief Macro used by the assert function to check the different channels values. 198 | */ 199 | #define IS_ADC2_CHANNEL_OK(CHANNEL) (((CHANNEL) == ADC2_CHANNEL_0) || \ 200 | ((CHANNEL) == ADC2_CHANNEL_1) || \ 201 | ((CHANNEL) == ADC2_CHANNEL_2) || \ 202 | ((CHANNEL) == ADC2_CHANNEL_3) || \ 203 | ((CHANNEL) == ADC2_CHANNEL_4) || \ 204 | ((CHANNEL) == ADC2_CHANNEL_5) || \ 205 | ((CHANNEL) == ADC2_CHANNEL_6) || \ 206 | ((CHANNEL) == ADC2_CHANNEL_7) || \ 207 | ((CHANNEL) == ADC2_CHANNEL_8) || \ 208 | ((CHANNEL) == ADC2_CHANNEL_9) || \ 209 | ((CHANNEL) == ADC2_CHANNEL_10) || \ 210 | ((CHANNEL) == ADC2_CHANNEL_11) || \ 211 | ((CHANNEL) == ADC2_CHANNEL_12) || \ 212 | ((CHANNEL) == ADC2_CHANNEL_13) || \ 213 | ((CHANNEL) == ADC2_CHANNEL_14) || \ 214 | ((CHANNEL) == ADC2_CHANNEL_15)) 215 | 216 | /** 217 | * @} 218 | */ 219 | 220 | /* Exported functions ------------------------------------------------------- */ 221 | 222 | /** @addtogroup ADC2_Exported_Functions 223 | * @{ 224 | */ 225 | void ADC2_DeInit(void); 226 | void ADC2_Init(ADC2_ConvMode_TypeDef ADC2_ConversionMode, 227 | ADC2_Channel_TypeDef ADC2_Channel, 228 | ADC2_PresSel_TypeDef ADC2_PrescalerSelection, 229 | ADC2_ExtTrig_TypeDef ADC2_ExtTrigger, 230 | FunctionalState ADC2_ExtTriggerState, 231 | ADC2_Align_TypeDef ADC2_Align, 232 | ADC2_SchmittTrigg_TypeDef ADC2_SchmittTriggerChannel, 233 | FunctionalState ADC2_SchmittTriggerState); 234 | void ADC2_Cmd(FunctionalState NewState); 235 | void ADC2_ITConfig(FunctionalState NewState); 236 | void ADC2_PrescalerConfig(ADC2_PresSel_TypeDef ADC2_Prescaler); 237 | void ADC2_SchmittTriggerConfig(ADC2_SchmittTrigg_TypeDef ADC2_SchmittTriggerChannel, 238 | FunctionalState NewState); 239 | void ADC2_ConversionConfig(ADC2_ConvMode_TypeDef ADC2_ConversionMode, 240 | ADC2_Channel_TypeDef ADC2_Channel, 241 | ADC2_Align_TypeDef ADC2_Align); 242 | void ADC2_ExternalTriggerConfig(ADC2_ExtTrig_TypeDef ADC2_ExtTrigger, FunctionalState NewState); 243 | void ADC2_StartConversion(void); 244 | uint16_t ADC2_GetConversionValue(void); 245 | FlagStatus ADC2_GetFlagStatus(void); 246 | void ADC2_ClearFlag(void); 247 | ITStatus ADC2_GetITStatus(void); 248 | void ADC2_ClearITPendingBit(void); 249 | /** 250 | * @} 251 | */ 252 | 253 | #endif /* __STM8S_ADC2_H */ 254 | 255 | 256 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 257 | -------------------------------------------------------------------------------- /NetworkModule/STM8S_StdPeriph_Driver/inc/stm8s_awu.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8s_awu.h 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all functions prototype and macros for the AWU peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM8S_AWU_H 30 | #define __STM8S_AWU_H 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | #include "stm8s.h" 34 | 35 | /* Exported types ------------------------------------------------------------*/ 36 | 37 | /** @addtogroup AWU_Exported_Types 38 | * @{ 39 | */ 40 | 41 | /** 42 | * @brief AWU TimeBase selection 43 | */ 44 | 45 | typedef enum 46 | { 47 | AWU_TIMEBASE_NO_IT = (uint8_t)0, /*!< No AWU interrupt selected */ 48 | AWU_TIMEBASE_250US = (uint8_t)1, /*!< AWU Timebase equals 0.25 ms */ 49 | AWU_TIMEBASE_500US = (uint8_t)2, /*!< AWU Timebase equals 0.5 ms */ 50 | AWU_TIMEBASE_1MS = (uint8_t)3, /*!< AWU Timebase equals 1 ms */ 51 | AWU_TIMEBASE_2MS = (uint8_t)4, /*!< AWU Timebase equals 2 ms */ 52 | AWU_TIMEBASE_4MS = (uint8_t)5, /*!< AWU Timebase equals 4 ms */ 53 | AWU_TIMEBASE_8MS = (uint8_t)6, /*!< AWU Timebase equals 8 ms */ 54 | AWU_TIMEBASE_16MS = (uint8_t)7, /*!< AWU Timebase equals 16 ms */ 55 | AWU_TIMEBASE_32MS = (uint8_t)8, /*!< AWU Timebase equals 32 ms */ 56 | AWU_TIMEBASE_64MS = (uint8_t)9, /*!< AWU Timebase equals 64 ms */ 57 | AWU_TIMEBASE_128MS = (uint8_t)10, /*!< AWU Timebase equals 128 ms */ 58 | AWU_TIMEBASE_256MS = (uint8_t)11, /*!< AWU Timebase equals 256 ms */ 59 | AWU_TIMEBASE_512MS = (uint8_t)12, /*!< AWU Timebase equals 512 ms */ 60 | AWU_TIMEBASE_1S = (uint8_t)13, /*!< AWU Timebase equals 1 s */ 61 | AWU_TIMEBASE_2S = (uint8_t)14, /*!< AWU Timebase equals 2 s */ 62 | AWU_TIMEBASE_12S = (uint8_t)15, /*!< AWU Timebase equals 12 s */ 63 | AWU_TIMEBASE_30S = (uint8_t)16 /*!< AWU Timebase equals 30 s */ 64 | } AWU_Timebase_TypeDef; 65 | 66 | /** 67 | * @} 68 | */ 69 | 70 | /* Exported constants --------------------------------------------------------*/ 71 | 72 | /** @addtogroup AWU_Exported_Constants 73 | * @{ 74 | */ 75 | 76 | #define LSI_FREQUENCY_MIN ((uint32_t)110000) /*!< LSI minimum value in Hertz */ 77 | #define LSI_FREQUENCY_MAX ((uint32_t)150000) /*!< LSI maximum value in Hertz */ 78 | 79 | /** 80 | * @} 81 | */ 82 | 83 | /* Exported macros ------------------------------------------------------------*/ 84 | 85 | /* Private macros ------------------------------------------------------------*/ 86 | 87 | /** @addtogroup AWU_Private_Macros 88 | * @{ 89 | */ 90 | 91 | /** 92 | * @brief Macro used by the assert function to check the different functions parameters. 93 | */ 94 | 95 | /** 96 | * @brief Macro used by the assert function to check the AWU timebases 97 | */ 98 | #define IS_AWU_TIMEBASE_OK(TB) \ 99 | (((TB) == AWU_TIMEBASE_NO_IT) || \ 100 | ((TB) == AWU_TIMEBASE_250US) || \ 101 | ((TB) == AWU_TIMEBASE_500US) || \ 102 | ((TB) == AWU_TIMEBASE_1MS) || \ 103 | ((TB) == AWU_TIMEBASE_2MS) || \ 104 | ((TB) == AWU_TIMEBASE_4MS) || \ 105 | ((TB) == AWU_TIMEBASE_8MS) || \ 106 | ((TB) == AWU_TIMEBASE_16MS) || \ 107 | ((TB) == AWU_TIMEBASE_32MS) || \ 108 | ((TB) == AWU_TIMEBASE_64MS) || \ 109 | ((TB) == AWU_TIMEBASE_128MS) || \ 110 | ((TB) == AWU_TIMEBASE_256MS) || \ 111 | ((TB) == AWU_TIMEBASE_512MS) || \ 112 | ((TB) == AWU_TIMEBASE_1S) || \ 113 | ((TB) == AWU_TIMEBASE_2S) || \ 114 | ((TB) == AWU_TIMEBASE_12S) || \ 115 | ((TB) == AWU_TIMEBASE_30S)) 116 | 117 | /** 118 | * @brief Macro used by the assert function to check the LSI frequency (in Hz) 119 | */ 120 | #define IS_LSI_FREQUENCY_OK(FREQ) \ 121 | (((FREQ) >= LSI_FREQUENCY_MIN) && \ 122 | ((FREQ) <= LSI_FREQUENCY_MAX)) 123 | 124 | /** 125 | * @} 126 | */ 127 | 128 | /* Exported functions ------------------------------------------------------- */ 129 | 130 | /** @addtogroup AWU_Exported_Functions 131 | * @{ 132 | */ 133 | void AWU_DeInit(void); 134 | void AWU_Init(AWU_Timebase_TypeDef AWU_TimeBase); 135 | void AWU_Cmd(FunctionalState NewState); 136 | void AWU_LSICalibrationConfig(uint32_t LSIFreqHz); 137 | void AWU_IdleModeEnable(void); 138 | FlagStatus AWU_GetFlagStatus(void); 139 | 140 | /** 141 | * @} 142 | */ 143 | 144 | #endif /* __STM8S_AWU_H */ 145 | 146 | 147 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 148 | -------------------------------------------------------------------------------- /NetworkModule/STM8S_StdPeriph_Driver/inc/stm8s_beep.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8s_beep.h 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all functions prototype and macros for the BEEP peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM8S_BEEP_H 31 | #define __STM8S_BEEP_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | #include "stm8s.h" 35 | 36 | /* Exported types ------------------------------------------------------------*/ 37 | 38 | /** @addtogroup BEEP_Exported_Types 39 | * @{ 40 | */ 41 | 42 | /** 43 | * @brief BEEP Frequency selection 44 | */ 45 | typedef enum { 46 | BEEP_FREQUENCY_1KHZ = (uint8_t)0x00, /*!< Beep signal output frequency equals to 1 KHz */ 47 | BEEP_FREQUENCY_2KHZ = (uint8_t)0x40, /*!< Beep signal output frequency equals to 2 KHz */ 48 | BEEP_FREQUENCY_4KHZ = (uint8_t)0x80 /*!< Beep signal output frequency equals to 4 KHz */ 49 | } BEEP_Frequency_TypeDef; 50 | 51 | /** 52 | * @} 53 | */ 54 | 55 | /* Exported constants --------------------------------------------------------*/ 56 | 57 | /** @addtogroup BEEP_Exported_Constants 58 | * @{ 59 | */ 60 | 61 | #define BEEP_CALIBRATION_DEFAULT ((uint8_t)0x0B) /*!< Default value when calibration is not done */ 62 | 63 | #define LSI_FREQUENCY_MIN ((uint32_t)110000) /*!< LSI minimum value in Hertz */ 64 | #define LSI_FREQUENCY_MAX ((uint32_t)150000) /*!< LSI maximum value in Hertz */ 65 | 66 | /** 67 | * @} 68 | */ 69 | 70 | /* Exported macros -----------------------------------------------------------*/ 71 | /* Private macros ------------------------------------------------------------*/ 72 | 73 | /** @addtogroup BEEP_Private_Macros 74 | * @{ 75 | */ 76 | 77 | /** 78 | * @brief Macro used by the assert function to check the different functions parameters. 79 | */ 80 | 81 | /** 82 | * @brief Macro used by the assert function to check the BEEP frequencies. 83 | */ 84 | #define IS_BEEP_FREQUENCY_OK(FREQ) \ 85 | (((FREQ) == BEEP_FREQUENCY_1KHZ) || \ 86 | ((FREQ) == BEEP_FREQUENCY_2KHZ) || \ 87 | ((FREQ) == BEEP_FREQUENCY_4KHZ)) 88 | 89 | /** 90 | * @brief Macro used by the assert function to check the LSI frequency (in Hz). 91 | */ 92 | #define IS_LSI_FREQUENCY_OK(FREQ) \ 93 | (((FREQ) >= LSI_FREQUENCY_MIN) && \ 94 | ((FREQ) <= LSI_FREQUENCY_MAX)) 95 | 96 | /** 97 | * @} 98 | */ 99 | 100 | /* Exported functions ------------------------------------------------------- */ 101 | 102 | /** @addtogroup BEEP_Exported_Functions 103 | * @{ 104 | */ 105 | 106 | void BEEP_DeInit(void); 107 | void BEEP_Init(BEEP_Frequency_TypeDef BEEP_Frequency); 108 | void BEEP_Cmd(FunctionalState NewState); 109 | void BEEP_LSICalibrationConfig(uint32_t LSIFreqHz); 110 | 111 | 112 | /** 113 | * @} 114 | */ 115 | 116 | #endif /* __STM8S_BEEP_H */ 117 | 118 | 119 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 120 | -------------------------------------------------------------------------------- /NetworkModule/STM8S_StdPeriph_Driver/inc/stm8s_exti.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8s_exti.h 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all functions prototype and macros for the EXTI peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM8S_EXTI_H 30 | #define __STM8S_EXTI_H 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | #include "stm8s.h" 34 | 35 | /* Exported types ------------------------------------------------------------*/ 36 | 37 | /** @addtogroup EXTI_Exported_Types 38 | * @{ 39 | */ 40 | 41 | /** 42 | * @brief EXTI Sensitivity values for PORTA to PORTE 43 | */ 44 | typedef enum { 45 | EXTI_SENSITIVITY_FALL_LOW = (uint8_t)0x00, /*!< Interrupt on Falling edge and Low level */ 46 | EXTI_SENSITIVITY_RISE_ONLY = (uint8_t)0x01, /*!< Interrupt on Rising edge only */ 47 | EXTI_SENSITIVITY_FALL_ONLY = (uint8_t)0x02, /*!< Interrupt on Falling edge only */ 48 | EXTI_SENSITIVITY_RISE_FALL = (uint8_t)0x03 /*!< Interrupt on Rising and Falling edges */ 49 | } EXTI_Sensitivity_TypeDef; 50 | 51 | /** 52 | * @brief EXTI Sensitivity values for TLI 53 | */ 54 | typedef enum { 55 | EXTI_TLISENSITIVITY_FALL_ONLY = (uint8_t)0x00, /*!< Top Level Interrupt on Falling edge only */ 56 | EXTI_TLISENSITIVITY_RISE_ONLY = (uint8_t)0x04 /*!< Top Level Interrupt on Rising edge only */ 57 | } EXTI_TLISensitivity_TypeDef; 58 | 59 | /** 60 | * @brief EXTI PortNum possible values 61 | */ 62 | typedef enum { 63 | EXTI_PORT_GPIOA = (uint8_t)0x00, /*!< GPIO Port A */ 64 | EXTI_PORT_GPIOB = (uint8_t)0x01, /*!< GPIO Port B */ 65 | EXTI_PORT_GPIOC = (uint8_t)0x02, /*!< GPIO Port C */ 66 | EXTI_PORT_GPIOD = (uint8_t)0x03, /*!< GPIO Port D */ 67 | EXTI_PORT_GPIOE = (uint8_t)0x04 /*!< GPIO Port E */ 68 | } EXTI_Port_TypeDef; 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /* Private macros ------------------------------------------------------------*/ 75 | 76 | /** @addtogroup EXTI_Private_Macros 77 | * @{ 78 | */ 79 | 80 | /** 81 | * @brief Macro used by the assert function in order to check the different sensitivity values for PORTA to PORTE. 82 | */ 83 | #define IS_EXTI_SENSITIVITY_OK(SensitivityValue) \ 84 | (((SensitivityValue) == EXTI_SENSITIVITY_FALL_LOW) || \ 85 | ((SensitivityValue) == EXTI_SENSITIVITY_RISE_ONLY) || \ 86 | ((SensitivityValue) == EXTI_SENSITIVITY_FALL_ONLY) || \ 87 | ((SensitivityValue) == EXTI_SENSITIVITY_RISE_FALL)) 88 | 89 | /** 90 | * @brief Macro used by the assert function in order to check the different sensitivity values for TLI. 91 | */ 92 | #define IS_EXTI_TLISENSITIVITY_OK(SensitivityValue) \ 93 | (((SensitivityValue) == EXTI_TLISENSITIVITY_FALL_ONLY) || \ 94 | ((SensitivityValue) == EXTI_TLISENSITIVITY_RISE_ONLY)) 95 | 96 | /** 97 | * @brief Macro used by the assert function in order to check the different Port values 98 | */ 99 | #define IS_EXTI_PORT_OK(PORT) \ 100 | (((PORT) == EXTI_PORT_GPIOA) ||\ 101 | ((PORT) == EXTI_PORT_GPIOB) ||\ 102 | ((PORT) == EXTI_PORT_GPIOC) ||\ 103 | ((PORT) == EXTI_PORT_GPIOD) ||\ 104 | ((PORT) == EXTI_PORT_GPIOE)) 105 | 106 | /** 107 | * @brief Macro used by the assert function in order to check the different values of the EXTI PinMask 108 | */ 109 | #define IS_EXTI_PINMASK_OK(PinMask) ((((PinMask) & (uint8_t)0x00) == (uint8_t)0x00) && ((PinMask) != (uint8_t)0x00)) 110 | 111 | /** 112 | * @} 113 | */ 114 | 115 | /* Exported functions ------------------------------------------------------- */ 116 | 117 | /** @addtogroup EXTI_Exported_Functions 118 | * @{ 119 | */ 120 | 121 | void EXTI_DeInit(void); 122 | void EXTI_SetExtIntSensitivity(EXTI_Port_TypeDef Port, EXTI_Sensitivity_TypeDef SensitivityValue); 123 | void EXTI_SetTLISensitivity(EXTI_TLISensitivity_TypeDef SensitivityValue); 124 | EXTI_Sensitivity_TypeDef EXTI_GetExtIntSensitivity(EXTI_Port_TypeDef Port); 125 | EXTI_TLISensitivity_TypeDef EXTI_GetTLISensitivity(void); 126 | 127 | /** 128 | * @} 129 | */ 130 | 131 | #endif /* __STM8S_EXTI_H */ 132 | 133 | 134 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 135 | -------------------------------------------------------------------------------- /NetworkModule/STM8S_StdPeriph_Driver/inc/stm8s_gpio.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8s_gpio.h 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all functions prototype and macros for the GPIO peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM8S_GPIO_H 30 | #define __STM8S_GPIO_H 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | #include "stm8s.h" 34 | 35 | /* Exported variables ------------------------------------------------------- */ 36 | /* Exported types ------------------------------------------------------------*/ 37 | 38 | /** @addtogroup GPIO_Exported_Types 39 | * @{ 40 | */ 41 | 42 | /** 43 | * @brief GPIO modes 44 | * 45 | * Bits definitions: 46 | * - Bit 7: 0 = INPUT mode 47 | * 1 = OUTPUT mode 48 | * 1 = PULL-UP (input) or PUSH-PULL (output) 49 | * - Bit 5: 0 = No external interrupt (input) or No slope control (output) 50 | * 1 = External interrupt (input) or Slow control enabled (output) 51 | * - Bit 4: 0 = Low level (output) 52 | * 1 = High level (output push-pull) or HI-Z (output open-drain) 53 | */ 54 | typedef enum 55 | { 56 | GPIO_MODE_IN_FL_NO_IT = (uint8_t)0x00, /*!< Input floating, no external interrupt */ 57 | GPIO_MODE_IN_PU_NO_IT = (uint8_t)0x40, /*!< Input pull-up, no external interrupt */ 58 | GPIO_MODE_IN_FL_IT = (uint8_t)0x20, /*!< Input floating, external interrupt */ 59 | GPIO_MODE_IN_PU_IT = (uint8_t)0x60, /*!< Input pull-up, external interrupt */ 60 | GPIO_MODE_OUT_OD_LOW_FAST = (uint8_t)0xA0, /*!< Output open-drain, low level, 10MHz */ 61 | GPIO_MODE_OUT_PP_LOW_FAST = (uint8_t)0xE0, /*!< Output push-pull, low level, 10MHz */ 62 | GPIO_MODE_OUT_OD_LOW_SLOW = (uint8_t)0x80, /*!< Output open-drain, low level, 2MHz */ 63 | GPIO_MODE_OUT_PP_LOW_SLOW = (uint8_t)0xC0, /*!< Output push-pull, low level, 2MHz */ 64 | GPIO_MODE_OUT_OD_HIZ_FAST = (uint8_t)0xB0, /*!< Output open-drain, high-impedance level,10MHz */ 65 | GPIO_MODE_OUT_PP_HIGH_FAST = (uint8_t)0xF0, /*!< Output push-pull, high level, 10MHz */ 66 | GPIO_MODE_OUT_OD_HIZ_SLOW = (uint8_t)0x90, /*!< Output open-drain, high-impedance level, 2MHz */ 67 | GPIO_MODE_OUT_PP_HIGH_SLOW = (uint8_t)0xD0 /*!< Output push-pull, high level, 2MHz */ 68 | }GPIO_Mode_TypeDef; 69 | 70 | /** 71 | * @brief Definition of the GPIO pins. Used by the @ref GPIO_Init function in 72 | * order to select the pins to be initialized. 73 | */ 74 | 75 | typedef enum 76 | { 77 | GPIO_PIN_0 = ((uint8_t)0x01), /*!< Pin 0 selected */ 78 | GPIO_PIN_1 = ((uint8_t)0x02), /*!< Pin 1 selected */ 79 | GPIO_PIN_2 = ((uint8_t)0x04), /*!< Pin 2 selected */ 80 | GPIO_PIN_3 = ((uint8_t)0x08), /*!< Pin 3 selected */ 81 | GPIO_PIN_4 = ((uint8_t)0x10), /*!< Pin 4 selected */ 82 | GPIO_PIN_5 = ((uint8_t)0x20), /*!< Pin 5 selected */ 83 | GPIO_PIN_6 = ((uint8_t)0x40), /*!< Pin 6 selected */ 84 | GPIO_PIN_7 = ((uint8_t)0x80), /*!< Pin 7 selected */ 85 | GPIO_PIN_LNIB = ((uint8_t)0x0F), /*!< Low nibble pins selected */ 86 | GPIO_PIN_HNIB = ((uint8_t)0xF0), /*!< High nibble pins selected */ 87 | GPIO_PIN_ALL = ((uint8_t)0xFF) /*!< All pins selected */ 88 | }GPIO_Pin_TypeDef; 89 | 90 | /** 91 | * @} 92 | */ 93 | 94 | /* Exported constants --------------------------------------------------------*/ 95 | /* Exported macros -----------------------------------------------------------*/ 96 | /* Private macros ------------------------------------------------------------*/ 97 | 98 | /** @addtogroup GPIO_Private_Macros 99 | * @{ 100 | */ 101 | 102 | /** 103 | * @brief Macro used by the assert function to check the different functions parameters. 104 | */ 105 | 106 | /** 107 | * @brief Macro used by the assert function in order to check the different 108 | * values of GPIOMode_TypeDef. 109 | */ 110 | #define IS_GPIO_MODE_OK(MODE) \ 111 | (((MODE) == GPIO_MODE_IN_FL_NO_IT) || \ 112 | ((MODE) == GPIO_MODE_IN_PU_NO_IT) || \ 113 | ((MODE) == GPIO_MODE_IN_FL_IT) || \ 114 | ((MODE) == GPIO_MODE_IN_PU_IT) || \ 115 | ((MODE) == GPIO_MODE_OUT_OD_LOW_FAST) || \ 116 | ((MODE) == GPIO_MODE_OUT_PP_LOW_FAST) || \ 117 | ((MODE) == GPIO_MODE_OUT_OD_LOW_SLOW) || \ 118 | ((MODE) == GPIO_MODE_OUT_PP_LOW_SLOW) || \ 119 | ((MODE) == GPIO_MODE_OUT_OD_HIZ_FAST) || \ 120 | ((MODE) == GPIO_MODE_OUT_PP_HIGH_FAST) || \ 121 | ((MODE) == GPIO_MODE_OUT_OD_HIZ_SLOW) || \ 122 | ((MODE) == GPIO_MODE_OUT_PP_HIGH_SLOW)) 123 | 124 | /** 125 | * @brief Macro used by the assert function in order to check the different 126 | * values of GPIO_Pins. 127 | */ 128 | #define IS_GPIO_PIN_OK(PIN) ((PIN) != (uint8_t)0x00) 129 | 130 | /** 131 | * @} 132 | */ 133 | 134 | /* Exported functions ------------------------------------------------------- */ 135 | /** @addtogroup GPIO_Exported_Functions 136 | * @{ 137 | */ 138 | 139 | void GPIO_DeInit(GPIO_TypeDef* GPIOx); 140 | void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef GPIO_Pin, GPIO_Mode_TypeDef GPIO_Mode); 141 | void GPIO_Write(GPIO_TypeDef* GPIOx, uint8_t PortVal); 142 | void GPIO_WriteHigh(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef PortPins); 143 | void GPIO_WriteLow(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef PortPins); 144 | void GPIO_WriteReverse(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef PortPins); 145 | uint8_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx); 146 | uint8_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx); 147 | BitStatus GPIO_ReadInputPin(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef GPIO_Pin); 148 | void GPIO_ExternalPullUpConfig(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef GPIO_Pin, FunctionalState NewState); 149 | /** 150 | * @} 151 | */ 152 | 153 | #endif /* __STM8L_GPIO_H */ 154 | 155 | 156 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 157 | -------------------------------------------------------------------------------- /NetworkModule/STM8S_StdPeriph_Driver/inc/stm8s_itc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8s_itc.h 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all functions prototype and macros for the ITC peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM8S_ITC_H 30 | #define __STM8S_ITC_H 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | #include "stm8s.h" 34 | 35 | /* Exported types ------------------------------------------------------------*/ 36 | 37 | /** @addtogroup ITC_Exported_Types 38 | * @{ 39 | */ 40 | 41 | /** 42 | * @brief ITC Interrupt Lines selection 43 | */ 44 | typedef enum { 45 | ITC_IRQ_TLI = (uint8_t)0, /*!< Software interrupt */ 46 | ITC_IRQ_AWU = (uint8_t)1, /*!< Auto wake up from halt interrupt */ 47 | ITC_IRQ_CLK = (uint8_t)2, /*!< Clock controller interrupt */ 48 | ITC_IRQ_PORTA = (uint8_t)3, /*!< Port A external interrupts */ 49 | ITC_IRQ_PORTB = (uint8_t)4, /*!< Port B external interrupts */ 50 | ITC_IRQ_PORTC = (uint8_t)5, /*!< Port C external interrupts */ 51 | ITC_IRQ_PORTD = (uint8_t)6, /*!< Port D external interrupts */ 52 | ITC_IRQ_PORTE = (uint8_t)7, /*!< Port E external interrupts */ 53 | 54 | #if defined(STM8S208) || defined(STM8AF52Ax) 55 | ITC_IRQ_CAN_RX = (uint8_t)8, /*!< beCAN RX interrupt */ 56 | ITC_IRQ_CAN_TX = (uint8_t)9, /*!< beCAN TX/ER/SC interrupt */ 57 | #endif /*STM8S208 or STM8AF52Ax */ 58 | 59 | #if defined(STM8S903) || defined(STM8AF622x) 60 | ITC_IRQ_PORTF = (uint8_t)8, /*!< Port F external interrupts */ 61 | #endif /*STM8S903 or STM8AF622x */ 62 | 63 | ITC_IRQ_SPI = (uint8_t)10, /*!< SPI interrupt */ 64 | ITC_IRQ_TIM1_OVF = (uint8_t)11, /*!< TIM1 update/overflow/underflow/trigger/ 65 | break interrupt*/ 66 | ITC_IRQ_TIM1_CAPCOM = (uint8_t)12, /*!< TIM1 capture/compare interrupt */ 67 | 68 | #if defined(STM8S903) || defined(STM8AF622x) 69 | ITC_IRQ_TIM5_OVFTRI = (uint8_t)13, /*!< TIM5 update/overflow/underflow/trigger/ 70 | interrupt */ 71 | ITC_IRQ_TIM5_CAPCOM = (uint8_t)14, /*!< TIM5 capture/compare interrupt */ 72 | #else 73 | ITC_IRQ_TIM2_OVF = (uint8_t)13, /*!< TIM2 update /overflow interrupt */ 74 | ITC_IRQ_TIM2_CAPCOM = (uint8_t)14, /*!< TIM2 capture/compare interrupt */ 75 | #endif /*STM8S903 or STM8AF622x */ 76 | 77 | ITC_IRQ_TIM3_OVF = (uint8_t)15, /*!< TIM3 update /overflow interrupt*/ 78 | ITC_IRQ_TIM3_CAPCOM = (uint8_t)16, /*!< TIM3 update /overflow interrupt */ 79 | 80 | #if defined(STM8S208) ||defined(STM8S207) || defined (STM8S007) || defined(STM8S103) || \ 81 | defined(STM8S003) || defined(STM8S001) ||defined(STM8S903) || defined (STM8AF52Ax) || defined (STM8AF62Ax) 82 | ITC_IRQ_UART1_TX = (uint8_t)17, /*!< UART1 TX interrupt */ 83 | ITC_IRQ_UART1_RX = (uint8_t)18, /*!< UART1 RX interrupt */ 84 | #endif /*STM8S208 or STM8S207 or STM8S007 or STM8S103 or STM8S003 or STM8S001 or STM8S903 or STM8AF52Ax or STM8AF62Ax */ 85 | #if defined(STM8AF622x) 86 | ITC_IRQ_UART4_TX = (uint8_t)17, /*!< UART4 TX interrupt */ 87 | ITC_IRQ_UART4_RX = (uint8_t)18, /*!< UART4 RX interrupt */ 88 | #endif /*STM8AF622x */ 89 | 90 | ITC_IRQ_I2C = (uint8_t)19, /*!< I2C interrupt */ 91 | 92 | #if defined(STM8S105) || defined(STM8S005) || defined(STM8AF626x) 93 | ITC_IRQ_UART2_TX = (uint8_t)20, /*!< USART2 TX interrupt */ 94 | ITC_IRQ_UART2_RX = (uint8_t)21, /*!< USART2 RX interrupt */ 95 | #endif /*STM8S105 or STM8AF626x */ 96 | 97 | #if defined(STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8AF52Ax) || defined(STM8AF62Ax) 98 | ITC_IRQ_UART3_TX = (uint8_t)20, /*!< USART3 TX interrupt */ 99 | ITC_IRQ_UART3_RX = (uint8_t)21, /*!< USART3 RX interrupt */ 100 | ITC_IRQ_ADC2 = (uint8_t)22, /*!< ADC2 interrupt */ 101 | #endif /*STM8S208 or STM8S207 or STM8AF52Ax or STM8AF62Ax */ 102 | 103 | #if defined(STM8S105) || defined(STM8S005) || defined(STM8S103) || defined(STM8S003) || defined(STM8S001) || defined(STM8S903) || defined(STM8AF626x) || defined(STM8AF622x) 104 | ITC_IRQ_ADC1 = (uint8_t)22, /*!< ADC1 interrupt */ 105 | #endif /*STM8S105 or STM8S005 or STM8S003 or STM8S103 or STM8S001 or STM8S903 or STM8AF626x or STM8AF622x */ 106 | 107 | #if defined(STM8S903) || defined(STM8AF622x) 108 | ITC_IRQ_TIM6_OVFTRI = (uint8_t)23, /*!< TIM6 update/overflow/underflow/trigger/ 109 | interrupt */ 110 | #else 111 | ITC_IRQ_TIM4_OVF = (uint8_t)23, /*!< TIM4 update /overflow interrupt */ 112 | #endif /*STM8S903 or STM8AF622x */ 113 | 114 | ITC_IRQ_EEPROM_EEC = (uint8_t)24 /*!< Flash interrupt */ 115 | } ITC_Irq_TypeDef; 116 | 117 | /** 118 | * @brief ITC Priority Levels selection 119 | */ 120 | typedef enum { 121 | ITC_PRIORITYLEVEL_0 = (uint8_t)0x02, /*!< Software priority level 0 (cannot be written) */ 122 | ITC_PRIORITYLEVEL_1 = (uint8_t)0x01, /*!< Software priority level 1 */ 123 | ITC_PRIORITYLEVEL_2 = (uint8_t)0x00, /*!< Software priority level 2 */ 124 | ITC_PRIORITYLEVEL_3 = (uint8_t)0x03 /*!< Software priority level 3 */ 125 | } ITC_PriorityLevel_TypeDef; 126 | 127 | /** 128 | * @} 129 | */ 130 | 131 | /* Exported constants --------------------------------------------------------*/ 132 | 133 | /** @addtogroup ITC_Exported_Constants 134 | * @{ 135 | */ 136 | #define CPU_SOFT_INT_DISABLED ((uint8_t)0x28) /*!< Mask for I1 and I0 bits in CPU_CC register */ 137 | 138 | /** 139 | * @} 140 | */ 141 | 142 | /* Private macros ------------------------------------------------------------*/ 143 | 144 | /** 145 | * @brief Macros used by the assert function in order to check the different functions parameters. 146 | * @addtogroup ITC_Private_Macros 147 | * @{ 148 | */ 149 | 150 | /* Used by assert function */ 151 | #define IS_ITC_IRQ_OK(IRQ) ((IRQ) <= (uint8_t)24) 152 | 153 | /* Used by assert function */ 154 | #define IS_ITC_PRIORITY_OK(PriorityValue) \ 155 | (((PriorityValue) == ITC_PRIORITYLEVEL_0) || \ 156 | ((PriorityValue) == ITC_PRIORITYLEVEL_1) || \ 157 | ((PriorityValue) == ITC_PRIORITYLEVEL_2) || \ 158 | ((PriorityValue) == ITC_PRIORITYLEVEL_3)) 159 | 160 | /* Used by assert function */ 161 | #define IS_ITC_INTERRUPTS_DISABLED (ITC_GetSoftIntStatus() == CPU_SOFT_INT_DISABLED) 162 | 163 | /** 164 | * @} 165 | */ 166 | 167 | /* Exported functions ------------------------------------------------------- */ 168 | 169 | /** @addtogroup ITC_Exported_Functions 170 | * @{ 171 | */ 172 | 173 | uint8_t ITC_GetCPUCC(void); 174 | void ITC_DeInit(void); 175 | uint8_t ITC_GetSoftIntStatus(void); 176 | void ITC_SetSoftwarePriority(ITC_Irq_TypeDef IrqNum, ITC_PriorityLevel_TypeDef PriorityValue); 177 | ITC_PriorityLevel_TypeDef ITC_GetSoftwarePriority(ITC_Irq_TypeDef IrqNum); 178 | 179 | /** 180 | * @} 181 | */ 182 | 183 | #endif /* __STM8S_ITC_H */ 184 | 185 | 186 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 187 | -------------------------------------------------------------------------------- /NetworkModule/STM8S_StdPeriph_Driver/inc/stm8s_iwdg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8s_iwdg.h 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all functions prototypes and macros for the IWDG peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM8S_IWDG_H 30 | #define __STM8S_IWDG_H 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | #include "stm8s.h" 34 | 35 | /** @addtogroup STM8S_StdPeriph_Driver 36 | * @{ 37 | */ 38 | 39 | /** @addtogroup IWDG_Private_Define 40 | * @{ 41 | */ 42 | 43 | /** 44 | * @brief Define used to prevent watchdog reset 45 | */ 46 | #define IWDG_KEY_REFRESH ((uint8_t)0xAA) /*!< This value written in the Key register prevent the watchdog reset */ 47 | 48 | /** 49 | * @brief Define used to start the watchdog counter down 50 | */ 51 | #define IWDG_KEY_ENABLE ((uint8_t)0xCC) /*!< This value written in the Key register start the watchdog counting down*/ 52 | 53 | /** 54 | * @} 55 | */ 56 | 57 | /** @addtogroup IWDG_Private_Macros 58 | * @{ 59 | */ 60 | 61 | /** 62 | * @brief Macro used by the assert function in order to check the different 63 | * values of the prescaler. 64 | */ 65 | #define IS_IWDG_PRESCALER_OK(VALUE) (((VALUE) == IWDG_Prescaler_4 ) || \ 66 | ((VALUE) == IWDG_Prescaler_8 ) || \ 67 | ((VALUE) == IWDG_Prescaler_16 ) || \ 68 | ((VALUE) == IWDG_Prescaler_32 ) || \ 69 | ((VALUE) == IWDG_Prescaler_64 ) || \ 70 | ((VALUE) == IWDG_Prescaler_128 ) || \ 71 | ((VALUE) == IWDG_Prescaler_256)) 72 | 73 | /** 74 | * @brief Macro used by the assert function in order to check the different 75 | * values of the counter register. 76 | */ 77 | #define IS_IWDG_WRITEACCESS_MODE_OK(MODE) (((MODE) == IWDG_WriteAccess_Enable) || ((MODE) == IWDG_WriteAccess_Disable)) 78 | 79 | /** 80 | * @} 81 | */ 82 | 83 | /** @addtogroup IWDG_Exported_Types 84 | * @{ 85 | */ 86 | 87 | /** IWDG write access enumeration */ 88 | typedef enum 89 | { 90 | IWDG_WriteAccess_Enable = (uint8_t)0x55, /*!< Code 0x55 in Key register, allow write access to Prescaler and Reload registers */ 91 | IWDG_WriteAccess_Disable = (uint8_t)0x00 /*!< Code 0x00 in Key register, not allow write access to Prescaler and Reload registers */ 92 | } IWDG_WriteAccess_TypeDef; 93 | 94 | /** IWDG prescaler enumaration */ 95 | typedef enum 96 | { 97 | IWDG_Prescaler_4 = (uint8_t)0x00, /*!< Used to set prescaler register to 4 */ 98 | IWDG_Prescaler_8 = (uint8_t)0x01, /*!< Used to set prescaler register to 8 */ 99 | IWDG_Prescaler_16 = (uint8_t)0x02, /*!< Used to set prescaler register to 16 */ 100 | IWDG_Prescaler_32 = (uint8_t)0x03, /*!< Used to set prescaler register to 32 */ 101 | IWDG_Prescaler_64 = (uint8_t)0x04, /*!< Used to set prescaler register to 64 */ 102 | IWDG_Prescaler_128 = (uint8_t)0x05, /*!< Used to set prescaler register to 128 */ 103 | IWDG_Prescaler_256 = (uint8_t)0x06 /*!< Used to set prescaler register to 256 */ 104 | } IWDG_Prescaler_TypeDef; 105 | 106 | /** 107 | * @} 108 | */ 109 | 110 | /** @addtogroup IWDG_Exported_Functions 111 | * @{ 112 | */ 113 | 114 | void IWDG_WriteAccessCmd(IWDG_WriteAccess_TypeDef IWDG_WriteAccess); 115 | void IWDG_SetPrescaler(IWDG_Prescaler_TypeDef IWDG_Prescaler); 116 | void IWDG_SetReload(uint8_t IWDG_Reload); 117 | void IWDG_ReloadCounter(void); 118 | void IWDG_Enable(void); 119 | 120 | /** 121 | * @} 122 | */ 123 | 124 | #endif /* __STM8S_IWDG_H */ 125 | 126 | /** 127 | * @} 128 | */ 129 | 130 | 131 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 132 | -------------------------------------------------------------------------------- /NetworkModule/STM8S_StdPeriph_Driver/inc/stm8s_rst.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8s_rst.h 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all functions prototype and macros for the RST peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | /* Define to prevent recursive inclusion -------------------------------------*/ 28 | #ifndef __STM8S_RST_H 29 | #define __STM8S_RST_H 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm8s.h" 33 | 34 | /** @addtogroup STM8S_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup RST_Exported_Types 39 | * @{ 40 | */ 41 | typedef enum { 42 | RST_FLAG_EMCF = (uint8_t)0x10, /*!< EMC reset flag */ 43 | RST_FLAG_SWIMF = (uint8_t)0x08, /*!< SWIM reset flag */ 44 | RST_FLAG_ILLOPF = (uint8_t)0x04, /*!< Illigal opcode reset flag */ 45 | RST_FLAG_IWDGF = (uint8_t)0x02, /*!< Independent watchdog reset flag */ 46 | RST_FLAG_WWDGF = (uint8_t)0x01 /*!< Window watchdog reset flag */ 47 | }RST_Flag_TypeDef; 48 | 49 | /** 50 | * @} 51 | */ 52 | 53 | /* Exported constants --------------------------------------------------------*/ 54 | /* Exported macros -----------------------------------------------------------*/ 55 | 56 | /** @addtogroup RST_Private_Macros 57 | * @{ 58 | */ 59 | 60 | /** 61 | * @brief Macro used by the assert function to check the different functions parameters. 62 | */ 63 | /** 64 | * @brief Macro used by the assert function to check the different RST flags. 65 | */ 66 | #define IS_RST_FLAG_OK(FLAG) (((FLAG) == RST_FLAG_EMCF) || \ 67 | ((FLAG) == RST_FLAG_SWIMF) ||\ 68 | ((FLAG) == RST_FLAG_ILLOPF) ||\ 69 | ((FLAG) == RST_FLAG_IWDGF) ||\ 70 | ((FLAG) == RST_FLAG_WWDGF)) 71 | 72 | /** 73 | * @} 74 | */ 75 | 76 | /** @addtogroup RST_Exported_functions 77 | * @{ 78 | */ 79 | FlagStatus RST_GetFlagStatus(RST_Flag_TypeDef RST_Flag); 80 | void RST_ClearFlag(RST_Flag_TypeDef RST_Flag); 81 | 82 | /** 83 | * @} 84 | */ 85 | 86 | #endif /* __STM8S_RST_H */ 87 | 88 | /** 89 | * @} 90 | */ 91 | 92 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 93 | -------------------------------------------------------------------------------- /NetworkModule/STM8S_StdPeriph_Driver/inc/stm8s_tim4.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8s_tim4.h 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all functions prototype and macros for the TIM4 peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM8S_TIM4_H 30 | #define __STM8S_TIM4_H 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | #include "stm8s.h" 34 | 35 | /** @addtogroup STM8S_StdPeriph_Driver 36 | * @{ 37 | */ 38 | 39 | /* Exported types ------------------------------------------------------------*/ 40 | 41 | /** @addtogroup TIM4_Exported_Types 42 | * @{ 43 | */ 44 | 45 | 46 | 47 | /** TIM4 Prescaler */ 48 | typedef enum 49 | { 50 | TIM4_PRESCALER_1 = ((uint8_t)0x00), 51 | TIM4_PRESCALER_2 = ((uint8_t)0x01), 52 | TIM4_PRESCALER_4 = ((uint8_t)0x02), 53 | TIM4_PRESCALER_8 = ((uint8_t)0x03), 54 | TIM4_PRESCALER_16 = ((uint8_t)0x04), 55 | TIM4_PRESCALER_32 = ((uint8_t)0x05), 56 | TIM4_PRESCALER_64 = ((uint8_t)0x06), 57 | TIM4_PRESCALER_128 = ((uint8_t)0x07) 58 | } TIM4_Prescaler_TypeDef; 59 | 60 | #define IS_TIM4_PRESCALER_OK(PRESCALER) (((PRESCALER) == TIM4_PRESCALER_1 ) || \ 61 | ((PRESCALER) == TIM4_PRESCALER_2 ) || \ 62 | ((PRESCALER) == TIM4_PRESCALER_4 ) || \ 63 | ((PRESCALER) == TIM4_PRESCALER_8 ) || \ 64 | ((PRESCALER) == TIM4_PRESCALER_16 ) || \ 65 | ((PRESCALER) == TIM4_PRESCALER_32 ) || \ 66 | ((PRESCALER) == TIM4_PRESCALER_64 ) || \ 67 | ((PRESCALER) == TIM4_PRESCALER_128 ) ) 68 | 69 | /** TIM4 One Pulse Mode */ 70 | typedef enum 71 | { 72 | TIM4_OPMODE_SINGLE = ((uint8_t)0x01), 73 | TIM4_OPMODE_REPETITIVE = ((uint8_t)0x00) 74 | } TIM4_OPMode_TypeDef; 75 | 76 | #define IS_TIM4_OPM_MODE_OK(MODE) (((MODE) == TIM4_OPMODE_SINGLE) || \ 77 | ((MODE) == TIM4_OPMODE_REPETITIVE)) 78 | 79 | /** TIM4 Prescaler Reload Mode */ 80 | typedef enum 81 | { 82 | TIM4_PSCRELOADMODE_UPDATE = ((uint8_t)0x00), 83 | TIM4_PSCRELOADMODE_IMMEDIATE = ((uint8_t)0x01) 84 | } TIM4_PSCReloadMode_TypeDef; 85 | 86 | #define IS_TIM4_PRESCALER_RELOAD_OK(RELOAD) (((RELOAD) == TIM4_PSCRELOADMODE_UPDATE) || \ 87 | ((RELOAD) == TIM4_PSCRELOADMODE_IMMEDIATE)) 88 | 89 | /** TIM4 Update Source */ 90 | typedef enum 91 | { 92 | TIM4_UPDATESOURCE_GLOBAL = ((uint8_t)0x00), 93 | TIM4_UPDATESOURCE_REGULAR = ((uint8_t)0x01) 94 | } TIM4_UpdateSource_TypeDef; 95 | 96 | #define IS_TIM4_UPDATE_SOURCE_OK(SOURCE) (((SOURCE) == TIM4_UPDATESOURCE_GLOBAL) || \ 97 | ((SOURCE) == TIM4_UPDATESOURCE_REGULAR)) 98 | 99 | /** TIM4 Event Source */ 100 | typedef enum 101 | { 102 | TIM4_EVENTSOURCE_UPDATE = ((uint8_t)0x01) 103 | }TIM4_EventSource_TypeDef; 104 | 105 | #define IS_TIM4_EVENT_SOURCE_OK(SOURCE) (((SOURCE) == 0x01)) 106 | 107 | /** TIM4 Flags */ 108 | typedef enum 109 | { 110 | TIM4_FLAG_UPDATE = ((uint8_t)0x01) 111 | }TIM4_FLAG_TypeDef; 112 | 113 | #define IS_TIM4_GET_FLAG_OK(FLAG) ((FLAG) == TIM4_FLAG_UPDATE) 114 | 115 | 116 | 117 | /** TIM4 interrupt sources */ 118 | typedef enum 119 | { 120 | TIM4_IT_UPDATE = ((uint8_t)0x01) 121 | }TIM4_IT_TypeDef; 122 | 123 | #define IS_TIM4_IT_OK(IT) ((IT) == TIM4_IT_UPDATE) 124 | 125 | 126 | 127 | /** 128 | * @} 129 | */ 130 | 131 | /* Exported macro ------------------------------------------------------------*/ 132 | 133 | /* Exported functions --------------------------------------------------------*/ 134 | 135 | /** @addtogroup TIM4_Exported_Functions 136 | * @{ 137 | */ 138 | void TIM4_DeInit(void); 139 | void TIM4_TimeBaseInit(TIM4_Prescaler_TypeDef TIM4_Prescaler, uint8_t TIM4_Period); 140 | void TIM4_Cmd(FunctionalState NewState); 141 | void TIM4_ITConfig(TIM4_IT_TypeDef TIM4_IT, FunctionalState NewState); 142 | void TIM4_UpdateDisableConfig(FunctionalState NewState); 143 | void TIM4_UpdateRequestConfig(TIM4_UpdateSource_TypeDef TIM4_UpdateSource); 144 | void TIM4_SelectOnePulseMode(TIM4_OPMode_TypeDef TIM4_OPMode); 145 | void TIM4_PrescalerConfig(TIM4_Prescaler_TypeDef Prescaler, TIM4_PSCReloadMode_TypeDef TIM4_PSCReloadMode); 146 | void TIM4_ARRPreloadConfig(FunctionalState NewState); 147 | void TIM4_GenerateEvent(TIM4_EventSource_TypeDef TIM4_EventSource); 148 | void TIM4_SetCounter(uint8_t Counter); 149 | void TIM4_SetAutoreload(uint8_t Autoreload); 150 | uint8_t TIM4_GetCounter(void); 151 | TIM4_Prescaler_TypeDef TIM4_GetPrescaler(void); 152 | FlagStatus TIM4_GetFlagStatus(TIM4_FLAG_TypeDef TIM4_FLAG); 153 | void TIM4_ClearFlag(TIM4_FLAG_TypeDef TIM4_FLAG); 154 | ITStatus TIM4_GetITStatus(TIM4_IT_TypeDef TIM4_IT); 155 | void TIM4_ClearITPendingBit(TIM4_IT_TypeDef TIM4_IT); 156 | 157 | 158 | /** 159 | * @} 160 | */ 161 | 162 | #endif /* __STM8S_TIM4_H */ 163 | 164 | /** 165 | * @} 166 | */ 167 | 168 | 169 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 170 | -------------------------------------------------------------------------------- /NetworkModule/STM8S_StdPeriph_Driver/inc/stm8s_tim6.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8s_tim6.h 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all functions prototype and macros for the TIM6 peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM8S_TIM6_H 30 | #define __STM8S_TIM6_H 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | #include "stm8s.h" 34 | 35 | /** @addtogroup STM8S_StdPeriph_Driver 36 | * @{ 37 | */ 38 | 39 | /* Exported variables ------------------------------------------------------- */ 40 | /* Exported types ------------------------------------------------------------*/ 41 | 42 | /** @addtogroup TIM6_Exported_Types 43 | * @{ 44 | */ 45 | 46 | 47 | /** 48 | * @brief TIM6 Prescaler 49 | */ 50 | typedef enum 51 | { 52 | TIM6_PRESCALER_1 = ((uint8_t)0x00), /*!< Time base Prescaler = 1 (No effect)*/ 53 | TIM6_PRESCALER_2 = ((uint8_t)0x01), /*!< Time base Prescaler = 2 */ 54 | TIM6_PRESCALER_4 = ((uint8_t)0x02), /*!< Time base Prescaler = 4 */ 55 | TIM6_PRESCALER_8 = ((uint8_t)0x03), /*!< Time base Prescaler = 8 */ 56 | TIM6_PRESCALER_16 = ((uint8_t)0x04), /*!< Time base Prescaler = 16 */ 57 | TIM6_PRESCALER_32 = ((uint8_t)0x05), /*!< Time base Prescaler = 32 */ 58 | TIM6_PRESCALER_64 = ((uint8_t)0x06), /*!< Time base Prescaler = 64 */ 59 | TIM6_PRESCALER_128 = ((uint8_t)0x07) /*!< Time base Prescaler = 128 */ 60 | }TIM6_Prescaler_TypeDef; 61 | 62 | /** 63 | * @brief TIM6 One Pulse Mode 64 | */ 65 | typedef enum 66 | { 67 | TIM6_OPMODE_SINGLE = ((uint8_t)0x01), /*!< Single one Pulse mode (OPM Active) */ 68 | TIM6_OPMODE_REPETITIVE = ((uint8_t)0x00) /*!< Repetitive Pulse mode (OPM inactive) */ 69 | }TIM6_OPMode_TypeDef; 70 | 71 | /** 72 | * @brief TIM6 Prescaler Reload Mode 73 | */ 74 | typedef enum 75 | { 76 | TIM6_PSCRELOADMODE_UPDATE =((uint8_t)0x00), /*!< Prescaler value is reloaded at every update*/ 77 | TIM6_PSCRELOADMODE_IMMEDIATE =((uint8_t)0x01) /*!< Prescaler value is reloaded immediately*/ 78 | }TIM6_PSCReloadMode_TypeDef; 79 | 80 | /** 81 | * @brief TIM6 Update Source 82 | */ 83 | typedef enum 84 | { 85 | TIM6_UPDATESOURCE_GLOBAL =((uint8_t)0x00), /*!< Global Update request source */ 86 | TIM6_UPDATESOURCE_REGULAR =((uint8_t)0x01) /*!< Regular Update request source */ 87 | }TIM6_UpdateSource_TypeDef; 88 | 89 | /** 90 | * @brief TIM6 Event Source 91 | */ 92 | typedef enum 93 | { 94 | TIM6_EVENTSOURCE_UPDATE = ((uint8_t)0x01), /*!< Update Event*/ 95 | TIM6_EVENTSOURCE_TRIGGER = ((uint8_t)0x40) /*!< Trigger Event*/ 96 | }TIM6_EventSource_TypeDef; 97 | 98 | /** 99 | * @brief TIM6 Trigger Output Source 100 | */ 101 | typedef enum 102 | { 103 | TIM6_TRGOSOURCE_RESET = ((uint8_t)0x00), /*!< Trigger Output source = Reset*/ 104 | TIM6_TRGOSOURCE_ENABLE = ((uint8_t)0x10), /*!< Trigger Output source = TIM5 is enabled*/ 105 | TIM6_TRGOSOURCE_UPDATE = ((uint8_t)0x20) /*!< Trigger Output source = Update event*/ 106 | }TIM6_TRGOSource_TypeDef; 107 | 108 | /** 109 | * @brief TIM6 Slave Mode 110 | */ 111 | typedef enum 112 | { 113 | TIM6_SLAVEMODE_DISABLE = ((uint8_t)0x00), /*!< Disable slave mode to clock the prescaler directly with the internal clock */ 114 | TIM6_SLAVEMODE_RESET = ((uint8_t)0x04), /*!< Slave Mode Selection = Reset*/ 115 | TIM6_SLAVEMODE_GATED = ((uint8_t)0x05), /*!< Slave Mode Selection = Gated*/ 116 | TIM6_SLAVEMODE_TRIGGER = ((uint8_t)0x06), /*!< Slave Mode Selection = Trigger*/ 117 | TIM6_SLAVEMODE_EXTERNAL1 = ((uint8_t)0x07) /*!< Slave Mode Selection = External 1*/ 118 | }TIM6_SlaveMode_TypeDef; 119 | 120 | /** 121 | * @brief TIM6 Flags 122 | */ 123 | typedef enum 124 | { 125 | TIM6_FLAG_UPDATE = ((uint8_t)0x01), /*!< Update Flag */ 126 | TIM6_FLAG_TRIGGER = ((uint8_t)0x40) /*!< Trigger Flag */ 127 | }TIM6_FLAG_TypeDef; 128 | 129 | /** 130 | * @brief TIM6 interrupt sources 131 | */ 132 | typedef enum 133 | { 134 | TIM6_IT_UPDATE = ((uint8_t)0x01), /*!< Update Interrupt*/ 135 | TIM6_IT_TRIGGER = ((uint8_t)0x40) /*!< Trigger Interrupt*/ 136 | }TIM6_IT_TypeDef; 137 | 138 | /** 139 | * @brief TIM6 Internal Trigger Selection 140 | */ 141 | typedef enum 142 | { 143 | TIM6_TS_TIM1 = ((uint8_t)0x20),/*!< TRIG Input source = TIM1 TRIG Output */ 144 | TIM6_TS_TIM5 = ((uint8_t)0x30) /*!< TRIG Input source = TIM5 TRIG Output */ 145 | }TIM6_TS_TypeDef; 146 | 147 | /** 148 | * @} 149 | */ 150 | 151 | /* Exported constants --------------------------------------------------------*/ 152 | /* Exported macros -----------------------------------------------------------*/ 153 | /* Private macros ------------------------------------------------------------*/ 154 | 155 | /** @addtogroup TIM6_Private_Macros 156 | * @{ 157 | */ 158 | 159 | /** 160 | * @brief Macro used by the assert function to check the different functions parameters. 161 | */ 162 | 163 | /** 164 | * @brief Macro TIM6 Prescaler 165 | */ 166 | #define IS_TIM6_PRESCALER_OK(PRESCALER) \ 167 | (((PRESCALER) == TIM6_PRESCALER_1) || \ 168 | ((PRESCALER) == TIM6_PRESCALER_2) || \ 169 | ((PRESCALER) == TIM6_PRESCALER_4) || \ 170 | ((PRESCALER) == TIM6_PRESCALER_8) || \ 171 | ((PRESCALER) == TIM6_PRESCALER_16) || \ 172 | ((PRESCALER) == TIM6_PRESCALER_32) || \ 173 | ((PRESCALER) == TIM6_PRESCALER_64) || \ 174 | ((PRESCALER) == TIM6_PRESCALER_128)) 175 | /** 176 | * @brief Macro TIM6 One Pulse Mode 177 | */ 178 | #define IS_TIM6_OPM_MODE_OK(MODE) \ 179 | (((MODE) == TIM6_OPMODE_SINGLE) || \ 180 | ((MODE) == TIM6_OPMODE_REPETITIVE)) 181 | 182 | /** 183 | * @brief Macro TIM6 Prescaler reload 184 | */ 185 | #define IS_TIM6_PRESCALER_RELOAD_OK(RELOAD) \ 186 | (((RELOAD) == TIM6_PSCRELOADMODE_UPDATE) || \ 187 | ((RELOAD) == TIM6_PSCRELOADMODE_IMMEDIATE)) 188 | /** 189 | * @brief Macro TIM6 Update source 190 | */ 191 | #define IS_TIM6_UPDATE_SOURCE_OK(SOURCE) \ 192 | (((SOURCE) == TIM6_UPDATESOURCE_GLOBAL) || \ 193 | ((SOURCE) == TIM6_UPDATESOURCE_REGULAR)) 194 | /** 195 | * @brief Macro TIM6 Event source 196 | */ 197 | #define IS_TIM6_EVENT_SOURCE_OK(SOURCE) \ 198 | ((((SOURCE) & (uint8_t)0xBE) == 0x00) && \ 199 | ((SOURCE) != 0x00)) 200 | 201 | /** 202 | * @brief Macro TIM6 TRGO source 203 | */ 204 | #define IS_TIM6_TRGO_SOURCE_OK(SOURCE) \ 205 | (((SOURCE) == TIM6_TRGOSOURCE_RESET) || \ 206 | ((SOURCE) == TIM6_TRGOSOURCE_ENABLE)|| \ 207 | ((SOURCE) == TIM6_TRGOSOURCE_UPDATE)) 208 | /** 209 | * @brief Macro TIM6 Slave mode 210 | */ 211 | #define IS_TIM6_SLAVE_MODE_OK(MODE) \ 212 | (((MODE) == TIM6_SLAVEMODE_DISABLE) || \ 213 | ((MODE) == TIM6_SLAVEMODE_RESET) || \ 214 | ((MODE) == TIM6_SLAVEMODE_GATED) || \ 215 | ((MODE) == TIM6_SLAVEMODE_TRIGGER) || \ 216 | ((MODE) == TIM6_SLAVEMODE_EXTERNAL1)) 217 | /** 218 | * @brief Macro TIM6 Flags 219 | */ 220 | #define IS_TIM6_GET_FLAG_OK(FLAG) \ 221 | (((FLAG) == TIM6_FLAG_UPDATE) || \ 222 | ((FLAG) == TIM6_FLAG_TRIGGER)) 223 | 224 | #define IS_TIM6_CLEAR_FLAG_OK(FLAG) \ 225 | ((((FLAG) & (uint8_t)0xBE) == 0x00) && ((FLAG) != 0x00)) 226 | /** 227 | * @brief Macro TIM6 interrupts 228 | */ 229 | #define IS_TIM6_IT_OK(IT) \ 230 | (((IT) != 0x00) && \ 231 | (((IT) & (uint8_t)(~(uint8_t)(0x41)))== 0x00)) 232 | 233 | #define IS_TIM6_GET_IT_OK(IT) \ 234 | (((IT) == TIM6_IT_UPDATE) || \ 235 | ((IT) == TIM6_IT_TRIGGER)) 236 | /** 237 | * @brief Macro TIM6 Trigger selection 238 | */ 239 | #define IS_TIM6_TRIGGER_SELECTION_OK(SELECTION) \ 240 | (((SELECTION) == TIM6_TS_TIM5) || \ 241 | ((SELECTION) == TIM6_TS_TIM1)) 242 | /** 243 | * @} 244 | */ 245 | 246 | /* Exported functions --------------------------------------------------------*/ 247 | 248 | /** @addtogroup TIM6_Exported_Functions 249 | * @{ 250 | */ 251 | 252 | void TIM6_DeInit(void); 253 | void TIM6_TimeBaseInit(TIM6_Prescaler_TypeDef TIM6_Prescaler, uint8_t TIM6_Period); 254 | void TIM6_Cmd(FunctionalState NewState); 255 | void TIM6_UpdateDisableConfig(FunctionalState NewState); 256 | void TIM6_UpdateRequestConfig(TIM6_UpdateSource_TypeDef TIM6_UpdateSource); 257 | void TIM6_SelectOnePulseMode(TIM6_OPMode_TypeDef TIM6_OPMode); 258 | void TIM6_PrescalerConfig(TIM6_Prescaler_TypeDef Prescaler, TIM6_PSCReloadMode_TypeDef TIM6_PSCReloadMode); 259 | void TIM6_ARRPreloadConfig(FunctionalState NewState); 260 | void TIM6_SetCounter(uint8_t Counter); 261 | void TIM6_SetAutoreload(uint8_t Autoreload); 262 | uint8_t TIM6_GetCounter(void); 263 | TIM6_Prescaler_TypeDef TIM6_GetPrescaler(void); 264 | void TIM6_ITConfig(TIM6_IT_TypeDef TIM6_IT, FunctionalState NewState); 265 | void TIM6_ClearFlag(TIM6_FLAG_TypeDef TIM6_FLAG); 266 | ITStatus TIM6_GetITStatus(TIM6_IT_TypeDef TIM6_IT); 267 | void TIM6_GenerateEvent(TIM6_EventSource_TypeDef TIM6_EventSource); 268 | FlagStatus TIM6_GetFlagStatus(TIM6_FLAG_TypeDef TIM6_FLAG); 269 | void TIM6_ClearITPendingBit(TIM6_IT_TypeDef TIM6_IT); 270 | void TIM6_SelectOutputTrigger(TIM6_TRGOSource_TypeDef TIM6_TRGOSource); 271 | void TIM6_SelectMasterSlaveMode(FunctionalState NewState); 272 | void TIM6_SelectInputTrigger(TIM6_TS_TypeDef TIM6_InputTriggerSource); 273 | void TIM6_InternalClockConfig(void); 274 | void TIM6_SelectSlaveMode(TIM6_SlaveMode_TypeDef TIM6_SlaveMode); 275 | 276 | /** 277 | * @} 278 | */ 279 | 280 | #endif /* __STM8S_TIM6_H */ 281 | 282 | /** 283 | * @} 284 | */ 285 | 286 | 287 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 288 | -------------------------------------------------------------------------------- /NetworkModule/STM8S_StdPeriph_Driver/inc/stm8s_wwdg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ******************************************************************************** 3 | * @file stm8s_wwdg.h 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all functions prototype and macros for the WWDG peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM8S_WWDG_H 30 | #define __STM8S_WWDG_H 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | #include "stm8s.h" 34 | 35 | /** @addtogroup STM8S_StdPeriph_Driver 36 | * @{ 37 | */ 38 | 39 | /* Private macros ------------------------------------------------------------*/ 40 | 41 | /** @addtogroup WWDG_Private_Macros 42 | * @{ 43 | */ 44 | 45 | /** 46 | * @brief Macro used by the assert function in order to check the 47 | * values of the window register. 48 | */ 49 | #define IS_WWDG_WINDOWLIMITVALUE_OK(WindowLimitValue) ((WindowLimitValue) <= 0x7F) 50 | 51 | /** 52 | * @brief Macro used by the assert function in order to check the different 53 | * values of the counter register. 54 | */ 55 | #define IS_WWDG_COUNTERVALUE_OK(CounterValue) ((CounterValue) <= 0x7F) 56 | 57 | /** 58 | * @} 59 | */ 60 | 61 | /* Exported types ------------------------------------------------------------*/ 62 | 63 | /* Exported functions ------------------------------------------------------- */ 64 | 65 | /** @addtogroup WWDG_Exported_Functions 66 | * @{ 67 | */ 68 | 69 | void WWDG_Init(uint8_t Counter, uint8_t WindowValue); 70 | void WWDG_SetCounter(uint8_t Counter); 71 | uint8_t WWDG_GetCounter(void); 72 | void WWDG_SWReset(void); 73 | void WWDG_SetWindowValue(uint8_t WindowValue); 74 | 75 | 76 | /** 77 | * @} 78 | */ 79 | 80 | #endif /* __STM8S_WWDG_H */ 81 | 82 | /** 83 | * @} 84 | */ 85 | 86 | 87 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 88 | -------------------------------------------------------------------------------- /NetworkModule/STM8S_StdPeriph_Driver/src/stm8s_awu.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8s_awu.c 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all the functions for the AWU peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm8s_awu.h" 30 | 31 | /** @addtogroup STM8S_StdPeriph_Driver 32 | * @{ 33 | */ 34 | /* Private typedef -----------------------------------------------------------*/ 35 | /* Private define ------------------------------------------------------------*/ 36 | /* Private macro -------------------------------------------------------------*/ 37 | /* Private variables ---------------------------------------------------------*/ 38 | /* Private function prototypes -----------------------------------------------*/ 39 | /* Private functions ---------------------------------------------------------*/ 40 | 41 | /* See also AWU_Timebase_TypeDef structure in stm8s_awu.h file : 42 | N 2 5 1 2 4 8 1 3 6 1 2 5 1 2 1 3 43 | O 5 0 m m m m 6 2 4 2 5 1 s s 2 0 44 | I 0 0 s s s s m m m 8 6 2 s s 45 | T u u s s s m m m 46 | s s s s s 47 | */ 48 | /** Contains the different values to write in the APR register (used by AWU_Init function) */ 49 | CONST uint8_t APR_Array[17] = 50 | { 51 | 0, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 61, 23, 23, 62 52 | }; 53 | 54 | /** Contains the different values to write in the TBR register (used by AWU_Init function) */ 55 | CONST uint8_t TBR_Array[17] = 56 | { 57 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, 14, 15, 15 58 | }; 59 | 60 | /* Public functions ----------------------------------------------------------*/ 61 | 62 | /** 63 | * @addtogroup AWU_Public_Functions 64 | * @{ 65 | */ 66 | 67 | /** 68 | * @brief Deinitializes the AWU peripheral registers to their default reset 69 | * values. 70 | * @param None 71 | * @retval None 72 | */ 73 | void AWU_DeInit(void) 74 | { 75 | AWU->CSR = AWU_CSR_RESET_VALUE; 76 | AWU->APR = AWU_APR_RESET_VALUE; 77 | AWU->TBR = AWU_TBR_RESET_VALUE; 78 | } 79 | 80 | /** 81 | * @brief Initializes the AWU peripheral according to the specified parameters. 82 | * @param AWU_TimeBase : Time base selection (interval between AWU interrupts). 83 | * can be one of the values of @ref AWU_Timebase_TypeDef. 84 | * @retval None 85 | * @par Required preconditions: 86 | * The LS RC calibration must be performed before calling this function. 87 | */ 88 | void AWU_Init(AWU_Timebase_TypeDef AWU_TimeBase) 89 | { 90 | /* Check parameter */ 91 | assert_param(IS_AWU_TIMEBASE_OK(AWU_TimeBase)); 92 | 93 | /* Enable the AWU peripheral */ 94 | AWU->CSR |= AWU_CSR_AWUEN; 95 | 96 | /* Set the TimeBase */ 97 | AWU->TBR &= (uint8_t)(~AWU_TBR_AWUTB); 98 | AWU->TBR |= TBR_Array[(uint8_t)AWU_TimeBase]; 99 | 100 | /* Set the APR divider */ 101 | AWU->APR &= (uint8_t)(~AWU_APR_APR); 102 | AWU->APR |= APR_Array[(uint8_t)AWU_TimeBase]; 103 | } 104 | 105 | /** 106 | * @brief Enable or disable the AWU peripheral. 107 | * @param NewState Indicates the new state of the AWU peripheral. 108 | * @retval None 109 | * @par Required preconditions: 110 | * Initialisation of AWU and LS RC calibration must be done before. 111 | */ 112 | void AWU_Cmd(FunctionalState NewState) 113 | { 114 | if (NewState != DISABLE) 115 | { 116 | /* Enable the AWU peripheral */ 117 | AWU->CSR |= AWU_CSR_AWUEN; 118 | } 119 | else 120 | { 121 | /* Disable the AWU peripheral */ 122 | AWU->CSR &= (uint8_t)(~AWU_CSR_AWUEN); 123 | } 124 | } 125 | 126 | /** 127 | * @brief Update APR register with the measured LSI frequency. 128 | * @par Note on the APR calculation: 129 | * A is the integer part of lsifreqkhz/4 and x the decimal part. 130 | * x <= A/(1+2A) is equivalent to A >= x(1+2A) and also to 4A >= 4x(1+2A) [F1] 131 | * but we know that A + x = lsifreqkhz/4 ==> 4x = lsifreqkhz-4A 132 | * so [F1] can be written : 133 | * 4A >= (lsifreqkhz-4A)(1+2A) 134 | * @param LSIFreqHz Low Speed RC frequency measured by timer (in Hz). 135 | * @retval None 136 | * @par Required preconditions: 137 | * - AWU must be disabled to avoid unwanted interrupts. 138 | */ 139 | void AWU_LSICalibrationConfig(uint32_t LSIFreqHz) 140 | { 141 | uint16_t lsifreqkhz = 0x0; 142 | uint16_t A = 0x0; 143 | 144 | /* Check parameter */ 145 | assert_param(IS_LSI_FREQUENCY_OK(LSIFreqHz)); 146 | 147 | lsifreqkhz = (uint16_t)(LSIFreqHz / 1000); /* Converts value in kHz */ 148 | 149 | /* Calculation of AWU calibration value */ 150 | 151 | A = (uint16_t)(lsifreqkhz >> 2U); /* Division by 4, keep integer part only */ 152 | 153 | if ((4U * A) >= ((lsifreqkhz - (4U * A)) * (1U + (2U * A)))) 154 | { 155 | AWU->APR = (uint8_t)(A - 2U); 156 | } 157 | else 158 | { 159 | AWU->APR = (uint8_t)(A - 1U); 160 | } 161 | } 162 | 163 | /** 164 | * @brief Configures AWU in Idle mode to reduce power consumption. 165 | * @param None 166 | * @retval None 167 | */ 168 | void AWU_IdleModeEnable(void) 169 | { 170 | /* Disable AWU peripheral */ 171 | AWU->CSR &= (uint8_t)(~AWU_CSR_AWUEN); 172 | 173 | /* No AWU timebase */ 174 | AWU->TBR = (uint8_t)(~AWU_TBR_AWUTB); 175 | } 176 | 177 | /** 178 | * @brief Returns status of the AWU peripheral flag. 179 | * @param None 180 | * @retval FlagStatus : Status of the AWU flag. 181 | * This parameter can be any of the @ref FlagStatus enumeration. 182 | */ 183 | FlagStatus AWU_GetFlagStatus(void) 184 | { 185 | return((FlagStatus)(((uint8_t)(AWU->CSR & AWU_CSR_AWUF) == (uint8_t)0x00) ? RESET : SET)); 186 | } 187 | 188 | 189 | /** 190 | * @} 191 | */ 192 | 193 | /** 194 | * @} 195 | */ 196 | 197 | 198 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 199 | -------------------------------------------------------------------------------- /NetworkModule/STM8S_StdPeriph_Driver/src/stm8s_beep.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8s_beep.c 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all the functions for the BEEP peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm8s_beep.h" 30 | 31 | /** @addtogroup STM8S_StdPeriph_Driver 32 | * @{ 33 | */ 34 | /* Private typedef -----------------------------------------------------------*/ 35 | /* Private define ------------------------------------------------------------*/ 36 | /* Private macro -------------------------------------------------------------*/ 37 | /* Private variables ---------------------------------------------------------*/ 38 | /* Private function prototypes -----------------------------------------------*/ 39 | /* Private functions ---------------------------------------------------------*/ 40 | 41 | /* Public functions ----------------------------------------------------------*/ 42 | 43 | /** 44 | * @addtogroup BEEP_Public_Functions 45 | * @{ 46 | */ 47 | 48 | /** 49 | * @brief Deinitializes the BEEP peripheral registers to their default reset 50 | * values. 51 | * @param None 52 | * @retval None 53 | */ 54 | void BEEP_DeInit(void) 55 | { 56 | BEEP->CSR = BEEP_CSR_RESET_VALUE; 57 | } 58 | 59 | /** 60 | * @brief Initializes the BEEP function according to the specified parameters. 61 | * @param BEEP_Frequency Frequency selection. 62 | * can be one of the values of @ref BEEP_Frequency_TypeDef. 63 | * @retval None 64 | * @par Required preconditions: 65 | * The LS RC calibration must be performed before calling this function. 66 | */ 67 | void BEEP_Init(BEEP_Frequency_TypeDef BEEP_Frequency) 68 | { 69 | /* Check parameter */ 70 | assert_param(IS_BEEP_FREQUENCY_OK(BEEP_Frequency)); 71 | 72 | /* Set a default calibration value if no calibration is done */ 73 | if ((BEEP->CSR & BEEP_CSR_BEEPDIV) == BEEP_CSR_BEEPDIV) 74 | { 75 | BEEP->CSR &= (uint8_t)(~BEEP_CSR_BEEPDIV); /* Clear bits */ 76 | BEEP->CSR |= BEEP_CALIBRATION_DEFAULT; 77 | } 78 | 79 | /* Select the output frequency */ 80 | BEEP->CSR &= (uint8_t)(~BEEP_CSR_BEEPSEL); 81 | BEEP->CSR |= (uint8_t)(BEEP_Frequency); 82 | } 83 | 84 | /** 85 | * @brief Enable or disable the BEEP function. 86 | * @param NewState Indicates the new state of the BEEP function. 87 | * @retval None 88 | * @par Required preconditions: 89 | * Initialisation of BEEP and LS RC calibration must be done before. 90 | */ 91 | void BEEP_Cmd(FunctionalState NewState) 92 | { 93 | if (NewState != DISABLE) 94 | { 95 | /* Enable the BEEP peripheral */ 96 | BEEP->CSR |= BEEP_CSR_BEEPEN; 97 | } 98 | else 99 | { 100 | /* Disable the BEEP peripheral */ 101 | BEEP->CSR &= (uint8_t)(~BEEP_CSR_BEEPEN); 102 | } 103 | } 104 | 105 | /** 106 | * @brief Update CSR register with the measured LSI frequency. 107 | * @par Note on the APR calculation: 108 | * A is the integer part of LSIFreqkHz/4 and x the decimal part. 109 | * x <= A/(1+2A) is equivalent to A >= x(1+2A) and also to 4A >= 4x(1+2A) [F1] 110 | * but we know that A + x = LSIFreqkHz/4 ==> 4x = LSIFreqkHz-4A 111 | * so [F1] can be written : 112 | * 4A >= (LSIFreqkHz-4A)(1+2A) 113 | * @param LSIFreqHz Low Speed RC frequency measured by timer (in Hz). 114 | * @retval None 115 | * @par Required preconditions: 116 | * - BEEP must be disabled to avoid unwanted interrupts. 117 | */ 118 | void BEEP_LSICalibrationConfig(uint32_t LSIFreqHz) 119 | { 120 | uint16_t lsifreqkhz; 121 | uint16_t A; 122 | 123 | /* Check parameter */ 124 | assert_param(IS_LSI_FREQUENCY_OK(LSIFreqHz)); 125 | 126 | lsifreqkhz = (uint16_t)(LSIFreqHz / 1000); /* Converts value in kHz */ 127 | 128 | /* Calculation of BEEPER calibration value */ 129 | 130 | BEEP->CSR &= (uint8_t)(~BEEP_CSR_BEEPDIV); /* Clear bits */ 131 | 132 | A = (uint16_t)(lsifreqkhz >> 3U); /* Division by 8, keep integer part only */ 133 | 134 | if ((8U * A) >= ((lsifreqkhz - (8U * A)) * (1U + (2U * A)))) 135 | { 136 | BEEP->CSR |= (uint8_t)(A - 2U); 137 | } 138 | else 139 | { 140 | BEEP->CSR |= (uint8_t)(A - 1U); 141 | } 142 | } 143 | 144 | /** 145 | * @} 146 | */ 147 | 148 | /** 149 | * @} 150 | */ 151 | 152 | 153 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 154 | -------------------------------------------------------------------------------- /NetworkModule/STM8S_StdPeriph_Driver/src/stm8s_can.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nielsonm236/NetMod-ServerApp/1700e7a9aa5b377ca4deb89e6a47fe72e026d3f7/NetworkModule/STM8S_StdPeriph_Driver/src/stm8s_can.c -------------------------------------------------------------------------------- /NetworkModule/STM8S_StdPeriph_Driver/src/stm8s_clk.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nielsonm236/NetMod-ServerApp/1700e7a9aa5b377ca4deb89e6a47fe72e026d3f7/NetworkModule/STM8S_StdPeriph_Driver/src/stm8s_clk.c -------------------------------------------------------------------------------- /NetworkModule/STM8S_StdPeriph_Driver/src/stm8s_exti.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8s_exti.c 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all the functions for the EXTI peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm8s_exti.h" 30 | 31 | /** @addtogroup STM8S_StdPeriph_Driver 32 | * @{ 33 | */ 34 | /* Private typedef -----------------------------------------------------------*/ 35 | /* Private define ------------------------------------------------------------*/ 36 | /* Private macro -------------------------------------------------------------*/ 37 | /* Private variables ---------------------------------------------------------*/ 38 | /* Private function prototypes -----------------------------------------------*/ 39 | /* Private functions ---------------------------------------------------------*/ 40 | 41 | /* Public functions ----------------------------------------------------------*/ 42 | 43 | /** 44 | * @addtogroup EXTI_Public_Functions 45 | * @{ 46 | */ 47 | 48 | /** 49 | * @brief Deinitializes the external interrupt control registers to their default reset value. 50 | * @param None 51 | * @retval None 52 | */ 53 | void EXTI_DeInit(void) 54 | { 55 | EXTI->CR1 = EXTI_CR1_RESET_VALUE; 56 | EXTI->CR2 = EXTI_CR2_RESET_VALUE; 57 | } 58 | 59 | /** 60 | * @brief Set the external interrupt sensitivity of the selected port. 61 | * @warning 62 | * - The modification of external interrupt sensitivity is only possible when the interrupts are disabled. 63 | * - The normal behavior is to disable the interrupts before calling this function, and re-enable them after. 64 | * @param Port The port number to access. 65 | * @param SensitivityValue The external interrupt sensitivity value to set. 66 | * @retval None 67 | * @par Required preconditions: 68 | * Global interrupts must be disabled before calling this function. 69 | */ 70 | void EXTI_SetExtIntSensitivity(EXTI_Port_TypeDef Port, EXTI_Sensitivity_TypeDef SensitivityValue) 71 | { 72 | /* Check function parameters */ 73 | assert_param(IS_EXTI_PORT_OK(Port)); 74 | assert_param(IS_EXTI_SENSITIVITY_OK(SensitivityValue)); 75 | 76 | /* Set external interrupt sensitivity */ 77 | switch (Port) 78 | { 79 | case EXTI_PORT_GPIOA: 80 | EXTI->CR1 &= (uint8_t)(~EXTI_CR1_PAIS); 81 | EXTI->CR1 |= (uint8_t)(SensitivityValue); 82 | break; 83 | case EXTI_PORT_GPIOB: 84 | EXTI->CR1 &= (uint8_t)(~EXTI_CR1_PBIS); 85 | EXTI->CR1 |= (uint8_t)((uint8_t)(SensitivityValue) << 2); 86 | break; 87 | case EXTI_PORT_GPIOC: 88 | EXTI->CR1 &= (uint8_t)(~EXTI_CR1_PCIS); 89 | EXTI->CR1 |= (uint8_t)((uint8_t)(SensitivityValue) << 4); 90 | break; 91 | case EXTI_PORT_GPIOD: 92 | EXTI->CR1 &= (uint8_t)(~EXTI_CR1_PDIS); 93 | EXTI->CR1 |= (uint8_t)((uint8_t)(SensitivityValue) << 6); 94 | break; 95 | case EXTI_PORT_GPIOE: 96 | EXTI->CR2 &= (uint8_t)(~EXTI_CR2_PEIS); 97 | EXTI->CR2 |= (uint8_t)(SensitivityValue); 98 | break; 99 | default: 100 | break; 101 | } 102 | } 103 | 104 | /** 105 | * @brief Set the TLI interrupt sensitivity. 106 | * @param SensitivityValue The TLI interrupt sensitivity value. 107 | * @retval None 108 | * @par Required preconditions: 109 | * Global interrupts must be disabled before calling this function. 110 | */ 111 | void EXTI_SetTLISensitivity(EXTI_TLISensitivity_TypeDef SensitivityValue) 112 | { 113 | /* Check function parameters */ 114 | assert_param(IS_EXTI_TLISENSITIVITY_OK(SensitivityValue)); 115 | 116 | /* Set TLI interrupt sensitivity */ 117 | EXTI->CR2 &= (uint8_t)(~EXTI_CR2_TLIS); 118 | EXTI->CR2 |= (uint8_t)(SensitivityValue); 119 | } 120 | 121 | /** 122 | * @brief Get the external interrupt sensitivity of the selected port. 123 | * @param Port The port number to access. 124 | * @retval EXTI_Sensitivity_TypeDef The external interrupt sensitivity of the selected port. 125 | */ 126 | EXTI_Sensitivity_TypeDef EXTI_GetExtIntSensitivity(EXTI_Port_TypeDef Port) 127 | { 128 | uint8_t value = 0; 129 | 130 | /* Check function parameters */ 131 | assert_param(IS_EXTI_PORT_OK(Port)); 132 | 133 | switch (Port) 134 | { 135 | case EXTI_PORT_GPIOA: 136 | value = (uint8_t)(EXTI->CR1 & EXTI_CR1_PAIS); 137 | break; 138 | case EXTI_PORT_GPIOB: 139 | value = (uint8_t)((uint8_t)(EXTI->CR1 & EXTI_CR1_PBIS) >> 2); 140 | break; 141 | case EXTI_PORT_GPIOC: 142 | value = (uint8_t)((uint8_t)(EXTI->CR1 & EXTI_CR1_PCIS) >> 4); 143 | break; 144 | case EXTI_PORT_GPIOD: 145 | value = (uint8_t)((uint8_t)(EXTI->CR1 & EXTI_CR1_PDIS) >> 6); 146 | break; 147 | case EXTI_PORT_GPIOE: 148 | value = (uint8_t)(EXTI->CR2 & EXTI_CR2_PEIS); 149 | break; 150 | default: 151 | break; 152 | } 153 | 154 | return((EXTI_Sensitivity_TypeDef)value); 155 | } 156 | 157 | /** 158 | * @brief Get the TLI interrupt sensitivity. 159 | * @param None 160 | * @retval EXTI_TLISensitivity_TypeDef The TLI interrupt sensitivity read. 161 | */ 162 | EXTI_TLISensitivity_TypeDef EXTI_GetTLISensitivity(void) 163 | { 164 | uint8_t value = 0; 165 | 166 | /* Get TLI interrupt sensitivity */ 167 | value = (uint8_t)(EXTI->CR2 & EXTI_CR2_TLIS); 168 | 169 | return((EXTI_TLISensitivity_TypeDef)value); 170 | } 171 | 172 | /** 173 | * @} 174 | */ 175 | 176 | /** 177 | * @} 178 | */ 179 | 180 | 181 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 182 | -------------------------------------------------------------------------------- /NetworkModule/STM8S_StdPeriph_Driver/src/stm8s_flash.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nielsonm236/NetMod-ServerApp/1700e7a9aa5b377ca4deb89e6a47fe72e026d3f7/NetworkModule/STM8S_StdPeriph_Driver/src/stm8s_flash.c -------------------------------------------------------------------------------- /NetworkModule/STM8S_StdPeriph_Driver/src/stm8s_gpio.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8s_gpio.c 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all the functions for the GPIO peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm8s_gpio.h" 30 | 31 | /** @addtogroup STM8S_StdPeriph_Driver 32 | * @{ 33 | */ 34 | /* Private typedef -----------------------------------------------------------*/ 35 | /* Private define ------------------------------------------------------------*/ 36 | /* Private macro -------------------------------------------------------------*/ 37 | /* Private variables ---------------------------------------------------------*/ 38 | /* Private function prototypes -----------------------------------------------*/ 39 | /* Private functions ---------------------------------------------------------*/ 40 | 41 | /* Public functions ----------------------------------------------------------*/ 42 | 43 | /** 44 | * @addtogroup GPIO_Public_Functions 45 | * @{ 46 | */ 47 | 48 | /** 49 | * @brief Deinitializes the GPIOx peripheral registers to their default reset values. 50 | * @param GPIOx: Select the GPIO peripheral number (x = A to I). 51 | * @retval None 52 | */ 53 | void GPIO_DeInit(GPIO_TypeDef* GPIOx) 54 | { 55 | GPIOx->ODR = GPIO_ODR_RESET_VALUE; /* Reset Output Data Register */ 56 | GPIOx->DDR = GPIO_DDR_RESET_VALUE; /* Reset Data Direction Register */ 57 | GPIOx->CR1 = GPIO_CR1_RESET_VALUE; /* Reset Control Register 1 */ 58 | GPIOx->CR2 = GPIO_CR2_RESET_VALUE; /* Reset Control Register 2 */ 59 | } 60 | 61 | /** 62 | * @brief Initializes the GPIOx according to the specified parameters. 63 | * @param GPIOx : Select the GPIO peripheral number (x = A to I). 64 | * @param GPIO_Pin : This parameter contains the pin number, it can be any value 65 | * of the @ref GPIO_Pin_TypeDef enumeration. 66 | * @param GPIO_Mode : This parameter can be a value of the 67 | * @ref GPIO_Mode_TypeDef enumeration. 68 | * @retval None 69 | */ 70 | 71 | void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef GPIO_Pin, GPIO_Mode_TypeDef GPIO_Mode) 72 | { 73 | /*----------------------*/ 74 | /* Check the parameters */ 75 | /*----------------------*/ 76 | 77 | assert_param(IS_GPIO_MODE_OK(GPIO_Mode)); 78 | assert_param(IS_GPIO_PIN_OK(GPIO_Pin)); 79 | 80 | /* Reset corresponding bit to GPIO_Pin in CR2 register */ 81 | GPIOx->CR2 &= (uint8_t)(~(GPIO_Pin)); 82 | 83 | /*-----------------------------*/ 84 | /* Input/Output mode selection */ 85 | /*-----------------------------*/ 86 | 87 | if ((((uint8_t)(GPIO_Mode)) & (uint8_t)0x80) != (uint8_t)0x00) /* Output mode */ 88 | { 89 | if ((((uint8_t)(GPIO_Mode)) & (uint8_t)0x10) != (uint8_t)0x00) /* High level */ 90 | { 91 | GPIOx->ODR |= (uint8_t)GPIO_Pin; 92 | } 93 | else /* Low level */ 94 | { 95 | GPIOx->ODR &= (uint8_t)(~(GPIO_Pin)); 96 | } 97 | /* Set Output mode */ 98 | GPIOx->DDR |= (uint8_t)GPIO_Pin; 99 | } 100 | else /* Input mode */ 101 | { 102 | /* Set Input mode */ 103 | GPIOx->DDR &= (uint8_t)(~(GPIO_Pin)); 104 | } 105 | 106 | /*------------------------------------------------------------------------*/ 107 | /* Pull-Up/Float (Input) or Push-Pull/Open-Drain (Output) modes selection */ 108 | /*------------------------------------------------------------------------*/ 109 | 110 | if ((((uint8_t)(GPIO_Mode)) & (uint8_t)0x40) != (uint8_t)0x00) /* Pull-Up or Push-Pull */ 111 | { 112 | GPIOx->CR1 |= (uint8_t)GPIO_Pin; 113 | } 114 | else /* Float or Open-Drain */ 115 | { 116 | GPIOx->CR1 &= (uint8_t)(~(GPIO_Pin)); 117 | } 118 | 119 | /*-----------------------------------------------------*/ 120 | /* Interrupt (Input) or Slope (Output) modes selection */ 121 | /*-----------------------------------------------------*/ 122 | 123 | if ((((uint8_t)(GPIO_Mode)) & (uint8_t)0x20) != (uint8_t)0x00) /* Interrupt or Slow slope */ 124 | { 125 | GPIOx->CR2 |= (uint8_t)GPIO_Pin; 126 | } 127 | else /* No external interrupt or No slope control */ 128 | { 129 | GPIOx->CR2 &= (uint8_t)(~(GPIO_Pin)); 130 | } 131 | } 132 | 133 | /** 134 | * @brief Writes data to the specified GPIO data port. 135 | * @note The port must be configured in output mode. 136 | * @param GPIOx : Select the GPIO peripheral number (x = A to I). 137 | * @param PortVal : Specifies the value to be written to the port output 138 | * data register. 139 | * @retval None 140 | */ 141 | void GPIO_Write(GPIO_TypeDef* GPIOx, uint8_t PortVal) 142 | { 143 | GPIOx->ODR = PortVal; 144 | } 145 | 146 | /** 147 | * @brief Writes high level to the specified GPIO pins. 148 | * @note The port must be configured in output mode. 149 | * @param GPIOx : Select the GPIO peripheral number (x = A to I). 150 | * @param PortPins : Specifies the pins to be turned high to the port output. 151 | * data register. 152 | * @retval None 153 | */ 154 | void GPIO_WriteHigh(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef PortPins) 155 | { 156 | GPIOx->ODR |= (uint8_t)PortPins; 157 | } 158 | 159 | /** 160 | * @brief Writes low level to the specified GPIO pins. 161 | * @note The port must be configured in output mode. 162 | * @param GPIOx : Select the GPIO peripheral number (x = A to I). 163 | * @param PortPins : Specifies the pins to be turned low to the port output. 164 | * data register. 165 | * @retval None 166 | */ 167 | void GPIO_WriteLow(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef PortPins) 168 | { 169 | GPIOx->ODR &= (uint8_t)(~PortPins); 170 | } 171 | 172 | /** 173 | * @brief Writes reverse level to the specified GPIO pins. 174 | * @note The port must be configured in output mode. 175 | * @param GPIOx : Select the GPIO peripheral number (x = A to I). 176 | * @param PortPins : Specifies the pins to be reversed to the port output. 177 | * data register. 178 | * @retval None 179 | */ 180 | void GPIO_WriteReverse(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef PortPins) 181 | { 182 | GPIOx->ODR ^= (uint8_t)PortPins; 183 | } 184 | 185 | /** 186 | * @brief Reads the specified GPIO output data port. 187 | * @note The port must be configured in input mode. 188 | * @param GPIOx : Select the GPIO peripheral number (x = A to I). 189 | * @retval GPIO output data port value. 190 | */ 191 | uint8_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx) 192 | { 193 | return ((uint8_t)GPIOx->ODR); 194 | } 195 | 196 | /** 197 | * @brief Reads the specified GPIO input data port. 198 | * @note The port must be configured in input mode. 199 | * @param GPIOx : Select the GPIO peripheral number (x = A to I). 200 | * @retval GPIO input data port value. 201 | */ 202 | uint8_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx) 203 | { 204 | return ((uint8_t)GPIOx->IDR); 205 | } 206 | 207 | /** 208 | * @brief Reads the specified GPIO input data pin. 209 | * @param GPIOx : Select the GPIO peripheral number (x = A to I). 210 | * @param GPIO_Pin : Specifies the pin number. 211 | * @retval BitStatus : GPIO input pin status. 212 | */ 213 | BitStatus GPIO_ReadInputPin(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef GPIO_Pin) 214 | { 215 | return ((BitStatus)(GPIOx->IDR & (uint8_t)GPIO_Pin)); 216 | } 217 | 218 | /** 219 | * @brief Configures the external pull-up on GPIOx pins. 220 | * @param GPIOx : Select the GPIO peripheral number (x = A to I). 221 | * @param GPIO_Pin : Specifies the pin number 222 | * @param NewState : The new state of the pull up pin. 223 | * @retval None 224 | */ 225 | void GPIO_ExternalPullUpConfig(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef GPIO_Pin, FunctionalState NewState) 226 | { 227 | /* Check the parameters */ 228 | assert_param(IS_GPIO_PIN_OK(GPIO_Pin)); 229 | assert_param(IS_FUNCTIONALSTATE_OK(NewState)); 230 | 231 | if (NewState != DISABLE) /* External Pull-Up Set*/ 232 | { 233 | GPIOx->CR1 |= (uint8_t)GPIO_Pin; 234 | } else /* External Pull-Up Reset*/ 235 | { 236 | GPIOx->CR1 &= (uint8_t)(~(GPIO_Pin)); 237 | } 238 | } 239 | 240 | /** 241 | * @} 242 | */ 243 | 244 | /** 245 | * @} 246 | */ 247 | 248 | 249 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 250 | -------------------------------------------------------------------------------- /NetworkModule/STM8S_StdPeriph_Driver/src/stm8s_i2c.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nielsonm236/NetMod-ServerApp/1700e7a9aa5b377ca4deb89e6a47fe72e026d3f7/NetworkModule/STM8S_StdPeriph_Driver/src/stm8s_i2c.c -------------------------------------------------------------------------------- /NetworkModule/STM8S_StdPeriph_Driver/src/stm8s_itc.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8s_itc.c 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all the functions for the ITC peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm8s_itc.h" 30 | 31 | /** @addtogroup STM8S_StdPeriph_Driver 32 | * @{ 33 | */ 34 | /* Private typedef -----------------------------------------------------------*/ 35 | /* Private define ------------------------------------------------------------*/ 36 | /* Private macro -------------------------------------------------------------*/ 37 | /* Private variables ---------------------------------------------------------*/ 38 | /* Private function prototypes -----------------------------------------------*/ 39 | /* Private functions ---------------------------------------------------------*/ 40 | 41 | /** @addtogroup ITC_Private_Functions 42 | * @{ 43 | */ 44 | 45 | /** 46 | * @brief Utility function used to read CC register. 47 | * @param None 48 | * @retval CPU CC register value 49 | */ 50 | uint8_t ITC_GetCPUCC(void) 51 | { 52 | #ifdef _COSMIC_ 53 | _asm("push cc"); 54 | _asm("pop a"); 55 | return; /* Ignore compiler warning, the returned value is in A register */ 56 | #elif defined _RAISONANCE_ /* _RAISONANCE_ */ 57 | return _getCC_(); 58 | #else /* _IAR_ */ 59 | asm("push cc"); 60 | asm("pop a"); /* Ignore compiler warning, the returned value is in A register */ 61 | #endif /* _COSMIC_*/ 62 | } 63 | 64 | 65 | /** 66 | * @} 67 | */ 68 | 69 | /* Public functions ----------------------------------------------------------*/ 70 | 71 | /** @addtogroup ITC_Public_Functions 72 | * @{ 73 | */ 74 | 75 | /** 76 | * @brief Deinitializes the ITC registers to their default reset value. 77 | * @param None 78 | * @retval None 79 | */ 80 | void ITC_DeInit(void) 81 | { 82 | ITC->ISPR1 = ITC_SPRX_RESET_VALUE; 83 | ITC->ISPR2 = ITC_SPRX_RESET_VALUE; 84 | ITC->ISPR3 = ITC_SPRX_RESET_VALUE; 85 | ITC->ISPR4 = ITC_SPRX_RESET_VALUE; 86 | ITC->ISPR5 = ITC_SPRX_RESET_VALUE; 87 | ITC->ISPR6 = ITC_SPRX_RESET_VALUE; 88 | ITC->ISPR7 = ITC_SPRX_RESET_VALUE; 89 | ITC->ISPR8 = ITC_SPRX_RESET_VALUE; 90 | } 91 | 92 | /** 93 | * @brief Gets the interrupt software priority bits (I1, I0) value from CPU CC register. 94 | * @param None 95 | * @retval The interrupt software priority bits value. 96 | */ 97 | uint8_t ITC_GetSoftIntStatus(void) 98 | { 99 | return (uint8_t)(ITC_GetCPUCC() & CPU_CC_I1I0); 100 | } 101 | 102 | /** 103 | * @brief Gets the software priority of the specified interrupt source. 104 | * @param IrqNum : Specifies the peripheral interrupt source. 105 | * @retval ITC_PriorityLevel_TypeDef : Specifies the software priority of the interrupt source. 106 | */ 107 | ITC_PriorityLevel_TypeDef ITC_GetSoftwarePriority(ITC_Irq_TypeDef IrqNum) 108 | { 109 | uint8_t Value = 0; 110 | uint8_t Mask = 0; 111 | 112 | /* Check function parameters */ 113 | assert_param(IS_ITC_IRQ_OK((uint8_t)IrqNum)); 114 | 115 | /* Define the mask corresponding to the bits position in the SPR register */ 116 | Mask = (uint8_t)(0x03U << (((uint8_t)IrqNum % 4U) * 2U)); 117 | 118 | switch (IrqNum) 119 | { 120 | case ITC_IRQ_TLI: /* TLI software priority can be read but has no meaning */ 121 | case ITC_IRQ_AWU: 122 | case ITC_IRQ_CLK: 123 | case ITC_IRQ_PORTA: 124 | Value = (uint8_t)(ITC->ISPR1 & Mask); /* Read software priority */ 125 | break; 126 | 127 | case ITC_IRQ_PORTB: 128 | case ITC_IRQ_PORTC: 129 | case ITC_IRQ_PORTD: 130 | case ITC_IRQ_PORTE: 131 | Value = (uint8_t)(ITC->ISPR2 & Mask); /* Read software priority */ 132 | break; 133 | 134 | #if defined(STM8S208) || defined(STM8AF52Ax) 135 | case ITC_IRQ_CAN_RX: 136 | case ITC_IRQ_CAN_TX: 137 | #endif /*STM8S208 or STM8AF52Ax */ 138 | #if defined(STM8S903) || defined(STM8AF622x) 139 | case ITC_IRQ_PORTF: 140 | #endif /*STM8S903 or STM8AF622x */ 141 | case ITC_IRQ_SPI: 142 | case ITC_IRQ_TIM1_OVF: 143 | Value = (uint8_t)(ITC->ISPR3 & Mask); /* Read software priority */ 144 | break; 145 | 146 | case ITC_IRQ_TIM1_CAPCOM: 147 | #if defined (STM8S903) || defined (STM8AF622x) 148 | case ITC_IRQ_TIM5_OVFTRI: 149 | case ITC_IRQ_TIM5_CAPCOM: 150 | #else 151 | case ITC_IRQ_TIM2_OVF: 152 | case ITC_IRQ_TIM2_CAPCOM: 153 | #endif /* STM8S903 or STM8AF622x*/ 154 | case ITC_IRQ_TIM3_OVF: 155 | Value = (uint8_t)(ITC->ISPR4 & Mask); /* Read software priority */ 156 | break; 157 | 158 | case ITC_IRQ_TIM3_CAPCOM: 159 | #if defined(STM8S208) ||defined(STM8S207) || defined (STM8S007) || defined(STM8S103) || \ 160 | defined(STM8S003) ||defined(STM8S001) || defined (STM8S903) || defined (STM8AF52Ax) || defined (STM8AF62Ax) 161 | case ITC_IRQ_UART1_TX: 162 | case ITC_IRQ_UART1_RX: 163 | #endif /*STM8S208 or STM8S207 or STM8S007 or STM8S103 or STM8S003 or STM8S001 or STM8S903 or STM8AF52Ax or STM8AF62Ax */ 164 | #if defined(STM8AF622x) 165 | case ITC_IRQ_UART4_TX: 166 | case ITC_IRQ_UART4_RX: 167 | #endif /*STM8AF622x */ 168 | case ITC_IRQ_I2C: 169 | Value = (uint8_t)(ITC->ISPR5 & Mask); /* Read software priority */ 170 | break; 171 | 172 | #if defined(STM8S105) || defined(STM8S005) || defined(STM8AF626x) 173 | case ITC_IRQ_UART2_TX: 174 | case ITC_IRQ_UART2_RX: 175 | #endif /*STM8S105 or STM8AF626x*/ 176 | #if defined(STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8AF52Ax) || \ 177 | defined(STM8AF62Ax) 178 | case ITC_IRQ_UART3_TX: 179 | case ITC_IRQ_UART3_RX: 180 | case ITC_IRQ_ADC2: 181 | #endif /*STM8S208 or STM8S207 or STM8AF52Ax or STM8AF62Ax */ 182 | #if defined(STM8S105) || defined(STM8S005) || defined(STM8S103) || defined(STM8S003) || \ 183 | defined(STM8S001) || defined(STM8S903) || defined(STM8AF626x) || defined(STM8AF622x) 184 | case ITC_IRQ_ADC1: 185 | #endif /*STM8S105, STM8S005, STM8S103 or STM8S003 or STM8S001 or STM8S903 or STM8AF626x or STM8AF622x */ 186 | #if defined (STM8S903) || defined (STM8AF622x) 187 | case ITC_IRQ_TIM6_OVFTRI: 188 | #else 189 | case ITC_IRQ_TIM4_OVF: 190 | #endif /*STM8S903 or STM8AF622x */ 191 | Value = (uint8_t)(ITC->ISPR6 & Mask); /* Read software priority */ 192 | break; 193 | 194 | case ITC_IRQ_EEPROM_EEC: 195 | Value = (uint8_t)(ITC->ISPR7 & Mask); /* Read software priority */ 196 | break; 197 | 198 | default: 199 | break; 200 | } 201 | 202 | Value >>= (uint8_t)(((uint8_t)IrqNum % 4u) * 2u); 203 | 204 | return((ITC_PriorityLevel_TypeDef)Value); 205 | } 206 | 207 | /** 208 | * @brief Sets the software priority of the specified interrupt source. 209 | * @note - The modification of the software priority is only possible when 210 | * the interrupts are disabled. 211 | * - The normal behavior is to disable the interrupt before calling 212 | * this function, and re-enable it after. 213 | * - The priority level 0 cannot be set (see product specification 214 | * for more details). 215 | * @param IrqNum : Specifies the peripheral interrupt source. 216 | * @param PriorityValue : Specifies the software priority value to set, 217 | * can be a value of @ref ITC_PriorityLevel_TypeDef . 218 | * @retval None 219 | */ 220 | void ITC_SetSoftwarePriority(ITC_Irq_TypeDef IrqNum, ITC_PriorityLevel_TypeDef PriorityValue) 221 | { 222 | uint8_t Mask = 0; 223 | uint8_t NewPriority = 0; 224 | 225 | /* Check function parameters */ 226 | assert_param(IS_ITC_IRQ_OK((uint8_t)IrqNum)); 227 | assert_param(IS_ITC_PRIORITY_OK(PriorityValue)); 228 | 229 | /* Check if interrupts are disabled */ 230 | assert_param(IS_ITC_INTERRUPTS_DISABLED); 231 | 232 | /* Define the mask corresponding to the bits position in the SPR register */ 233 | /* The mask is reversed in order to clear the 2 bits after more easily */ 234 | Mask = (uint8_t)(~(uint8_t)(0x03U << (((uint8_t)IrqNum % 4U) * 2U))); 235 | 236 | /* Define the new priority to write */ 237 | NewPriority = (uint8_t)((uint8_t)(PriorityValue) << (((uint8_t)IrqNum % 4U) * 2U)); 238 | 239 | switch (IrqNum) 240 | { 241 | case ITC_IRQ_TLI: /* TLI software priority can be written but has no meaning */ 242 | case ITC_IRQ_AWU: 243 | case ITC_IRQ_CLK: 244 | case ITC_IRQ_PORTA: 245 | ITC->ISPR1 &= Mask; 246 | ITC->ISPR1 |= NewPriority; 247 | break; 248 | 249 | case ITC_IRQ_PORTB: 250 | case ITC_IRQ_PORTC: 251 | case ITC_IRQ_PORTD: 252 | case ITC_IRQ_PORTE: 253 | ITC->ISPR2 &= Mask; 254 | ITC->ISPR2 |= NewPriority; 255 | break; 256 | 257 | #if defined(STM8S208) || defined(STM8AF52Ax) 258 | case ITC_IRQ_CAN_RX: 259 | case ITC_IRQ_CAN_TX: 260 | #endif /*STM8S208 or STM8AF52Ax */ 261 | #if defined(STM8S903) || defined(STM8AF622x) 262 | case ITC_IRQ_PORTF: 263 | #endif /*STM8S903 or STM8AF622x */ 264 | case ITC_IRQ_SPI: 265 | case ITC_IRQ_TIM1_OVF: 266 | ITC->ISPR3 &= Mask; 267 | ITC->ISPR3 |= NewPriority; 268 | break; 269 | 270 | case ITC_IRQ_TIM1_CAPCOM: 271 | #if defined(STM8S903) || defined(STM8AF622x) 272 | case ITC_IRQ_TIM5_OVFTRI: 273 | case ITC_IRQ_TIM5_CAPCOM: 274 | #else 275 | case ITC_IRQ_TIM2_OVF: 276 | case ITC_IRQ_TIM2_CAPCOM: 277 | #endif /*STM8S903 or STM8AF622x */ 278 | case ITC_IRQ_TIM3_OVF: 279 | ITC->ISPR4 &= Mask; 280 | ITC->ISPR4 |= NewPriority; 281 | break; 282 | 283 | case ITC_IRQ_TIM3_CAPCOM: 284 | #if defined(STM8S208) ||defined(STM8S207) || defined (STM8S007) || defined(STM8S103) || \ 285 | defined(STM8S001) ||defined(STM8S003) ||defined(STM8S903) || defined (STM8AF52Ax) || defined (STM8AF62Ax) 286 | case ITC_IRQ_UART1_TX: 287 | case ITC_IRQ_UART1_RX: 288 | #endif /*STM8S208 or STM8S207 or STM8S007 or STM8S103 or STM8S003 or STM8S001 or STM8S903 or STM8AF52Ax or STM8AF62Ax */ 289 | #if defined(STM8AF622x) 290 | case ITC_IRQ_UART4_TX: 291 | case ITC_IRQ_UART4_RX: 292 | #endif /*STM8AF622x */ 293 | case ITC_IRQ_I2C: 294 | ITC->ISPR5 &= Mask; 295 | ITC->ISPR5 |= NewPriority; 296 | break; 297 | 298 | #if defined(STM8S105) || defined(STM8S005) || defined(STM8AF626x) 299 | case ITC_IRQ_UART2_TX: 300 | case ITC_IRQ_UART2_RX: 301 | #endif /*STM8S105 or STM8AF626x */ 302 | 303 | #if defined(STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8AF52Ax) || \ 304 | defined(STM8AF62Ax) 305 | case ITC_IRQ_UART3_TX: 306 | case ITC_IRQ_UART3_RX: 307 | case ITC_IRQ_ADC2: 308 | #endif /*STM8S208 or STM8S207 or STM8AF52Ax or STM8AF62Ax */ 309 | 310 | #if defined(STM8S105) || defined(STM8S005) || defined(STM8S103) || defined(STM8S003) || \ 311 | defined(STM8S001) || defined(STM8S903) || defined(STM8AF626x) || defined (STM8AF622x) 312 | case ITC_IRQ_ADC1: 313 | #endif /*STM8S105, STM8S005, STM8S103 or STM8S003 or STM8S001 or STM8S903 or STM8AF626x or STM8AF622x */ 314 | 315 | #if defined (STM8S903) || defined (STM8AF622x) 316 | case ITC_IRQ_TIM6_OVFTRI: 317 | #else 318 | case ITC_IRQ_TIM4_OVF: 319 | #endif /* STM8S903 or STM8AF622x */ 320 | ITC->ISPR6 &= Mask; 321 | ITC->ISPR6 |= NewPriority; 322 | break; 323 | 324 | case ITC_IRQ_EEPROM_EEC: 325 | ITC->ISPR7 &= Mask; 326 | ITC->ISPR7 |= NewPriority; 327 | break; 328 | 329 | default: 330 | break; 331 | } 332 | } 333 | 334 | /** 335 | * @} 336 | */ 337 | 338 | /** 339 | * @} 340 | */ 341 | 342 | 343 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 344 | -------------------------------------------------------------------------------- /NetworkModule/STM8S_StdPeriph_Driver/src/stm8s_iwdg.c: -------------------------------------------------------------------------------- 1 | /** 2 | ******************************************************************************** 3 | * @file stm8s_iwdg.c 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all the functions for the IWDG peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm8s_iwdg.h" 30 | 31 | /* Private define ------------------------------------------------------------*/ 32 | /* Private macro -------------------------------------------------------------*/ 33 | /* Private variables ---------------------------------------------------------*/ 34 | /* Private function prototypes -----------------------------------------------*/ 35 | /* Private functions ---------------------------------------------------------*/ 36 | /* Public functions ----------------------------------------------------------*/ 37 | 38 | /** @addtogroup IWDG_Public_Functions 39 | * @{ 40 | */ 41 | 42 | /** 43 | * @brief Enables or disables write access to Prescaler and Reload registers. 44 | * @param IWDG_WriteAccess : New state of write access to Prescaler and Reload 45 | * registers. This parameter can be a value of @ref IWDG_WriteAccess_TypeDef. 46 | * @retval None 47 | */ 48 | void IWDG_WriteAccessCmd(IWDG_WriteAccess_TypeDef IWDG_WriteAccess) 49 | { 50 | /* Check the parameters */ 51 | assert_param(IS_IWDG_WRITEACCESS_MODE_OK(IWDG_WriteAccess)); 52 | 53 | IWDG->KR = (uint8_t)IWDG_WriteAccess; /* Write Access */ 54 | } 55 | 56 | /** 57 | * @brief Sets IWDG Prescaler value. 58 | * @note Write access should be enabled 59 | * @param IWDG_Prescaler : Specifies the IWDG Prescaler value. 60 | * This parameter can be a value of @ref IWDG_Prescaler_TypeDef. 61 | * @retval None 62 | */ 63 | void IWDG_SetPrescaler(IWDG_Prescaler_TypeDef IWDG_Prescaler) 64 | { 65 | /* Check the parameters */ 66 | assert_param(IS_IWDG_PRESCALER_OK(IWDG_Prescaler)); 67 | 68 | IWDG->PR = (uint8_t)IWDG_Prescaler; 69 | } 70 | 71 | /** 72 | * @brief Sets IWDG Reload value. 73 | * @note Write access should be enabled 74 | * @param IWDG_Reload : Reload register value. 75 | * This parameter must be a number between 0 and 0xFF. 76 | * @retval None 77 | */ 78 | void IWDG_SetReload(uint8_t IWDG_Reload) 79 | { 80 | IWDG->RLR = IWDG_Reload; 81 | } 82 | 83 | /** 84 | * @brief Reloads IWDG counter 85 | * @note Write access should be enabled 86 | * @param None 87 | * @retval None 88 | */ 89 | void IWDG_ReloadCounter(void) 90 | { 91 | IWDG->KR = IWDG_KEY_REFRESH; 92 | } 93 | 94 | /** 95 | * @brief Enables IWDG. 96 | * @param None 97 | * @retval None 98 | */ 99 | void IWDG_Enable(void) 100 | { 101 | IWDG->KR = IWDG_KEY_ENABLE; 102 | } 103 | 104 | /** 105 | * @} 106 | */ 107 | 108 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 109 | -------------------------------------------------------------------------------- /NetworkModule/STM8S_StdPeriph_Driver/src/stm8s_rst.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8s_rst.c 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all the functions for the RST peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | 30 | #include "stm8s_rst.h" 31 | 32 | /** @addtogroup STM8S_StdPeriph_Driver 33 | * @{ 34 | */ 35 | /* Private typedef -----------------------------------------------------------*/ 36 | /* Private define ------------------------------------------------------------*/ 37 | /* Private macro -------------------------------------------------------------*/ 38 | /* Private variables ---------------------------------------------------------*/ 39 | /* Private function prototypes -----------------------------------------------*/ 40 | /* Private Constants ---------------------------------------------------------*/ 41 | /* Public functions ----------------------------------------------------------*/ 42 | /** 43 | * @addtogroup RST_Public_Functions 44 | * @{ 45 | */ 46 | 47 | 48 | /** 49 | * @brief Checks whether the specified RST flag is set or not. 50 | * @param RST_Flag : specify the reset flag to check. 51 | * This parameter can be a value of @ref RST_Flag_TypeDef. 52 | * @retval FlagStatus: status of the given RST flag. 53 | */ 54 | FlagStatus RST_GetFlagStatus(RST_Flag_TypeDef RST_Flag) 55 | { 56 | /* Check the parameters */ 57 | assert_param(IS_RST_FLAG_OK(RST_Flag)); 58 | 59 | /* Get flag status */ 60 | return((FlagStatus)(((uint8_t)(RST->SR & RST_Flag) == (uint8_t)0x00) ? RESET : SET)); 61 | } 62 | 63 | /** 64 | * @brief Clears the specified RST flag. 65 | * @param RST_Flag : specify the reset flag to clear. 66 | * This parameter can be a value of @ref RST_Flag_TypeDef. 67 | * @retval None 68 | */ 69 | void RST_ClearFlag(RST_Flag_TypeDef RST_Flag) 70 | { 71 | /* Check the parameters */ 72 | assert_param(IS_RST_FLAG_OK(RST_Flag)); 73 | 74 | RST->SR = (uint8_t)RST_Flag; 75 | } 76 | 77 | /** 78 | * @} 79 | */ 80 | 81 | /** 82 | * @} 83 | */ 84 | 85 | 86 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 87 | -------------------------------------------------------------------------------- /NetworkModule/STM8S_StdPeriph_Driver/src/stm8s_tim1.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nielsonm236/NetMod-ServerApp/1700e7a9aa5b377ca4deb89e6a47fe72e026d3f7/NetworkModule/STM8S_StdPeriph_Driver/src/stm8s_tim1.c -------------------------------------------------------------------------------- /NetworkModule/STM8S_StdPeriph_Driver/src/stm8s_tim2.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nielsonm236/NetMod-ServerApp/1700e7a9aa5b377ca4deb89e6a47fe72e026d3f7/NetworkModule/STM8S_StdPeriph_Driver/src/stm8s_tim2.c -------------------------------------------------------------------------------- /NetworkModule/STM8S_StdPeriph_Driver/src/stm8s_tim3.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nielsonm236/NetMod-ServerApp/1700e7a9aa5b377ca4deb89e6a47fe72e026d3f7/NetworkModule/STM8S_StdPeriph_Driver/src/stm8s_tim3.c -------------------------------------------------------------------------------- /NetworkModule/STM8S_StdPeriph_Driver/src/stm8s_tim4.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nielsonm236/NetMod-ServerApp/1700e7a9aa5b377ca4deb89e6a47fe72e026d3f7/NetworkModule/STM8S_StdPeriph_Driver/src/stm8s_tim4.c -------------------------------------------------------------------------------- /NetworkModule/STM8S_StdPeriph_Driver/src/stm8s_tim5.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nielsonm236/NetMod-ServerApp/1700e7a9aa5b377ca4deb89e6a47fe72e026d3f7/NetworkModule/STM8S_StdPeriph_Driver/src/stm8s_tim5.c -------------------------------------------------------------------------------- /NetworkModule/STM8S_StdPeriph_Driver/src/stm8s_tim6.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nielsonm236/NetMod-ServerApp/1700e7a9aa5b377ca4deb89e6a47fe72e026d3f7/NetworkModule/STM8S_StdPeriph_Driver/src/stm8s_tim6.c -------------------------------------------------------------------------------- /NetworkModule/STM8S_StdPeriph_Driver/src/stm8s_uart1.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nielsonm236/NetMod-ServerApp/1700e7a9aa5b377ca4deb89e6a47fe72e026d3f7/NetworkModule/STM8S_StdPeriph_Driver/src/stm8s_uart1.c -------------------------------------------------------------------------------- /NetworkModule/STM8S_StdPeriph_Driver/src/stm8s_uart2.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nielsonm236/NetMod-ServerApp/1700e7a9aa5b377ca4deb89e6a47fe72e026d3f7/NetworkModule/STM8S_StdPeriph_Driver/src/stm8s_uart2.c -------------------------------------------------------------------------------- /NetworkModule/STM8S_StdPeriph_Driver/src/stm8s_uart4.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nielsonm236/NetMod-ServerApp/1700e7a9aa5b377ca4deb89e6a47fe72e026d3f7/NetworkModule/STM8S_StdPeriph_Driver/src/stm8s_uart4.c -------------------------------------------------------------------------------- /NetworkModule/STM8S_StdPeriph_Driver/src/stm8s_wwdg.c: -------------------------------------------------------------------------------- 1 | /** 2 | ******************************************************************************** 3 | * @file stm8s_wwdg.c 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all the functions for the WWDG peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm8s_wwdg.h" 30 | 31 | /** @addtogroup STM8S_StdPeriph_Driver 32 | * @{ 33 | */ 34 | /* Private define ------------------------------------------------------------*/ 35 | #define BIT_MASK ((uint8_t)0x7F) 36 | /* Private macro -------------------------------------------------------------*/ 37 | /* Private variables ---------------------------------------------------------*/ 38 | /* Private function prototypes -----------------------------------------------*/ 39 | /* Private functions ---------------------------------------------------------*/ 40 | 41 | /** @addtogroup WWDG_Public_Functions 42 | * @{ 43 | */ 44 | 45 | /** 46 | * @brief Initializes the WWDG peripheral. 47 | * This function set Window Register = WindowValue, Counter Register 48 | * according to Counter and \b ENABLE \b WWDG 49 | * @param Counter : WWDG counter value 50 | * @param WindowValue : specifies the WWDG Window Register, range is 0x00 to 0x7F. 51 | * @retval None 52 | */ 53 | void WWDG_Init(uint8_t Counter, uint8_t WindowValue) 54 | { 55 | /* Check the parameters */ 56 | assert_param(IS_WWDG_WINDOWLIMITVALUE_OK(WindowValue)); 57 | 58 | WWDG->WR = WWDG_WR_RESET_VALUE; 59 | WWDG->CR = (uint8_t)((uint8_t)(WWDG_CR_WDGA | WWDG_CR_T6) | (uint8_t)Counter); 60 | WWDG->WR = (uint8_t)((uint8_t)(~WWDG_CR_WDGA) & (uint8_t)(WWDG_CR_T6 | WindowValue)); 61 | } 62 | 63 | /** 64 | * @brief Refreshes the WWDG peripheral. 65 | * @param Counter : WWDG Counter Value 66 | * This parameter must be a number between 0x40 and 0x7F. 67 | * @retval None 68 | */ 69 | void WWDG_SetCounter(uint8_t Counter) 70 | { 71 | /* Check the parameters */ 72 | assert_param(IS_WWDG_COUNTERVALUE_OK(Counter)); 73 | 74 | /* Write to T[6:0] bits to configure the counter value, no need to do 75 | a read-modify-write; writing a 0 to WDGA bit does nothing */ 76 | WWDG->CR = (uint8_t)(Counter & (uint8_t)BIT_MASK); 77 | } 78 | 79 | /** 80 | * @brief Gets the WWDG Counter Value. 81 | * This value could be used to check if WWDG is in the window, where 82 | * refresh is allowed. 83 | * @param None 84 | * @retval WWDG Counter Value 85 | */ 86 | uint8_t WWDG_GetCounter(void) 87 | { 88 | return(WWDG->CR); 89 | } 90 | 91 | /** 92 | * @brief Generates immediate WWDG RESET. 93 | * @param None 94 | * @retval None 95 | */ 96 | void WWDG_SWReset(void) 97 | { 98 | WWDG->CR = WWDG_CR_WDGA; /* Activate WWDG, with clearing T6 */ 99 | } 100 | 101 | /** 102 | * @brief Sets the WWDG window value. 103 | * @param WindowValue: specifies the window value to be compared to the 104 | * downcounter. 105 | * This parameter value must be lower than 0x80. 106 | * @retval None 107 | */ 108 | void WWDG_SetWindowValue(uint8_t WindowValue) 109 | { 110 | /* Check the parameters */ 111 | assert_param(IS_WWDG_WINDOWLIMITVALUE_OK(WindowValue)); 112 | 113 | WWDG->WR = (uint8_t)((uint8_t)(~WWDG_CR_WDGA) & (uint8_t)(WWDG_CR_T6 | WindowValue)); 114 | } 115 | 116 | /** 117 | * @} 118 | */ 119 | 120 | /** 121 | * @} 122 | */ 123 | 124 | 125 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 126 | -------------------------------------------------------------------------------- /NetworkModule/STM8S_StdPeriph_Driver/stm8s-a_stdperiph_drivers_um.chm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nielsonm236/NetMod-ServerApp/1700e7a9aa5b377ca4deb89e6a47fe72e026d3f7/NetworkModule/STM8S_StdPeriph_Driver/stm8s-a_stdperiph_drivers_um.chm -------------------------------------------------------------------------------- /NetworkModule/Spi.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Source file containing functions and pre-compiler definitions 3 | * Note that this code module is not optimized on speed! 4 | * 5 | * Author: Simon Kueppers 6 | * Email: simon.kueppers@web.de 7 | * Homepage: http://klinkerstein.m-faq.de 8 | * 9 | This program is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program. If not, see . 21 | 22 | Copyright 2008 Simon Kueppers 23 | * 24 | */ 25 | 26 | /* Modifications 2020-2022 Michael Nielson 27 | * Adapted for STM8S005 processor, ENC28J60 Ethernet Controller, 28 | * Web_Relay_Con V2.0 HW-584, and compilation with Cosmic tool set. 29 | * Author: Michael Nielson 30 | * Email: nielsonm.projects@gmail.com 31 | This program is free software: you can redistribute it and/or modify 32 | it under the terms of the GNU General Public License as published by 33 | the Free Software Foundation, either version 3 of the License, or 34 | (at your option) any later version. 35 | 36 | This program is distributed in the hope that it will be useful, but 37 | WITHOUT ANY WARRANTY; without even the implied warranty of 38 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 39 | General Public License for more details. 40 | 41 | See GNU General Public License at . 42 | 43 | Copyright 2022 Michael Nielson 44 | */ 45 | 46 | 47 | // All includes are in main.h 48 | #include "main.h" 49 | 50 | 51 | void spi_init(void) 52 | { 53 | int i; 54 | 55 | // Set specific GPIO pins to initial values for use as SPI bit 56 | // bang. Hold ENC28J60 in reset until SPI pins are set up. 57 | 58 | // The GPIO pins used for SPI bit bang are: 59 | // Port C 60 | // Bit 5 - Pin 30 - Input - ENC28J60 -INT (not used) 61 | // Bit 4 - Pin 29 - Input - ENC28J60 SO 62 | // Bit 3 - Pin 28 - Output - ENC28J60 SI 63 | // Bit 2 - Pin 27 - Output - ENC28J60 SCK 64 | // Bit 1 - Pin 26 - Output - ENC28J60 -CS 65 | // Port E 66 | // Bit 5 - Pin 25 - Output - ENC28J60 -RESET 67 | 68 | // At initialization time (just after reset) all output bits are 0. 69 | // Some need to be set to 1. The ENC28J60 should already be held in 70 | // reset but we will make sure here. 71 | PC_ODR |= (uint8_t)0x02; // 0b00000010 SI=0, SCK=0, -CS=1 72 | PE_ODR &= (uint8_t)(~0x20); // 0b00100000 -RESET=0 73 | 74 | // wait 250ms 75 | for(i=0; i<5; i++) wait_timer((uint16_t)50000); // wait 250ms 76 | 77 | // Release ENC28J60 from reset 78 | PE_ODR |= (uint8_t)0x20; // 0b00100000 -RESET=1 79 | 80 | // wait 50ms 81 | wait_timer((uint16_t)50000); // Wait 50ms 82 | 83 | // From this point forward the -RESET output and -INT input should 84 | // not be needed. 85 | // Use the following functions to work with the SPI output pins 86 | // PC_ODR |= (uint8_t)0x02; // -CS high 87 | // PC_ODR &= (uint8_t)(~0x02); // -CS low 88 | // PC_ODR |= (uint8_t)0x04; // SCK high 89 | // PC_ODR &= (uint8_t)(~0x04); // SCK low 90 | // PC_ODR |= (uint8_t)0x08; // SPI SO high 91 | // PC_ODR &= (uint8_t)(~0x08); // SPI SO low 92 | // SPI Input pin 93 | // if (PC_IDR & (uint8_t)(~0x10))==1 databit = 1; 94 | // else databit = 0; 95 | // 96 | } 97 | 98 | 99 | void SpiWriteByte(uint8_t nByte) 100 | { 101 | // nByte is the data to be sent 102 | // MSB is sent first 103 | uint8_t bitnum = (uint8_t)0x80; // Point at MSB 104 | while(bitnum != 0) { 105 | if (nByte & bitnum) PC_ODR |= (uint8_t)0x08; // If bit is 1 then 106 | // SPI SO (ENC28J60 SI) high 107 | else PC_ODR &= (uint8_t)(~0x08); // else SPI SO low 108 | 109 | // nop(); 110 | // PC_ODR |= (uint8_t)0x04; // SCK high 111 | // nop(); 112 | // PC_ODR &= (uint8_t)(~0x04); // SCK low 113 | SPI_clock_pulse(); 114 | 115 | bitnum = (uint8_t)(bitnum >> 1); // Shift bitnum right one place 116 | // Once bitnum has shifted to equal 0 117 | // we know all 8 bits have been sent 118 | } 119 | PC_ODR &= (uint8_t)(~0x08); // SPI SO low on exit 120 | } 121 | 122 | 123 | void SpiWriteChunk(const uint8_t* pChunk, uint16_t nBytes) 124 | { 125 | uint8_t bitnum; 126 | uint8_t OutByte; 127 | 128 | while (nBytes--) { 129 | bitnum = (uint8_t)0x80; // Point at MSB 130 | OutByte = *pChunk++; 131 | 132 | while(bitnum != 0) { 133 | if (OutByte & bitnum) PC_ODR |= (uint8_t)0x08; // If bit is 1 then 134 | // SPI SO (ENC28J60 SI) high 135 | else PC_ODR &= (uint8_t)(~0x08); // else SPI SO low 136 | 137 | // nop(); 138 | // PC_ODR |= (uint8_t)0x04; // SCK high 139 | // nop(); 140 | // PC_ODR &= (uint8_t)(~0x04); // SCK low 141 | SPI_clock_pulse(); 142 | 143 | bitnum = (uint8_t)(bitnum >> 1); // Shift bitnum right one place 144 | // Once bitnum has shifted to equal 0 145 | // we know all 8 bits have been sent 146 | } 147 | } 148 | PC_ODR &= (uint8_t)(~0x08); // SPI SO low on exit 149 | } 150 | 151 | 152 | uint8_t SpiReadByte(void) 153 | { 154 | // Reading a byte works by sending a dummy byte. The ENC28J60 will 155 | // ignore the dummy byte, and the clocks used to send the dummy byte 156 | // are used to transfer the read byte. 157 | // MSB is received first 158 | uint8_t bitnum = (uint8_t)0x80; // Point at MSB 159 | uint8_t InByte = 0; 160 | while(bitnum != 0) { 161 | // Read SI and set appropriate bit in InByte 162 | // Data is already there to be read due to previous command write 163 | if (PC_IDR & (uint8_t)0x10) InByte |= bitnum; // SPI incoming bit = 1 164 | else InByte &= (uint8_t)(~bitnum); // SPI incoming bit = 0 165 | 166 | // PC_ODR |= (uint8_t)0x04; // SCK high 167 | // nop(); 168 | // PC_ODR &= (uint8_t)(~0x04); // SCK low 169 | SPI_clock_pulse(); 170 | 171 | bitnum = (uint8_t)(bitnum >> 1); // Shift bitnum right one place 172 | // Once bitnum has shifted to equal 0 173 | // we know all 8 bits have been collected 174 | } 175 | return InByte; 176 | } 177 | 178 | 179 | void SpiReadChunk(uint8_t* pChunk, uint16_t nBytes) 180 | { 181 | // Reading data works by sending dummy bytes. The ENC28J60 will 182 | // ignore the dummy bytes, and the clocks used to send the dummy bytes 183 | // are used to collect the read bytes. 184 | // MSB is received first 185 | uint8_t bitnum; 186 | uint8_t InByte; 187 | 188 | PC_ODR &= (uint8_t)(~0x08); // SO low 189 | 190 | while (nBytes--) { 191 | bitnum = (uint8_t)0x80; // Point at MSBif 192 | InByte = 0; 193 | while(bitnum != 0) { 194 | // Read SI and set appropriate bit in InByte 195 | // Data is already there to be read due to previous command write 196 | // or byte read 197 | if (PC_IDR & (uint8_t)0x10) InByte |= bitnum; // SPI incoming bit = 1 198 | else InByte &= (uint8_t)(~bitnum); // SPI incoming bit = 0 199 | 200 | // PC_ODR |= (uint8_t)0x04; // SCK high 201 | // nop(); 202 | // PC_ODR &= (uint8_t)(~0x04); // SCK low 203 | SPI_clock_pulse(); 204 | 205 | bitnum = (uint8_t)(bitnum >> 1); // Shift bitnum right one place 206 | // Once bitnum has shifted to equal 0 207 | // we know all 8 bits have been collected 208 | } 209 | *pChunk++ = InByte; // Save byte in the buffer 210 | } 211 | } 212 | 213 | void SPI_clock_pulse(void) 214 | { 215 | nop(); 216 | PC_ODR |= (uint8_t)0x04; // SCK high 217 | nop(); 218 | PC_ODR &= (uint8_t)(~0x04); // SCK low 219 | } 220 | -------------------------------------------------------------------------------- /NetworkModule/Spi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Defines and function-declarations regarding the Spi Code Module 3 | * which is used by the ENC28J60 Code Module 4 | * 5 | * Author: Simon Kueppers 6 | * Email: simon.kueppers@web.de 7 | * Homepage: http://klinkerstein.m-faq.de 8 | * 9 | This program is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program. If not, see . 21 | 22 | Copyright 2008 Simon Kueppers 23 | * 24 | */ 25 | 26 | /* Modifications 2020-2022 Michael Nielson 27 | * Adapted for STM8S005 processor, ENC28J60 Ethernet Controller, 28 | * Web_Relay_Con V2.0 HW-584, and compilation with Cosmic tool set. 29 | * Author: Michael Nielson 30 | * Email: nielsonm.projects@gmail.com 31 | This program is free software: you can redistribute it and/or modify 32 | it under the terms of the GNU General Public License as published by 33 | the Free Software Foundation, either version 3 of the License, or 34 | (at your option) any later version. 35 | 36 | This program is distributed in the hope that it will be useful, but 37 | WITHOUT ANY WARRANTY; without even the implied warranty of 38 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 39 | General Public License for more details. 40 | 41 | See GNU General Public License at . 42 | 43 | Copyright 2022 Michael Nielson 44 | */ 45 | 46 | 47 | 48 | 49 | #ifndef SPI_H_ 50 | #define SPI_H_ 51 | 52 | #include 53 | 54 | void spi_init(void); 55 | void SpiWriteByte(uint8_t nByte); 56 | void SpiWriteChunk(const uint8_t* pChunk, uint16_t nBytes); 57 | uint8_t SpiReadByte(void); 58 | void SpiReadChunk(uint8_t* pChunk, uint16_t nBytes); 59 | void SPI_clock_pulse(void); 60 | 61 | #endif /*SPI_H_*/ 62 | -------------------------------------------------------------------------------- /NetworkModule/UART.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nielsonm236/NetMod-ServerApp/1700e7a9aa5b377ca4deb89e6a47fe72e026d3f7/NetworkModule/UART.c -------------------------------------------------------------------------------- /NetworkModule/UART.h: -------------------------------------------------------------------------------- 1 | /* 2021 Michael Nielson 2 | * Adapted for STM8S005 processor, ENC28J60 Ethernet Controller, 3 | * Web_Relay_Con V2.0 HW-584, and compilation with Cosmic tool set. 4 | * Author: Michael Nielson 5 | * Email: nielsonm.projects@gmail.com 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, but 12 | WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | General Public License for more details. 15 | 16 | See GNU General Public License at . 17 | 18 | Copyright 2021 Michael Nielson 19 | */ 20 | 21 | 22 | #ifndef __UART_H__ 23 | #define __UART_H__ 24 | 25 | 26 | void InitializeUART(void); 27 | void UARTPrintf(char *message); 28 | 29 | 30 | 31 | #endif /* __UART_H__ */ 32 | -------------------------------------------------------------------------------- /NetworkModule/bme280.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nielsonm236/NetMod-ServerApp/1700e7a9aa5b377ca4deb89e6a47fe72e026d3f7/NetworkModule/bme280.c -------------------------------------------------------------------------------- /NetworkModule/httpd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Important defines and function prototypes for the HTTP Daemon Implementation 3 | * 4 | * Author: Simon Kueppers 5 | * Email: simon.kueppers@web.de 6 | * Homepage: http://klinkerstein.m-faq.de 7 | * 8 | This program is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | 21 | Copyright 2008 Simon Kueppers 22 | * 23 | */ 24 | 25 | /* Modifications 2020-2022 Michael Nielson 26 | * Adapted for STM8S005 processor, ENC28J60 Ethernet Controller, 27 | * Web_Relay_Con V2.0 HW-584, and compilation with Cosmic tool set. 28 | * Author: Michael Nielson 29 | * Email: nielsonm.projects@gmail.com 30 | This program is free software: you can redistribute it and/or modify 31 | it under the terms of the GNU General Public License as published by 32 | the Free Software Foundation, either version 3 of the License, or 33 | (at your option) any later version. 34 | 35 | This program is distributed in the hope that it will be useful, but 36 | WITHOUT ANY WARRANTY; without even the implied warranty of 37 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 38 | General Public License for more details. 39 | 40 | See GNU General Public License at . 41 | 42 | Copyright 2022 Michael Nielson 43 | */ 44 | 45 | 46 | #include 47 | 48 | 49 | 50 | #ifndef HTTPD_H_ 51 | #define HTTPD_H_ 52 | 53 | #define SEEK_CONTENT_INFO 0 54 | #define SEEK_FIRST_RNRN 1 55 | #define SEEK_SECOND_RNRN 2 56 | #define FOUND_CONTENT_INFO 4 57 | 58 | #define UPGRADE_OK 0 59 | #define UPGRADE_FAIL_FILE_READ_CHECKSUM 1 60 | #define UPGRADE_FAIL_EEPROM_MISCOMPARE 2 61 | #define STRING_EEPROM_MISCOMPARE 3 62 | #define UPGRADE_FAIL_NOT_SREC 5 63 | #define UPGRADE_FAIL_INVALID_FILETYPE 6 64 | #define UPGRADE_FAIL_TRUNCATED_FILE 7 65 | 66 | #define FILETYPE_SEARCH 0 67 | #define FILETYPE_PROGRAM 1 68 | #define FILETYPE_STRING 2 69 | 70 | // These defines locate the webpage content and webpage sizes stored in the 71 | // Strings region of the I2C EEPROM (EEPROM Region 2). In order to allow a 72 | // String File to be read using the same code used for reading Program Files 73 | // the code expects addresses starting at 0x8000, however in the I2C EEPROM 74 | // itself the base address for Strings is 0x0000. 75 | 76 | #define MQTT_WEBPAGE_IOCONTROL_ADDRESS_LOCATION 0x0040 77 | #define MQTT_WEBPAGE_CONFIGURATION_ADDRESS_LOCATION 0x0042 78 | #define MQTT_DOMO_WEBPAGE_IOCONTROL_ADDRESS_LOCATION 0x0044 79 | #define MQTT_DOMO_WEBPAGE_CONFIGURATION_ADDRESS_LOCATION 0x0046 80 | #define BROWSER_ONLY_WEBPAGE_IOCONTROL_ADDRESS_LOCATION 0x0048 81 | #define BROWSER_ONLY_WEBPAGE_CONFIGURATION_ADDRESS_LOCATION 0x004a 82 | #define MQTT_WEBPAGE_PCF8574_IOCONTROL_ADDRESS_LOCATION 0x004c 83 | #define MQTT_WEBPAGE_PCF8574_CONFIGURATION_ADDRESS_LOCATION 0x004e 84 | #define BROWSER_ONLY_WEBPAGE_PCF8574_IOCONTROL_ADDRESS_LOCATION 0x0050 85 | #define BROWSER_ONLY_WEBPAGE_PCF8574_CONFIGURATION_ADDRESS_LOCATION 0x0052 86 | #define WEBPAGE_LOGIN_ADDRESS_LOCATION 0x0054 87 | #define WEBPAGE_SET_PASSPHRASE_ADDRESS_LOCATION 0x0056 88 | #define WEBPAGE_LOADUPLOADER_ADDRESS_LOCATION 0x0058 89 | 90 | #define MQTT_WEBPAGE_IOCONTROL_SIZE_LOCATION 0x0080 91 | #define MQTT_WEBPAGE_CONFIGURATION_SIZE_LOCATION 0x0082 92 | #define MQTT_DOMO_WEBPAGE_IOCONTROL_SIZE_LOCATION 0x0084 93 | #define MQTT_DOMO_WEBPAGE_CONFIGURATION_SIZE_LOCATION 0x0086 94 | #define BROWSER_ONLY_WEBPAGE_IOCONTROL_SIZE_LOCATION 0x0088 95 | #define BROWSER_ONLY_WEBPAGE_CONFIGURATION_SIZE_LOCATION 0x008a 96 | #define MQTT_WEBPAGE_PCF8574_IOCONTROL_SIZE_LOCATION 0x008c 97 | #define MQTT_WEBPAGE_PCF8574_CONFIGURATION_SIZE_LOCATION 0x008e 98 | #define BROWSER_ONLY_WEBPAGE_PCF8574_IOCONTROL_SIZE_LOCATION 0x0090 99 | #define BROWSER_ONLY_WEBPAGE_PCF8574_CONFIGURATION_SIZE_LOCATION 0x0092 100 | #define WEBPAGE_LOGIN_SIZE_LOCATION 0x0094 101 | #define WEBPAGE_SET_PASSPHRASE_SIZE_LOCATION 0x0096 102 | #define WEBPAGE_LOADUPLOADER_SIZE_LOCATION 0x0098 103 | 104 | // The MQTT_WEBPAGE_IOCONTROL webpage is the first webpage string stored in 105 | // I2C EEPROM (EEPROM Region 2) and starts at 0x0100. The .sx file that 106 | // provides the strings to be stored in EEPROM Region 2 has the strings 107 | // start with SREC address 0x8100 rather than 0x0100. This is so that the 108 | // code in httpd.c that uploads Firmware .sx files can be the same code that 109 | // uploads String .sx files. As each string is stored the next string starts 110 | // at the next 128 byte address in EEPROM 2. The current map allows ADDRESS 111 | // and SIZE pointers for 32 strings (32 webpages). 112 | // Note: In addition to the "webpage strings" stored in I2C EEPROM Region 2 113 | // some other variables associated implementation of the PCF8574 IO pin 114 | // expander are also stored in I2C EEPROM Region 2. Those variables define 115 | // the IO Names, IO Timers, and pin_control valies for the PCF8574 IO pins. 116 | // See the main.h file for more information. 117 | 118 | 119 | struct tHttpD 120 | { 121 | uint8_t nState; 122 | const uint8_t* pData; 123 | uint16_t nDataLeft; 124 | uint8_t nNewlines; 125 | uint16_t nParseLeft; 126 | uint8_t ParseCmd; 127 | uint8_t ParseNum; 128 | uint8_t ParseState; 129 | uint16_t nPrevBytes; 130 | uint8_t current_webpage; 131 | uint8_t insertion_index; 132 | int structID; 133 | 134 | // nState Tracks the parsing state of a POST and subsequent 135 | // response to the Browser 136 | // pData Pointer to the webpage data to be transmitted 137 | // nDataLeft Tracks the data remaining to be transmitted from a 138 | // page pointed to by pData 139 | // nNewlines Tracks discovery of the \r\n\r\n sequence in a 140 | // received POST 141 | // nParseLeft Tracks parsing of POST data 142 | // ParseCmd Contains the Cmd part of a variable sequence when 143 | // parsing a POST, and used to store the Mode part of 144 | // a transmit sequence when bridging a packet sequence 145 | // when transmitting a webpage. 146 | // ParseNum Contains the Num parter of a variable sequence when 147 | // parsing a POST, and used to store the Num part of 148 | // a transmit sequence when bridging a packet sequence 149 | // when transmitting a webpage. 150 | // ParseState Tracks the state of a POST parsing process to allow 151 | // bridging of TCP Fragmentation. 152 | // nPrevBytes Used in the case of uip_rexmit to determine if the 153 | // header needs to be retransmitted. 154 | // current_webpage Tracks the current webpage being displayed in the GUI. 155 | // insertion_index Tracks the position in a "long string" being trans- 156 | // mitted in a webpage to allow bridging of TCP Frag- 157 | // mentation. 158 | // structID This was meant to be a temporary debug value to help 159 | // sort out when connections were being used. It will be 160 | // left in the code for now as it proved to be very 161 | // useful. 162 | }; 163 | 164 | 165 | void httpd_diagnostic(void); 166 | 167 | void HttpDStringInit(void); 168 | void init_off_board_string_pointers(struct tHttpD* pSocket); 169 | uint16_t read_two_bytes(void); 170 | void read_httpd_diagnostic_bytes(void); 171 | uint16_t adjust_template_size(struct tHttpD* pSocket); 172 | 173 | static uint16_t CopyHttpHeader(uint8_t* pBuffer, uint16_t nDataLen, uint8_t header_type); 174 | static uint16_t CopyHttpData(uint8_t* pBuffer, 175 | const char** ppData, 176 | uint16_t* pDataLeft, 177 | uint16_t nMaxBytes, 178 | struct tHttpD* pSocket); 179 | void create_sensor_ID(int8_t sensor); 180 | char *show_temperature_string(char * pBuffer, uint8_t nParsedNum); 181 | char *show_temperature_string_short_form(char *pBuffer, uint8_t nParsedNum); 182 | char *show_BME280_PTH_string(char *pBuffer); 183 | char *show_INA226_CVW_string(char *pBuffer); 184 | void INAint32ToString(int32_t fVal); 185 | char *show_space_or_minus(int32_t value, char *pBuffer); 186 | 187 | void emb_itoa(uint32_t num, char* str, uint8_t base, uint8_t pad); 188 | int hex2int(char ch); 189 | uint8_t two_hex2int(char chmsb, char chlsb); 190 | uint8_t int2nibble(uint8_t j); 191 | void int2hex(uint8_t i); 192 | void int16to4hex(uint16_t i); 193 | 194 | void HttpDInit(void); 195 | void init_tHttpD_struct(struct tHttpD* pSocket); 196 | void HttpDCall(uint8_t* pBuffer, uint16_t nBytes, struct tHttpD* pSocket); 197 | 198 | char *read_two_characters(char *pBuffer); 199 | void parsepost(struct tHttpD* pSocket, char *pBuffer, uint16_t nBytes); 200 | void parse_local_buf(struct tHttpD* pSocket, char* local_buf, uint16_t lbi_max); 201 | void update_ON_OFF(uint8_t i, uint8_t j); 202 | void parseget(struct tHttpD* pSocket, char *pBuffer); 203 | // void parse_val_case_0x55(void); 204 | // void parse_val_case_0x56(void); 205 | void parse_command_exception(struct tHttpD* pSocket); 206 | 207 | void login_timer_management(void); 208 | int8_t check_login_status(void); 209 | 210 | #endif /*HTTPD_H_*/ 211 | -------------------------------------------------------------------------------- /NetworkModule/ina226.h: -------------------------------------------------------------------------------- 1 | /** 2 | * INA226 implementation 3 | */ 4 | 5 | /* Modifications 2023 Michael Nielson 6 | * Adapted for STM8S005 processor, ENC28J60 Ethernet Controller, 7 | * Web_Relay_Con V2.0 HW-584, and compilation with Cosmic tool set. 8 | * Author: Michael Nielson 9 | * Email: nielsonm.projects@gmail.com 10 | This program is free software: you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation, either version 3 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, but 16 | WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | General Public License for more details. 19 | 20 | See GNU General Public License at . 21 | 22 | Copyright 2023 Michael Nielson 23 | */ 24 | 25 | #ifndef __INA226_H__ 26 | #define __INA226_H__ 27 | 28 | 29 | // Define Read/Write control words for each of 5 INA226 devices. 30 | #define INA226_1_read 0x81 // 1000 0001 0x40 31 | #define INA226_1_write 0x80 // 1000 0000 32 | #define INA226_2_read 0x83 // 1000 0011 0x41 33 | #define INA226_2_write 0x82 // 1000 0010 34 | #define INA226_3_read 0x85 // 1000 0101 0x42 35 | #define INA226_3_write 0x84 // 1000 0100 36 | #define INA226_4_read 0x89 // 1000 1001 0x44 37 | #define INA226_4_write 0x88 // 1000 1000 38 | #define INA226_5_read 0x8b // 1000 1011 0x45 39 | #define INA226_5_write 0x8a // 1000 1010 40 | 41 | 42 | // The following defines the register_address for each register within the 43 | // INA226 44 | #define INA226_REG_CONFIGURATION 0x00 45 | #define INA226_REG_SHUNT_VOLTAGE 0x01 46 | #define INA226_REG_BUS_VOLTAGE 0x02 47 | #define INA226_REG_POWER 0x03 48 | #define INA226_REG_CURRENT 0x04 49 | #define INA226_REG_CALIBRATION 0x05 50 | #define INA226_REG_MASK_ENABLE 0x06 51 | #define INA226_REG_ALERT_LIMIT 0x07 52 | #define INA226_REG_MFG_ID 0xfe 53 | #define INA226_REG_DIE_ID 0xff 54 | 55 | // The following defines the default register values for the INA226 56 | #define INA226_CONFIGURATION__RST 0x8000 57 | 58 | #define INA226_CONFIGURATION__AVG_MASK 0x0E00 59 | #define INA226_CONFIGURATION__AVG_SHIFT 9 60 | 61 | #define INA226_CONFIGURATION__BUS_CONV_TIME_MASK 0x01C0 62 | #define INA226_CONFIGURATION__BUS_CONV_TIME_SHIFT 6 63 | 64 | #define INA226_CONFIGURATION__SHUNT_CONV_TIME_MASK 0x0038 65 | #define INA226_CONFIGURATION__SHUNT_CONV_TIME_SHIFT 3 66 | 67 | #define INA226_CONFIGURATION__MODE_MASK 0x0007 68 | #define INA226_CONFIGURATION__MODE_SHIFT 0 69 | 70 | #define INA226_MASK_ENABLE__CVRF 0x0008 71 | 72 | #define INA226_MFG_ID 0x5449 73 | 74 | 75 | 76 | void ina226_init_all(void); 77 | void ina226_calibrate_all(void); 78 | // void ina226_calibrate(uint8_t write_command, float r_shunt, float max_current); 79 | void ina226_calibrate(uint8_t write_command, int32_t r_shunt, int32_t max_current); 80 | void ina226_configure_all(void); 81 | void ina226_configure(uint8_t write_command, uint8_t period, uint8_t average); 82 | int ina226_conversion_ready(uint8_t write_command, uint8_t read_command); 83 | void ina226_read_measurements(uint8_t write_command, uint8_t read_command); 84 | void ina226_write_reg(uint8_t write_command, uint8_t register_address, uint16_t value); 85 | uint16_t ina226_read_reg(uint8_t write_command, uint8_t read_command, uint8_t register_address); 86 | 87 | 88 | #endif /* __INA226_H__ */ 89 | -------------------------------------------------------------------------------- /NetworkModule/mqtt_pal.h: -------------------------------------------------------------------------------- 1 | #ifndef __MQTT_PAL_H__ 2 | #define __MQTT_PAL_H__ 3 | 4 | /* 5 | MIT License 6 | 7 | Copyright(c) 2018 Liam Bindle 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files(the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions : 15 | 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | SOFTWARE. 26 | */ 27 | 28 | 29 | /* Modifications 2020-2022 Michael Nielson 30 | * Adapted for STM8S005 processor, ENC28J60 Ethernet Controller, 31 | * Web_Relay_Con V2.0 HW-584, and compilation with Cosmic tool set. 32 | * Author: Michael Nielson 33 | * Email: nielsonm.projects@gmail.com 34 | This program is free software: you can redistribute it and/or modify 35 | it under the terms of the GNU General Public License as published by 36 | the Free Software Foundation, either version 3 of the License, or 37 | (at your option) any later version. 38 | 39 | This program is distributed in the hope that it will be useful, but 40 | WITHOUT ANY WARRANTY; without even the implied warranty of 41 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 42 | General Public License for more details. 43 | 44 | See GNU General Public License at . 45 | 46 | Copyright 2022 Michael Nielson 47 | */ 48 | 49 | 50 | 51 | #include 52 | #include 53 | #include 54 | 55 | // Sends all the bytes in a buffer. 56 | // buf - A pointer to the first byte in the buffer to send. 57 | // len - The number of bytes to send (starting at buf). 58 | // returns - The number of bytes sent if successful, an MQTTErrors otherwise. 59 | int16_t mqtt_pal_sendall(const void* buf, uint16_t len); 60 | 61 | 62 | //char *stpcpy(char * dest, const char * src); 63 | char *stpcpy(char * dest, char * src); 64 | 65 | 66 | #endif // define __MQTT_PAL_H__ 67 | 68 | -------------------------------------------------------------------------------- /NetworkModule/networkmodule_vector.c: -------------------------------------------------------------------------------- 1 | /* INTERRUPT VECTORS TABLE FOR STM8S005 2 | * Copyright (c) 2008 by COSMIC Software 3 | */ 4 | extern void _stext(); /* startup routine */ 5 | 6 | #pragma section const {vector} 7 | 8 | void (* const @vector _vectab[32])() = { 9 | _stext, /* RESET */ 10 | 0, /* TRAP */ 11 | 0, /* TLI */ 12 | 0, /* AWU */ 13 | 0, /* CLK */ 14 | 0, /* EXTI0 */ 15 | 0, /* EXTI1 */ 16 | 0, /* EXTI2 */ 17 | 0, /* EXTI3 */ 18 | 0, /* EXTI4 */ 19 | 0,0, /* Reserved */ 20 | 0, /* SPI */ 21 | 0, /* TIMER 1 OVF */ 22 | 0, /* TIMER 1 CAP */ 23 | 0, /* TIMER 2 OVF */ 24 | 0, /* TIMER 2 CAP */ 25 | 0, /* TIMER 3 OVF */ 26 | 0, /* TIMER 3 CAP */ 27 | 0,0, /* Reserved */ 28 | 0, /* I2C */ 29 | 0, /* UART2 TX */ 30 | 0, /* UART2 RX */ 31 | 0, /* ADC1 */ 32 | 0, /* TIMER 4 OVF */ 33 | 0, /* EEPROM ECC */ 34 | 0,0,0,0,0, /* Reserved */ 35 | }; 36 | -------------------------------------------------------------------------------- /NetworkModule/pcf8574.c: -------------------------------------------------------------------------------- 1 | /** 2 | * PCF8574 implementation 3 | */ 4 | 5 | /* Modifications 2023 Michael Nielson 6 | * Adapted for STM8S005 processor, ENC28J60 Ethernet Controller, 7 | * Web_Relay_Con V2.0 HW-584, and compilation with Cosmic tool set. 8 | * Author: Michael Nielson 9 | * Email: nielsonm.projects@gmail.com 10 | This program is free software: you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation, either version 3 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, but 16 | WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | General Public License for more details. 19 | 20 | See GNU General Public License at . 21 | 22 | Copyright 2023 Michael Nielson 23 | */ 24 | 25 | // All includes are in main.h 26 | #include "main.h" 27 | 28 | 29 | // PCF8574 Control Bytes 30 | #define I2C_PCF8574_READ 0x71 // 0111 0001 31 | #define I2C_PCF8574_WRITE 0x70 // 0111 0000 32 | 33 | #if PCF8574_SUPPORT == 1 34 | 35 | extern uint8_t stored_options1; // Additional options stored in EEPROM 36 | 37 | extern uint8_t OctetArray[14]; 38 | 39 | uint8_t I2C_PCF8574_1_WRITE_CMD; // Used to store the write command for the 40 | // first PCF8574 device found. This value 41 | // is initialized to zero, so if it is non- 42 | // zero this also serves as a "found" 43 | // indicator. If it remains at zero this 44 | // indicates no PCF devices were discovered. 45 | 46 | void PCF8574_init() 47 | { 48 | // Search for PCF8574 and PCF8574A devices. Either device type may be on the 49 | // I2C bus. The following table shows the address maps for both types of 50 | // devices. The value shown includes the R/W bit, thus the value is actually 51 | // the Command Byte used to access the device in either the Write mode or 52 | // the Read mode. 53 | // PCF8574 PCF8574A 54 | // Write Cmd Read Cmd Write Cmd Read Cmd 55 | // 0x40 0x41 0x70 0x71 56 | // 0x42 0x43 0x72 0x73 57 | // 0x44 0x45 0x74 0x75 58 | // 0x46 0x47 0x76 0x77 59 | // 0x48 0x49 0x78 0x79 60 | // 0x4a 0x4b 0x7a 0x7b 61 | // 0x4c 0x4d 0x7c 0x7d 62 | // 0x4e 0x4f 0x7e 0x7f 63 | // 64 | // The search is performed by attempting a Read from each address starting 65 | // at 0x41 and ending at 0x7f. As soon as 1 device responds the search will 66 | // terminate, and the Write Cmd value for that address will be saved in 67 | // variable I2C_PCF8574_1_WRITE_CMD. 68 | 69 | uint8_t found; 70 | found = 0; 71 | 72 | I2C_PCF8574_1_WRITE_CMD = 0x40; // Start search with PCF8574 devices 73 | while (1) { 74 | // In this loop the I2C_PCF8574_1_WRITE_CMD is used as the loop control 75 | // index. The called routines will modify I2C_PCF8574_1_WRITE_CMD into a 76 | // read command as needed. 77 | if (PCF8574_response_check() == 0) { 78 | // Found a device. Terminate the search. 79 | found = 1; 80 | 81 | #if DEBUG_SUPPORT == 15 82 | // UARTPrintf("Found PCF8574 at "); 83 | // emb_itoa(I2C_PCF8574_1_WRITE_CMD, OctetArray, 16, 2); 84 | // UARTPrintf(OctetArray); 85 | // UARTPrintf("\r\n"); 86 | #endif // DEBUG_SUPPORT == 15 87 | 88 | break; 89 | } 90 | else if (I2C_PCF8574_1_WRITE_CMD == 0x4e) { 91 | I2C_PCF8574_1_WRITE_CMD = 0x70; // Search for PCF8574A devices 92 | } 93 | else if (I2C_PCF8574_1_WRITE_CMD == 0x7e) break; 94 | else I2C_PCF8574_1_WRITE_CMD += 2; 95 | } 96 | if (found == 0) I2C_PCF8574_1_WRITE_CMD = 0x00; 97 | 98 | 99 | // Now update the stored_options1 byte if needed. 100 | { 101 | uint8_t j; 102 | j = stored_options1; 103 | 104 | if (I2C_PCF8574_1_WRITE_CMD) { 105 | // A PCF8574 or PCF8574A was found as indicated by a non-zero value in 106 | // variable I2C_PCF8574_1_WRITE_CMD. 107 | j |= 0x08; // Enable PCF8574 108 | } 109 | else { 110 | j &= 0xf7; // Disable PCF8574 111 | } 112 | 113 | // Update the stored_options1 byte in EEPROM. Only perform the eeprom 114 | // write if the value changed. 115 | update_settings_options(UPDATE_OPTIONS1, j); 116 | 117 | #if DEBUG_SUPPORT == 15 118 | if ((stored_options1 & 0x08) == 0x08) { 119 | UARTPrintf("\r\n"); 120 | UARTPrintf("PCF8574 found\r\n"); 121 | } 122 | else { 123 | UARTPrintf("\r\n"); 124 | UARTPrintf("PCF8574 not found\r\n"); 125 | } 126 | #endif // DEBUG_SUPPORT == 15 127 | 128 | } 129 | } 130 | 131 | 132 | void PCF8574_write(uint8_t byte) 133 | { 134 | // Function to write single byte to PCF8574 135 | I2C_control(I2C_PCF8574_1_WRITE_CMD); 136 | I2C_write_byte(byte); 137 | I2C_stop(); 138 | 139 | #if DEBUG_SUPPORT == 15 140 | // UARTPrintf("Write PCF8574 byte "); 141 | // emb_itoa(byte, OctetArray, 16, 2); 142 | // UARTPrintf(OctetArray); 143 | // UARTPrintf("\r\n"); 144 | #endif // DEBUG_SUPPORT == 15 145 | 146 | } 147 | 148 | 149 | uint8_t PCF8574_read() 150 | { 151 | // Function to read single byte from PCF8574. 152 | // Note: The PCF8574 spec is a little confusing with regard to data read, 153 | // in particular the TI spec seems to imply that a double read is required. 154 | // Other specs to not indicate this. A single byte read appears to work in 155 | // testing performed. I note this here just in case there are any reports 156 | // of functional issues. 157 | uint8_t byte; 158 | uint8_t read_cmd; 159 | 160 | read_cmd = (uint8_t)(I2C_PCF8574_1_WRITE_CMD | 0x01); 161 | I2C_control(read_cmd); 162 | byte = I2C_read_byte(1); 163 | // I2C_stop(); 164 | 165 | return byte; 166 | } 167 | 168 | 169 | uint8_t PCF8574_response_check() 170 | { 171 | // Function to check for presence of PCF8574 172 | // The function will attempt a read sequence but will return any error code 173 | // produced by the I2C_control() function call. 174 | uint8_t error; 175 | uint8_t read_cmd; 176 | 177 | #if DEBUG_SUPPORT == 15 178 | // UARTPrintf("Checking for PCF8574 at "); 179 | // emb_itoa(I2C_PCF8574_1_WRITE_CMD, OctetArray, 16, 2); 180 | // UARTPrintf(OctetArray); 181 | // UARTPrintf("\r\n"); 182 | #endif // DEBUG_SUPPORT == 15 183 | 184 | read_cmd = (uint8_t)(I2C_PCF8574_1_WRITE_CMD | 0x01); 185 | error = I2C_control(read_cmd); 186 | I2C_read_byte(1); 187 | // I2C_stop(); 188 | 189 | return error; 190 | } 191 | 192 | #endif // PCF8574_SUPPORT == 1 193 | -------------------------------------------------------------------------------- /NetworkModule/pcf8574.h: -------------------------------------------------------------------------------- 1 | /** 2 | * PCF8574 implementation 3 | */ 4 | 5 | /* Modifications 2023 Michael Nielson 6 | * Adapted for STM8S005 processor, ENC28J60 Ethernet Controller, 7 | * Web_Relay_Con V2.0 HW-584, and compilation with Cosmic tool set. 8 | * Author: Michael Nielson 9 | * Email: nielsonm.projects@gmail.com 10 | This program is free software: you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation, either version 3 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, but 16 | WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | General Public License for more details. 19 | 20 | See GNU General Public License at . 21 | 22 | Copyright 2023 Michael Nielson 23 | */ 24 | 25 | #ifndef __PCF8574_H__ 26 | #define __PCF8574_H__ 27 | 28 | 29 | void PCF8574_init(void); 30 | void PCF8574_write(uint8_t byte); 31 | uint8_t PCF8574_read(void); 32 | uint8_t PCF8574_response_check(void); 33 | 34 | #endif /* __PCF8574_H__ */ 35 | -------------------------------------------------------------------------------- /NetworkModule/sync.ffs_db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nielsonm236/NetMod-ServerApp/1700e7a9aa5b377ca4deb89e6a47fe72e026d3f7/NetworkModule/sync.ffs_db -------------------------------------------------------------------------------- /NetworkModule/timer.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nielsonm236/NetMod-ServerApp/1700e7a9aa5b377ca4deb89e6a47fe72e026d3f7/NetworkModule/timer.c -------------------------------------------------------------------------------- /NetworkModule/timer.h: -------------------------------------------------------------------------------- 1 | /* Modifications 2020-2022 Michael Nielson 2 | * Adapted for STM8S005 processor, ENC28J60 Ethernet Controller, 3 | * Web_Relay_Con V2.0 HW-584, and compilation with Cosmic tool set. 4 | * Author: Michael Nielson 5 | * Email: nielsonm.projects@gmail.com 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, but 12 | WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | General Public License for more details. 15 | 16 | See GNU General Public License at . 17 | 18 | Copyright 2022 Michael Nielson 19 | */ 20 | 21 | 22 | 23 | // Application must "manually" check if its timers have expired; this 24 | // is not done automatically. 25 | 26 | #ifndef __TIMER_H__ 27 | #define __TIMER_H__ 28 | 29 | void clock_init(void); 30 | void timer_update(void); 31 | uint8_t periodic_timer_expired(void); 32 | uint8_t arp_timer_expired(void); 33 | uint8_t mqtt_timer_expired(void); 34 | uint8_t t100ms_timer_expired(void); 35 | void wait_timer(uint16_t wait); 36 | 37 | #endif /* __TIMER_H__ */ 38 | 39 | -------------------------------------------------------------------------------- /NetworkModule/uip_TcpAppHub.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file implements all necessary Callback functions for 3 | * the uip Stack to route data properly to the right application. 4 | * 5 | * Author: Simon Kueppers 6 | * Email: simon.kueppers@web.de 7 | * Homepage: http://klinkerstein.m-faq.de 8 | * 9 | This program is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program. If not, see . 21 | 22 | Copyright 2008 Simon Kueppers 23 | * 24 | */ 25 | 26 | /* Modifications 2020-2022 Michael Nielson 27 | * Adapted for STM8S005 processor, ENC28J60 Ethernet Controller, 28 | * Web_Relay_Con V2.0 HW-584, and compilation with Cosmic tool set. 29 | * Author: Michael Nielson 30 | * Email: nielsonm.projects@gmail.com 31 | * 32 | * This declaration applies to modifications made by Michael Nielson 33 | * and in no way changes the Simon Kueppers declaration above. 34 | 35 | This program is free software: you can redistribute it and/or modify 36 | it under the terms of the GNU General Public License as published by 37 | the Free Software Foundation, either version 3 of the License, or 38 | (at your option) any later version. 39 | 40 | This program is distributed in the hope that it will be useful, but 41 | WITHOUT ANY WARRANTY; without even the implied warranty of 42 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 43 | General Public License for more details. 44 | 45 | See GNU General Public License at . 46 | 47 | Copyright 2022 Michael Nielson 48 | */ 49 | 50 | 51 | // All includes are in main.h 52 | #include "main.h" 53 | 54 | 55 | extern uint16_t Port_Httpd; 56 | extern uint16_t Port_Mqttd; 57 | extern uint16_t mqtt_local_port; 58 | 59 | #if BUILD_SUPPORT == MQTT_BUILD 60 | extern struct mqtt_client mqttclient; // Pointer to MQTT client declared in main.c 61 | extern uint8_t mqtt_start; 62 | extern uint8_t mqtt_close_tcp; 63 | #endif // BUILD_SUPPORT == MQTT_BUILD 64 | 65 | void uip_TcpAppHubCall(void) 66 | // We get here via UIP_APPCALL in the uip.c code 67 | { 68 | // Removed "htons" code to reduce Flash usage. This can be done as the 69 | // SMT8 is "Big Endian". Keep the commented code in case the application 70 | // is ported to a "Little Endian" architecture. 71 | // if(uip_conn->lport == htons(Port_Httpd)) { 72 | if(uip_conn->lport == Port_Httpd) { 73 | // This code is called if incoming traffic is HTTP. HttpDCall will read 74 | // the incoming data from the uip_buf, then create any needed output 75 | // data and put it in the uip_buf. 76 | // This code is also called if the UIP functions are just checking to 77 | // see if there is anything pending to send - for instance in the case 78 | // where multiple packets must be sent to fulfill a browser request. 79 | 80 | // UARTPrintf("uip_tcpapphub Browser call\r\n"); 81 | 82 | HttpDCall(uip_appdata, uip_datalen(), &uip_conn->appstate.HttpDSocket); 83 | } 84 | 85 | #if BUILD_SUPPORT == MQTT_BUILD 86 | // Removed "htons" code to reduce Flash usage. This can be done as the 87 | // SMT8 is "Big Endian". Keep the commented code in case the application 88 | // is ported to a "Little Endian" architecture. 89 | // else if(uip_conn->lport == htons(mqtt_local_port)) { 90 | else if(uip_conn->lport == mqtt_local_port) { 91 | // This code is called if incoming traffic is MQTT. mqtt_sync will read 92 | // the incoming data (if any) from the uip_buf, then create any needed 93 | // ouptut data and put it in the uip_buf. 94 | // This code is also called if the UIP functions are just checking to 95 | // see if there is anything pending to send. This can happen frequently 96 | // with MQTT. 97 | 98 | // UARTPrintf("uip_tcpapphub MQTT call\r\n"); 99 | 100 | if (mqtt_start > MQTT_START_QUEUE_CONNECT) { 101 | // Only call mqtt_sync if we know the client has been initialized 102 | mqtt_sync(&mqttclient); 103 | // If mqtt_close_tcp == 1 we are forcing a TCP connection close on return 104 | // to the UIP code. Note that the uip_TcpAppHubCall() function can only 105 | // be called if in the ESTABLISHED state - so a uip_close() is a valid 106 | // reply. 107 | } 108 | if (mqtt_close_tcp == 1) { 109 | mqtt_close_tcp = 0; 110 | uip_close(); 111 | } 112 | } 113 | #endif // BUILD_SUPPORT == MQTT_BUILD 114 | } 115 | -------------------------------------------------------------------------------- /NetworkModule/uip_TcpAppHub.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is meant to be an extension to the uip Stack. 3 | * The idea is, to implement an "Application Hub" that routes 4 | * incoming data to the right Daemons and Clients, that are 5 | * implemented. 6 | * Each Application has its own Socket-Structure. And all Socket Structures are 7 | * overlayed in memory internally. 8 | * 9 | * Author: Simon Kueppers 10 | * Email: simon.kueppers@web.de 11 | * Homepage: http://klinkerstein.m-faq.de 12 | * 13 | This program is free software: you can redistribute it and/or modify 14 | it under the terms of the GNU General Public License as published by 15 | the Free Software Foundation, either version 3 of the License, or 16 | (at your option) any later version. 17 | 18 | This program is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | GNU General Public License for more details. 22 | 23 | You should have received a copy of the GNU General Public License 24 | along with this program. If not, see . 25 | 26 | Copyright 2008 Simon Kueppers 27 | * 28 | */ 29 | 30 | /* Modifications 2020-2022 Michael Nielson 31 | * Adapted for STM8S005 processor, ENC28J60 Ethernet Controller, 32 | * Web_Relay_Con V2.0 HW-584, and compilation with Cosmic tool set. 33 | * Author: Michael Nielson 34 | * Email: nielsonm.projects@gmail.com 35 | * 36 | * This declaration applies to modifications made by Michael Nielson 37 | * and in no way changes the Simon Kueppers declaration above. 38 | 39 | This program is free software: you can redistribute it and/or modify 40 | it under the terms of the GNU General Public License as published by 41 | the Free Software Foundation, either version 3 of the License, or 42 | (at your option) any later version. 43 | 44 | This program is distributed in the hope that it will be useful, but 45 | WITHOUT ANY WARRANTY; without even the implied warranty of 46 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 47 | General Public License for more details. 48 | 49 | See GNU General Public License at . 50 | 51 | Copyright 2022 Michael Nielson 52 | */ 53 | 54 | 55 | 56 | #ifndef UIP_TCPAPPHUB_H_ 57 | #define UIP_TCPAPPHUB_H_ 58 | 59 | #include 60 | #include "httpd.h" 61 | 62 | void uip_TcpAppHubCall(void); 63 | 64 | #define UIP_APPCALL uip_TcpAppHubCall 65 | 66 | 67 | typedef union 68 | { 69 | struct tHttpD HttpDSocket; 70 | } uip_tcp_appstate_t; 71 | 72 | 73 | 74 | #endif /*UIP_TCPAPPHUB_H_*/ 75 | -------------------------------------------------------------------------------- /NetworkModule/uip_arch.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Architecture specific uIP functions 3 | * 4 | * The functions in the architecture specific module implement the IP 5 | * check sum and 32-bit additions. 6 | * 7 | * The IP checksum calculation is the most computationally expensive 8 | * operation in the TCP/IP stack and it therefore pays off to 9 | * implement this in efficient assembler. The purpose of the uip-arch 10 | * module is to let the checksum functions to be implemented in 11 | * architecture specific assembler. 12 | */ 13 | 14 | /** 15 | * Declarations of architecture specific functions. 16 | * \author Adam Dunkels 17 | */ 18 | 19 | /* 20 | * Copyright (c) 2001, Adam Dunkels. 21 | * All rights reserved. 22 | * 23 | * Redistribution and use in source and binary forms, with or without 24 | * modification, are permitted provided that the following conditions 25 | * are met: 26 | * 1. Redistributions of source code must retain the above copyright 27 | * notice, this list of conditions and the following disclaimer. 28 | * 2. Redistributions in binary form must reproduce the above copyright 29 | * notice, this list of conditions and the following disclaimer in the 30 | * documentation and/or other materials provided with the distribution. 31 | * 3. The name of the author may not be used to endorse or promote 32 | * products derived from this software without specific prior 33 | * written permission. 34 | * 35 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 36 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 37 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 38 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 39 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 40 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 41 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 42 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 43 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 44 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 45 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 46 | * 47 | * This file is part of the uIP TCP/IP stack. 48 | * 49 | * $Id: uip_arch.h,v 1.1 2007/01/04 11:06:41 adamdunkels Exp $ 50 | * 51 | */ 52 | 53 | /* Modifications 2020-2022 Michael Nielson 54 | * Adapted for STM8S005 processor, ENC28J60 Ethernet Controller, 55 | * Web_Relay_Con V2.0 HW-584, and compilation with Cosmic tool set. 56 | * Author: Michael Nielson 57 | * Email: nielsonm.projects@gmail.com 58 | * 59 | * This declaration applies to modifications made by Michael Nielson 60 | * and in no way changes the Adam Dunkels declaration above. 61 | 62 | This program is free software: you can redistribute it and/or modify 63 | it under the terms of the GNU General Public License as published by 64 | the Free Software Foundation, either version 3 of the License, or 65 | (at your option) any later version. 66 | 67 | This program is distributed in the hope that it will be useful, but 68 | WITHOUT ANY WARRANTY; without even the implied warranty of 69 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 70 | General Public License for more details. 71 | 72 | See GNU General Public License at . 73 | 74 | Copyright 2022 Michael Nielson 75 | */ 76 | 77 | 78 | 79 | #ifndef __UIP_ARCH_H__ 80 | #define __UIP_ARCH_H__ 81 | 82 | #include "uip.h" 83 | 84 | /** 85 | * Carry out a 32-bit addition. 86 | * 87 | * Because not all architectures for which uIP is intended has native 88 | * 32-bit arithmetic, uIP uses an external C function for doing the 89 | * required 32-bit additions in the TCP protocol processing. This 90 | * function should add the two arguments and place the result in the 91 | * global variable uip_acc32. 92 | * 93 | * The 32-bit integer pointed to by the op32 parameter and the 94 | * result in the uip_acc32 variable are in network byte order (big 95 | * endian). 96 | * 97 | * op32 - A pointer to a 4-byte array representing a 32-bit 98 | * integer in network byte order (big endian). 99 | * 100 | * op16 - A 16-bit integer in host byte order. 101 | */ 102 | void uip_add32(uint8_t *op32, uint16_t op16); 103 | 104 | /** 105 | * Calculate the Internet checksum over a buffer. 106 | * 107 | * The Internet checksum is the one's complement of the one's 108 | * complement sum of all 16-bit words in the buffer. 109 | * 110 | * See RFC1071. 111 | * 112 | * This function is not called in the current version of uIP, 113 | * but future versions might make use of it. 114 | * 115 | * buf - A pointer to the buffer over which the checksum is to be computed. 116 | * len - The length of the buffer over which the checksum is to be computed. 117 | * return - The Internet checksum of the buffer. 118 | */ 119 | uint16_t uip_chksum(uint16_t *buf, uint16_t len); 120 | 121 | /** 122 | * Calculate the IP header checksum of the packet header in uip_buf. 123 | * 124 | * The IP header checksum is the Internet checksum of the 20 bytes of 125 | * the IP header. 126 | * 127 | * return - The IP header checksum of the IP header in the uip_buf 128 | * buffer. 129 | */ 130 | uint16_t uip_ipchksum(void); 131 | 132 | /** 133 | * Calculate the TCP checksum of the packet in uip_buf and uip_appdata. 134 | * 135 | * The TCP checksum is the Internet checksum of data contents of the 136 | * TCP segment, and a pseudo-header as defined in RFC793. 137 | * 138 | * The uip_appdata pointer that points to the packet data may 139 | * point anywhere in memory, so it is not possible to simply calculate 140 | * the Internet checksum of the contents of the uip_buf buffer. 141 | * 142 | * return - The TCP checksum of the TCP segment in uip_buf and pointed 143 | * to by uip_appdata. 144 | */ 145 | uint16_t uip_tcpchksum(void); 146 | 147 | #endif /* __UIP_ARCH_H__ */ 148 | -------------------------------------------------------------------------------- /NetworkModule/uip_arp.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Macros and definitions for the ARP module. 3 | * \author Adam Dunkels 4 | */ 5 | 6 | 7 | /* 8 | * Copyright (c) 2001-2003, Adam Dunkels. 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 1. Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 3. The name of the author may not be used to endorse or promote 20 | * products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 24 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 27 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 29 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 31 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | * This file is part of the uIP TCP/IP stack. 36 | * 37 | * $Id: uip_arp.h,v 1.5 2006/06/11 21:46:39 adam Exp $ 38 | * 39 | */ 40 | 41 | /* Modifications 2020-2022 Michael Nielson 42 | * Adapted for STM8S005 processor, ENC28J60 Ethernet Controller, 43 | * Web_Relay_Con V2.0 HW-584, and compilation with Cosmic tool set. 44 | * Author: Michael Nielson 45 | * Email: nielsonm.projects@gmail.com 46 | * 47 | * This declaration applies to modifications made by Michael Nielson 48 | * and in no way changes the Adam Dunkels declaration above. 49 | 50 | This program is free software: you can redistribute it and/or modify 51 | it under the terms of the GNU General Public License as published by 52 | the Free Software Foundation, either version 3 of the License, or 53 | (at your option) any later version. 54 | 55 | This program is distributed in the hope that it will be useful, but 56 | WITHOUT ANY WARRANTY; without even the implied warranty of 57 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 58 | General Public License for more details. 59 | 60 | See GNU General Public License at . 61 | 62 | Copyright 2022 Michael Nielson 63 | */ 64 | 65 | 66 | 67 | #ifndef __UIP_ARP_H__ 68 | #define __UIP_ARP_H__ 69 | 70 | #include "uip.h" 71 | 72 | 73 | extern struct uip_eth_addr uip_ethaddr; 74 | 75 | /** 76 | * The Ethernet header. 77 | */ 78 | struct uip_eth_hdr { 79 | struct uip_eth_addr dest; 80 | struct uip_eth_addr src; 81 | uint16_t type; 82 | }; 83 | 84 | #define UIP_ETHTYPE_ARP 0x0806 85 | #define UIP_ETHTYPE_IP 0x0800 86 | #define UIP_ETHTYPE_IP6 0x86dd 87 | 88 | 89 | /* The uip_arp_init() function must be called before any of the other 90 | ARP functions. */ 91 | void uip_arp_init(void); 92 | 93 | /* The uip_arp_ipin() function should be called whenever an IP packet 94 | arrives from the Ethernet. This function refreshes the ARP table or 95 | inserts a new mapping if none exists. The function assumes that an 96 | IP packet with an Ethernet header is present in the uip_buf buffer 97 | and that the length of the packet is in the uip_len variable. */ 98 | /*void uip_arp_ipin(void);*/ 99 | #define uip_arp_ipin() 100 | 101 | /* The uip_arp_arpin() should be called when an ARP packet is received 102 | by the Ethernet driver. This function also assumes that the 103 | Ethernet frame is present in the uip_buf buffer. When the 104 | uip_arp_arpin() function returns, the contents of the uip_buf 105 | buffer should be sent out on the Ethernet if the uip_len variable 106 | is > 0. */ 107 | void uip_arp_arpin(void); 108 | 109 | /* The uip_arp_out() function should be called when an IP packet 110 | should be sent out on the Ethernet. This function creates an 111 | Ethernet header before the IP header in the uip_buf buffer. The 112 | Ethernet header will have the correct Ethernet MAC destination 113 | address filled in if an ARP table entry for the destination IP 114 | address (or the IP address of the default router) is present. If no 115 | such table entry is found, the IP packet is overwritten with an ARP 116 | request and we rely on TCP to retransmit the packet that was 117 | overwritten. In any case, the uip_len variable holds the length of 118 | the Ethernet frame that should be transmitted. */ 119 | void uip_arp_out(void); 120 | 121 | /* The uip_arp_timer() function should be called every ten seconds. It 122 | is responsible for flushing old entries in the ARP table. */ 123 | void uip_arp_timer(void); 124 | 125 | 126 | /** 127 | * Specifiy the Ethernet MAC address. 128 | * 129 | * The ARP code needs to know the MAC address of the Ethernet card in 130 | * order to be able to respond to ARP queries and to generate working 131 | * Ethernet headers. 132 | * 133 | * This macro only specifies the Ethernet MAC address to the ARP 134 | * code. It cannot be used to change the MAC address of the Ethernet 135 | * card. 136 | * 137 | * eaddr - A pointer to a struct uip_eth_addr containing the 138 | * Ethernet MAC address of the Ethernet card. 139 | * 140 | */ 141 | #define uip_setethaddr(eaddr) do {uip_ethaddr.addr[0] = eaddr.addr[0]; \ 142 | uip_ethaddr.addr[1] = eaddr.addr[1];\ 143 | uip_ethaddr.addr[2] = eaddr.addr[2];\ 144 | uip_ethaddr.addr[3] = eaddr.addr[3];\ 145 | uip_ethaddr.addr[4] = eaddr.addr[4];\ 146 | uip_ethaddr.addr[5] = eaddr.addr[5];} while(0) 147 | 148 | 149 | 150 | // Send an ARP Request for a specific MQTT Server IP address 151 | // void uip_get_mqtt_server_mac(uip_ipaddr_t uip_mqttserveraddr); 152 | 153 | // Check for the MQTT Server entry in the ARP Table 154 | int check_mqtt_server_arp_entry(void); 155 | 156 | 157 | #endif /* __UIP_ARP_H__ */ 158 | -------------------------------------------------------------------------------- /NetworkModule/uip_types.h: -------------------------------------------------------------------------------- 1 | /* Modifications 2020-2022 Michael Nielson 2 | * Adapted for STM8S005 processor, ENC28J60 Ethernet Controller, 3 | * Web_Relay_Con V2.0 HW-584, and compilation with Cosmic tool set. 4 | * Author: Michael Nielson 5 | * Email: nielsonm.projects@gmail.com 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, but 12 | WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | General Public License for more details. 15 | 16 | See GNU General Public License at . 17 | 18 | Copyright 2022 Michael Nielson 19 | */ 20 | 21 | 22 | 23 | 24 | /* uip configuration */ 25 | 26 | #ifndef __UIP_TYPES_H__ 27 | #define __UIP_TYPES_H__ 28 | 29 | #include 30 | 31 | /** 32 | * 8 bit datatype 33 | * This typedef defines the 8-bit type used throughout uIP. 34 | */ 35 | // typedef uint8_t u8_t; 36 | 37 | /** 38 | * 16 bit datatype 39 | * This typedef defines the 16-bit type used throughout uIP. 40 | */ 41 | // typedef uint16_t u16_t; 42 | 43 | /** 44 | * Statistics datatype 45 | * This typedef defines the dataype used for keeping statistics in uIP. 46 | */ 47 | typedef uint32_t uip_stats_t; 48 | 49 | #endif /* __UIP_TYPES_H__ */ 50 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NetMod-ServerApp 2 | 3 | Reprogramming the Web_Relay_Con V2.0 HW-584 Network Module 4 | Did you buy one (or more) of these Network Modules and then find disappointment in the software on the board? 5 | - In the original from-the-factory firmware all of the modules have the same MAC address. That's a problem if you want more than one module on your network. And the supplier does not give you a way to change the MAC. 6 | - If you change the IP Address the device returns to its default IP Address when it power cycles. That makes it pretty much useless even if you only put one on your network - unless you're OK with it always having IP Address 192.168.1.4. 7 | 8 | I decided to write my own firmware for the device to provide a web server interface that let's you change the IP Address, Gateway (Default Router) Address, Netmask, Port number (a REAL port number), and MAC Address. I also added the ability for the device to remember all these settings through a power cycle. Any Relay settings you make are also optionally saved through a power cycle. In addition the Network Module can be operated as a generic MQTT device or as a Home Assistant device with Auto Discovery. 9 | 10 | See the Wiki for links to the Youtube videos on how to install and operate the firmware. 11 | 12 | Contact: You can reach me at nielsonm.projects@gmail.com. But questions can also be asked via the Issues section. Sometimes others have the same questions and Q&A in the Issues section might help them out. 13 | 14 | Feature Comparison of the MQTT and Browser builds: 15 | 16 | | | | | | | | | | | 17 | |:-----------------------------|:-----:|:-----:|:-------:|:-----:|:-----:|:-------:|:------:|:------:| 18 | | | MQTT | MQTT | Browser | MQTT | MQTT | Browser | MQTT | MQTT | 19 | | | Home | Domo | Only | Home | Domo | Only | Home | Domo | 20 | | | Asst | Build | Build | Asst | UPG | UPG | Asst | BME280 | 21 | | | Build | | | UPG | Build | Build | BME280 | UPG | 22 | | | | | | Build | | | UPG | Build | 23 | | | | | | | | | Build | | 24 | |-------- Feature ------- | | | | | | | | | 25 | |SWIM Install | x | x | x | | | | | | 26 | |Upgradeable (Ethernet) Install| | | | x | x | x | x | x | 27 | |MQTT Support | x | x | | x | x | | x | x | 28 | |Home Assistant Support | x | | | x | | | x | | 29 | |Domoticz Support | | x | | | x | | | x | 30 | |Browser IO Control | x | x | x | x | x | x | x | x | 31 | |Browser Configuration | x | x | x | x | x | x | x | x | 32 | |Full/Half Duplex | x | x | x | x | x | x | x | x | 33 | |DS18B20 Temp Sensor | x | x | x | x | x | x | | | 34 | |BME280 Sensor | | | | | | | x | x | 35 | |IO Naming | | | x | | | x | | | 36 | |IO Timers | | | x | | | x | | | 37 | |Link Error Statistics | x | x | x | x | x | x | | | 38 | |Network Statistics | | | x | | | x | | | 39 | |I2C Support | | | | x | x | x | x | x | 40 | |Linked Pin Support | x | x | x | x | x | x | | | 41 | |PCF8574 Support | | | | x | x | x | | | 42 | |Alternative Pinout Support | x | x | x | | | | | | 43 | |Response Lockout Support | | | x | x | x | x | x | x | 44 | 45 | IMPORTANT: "Upgradeable (Ethernet) Install" requires additonal hardware - see Manual 46 | 47 | Short summary of recent history. See the change log in the manual and the Issues List for full descriptions. 48 | 49 | June 12, 2024 - Addressed several Issues: Maintenance: #193, #208, User Info: #195, #204. Features: #203, #211, #212, #214, Bugs: #210, #217, #218, #219, #220, #222. 50 | 51 | October 9, 2023 - Added Domoticz support and addressed several other Issues: #199, #200, #201, #202, #205, #206, #207. 52 | 53 | August 3, 2023 - Addressed numerous issues, most relatively small. Issues: #172, #174, #179, #180, #181, #183, #184, #185, #187, #188, #189, #190, and #191. 54 | 55 | June 3, 2023 - Addressed Issues: #175, #176. 56 | 57 | April 16, 2023 - Addressed Issues: #159, #167. 58 | 59 | March 28, 2023 - Addressed Issue #164. 60 | 61 | March 25, 2023 - Addressed Issue #161. 62 | 63 | March 24, 2023 - Addressed Issues: #147, #158. 64 | 65 | March 12, 2023 - Addressed Issues: #115, #120, #152. 66 | 67 | January 25, 2023 - Addressed Issues: #132, #93. 68 | 69 | December 17, 2022 - Addressed Issues: #113, #118, #116, #112, #126, #123, fixed several minor bugs. 70 | 71 | Help is available via a link in the Configuration page that will take you to the GitHub Wiki page. All functionality is described in detail in the "Network Module Manual". I suggest you take a look. 72 | 73 | If you upgrade from a pre-January 2021 version you will find that your Device Name, IP Address, Port Numbers, and MAC address entries are retained. However, since pins are now individually assigned your pinout settings will have to be re-entered in the Configuration page. Note that firmware downgrade is not supported in an automated way. Check the Network Module Manual for downgrade instructions. 74 | 75 | Videos: See the video links in the Wiki 76 | 77 | Many thanks to Carlos Ladeira and Jevgeni Kiski for their many hours of work in the 2021 releases. Their collaboration greatly improved the code for everyone. 78 | 79 | I haven't updated the "Tested with" section in awhile. Suffice it to say that the firmware has continued to work without issues resulting from external application updates. 80 | Tested with: 81 | - Windows 10 Firefox 104.0.2 (64-bit) 82 | - Windows 10 Chrome 105.0.5195.102 (64-bit) 83 | - Windows 10 Edge 105.0.1343.33 (64-bit) 84 | - Mac Safari Version 14.0.2 85 | - Mac Edge 87.0.664.75 86 | - Mac Opera 73.0.3856.344 87 | - Mac Firefox 84.0.2 88 | - Mac Firefox 72.0.2 89 | - Ubuntu 20.10 - Firefox 84.0.1 (64-bit) 90 | - Ubuntu 20.10 - Chromium 87.0.4280.88 (64-bit) 91 | - iPhone Safari on iOS 15.6.1 92 | - iPhone Chrome 105.0.5195.100 on iOS 15.6.1 93 | - Mosquitto 94 | - Node-Red 95 | - Chrome MQTTLens 96 | - Home Assistant 97 | 98 | - IE - NOT SUPPORTED - It won't work with the javascript that is now part of the Browser GUI. 99 | 100 | IMPORTANT NOTE: The software provided in this project only works with the “Web_Relays_Con V2.0 HW-584” which is based on the STM8S-005 or STM8S-105 processor and ENC28J60 ethernet controller. I haven't tried it with any other version of the hardware. I think the V.1 FC-160 is based on a Nuvoton processor and this code and the tools are incompatible. 101 | 102 | NOTE: I am not in any way associated with the manufacturer of this device. I only wrote code to run on it for my own hobby purposes, and I am making it available for other hobbyists. 103 | --------------------------------------------------------------------------------