diff --git a/.gitmodules b/.gitmodules index f8b454d..802603f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "robot_tests"] path = robot_tests - url = git@github.com:Ell-i/ELL-i-PyBot-Tests.git + url = https://github.com/asifsardar26/ELL-i-PyBot-Tests diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8a4b9e5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,45 @@ +FROM 32bit/ubuntu:14.04 + +MAINTAINER Asif Sardar + +ENV DEBIAN_FRONTEND noninteractive + +RUN apt-get update && apt-get install -y \ + make \ + gcc \ + g++ \ + git \ + python2.7 \ + python2.7-dev \ + python-setuptools \ + wget \ + zip \ + unzip \ + bridge-utils \ + valgrind \ + nano + +ADD https://launchpad.net/gcc-arm-embedded/4.9/4.9-2014-q4-major/+download/gcc-arm-none-eabi-4_9-2014q4-20141203-linux.tar.bz2 /home/Downloads/ +WORKDIR /home/Downloads/ +RUN tar xvjf gcc-arm-none-eabi-4_9-2014q4-20141203-linux.tar.bz2 + +ENV PATH /home/Downloads/gcc-arm-none-eabi-4_9-2014q4/bin:$PATH + +RUN easy_install -Z robotframework +RUN easy_install -Z docutils + +RUN git clone https://github.com/asifsardar26/Runtime.git /home/Runtime +RUN git --git-dir /home/Runtime/.git --work-tree /home/Runtime checkout feature-encX24J600-wip + +RUN git clone https://github.com/asifsardar26/ELL-i-PyBot-Tests /home/Runtime/robot_tests/ + +RUN git clone git://github.com/RIOT-OS/RIOT /home/RIOT + +#WORKDIR /home/Runtime/stm32/tests/robot_library/ +#RUN make PLATFORM=emulator + +VOLUME ["/home"] + +WORKDIR /home + +CMD ["/bin/bash"] diff --git a/Dockerfile-32-bit-Robotframework/Dockerfile b/Dockerfile-32-bit-Robotframework/Dockerfile new file mode 100644 index 0000000..5206fb4 --- /dev/null +++ b/Dockerfile-32-bit-Robotframework/Dockerfile @@ -0,0 +1,31 @@ +FROM 32bit/ubuntu:14.04 + +MAINTAINER Asif Sardar + +ENV DEBIAN_FRONTEND noninteractive + +RUN apt-get update && apt-get install -y \ + make \ + gcc \ + g++ \ + git \ + python2.7 \ + python2.7-dev \ + python-setuptools + +RUN easy_install -Z robotframework +RUN easy_install -Z docutils + +RUN git clone https://github.com/asifsardar26/Runtime.git /home/Runtime +RUN git --git-dir /home/Runtime/.git --work-tree /home/Runtime checkout feature-encX24J600-wip + +RUN git clone https://github.com/asifsardar26/ELL-i-PyBot-Tests /home/Runtime/robot_tests/ + +WORKDIR /home/Runtime/stm32/tests/robot_library/ +RUN make PLATFORM=emulator + +VOLUME ["/home"] + +WORKDIR /home/Runtime/robot_tests + +CMD ["/bin/bash"] diff --git a/Dockerfile-64-bit-Robotframework/Dockerfile b/Dockerfile-64-bit-Robotframework/Dockerfile new file mode 100644 index 0000000..07b5c9e --- /dev/null +++ b/Dockerfile-64-bit-Robotframework/Dockerfile @@ -0,0 +1,74 @@ +FROM ubuntu:14.04 + +MAINTAINER Asif Sardar + +RUN dpkg --add-architecture i386 + +ENV DEBIAN_FRONTEND noninteractive + +RUN apt-get update && apt-get install -y \ + build-essential \ + gcc-multilib \ + gcc-4.8-multilib \ + g++-multilib \ + g++-4.8-multilib \ + #ia32-libs \ + #ia32-libs-multiarch \ + libc6-dev \ + libgmp-dev \ + libmpfr-dev \ + libmpc-dev \ + + # Dependencies for python source code compilation + zlib1g-dev \ + lib32z1-dev \ + libreadline-dev \ + libreadline6-dev \ + lib32readline-dev \ + lib32readline6-dev \ + libgdm-dev \ + libsqlite3-dev \ + libgdbm-dev \ + libdbm-ocaml-dev \ + libdb4o-cil-dev \ + libx11-dev \ + lib32bz2-dev \ + libbz2-dev \ + libncurses5-dev \ + lib32ncurses5-dev \ + tk-dev \ + git + +ADD https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz /home/Downloads/ +WORKDIR /home/Downloads/ +RUN tar zxvf Python-2.7.8.tgz +WORKDIR /home/Downloads/Python-2.7.8/ +RUN BASECFLAGS=-m32 LDFLAGS=-m32 CFLAGS=-m32 ./configure --prefix=/opt/pym32 +RUN make +RUN make install + +ADD https://pypi.python.org/packages/source/r/robotframework/robotframework-2.8.7.tar.gz#md5=42a38054fb24787e6d767e0a96315627 /home/Downloads/ +WORKDIR /home/Downloads/ +RUN tar zxvf robotframework-2.8.7.tar.gz +WORKDIR /home/Downloads/robotframework-2.8.7 +RUN /opt/pym32/bin/python setup.py install + +ADD https://pypi.python.org/packages/source/d/docutils/docutils-0.12.tar.gz#md5=4622263b62c5c771c03502afa3157768 /home/Downloads/ +WORKDIR /home/Downloads/ +RUN tar zxvf docutils-0.12.tar.gz +WORKDIR /home/Downloads/docutils-0.12 +RUN /opt/pym32/bin/python setup.py install + +RUN git clone https://github.com/asifsardar26/Runtime.git /home/Runtime +RUN git --git-dir /home/Runtime/.git --work-tree /home/Runtime checkout feature-encX24J600-wip + +RUN git clone https://github.com/asifsardar26/ELL-i-PyBot-Tests /home/Runtime/robot_tests/ + +WORKDIR /home/Runtime/stm32/tests/robot_library/ +RUN make PLATFORM=emulator + +VOLUME ["/home"] + +WORKDIR /home/Runtime/robot_tests + +CMD ["/bin/bash"] diff --git a/robot_tests b/robot_tests index c240ef7..a88ccbc 160000 --- a/robot_tests +++ b/robot_tests @@ -1 +1 @@ -Subproject commit c240ef71f581a9b1613d1be88c8f70779a41a2b7 +Subproject commit a88ccbcf4a5fd292d16d2733c41ff8658d80803d diff --git a/stm32/cores/arduelli/Arduino_Serial.h b/stm32/cores/arduelli/Arduino_Serial.h index faaecb0..5be9950 100644 --- a/stm32/cores/arduelli/Arduino_Serial.h +++ b/stm32/cores/arduelli/Arduino_Serial.h @@ -51,6 +51,9 @@ class SerialClass : public Stream { constexpr SerialClass(const USART &); void begin(uint32_t) const; void write(uint8_t) const; + void writeHex(uint32_t) const; +private: + const uint8_t hex_digits[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; }; #define DEFINE_SERIAL(usart_number, tx_letter, tx_pin, tx_af, rx_letter, rx_pin, rx_af) \ @@ -95,4 +98,14 @@ void SerialClass::write(uint8_t c) const { } +ARDUINO_INLINE_MEMBER_FUNCTION +void SerialClass::writeHex(uint32_t n) const { + int32_t i; + uint32_t j; + for (i=7; i>=0; i--) { + j = (n >> (4*i)) & 0xf; + write(hex_digits[j]); + } +} + #endif//_ARDUINO_SERIAL_H_ diff --git a/stm32/emulator/inc/FLASH.h b/stm32/emulator/inc/FLASH.h index 6744906..d41dd5f 100644 --- a/stm32/emulator/inc/FLASH.h +++ b/stm32/emulator/inc/FLASH.h @@ -17,22 +17,41 @@ * along with ELL-i software. If not, see . */ +/** + * @author Pekka Nikander 2014 + */ + #include +#include +#include +#include +#include +#include class Flash { public: - DEFINE_REGISTER(32, FLASH, ACR, 0x0000000); - DEFINE_REGISTER(32, FLASH, KEYR, 0x0000000); - DEFINE_REGISTER(32, FLASH, OPTKEYR, 0x0000000); - DEFINE_REGISTER(32, FLASH, SR, 0x0000000); - DEFINE_REGISTER(32, FLASH, CR, 0x0000080); + //DEFINE_REGISTER(32, FLASH, ACR, 0x0000000); + //DEFINE_REGISTER(32, FLASH, KEYR, 0x0000000); + //DEFINE_REGISTER(32, FLASH, OPTKEYR, 0x0000000); + //DEFINE_REGISTER(32, FLASH, SR, 0x0000000); + //DEFINE_REGISTER(32, FLASH, CR, 0x0000080); + Register_FLASH_ACR ACR; + Register_FLASH_KEYR KEYR; + Register_FLASH_OPTKEYR OPTKEYR; + Register_FLASH_SR SR; + Register_FLASH_CR CR; protected: Flash() - : ACR() - , CR() + : CR(0x0000080) {} public: static Flash FLASH; + + void FLASH_ACR_VALUES( Flash *const flash, CALLBACK(FLASH_ACR_CALLBACK) ); + void FLASH_KEYR_VALUES( Flash *const flash, CALLBACK(FLASH_KEYR_CALLBACK) ); + void FLASH_OPTKEYR_VALUES( Flash *const flash, CALLBACK(FLASH_OPTKEYR_CALLBACK) ); + void FLASH_SR_VALUES( Flash *const flash, CALLBACK(FLASH_SR_CALLBACK) ); + void FLASH_CR_VALUES( Flash *const flash, CALLBACK(FLASH_CR_CALLBACK) ); }; Flash *const FLASH = &Flash::FLASH; diff --git a/stm32/emulator/inc/GPIO.h b/stm32/emulator/inc/GPIO.h index 42596a7..cf42917 100644 --- a/stm32/emulator/inc/GPIO.h +++ b/stm32/emulator/inc/GPIO.h @@ -17,6 +17,10 @@ * along with ELL-i software. If not, see . */ +/** + * @author Pekka Nikander 2014 + */ + #include #include //#include @@ -72,6 +76,7 @@ class GeneralPurposeInputOutput { # error "Unknown MCU die. Please define." #endif {} + public: static GeneralPurposeInputOutput GPIOA; static GeneralPurposeInputOutput GPIOB; @@ -82,6 +87,23 @@ class GeneralPurposeInputOutput { static GeneralPurposeInputOutput GPIOG; static GeneralPurposeInputOutput GPIOH; static GeneralPurposeInputOutput GPIOI; + + void GPIO_MODER_VALUES( GeneralPurposeInputOutput *const gpioPort, CALLBACK(GPIO_MODER_CALLBACK) ); + void GPIO_PUPDR_VALUES( GeneralPurposeInputOutput *const gpioPort, CALLBACK(GPIO_PUPDR_CALLBACK) ); + void GPIO_ODR_VALUES( GeneralPurposeInputOutput *const gpioPort, CALLBACK(GPIO_ODR_CALLBACK) ); + void GPIO_IDR_VALUES( GeneralPurposeInputOutput *const gpioPort, CALLBACK(GPIO_IDR_CALLBACK) ); +#if defined(__STM32F407__) || defined(__STM32F334__) + void GPIO_BSRRL_VALUES( GeneralPurposeInputOutput *const gpioPort, CALLBACK(GPIO_BSRRL_CALLBACK) ); + void GPIO_AFR_VALUES( GeneralPurposeInputOutput *const gpioPort, CALLBACK(GPIO_AFR_CALLBACK) ); + void GPIO_BSRRH_VALUES( GeneralPurposeInputOutput *const gpioPort, CALLBACK(GPIO_BSRRH_CALLBACK) ); +#elif defined(__STM32F051__) + void GPIO_BSRR_VALUES( GeneralPurposeInputOutput *const gpioPort, CALLBACK(GPIO_BSRR_CALLBACK) ); + void GPIO_AFR_VALUES( GeneralPurposeInputOutput *const gpioPort, CALLBACK(GPIO_AFR_CALLBACK) ); + void GPIO_BRR_VALUES( GeneralPurposeInputOutput *const gpioPort, CALLBACK(GPIO_BRR_CALLBACK) ); +#else +# error "Unknown MCU die. Please define." +#endif + }; GeneralPurposeInputOutput *const GPIOA = &GeneralPurposeInputOutput::GPIOA; @@ -93,3 +115,24 @@ GeneralPurposeInputOutput *const GPIOF = &GeneralPurposeInputOutput::GPIOF; GeneralPurposeInputOutput *const GPIOG = &GeneralPurposeInputOutput::GPIOG; GeneralPurposeInputOutput *const GPIOH = &GeneralPurposeInputOutput::GPIOH; GeneralPurposeInputOutput *const GPIOI = &GeneralPurposeInputOutput::GPIOI; + +/* + * Define macro for GPIO array index calculation from const char* string + * for table based approach and code readability + */ +#define IDX(port) (port[0] - 'A') + +/* + * An array of GPIO ports, the index of which is calculated according to + * the GPIO port for the board + */ +GeneralPurposeInputOutput *const GPIOPORT[] = { GPIOA + , GPIOB + , GPIOC + , GPIOD + , GPIOE + , GPIOF + , GPIOG + , GPIOH + , GPIOI +}; diff --git a/stm32/emulator/inc/PWR.h b/stm32/emulator/inc/PWR.h index 3cbd736..01ba750 100644 --- a/stm32/emulator/inc/PWR.h +++ b/stm32/emulator/inc/PWR.h @@ -17,20 +17,35 @@ * along with ELL-i software. If not, see . */ +/** + * @author Pekka Nikander 2014 + */ + #ifndef _PWR_H_ #define _PWR_H_ #include +#if defined(__STM32F407__) +# include +#endif class PowerController { public: #if defined(__STM32F407__) - DEFINE_REGISTER(32, PWR, CR, 0x00004000); // XXX Check, set to reset value + //DEFINE_REGISTER(32, PWR, CR, 0x00004000); // XXX Check, set to reset value + Register_PWR_CR CR; #endif protected: - PowerController() {} + PowerController() +#if defined(__STM32F407__) + : CR(0x00004000) +#endif + {} public: static PowerController PWR; +#if defined(__STM32F407__) + void PWR_CR_VALUES( PowerController *const pwr, CALLBACK(PWR_CR_CALLBACK) ); +#endif }; PowerController *const PWR = &PowerController::PWR; diff --git a/stm32/emulator/inc/RCC.h b/stm32/emulator/inc/RCC.h index f027530..842b2b5 100644 --- a/stm32/emulator/inc/RCC.h +++ b/stm32/emulator/inc/RCC.h @@ -17,54 +17,158 @@ * along with ELL-i software. If not, see . */ +/** + * @author Pekka Nikander 2014 + */ + #ifndef _RCC_H_ #define _RCC_H_ #include +#include +#if defined(__STM32F407__) +# include +#endif #include +#include +#include +#if defined(__STM32F407__) +# include +#elif defined(__STM32F051__) || defined(__STM32F334__) +# include +#else +# error "Unknown MCU die. Please define." +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include class ResetClockControl { public: +/* #if defined(__STM32F407__) || defined(__STM32F334__) - DEFINE_REGISTER(32, RCC, CR, 0x0202FF83); // HSERDY set for SetSysClock + //DEFINE_REGISTER(32, RCC, CR, 0x0202FF83); // HSERDY set for SetSysClock #elif defined(__STM32F051__) || defined(__STM32F334__) - DEFINE_REGISTER(32, RCC, CR, 0x0200FF83); // PLL set for SetSysClock + //DEFINE_REGISTER(32, RCC, CR, 0x0200FF83); // PLL set for SetSysClock #else # error "Unknown MCU die. Please define." #endif #if defined(__STM32F407__) - DEFINE_REGISTER(32, RCC, PLLCFGR, 0x24003010); // XXX Check, set to reset value + //DEFINE_REGISTER(32, RCC, PLLCFGR, 0x24003010); // XXX Check, set to reset value #endif #if defined(__STM32F407__) - Register_RCC_CFGR CFGR; + //Register_RCC_CFGR CFGR; #elif defined(__STM32F051__) || defined(__STM32F334__) - DEFINE_REGISTER(32, RCC, CFGR, 0x00000008); // PLL set for SetSysClock + //DEFINE_REGISTER(32, RCC, CFGR, 0x00000008); // PLL set for SetSysClock #else # error "Unknown MCU die. Please define." #endif - DEFINE_REGISTER(32, RCC, CIR, 0x00000000); - DEFINE_REGISTER(32, RCC, APB1RSTR, 0x00000000); + //DEFINE_REGISTER(32, RCC, CIR, 0x00000000); + //DEFINE_REGISTER(32, RCC, APB1RSTR, 0x00000000); #if defined(__STM32F407__) - DEFINE_REGISTER(32, RCC, AHB1ENR, 0x00000014 /* XXX CHECK ME */); + //DEFINE_REGISTER(32, RCC, AHB1ENR, 0x00000014 /* XXX CHECK ME /); #elif defined(__STM32F051__) || defined(__STM32F334__) - DEFINE_REGISTER(32, RCC, AHBENR, 0x00000014); + //DEFINE_REGISTER(32, RCC, AHBENR, 0x00000014); #else # error "Unknown MCU die. Please define." #endif - DEFINE_REGISTER(32, RCC, APB2ENR, 0x00000000); - DEFINE_REGISTER(32, RCC, APB1ENR, 0x00000000); - DEFINE_REGISTER(32, RCC, APB2RSTR, 0x00000000); - DEFINE_REGISTER(32, RCC, BDCR, 0x00000018); - DEFINE_REGISTER(32, RCC, CSR, 0x0C000000); - DEFINE_REGISTER(32, RCC, AHBRSTR, 0x00000000); - DEFINE_REGISTER(32, RCC, CFGR2, 0x00000000); - DEFINE_REGISTER(32, RCC, CFGR3, 0x00000000); - DEFINE_REGISTER(32, RCC, CR2, 0x0000FF80); + //DEFINE_REGISTER(32, RCC, APB2ENR, 0x00000000); + //DEFINE_REGISTER(32, RCC, APB1ENR, 0x00000000); + //DEFINE_REGISTER(32, RCC, APB2RSTR, 0x00000000); + //DEFINE_REGISTER(32, RCC, BDCR, 0x00000018); + //DEFINE_REGISTER(32, RCC, CSR, 0x0C000000); + //DEFINE_REGISTER(32, RCC, AHBRSTR, 0x00000000); + //DEFINE_REGISTER(32, RCC, CFGR2, 0x00000000); + //DEFINE_REGISTER(32, RCC, CFGR3, 0x00000000); + //DEFINE_REGISTER(32, RCC, CR2, 0x0000FF80); +//######################################## +*/ + Register_RCC_CR CR; +#if defined(__STM32F407__) + Register_RCC_PLLCFGR PLLCFGR; +#endif + Register_RCC_CFGR CFGR; + Register_RCC_CIR CIR; + Register_RCC_APB1RSTR APB1RSTR; +#if defined(__STM32F407__) + Register_RCC_AHB1ENR AHB1ENR; +#elif defined(__STM32F051__) || defined(__STM32F334__) + Register_RCC_AHBENR AHBENR; +#else +# error "Unknown MCU die. Please define." +#endif + Register_RCC_APB2ENR APB2ENR; + Register_RCC_APB1ENR APB1ENR; + Register_RCC_APB2RSTR APB2RSTR; + Register_RCC_BDCR BDCR; + Register_RCC_CSR CSR; + Register_RCC_AHBRSTR AHBRSTR; + Register_RCC_CFGR2 CFGR2; + Register_RCC_CFGR3 CFGR3; + Register_RCC_CR2 CR2; protected: - ResetClockControl() {} + ResetClockControl() +#if defined(__STM32F407__) || defined(__STM32F334__) + : CR(0x0202FF83) // HSERDY set for SetSysClock +#elif defined(__STM32F051__) || defined(__STM32F334__) + : CR(0x0200FF83) // PLL set for SetSysClock +#else +# error "Unknown MCU die. Please define." +#endif +#if defined(__STM32F407__) + , PLLCFGR(0x24003010) // XXX Check, set to reset value +#endif +#if defined(__STM32F407__) + , CFGR(0) +#elif defined(__STM32F051__) || defined(__STM32F334__) + , CFGR(0x00000008) // PLL set for SetSysClock +#else +# error "Unknown MCU die. Please define." +#endif +#if defined(__STM32F407__) + , AHB1ENR(0x00000014 /* XXX CHECK ME */) +#elif defined(__STM32F051__) || defined(__STM32F334__) + , AHBENR(0x00000014) +#else +# error "Unknown MCU die. Please define." +#endif + , BDCR(0x0C000000) + , CSR(0x0C000000) + , CR2(0x0000FF80) + {} public: static ResetClockControl RCC; + + void RCC_CR_VALUES( ResetClockControl *const rcc, CALLBACK(RCC_CR_CALLBACK) ); +#if defined(__STM32F407__) + void RCC_PLLCFGR_VALUES( ResetClockControl *const rcc, CALLBACK(RCC_PLLCFGR_CALLBACK) ); +#endif + void RCC_CFGR_VALUES( ResetClockControl *const rcc, CALLBACK(RCC_CFGR_CALLBACK) ); + void RCC_CIR_VALUES( ResetClockControl *const rcc, CALLBACK(RCC_CIR_CALLBACK) ); + void RCC_APB1RSTR_VALUES( ResetClockControl *const rcc, CALLBACK(RCC_APB1RSTR_CALLBACK) ); +#if defined(__STM32F407__) + void RCC_AHB1ENR_VALUES( ResetClockControl *const rcc, CALLBACK(RCC_AHB1ENR_CALLBACK) ); +#elif defined(__STM32F051__) || defined(__STM32F334__) + void RCC_AHBENR_VALUES( ResetClockControl *const rcc, CALLBACK(RCC_AHBENR_CALLBACK) ); +#else +# error "Unknown MCU die. Please define." +#endif + void RCC_APB2ENR_VALUES( ResetClockControl *const rcc, CALLBACK(RCC_APB2ENR_CALLBACK) ); + void RCC_APB1ENR_VALUES( ResetClockControl *const rcc, CALLBACK(RCC_APB1ENR_CALLBACK) ); + void RCC_APB2RSTR_VALUES( ResetClockControl *const rcc, CALLBACK(RCC_APB2RSTR_CALLBACK) ); + void RCC_BDCR_VALUES( ResetClockControl *const rcc, CALLBACK(RCC_BDCR_CALLBACK) ); + void RCC_CSR_VALUES( ResetClockControl *const rcc, CALLBACK(RCC_CSR_CALLBACK) ); + void RCC_AHBRSTR_VALUES( ResetClockControl *const rcc, CALLBACK(RCC_AHBRSTR_CALLBACK) ); + void RCC_CFGR2_VALUES( ResetClockControl *const rcc, CALLBACK(RCC_CFGR2_CALLBACK) ); + void RCC_CFGR3_VALUES( ResetClockControl *const rcc, CALLBACK(RCC_CFGR3_CALLBACK) ); + void RCC_CR2_VALUES( ResetClockControl *const rcc, CALLBACK(RCC_CR2_CALLBACK) ); }; ResetClockControl *const RCC = &ResetClockControl::RCC; diff --git a/stm32/emulator/inc/Register.h b/stm32/emulator/inc/Register.h index 40d33f5..aa60465 100644 --- a/stm32/emulator/inc/Register.h +++ b/stm32/emulator/inc/Register.h @@ -25,12 +25,15 @@ #include #include +#define CALLBACK(register) void (*register)(const char* periph, const char* name, uint32_t value, const char* opStr) + class Register { protected: uint32_t value_; const std::string periph_; const std::string name_; uint8_t size_; + std::string opStr_; Register(std::string periph, std::string name, uint8_t size, uint32_t value) @@ -45,12 +48,17 @@ class Register { uint32_t operator &= (uint32_t); uint32_t operator = (uint32_t); uint32_t operator = (uint32_t) volatile; - uint32_t operator & (uint32_t) const; - uint16_t operator & (uint16_t) const; // Used by SPI, Serial, ... + uint32_t operator & (uint32_t); + uint16_t operator & (uint16_t); // Used by SPI, Serial, ... operator uint32_t () volatile { return value_; } + uint32_t registerValue() const; + const std::string registerPeriph() const; + const std::string registerName() const; + std::string registerOpStr() const; + protected: - void printout(const std::string opStr, uint32_t result) const; + void printout(const std::string opStr, uint32_t result); }; #define DEFINE_REGISTER(size, periph, name, value) \ diff --git a/stm32/emulator/inc/Register_FLASH_ACR.h b/stm32/emulator/inc/Register_FLASH_ACR.h new file mode 100644 index 0000000..31c214a --- /dev/null +++ b/stm32/emulator/inc/Register_FLASH_ACR.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _Register_FLASH_ACR_H_ +#define _Register_FLASH_ACR_H_ + +#include + +class Register_FLASH_ACR : public Register { +public: + Register_FLASH_ACR() : Register("FLASH", "ACR", 32, 0) {} + + uint32_t operator = (uint32_t arg); +}; + +#endif //_Register_FLASH_ACR_H_ diff --git a/stm32/emulator/inc/Register_FLASH_CR.h b/stm32/emulator/inc/Register_FLASH_CR.h new file mode 100644 index 0000000..76fbbe8 --- /dev/null +++ b/stm32/emulator/inc/Register_FLASH_CR.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _Register_FLASH_CR_H_ +#define _Register_FLASH_CR_H_ + +#include + +class Register_FLASH_CR : public Register { +public: + Register_FLASH_CR(uint32_t val) : Register("FLASH", "CR", 32, val) {} + + uint32_t operator = (uint32_t arg); +}; + +#endif //_Register_FLASH_CR_H_ diff --git a/stm32/emulator/inc/Register_FLASH_KEYR.h b/stm32/emulator/inc/Register_FLASH_KEYR.h new file mode 100644 index 0000000..4c39cae --- /dev/null +++ b/stm32/emulator/inc/Register_FLASH_KEYR.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _Register_FLASH_KEYR_H_ +#define _Register_FLASH_KEYR_H_ + +#include + +class Register_FLASH_KEYR : public Register { +public: + Register_FLASH_KEYR() : Register("FLASH", "KEYR", 32, 0) {} + + uint32_t operator = (uint32_t arg); +}; + +#endif //_Register_FLASH_KEYR_H_ + diff --git a/stm32/emulator/inc/Register_FLASH_OPTKEYR.h b/stm32/emulator/inc/Register_FLASH_OPTKEYR.h new file mode 100644 index 0000000..a6540ea --- /dev/null +++ b/stm32/emulator/inc/Register_FLASH_OPTKEYR.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _Register_FLASH_OPTKEYR_H_ +#define _Register_FLASH_OPTKEYR_H_ + +#include + +class Register_FLASH_OPTKEYR : public Register { +public: + Register_FLASH_OPTKEYR() : Register("FLASH", "OPTKEYR", 32, 0) {} + + uint32_t operator = (uint32_t arg); +}; + +#endif //_Register_FLASH_OPTKEYR_H_ + diff --git a/stm32/emulator/inc/Register_FLASH_SR.h b/stm32/emulator/inc/Register_FLASH_SR.h new file mode 100644 index 0000000..d848283 --- /dev/null +++ b/stm32/emulator/inc/Register_FLASH_SR.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _Register_FLASH_SR_H_ +#define _Register_FLASH_SR_H_ + +#include + +class Register_FLASH_SR : public Register { +public: + Register_FLASH_SR() : Register("FLASH", "SR", 32, 0) {} + + uint32_t operator = (uint32_t arg); +}; + +#endif //_Register_FLASH_SR_H_ diff --git a/stm32/emulator/inc/Register_PWR_CR.h b/stm32/emulator/inc/Register_PWR_CR.h new file mode 100644 index 0000000..df0c840 --- /dev/null +++ b/stm32/emulator/inc/Register_PWR_CR.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _REGISTER_PWR_CR_H_ +#define _REGISTER_PWR_CR_H_ + +#include + +class Register_PWR_CR : public Register { +public: + Register_PWR_CR(uint32_t val) : Register("PWR", "CR", 32, val) {} + + uint32_t operator = (uint32_t arg); +}; + +#endif //_REGISTER_PWR_CR_H_ diff --git a/stm32/emulator/inc/Register_RCC_AHB1ENR.h b/stm32/emulator/inc/Register_RCC_AHB1ENR.h new file mode 100644 index 0000000..66a4d39 --- /dev/null +++ b/stm32/emulator/inc/Register_RCC_AHB1ENR.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _Register_RCC_AHB1ENR_H_ +#define _Register_RCC_AHB1ENR_H_ + +#include + +class Register_RCC_AHB1ENR : public Register { +public: + Register_RCC_AHB1ENR(uint32_t val) : Register("RCC", "AHB1ENR", 32, val) {} + + uint32_t operator = (uint32_t arg); +}; + +#endif //_Register_RCC_AHB1ENR_H_ diff --git a/stm32/emulator/inc/Register_RCC_AHBENR.h b/stm32/emulator/inc/Register_RCC_AHBENR.h new file mode 100644 index 0000000..9101a24 --- /dev/null +++ b/stm32/emulator/inc/Register_RCC_AHBENR.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _Register_RCC_AHBENR_H_ +#define _Register_RCC_AHBENR_H_ + +#include + +class Register_RCC_AHBENR : public Register { +public: + Register_RCC_AHBENR(uint32_t val) : Register("RCC", "AHBENR", 32, val) {} + + uint32_t operator = (uint32_t arg); +}; + +#endif //_Register_RCC_AHBENR_H_ diff --git a/stm32/emulator/inc/Register_RCC_AHBRSTR.h b/stm32/emulator/inc/Register_RCC_AHBRSTR.h new file mode 100644 index 0000000..db602c0 --- /dev/null +++ b/stm32/emulator/inc/Register_RCC_AHBRSTR.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _Register_RCC_AHBRSTR_H_ +#define _Register_RCC_AHBRSTR_H_ + +#include + +class Register_RCC_AHBRSTR : public Register { +public: + Register_RCC_AHBRSTR() : Register("RCC", "AHBRSTR", 32, 0) {} + + uint32_t operator = (uint32_t arg); +}; + +#endif //_Register_RCC_AHBRSTR_H_ diff --git a/stm32/emulator/inc/Register_RCC_APB1ENR.h b/stm32/emulator/inc/Register_RCC_APB1ENR.h new file mode 100644 index 0000000..17e1954 --- /dev/null +++ b/stm32/emulator/inc/Register_RCC_APB1ENR.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _Register_RCC_APB1ENR_H_ +#define _Register_RCC_APB1ENR_H_ + +#include + +class Register_RCC_APB1ENR : public Register { +public: + Register_RCC_APB1ENR() : Register("RCC", "APB1ENR", 32, 0) {} + + uint32_t operator = (uint32_t arg); +}; + +#endif //_Register_RCC_APB1ENR_H_ diff --git a/stm32/emulator/inc/Register_RCC_APB1RSTR.h b/stm32/emulator/inc/Register_RCC_APB1RSTR.h new file mode 100644 index 0000000..96dc526 --- /dev/null +++ b/stm32/emulator/inc/Register_RCC_APB1RSTR.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _Register_RCC_APB1RSTR_H_ +#define _Register_RCC_APB1RSTR_H_ + +#include + +class Register_RCC_APB1RSTR : public Register { +public: + Register_RCC_APB1RSTR() : Register("RCC", "APB1RSTR", 32, 0) {} + + uint32_t operator = (uint32_t arg); +}; + +#endif //_Register_RCC_APB1RSTR_H_ diff --git a/stm32/emulator/inc/Register_RCC_APB2ENR.h b/stm32/emulator/inc/Register_RCC_APB2ENR.h new file mode 100644 index 0000000..2931f39 --- /dev/null +++ b/stm32/emulator/inc/Register_RCC_APB2ENR.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _Register_RCC_APB2ENR_H_ +#define _Register_RCC_APB2ENR_H_ + +#include + +class Register_RCC_APB2ENR : public Register { +public: + Register_RCC_APB2ENR() : Register("RCC", "APB2ENR", 32, 0) {} + + uint32_t operator = (uint32_t arg); +}; + +#endif //_Register_RCC_APB2ENR_H_ diff --git a/stm32/emulator/inc/Register_RCC_APB2RSTR.h b/stm32/emulator/inc/Register_RCC_APB2RSTR.h new file mode 100644 index 0000000..844fdae --- /dev/null +++ b/stm32/emulator/inc/Register_RCC_APB2RSTR.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _Register_RCC_APB2RSTR_H_ +#define _Register_RCC_APB2RSTR_H_ + +#include + +class Register_RCC_APB2RSTR : public Register { +public: + Register_RCC_APB2RSTR() : Register("RCC", "APB2RSTR", 32, 0) {} + + uint32_t operator = (uint32_t arg); +}; + +#endif //_Register_RCC_APB2RSTR_H_ diff --git a/stm32/emulator/inc/Register_RCC_BDCR.h b/stm32/emulator/inc/Register_RCC_BDCR.h new file mode 100644 index 0000000..113bfe7 --- /dev/null +++ b/stm32/emulator/inc/Register_RCC_BDCR.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _Register_RCC_BDCR_H_ +#define _Register_RCC_BDCR_H_ + +#include + +class Register_RCC_BDCR : public Register { +public: + Register_RCC_BDCR(uint32_t val) : Register("RCC", "BDCR", 32, val) {} + + uint32_t operator = (uint32_t arg); +}; + +#endif //_Register_RCC_BDCR_H_ diff --git a/stm32/emulator/inc/Register_RCC_CFGR.h b/stm32/emulator/inc/Register_RCC_CFGR.h index 9f1cc97..b716f28 100644 --- a/stm32/emulator/inc/Register_RCC_CFGR.h +++ b/stm32/emulator/inc/Register_RCC_CFGR.h @@ -17,6 +17,10 @@ * along with ELL-i software. If not, see . */ +/** + * @author Pekka Nikander 2014 + */ + #ifndef _REGISTER_RCC_CFGR_H_ #define _REGISTER_RCC_CFGR_H_ @@ -24,7 +28,7 @@ class Register_RCC_CFGR : public Register { public: - Register_RCC_CFGR() : Register("RCC", "CFGR", 32, 0) {} + Register_RCC_CFGR(uint32_t val) : Register("RCC", "CFGR", 32, val) {} uint32_t operator = (uint32_t arg); }; diff --git a/stm32/emulator/inc/Register_RCC_CFGR2.h b/stm32/emulator/inc/Register_RCC_CFGR2.h new file mode 100644 index 0000000..4f8299a --- /dev/null +++ b/stm32/emulator/inc/Register_RCC_CFGR2.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _Register_RCC_CFGR2_H_ +#define _Register_RCC_CFGR2_H_ + +#include + +class Register_RCC_CFGR2 : public Register { +public: + Register_RCC_CFGR2() : Register("RCC", "CFGR2", 32, 0) {} + + uint32_t operator = (uint32_t arg); +}; + +#endif //_Register_RCC_CFGR2_H_ diff --git a/stm32/emulator/inc/Register_RCC_CFGR3.h b/stm32/emulator/inc/Register_RCC_CFGR3.h new file mode 100644 index 0000000..ecf19db --- /dev/null +++ b/stm32/emulator/inc/Register_RCC_CFGR3.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _Register_RCC_CFGR3_H_ +#define _Register_RCC_CFGR3_H_ + +#include + +class Register_RCC_CFGR3 : public Register { +public: + Register_RCC_CFGR3() : Register("RCC", "CFGR3", 32, 0) {} + + uint32_t operator = (uint32_t arg); +}; + +#endif //_Register_RCC_CFGR3_H_ diff --git a/stm32/emulator/inc/Register_RCC_CIR.h b/stm32/emulator/inc/Register_RCC_CIR.h new file mode 100644 index 0000000..d57f806 --- /dev/null +++ b/stm32/emulator/inc/Register_RCC_CIR.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _Register_RCC_CIR_H_ +#define _Register_RCC_CIR_H_ + +#include + +class Register_RCC_CIR : public Register { +public: + Register_RCC_CIR() : Register("RCC", "CIR", 32, 0) {} + + uint32_t operator = (uint32_t arg); +}; + +#endif //_Register_RCC_CIR_H_ diff --git a/stm32/emulator/inc/Register_RCC_CR.h b/stm32/emulator/inc/Register_RCC_CR.h new file mode 100644 index 0000000..3a030b9 --- /dev/null +++ b/stm32/emulator/inc/Register_RCC_CR.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _Register_RCC_CR_H_ +#define _Register_RCC_CR_H_ + +#include + +class Register_RCC_CR : public Register { +public: + Register_RCC_CR(uint32_t val) : Register("RCC", "CR", 32, val) {} + + uint32_t operator = (uint32_t arg); +}; + +#endif //_Register_RCC_CR_H_ diff --git a/stm32/emulator/inc/Register_RCC_CR2.h b/stm32/emulator/inc/Register_RCC_CR2.h new file mode 100644 index 0000000..75a567b --- /dev/null +++ b/stm32/emulator/inc/Register_RCC_CR2.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _Register_RCC_CR2_H_ +#define _Register_RCC_CR2_H_ + +#include + +class Register_RCC_CR2 : public Register { +public: + Register_RCC_CR2(uint32_t val) : Register("RCC", "CR2", 32, val) {} + + uint32_t operator = (uint32_t arg); +}; + +#endif //_Register_RCC_CR2_H_ diff --git a/stm32/emulator/inc/Register_RCC_CSR.h b/stm32/emulator/inc/Register_RCC_CSR.h new file mode 100644 index 0000000..91ca6ce --- /dev/null +++ b/stm32/emulator/inc/Register_RCC_CSR.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _Register_RCC_CSR_H_ +#define _Register_RCC_CSR_H_ + +#include + +class Register_RCC_CSR : public Register { +public: + Register_RCC_CSR(uint32_t val) : Register("RCC", "CSR", 32, val) {} + + uint32_t operator = (uint32_t arg); +}; + +#endif //_Register_RCC_CSR_H_ diff --git a/stm32/emulator/inc/Register_RCC_PLLCFGR.h b/stm32/emulator/inc/Register_RCC_PLLCFGR.h new file mode 100644 index 0000000..290da8d --- /dev/null +++ b/stm32/emulator/inc/Register_RCC_PLLCFGR.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _Register_RCC_PLLCFGR_H_ +#define _Register_RCC_PLLCFGR_H_ + +#include + +class Register_RCC_PLLCFGR : public Register { +public: + Register_RCC_PLLCFGR(uint32_t val) : Register("RCC", "PLLCFGR", 32, val) {} + + uint32_t operator = (uint32_t arg); +}; + +#endif //_Register_RCC_PLLCFGR_H_ diff --git a/stm32/emulator/inc/Register_SCB_CPUID.h b/stm32/emulator/inc/Register_SCB_CPUID.h new file mode 100644 index 0000000..7e27f7c --- /dev/null +++ b/stm32/emulator/inc/Register_SCB_CPUID.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _Register_SCB_CPUID_H_ +#define _Register_SCB_CPUID_H_ + +#include + +class Register_SCB_CPUID : public Register { +public: + Register_SCB_CPUID(uint32_t val) : Register("SCB", "CPUID", 32, val) {} + + uint32_t operator = (uint32_t arg); +}; + +#endif //_Register_SCB_CPUID_H_ diff --git a/stm32/emulator/inc/Register_SCB_ICSR.h b/stm32/emulator/inc/Register_SCB_ICSR.h new file mode 100644 index 0000000..d7ad3ee --- /dev/null +++ b/stm32/emulator/inc/Register_SCB_ICSR.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _Register_SCB_ICSR_H_ +#define _Register_SCB_ICSR_H_ + +#include + +class Register_SCB_ICSR : public Register { +public: + Register_SCB_ICSR(uint32_t val) : Register("SCB", "ICSR", 32, val) {} + + uint32_t operator = (uint32_t arg); +}; + +#endif //_Register_SCB_ICSR_H_ diff --git a/stm32/emulator/inc/Register_SCB_VTOR.h b/stm32/emulator/inc/Register_SCB_VTOR.h new file mode 100644 index 0000000..0bfff69 --- /dev/null +++ b/stm32/emulator/inc/Register_SCB_VTOR.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _Register_SCB_VTOR_H_ +#define _Register_SCB_VTOR_H_ + +#include + +class Register_SCB_VTOR : public Register { +public: + Register_SCB_VTOR(uint32_t val) : Register("SCB", "VTOR", 32, val) {} + + uint32_t operator = (uint32_t arg); +}; + +#endif //_Register_SCB_VTOR_H_ diff --git a/stm32/emulator/inc/Register_SPI_CR1.h b/stm32/emulator/inc/Register_SPI_CR1.h new file mode 100644 index 0000000..8a9d9ca --- /dev/null +++ b/stm32/emulator/inc/Register_SPI_CR1.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _REGISTER_SPI_CR1_H_ +#define _REGISTER_SPI_CR1_H_ + +#include + +class Register_SPI_CR1 : public Register { +public: + Register_SPI_CR1() : Register("SPI", "CR1", 16, 0) {} + + uint32_t operator = (uint32_t arg); +}; + +#endif //_REGISTER_SPI_CR1_H_ diff --git a/stm32/emulator/inc/Register_SPI_CR2.h b/stm32/emulator/inc/Register_SPI_CR2.h new file mode 100644 index 0000000..a0c3c2d --- /dev/null +++ b/stm32/emulator/inc/Register_SPI_CR2.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _REGISTER_SPI_CR2_H_ +#define _REGISTER_SPI_CR2_H_ + +#include + +class Register_SPI_CR2 : public Register { +public: + Register_SPI_CR2() : Register("SPI", "CR2", 16, 0) {} + + uint32_t operator = (uint32_t arg); +}; + +#endif //_REGISTER_SPI_CR2_H_ diff --git a/stm32/emulator/inc/Register_SPI_DR.h b/stm32/emulator/inc/Register_SPI_DR.h index 1cc160a..929a5e4 100644 --- a/stm32/emulator/inc/Register_SPI_DR.h +++ b/stm32/emulator/inc/Register_SPI_DR.h @@ -17,6 +17,10 @@ * along with ELL-i software. If not, see . */ +/** + * @author Pekka Nikander 2014 + */ + #ifndef _REGISTER_SPI_DR_H_ #define _REGISTER_SPI_DR_H_ diff --git a/stm32/emulator/inc/Register_SPI_SR.h b/stm32/emulator/inc/Register_SPI_SR.h index daf26b2..b93d6f7 100644 --- a/stm32/emulator/inc/Register_SPI_SR.h +++ b/stm32/emulator/inc/Register_SPI_SR.h @@ -17,12 +17,17 @@ * along with ELL-i software. If not, see . */ +/** + * @author Pekka Nikander 2014 + */ + #ifndef _REGISTER_SPI_SR_H_ # define _REGISTER_SPI_SR_H_ # include # include + class Register_SPI_SR : public Register { Register_SPI_DR & dr_; public: @@ -31,8 +36,8 @@ class Register_SPI_SR : public Register { , dr_(dr) {} uint32_t operator = (uint32_t arg); - uint16_t operator & (uint16_t) const; - uint16_t operator & (uint32_t) const; + uint16_t operator & (uint16_t); + uint16_t operator & (uint32_t); }; #endif //_REGISTER_SPI_SR_H_ diff --git a/stm32/emulator/inc/Register_TIM_ARR.h b/stm32/emulator/inc/Register_TIM_ARR.h new file mode 100644 index 0000000..ee181fd --- /dev/null +++ b/stm32/emulator/inc/Register_TIM_ARR.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _REGISTER_TIM_ARR_H_ +#define _REGISTER_TIM_ARR_H_ + +#include + +class Register_TIM_ARR : public Register { +public: + Register_TIM_ARR() + : Register("TIM", "ARR", 16, 0) + {} + uint32_t operator = (uint32_t arg); +}; + +#endif//_REGISTER_TIM_ARR_H_ diff --git a/stm32/emulator/inc/Register_TIM_BDTR.h b/stm32/emulator/inc/Register_TIM_BDTR.h new file mode 100644 index 0000000..182575b --- /dev/null +++ b/stm32/emulator/inc/Register_TIM_BDTR.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _REGISTER_TIM_BDTR_H_ +#define _REGISTER_TIM_BDTR_H_ + +#include + +class Register_TIM_BDTR : public Register { +public: + Register_TIM_BDTR() + : Register("TIM", "BDTR", 16, 0) + {} + uint32_t operator = (uint32_t arg); +}; + +#endif//_REGISTER_TIM_BDTR_H_ diff --git a/stm32/emulator/inc/Register_TIM_CCER.h b/stm32/emulator/inc/Register_TIM_CCER.h new file mode 100644 index 0000000..d0d85a0 --- /dev/null +++ b/stm32/emulator/inc/Register_TIM_CCER.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _REGISTER_TIM_CCER_H_ +#define _REGISTER_TIM_CCER_H_ + +#include + +class Register_TIM_CCER : public Register { +public: + Register_TIM_CCER() + : Register("TIM", "CCER", 16, 0) + {} + uint32_t operator = (uint32_t arg); +}; + +#endif//_REGISTER_TIM_CCER_H_ diff --git a/stm32/emulator/inc/Register_TIM_CCMR1.h b/stm32/emulator/inc/Register_TIM_CCMR1.h new file mode 100644 index 0000000..4848f78 --- /dev/null +++ b/stm32/emulator/inc/Register_TIM_CCMR1.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _REGISTER_TIM_CCMR1_H_ +#define _REGISTER_TIM_CCMR1_H_ + +#include + +class Register_TIM_CCMR1 : public Register { +public: + Register_TIM_CCMR1() + : Register("TIM", "CCMR1", 16, 0) + {} + uint32_t operator = (uint32_t arg); +}; + +#endif//_REGISTER_TIM_CCMR1_H_ diff --git a/stm32/emulator/inc/Register_TIM_CCMR2.h b/stm32/emulator/inc/Register_TIM_CCMR2.h new file mode 100644 index 0000000..6f8b036 --- /dev/null +++ b/stm32/emulator/inc/Register_TIM_CCMR2.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _REGISTER_TIM_CCMR2_H_ +#define _REGISTER_TIM_CCMR2_H_ + +#include + +class Register_TIM_CCMR2 : public Register { +public: + Register_TIM_CCMR2() + : Register("TIM", "CCMR2", 16, 0) + {} + uint32_t operator = (uint32_t arg); +}; + +#endif//_REGISTER_TIM_CCMR2_H_ diff --git a/stm32/emulator/inc/Register_TIM_CCR1.h b/stm32/emulator/inc/Register_TIM_CCR1.h new file mode 100644 index 0000000..99545bd --- /dev/null +++ b/stm32/emulator/inc/Register_TIM_CCR1.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _REGISTER_TIM_CCR1_H_ +#define _REGISTER_TIM_CCR1_H_ + +#include + +class Register_TIM_CCR1 : public Register { +public: + Register_TIM_CCR1() + : Register("TIM", "CCR1", 16, 0) + {} + uint32_t operator = (uint32_t arg); +}; + +#endif//_REGISTER_TIM_CCR1_H_ diff --git a/stm32/emulator/inc/Register_TIM_CCR2.h b/stm32/emulator/inc/Register_TIM_CCR2.h new file mode 100644 index 0000000..59a3a09 --- /dev/null +++ b/stm32/emulator/inc/Register_TIM_CCR2.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _REGISTER_TIM_CCR2_H_ +#define _REGISTER_TIM_CCR2_H_ + +#include + +class Register_TIM_CCR2 : public Register { +public: + Register_TIM_CCR2() + : Register("TIM", "CCR2", 16, 0) + {} + uint32_t operator = (uint32_t arg); +}; + +#endif//_REGISTER_TIM_CCR2_H_ diff --git a/stm32/emulator/inc/Register_TIM_CCR3.h b/stm32/emulator/inc/Register_TIM_CCR3.h new file mode 100644 index 0000000..a514360 --- /dev/null +++ b/stm32/emulator/inc/Register_TIM_CCR3.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _REGISTER_TIM_CCR3_H_ +#define _REGISTER_TIM_CCR3_H_ + +#include + +class Register_TIM_CCR3 : public Register { +public: + Register_TIM_CCR3() + : Register("TIM", "CCR3", 16, 0) + {} + uint32_t operator = (uint32_t arg); +}; + +#endif//_REGISTER_TIM_CCR3_H_ diff --git a/stm32/emulator/inc/Register_TIM_CCR4.h b/stm32/emulator/inc/Register_TIM_CCR4.h new file mode 100644 index 0000000..e76f39b --- /dev/null +++ b/stm32/emulator/inc/Register_TIM_CCR4.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _REGISTER_TIM_CCR4_H_ +#define _REGISTER_TIM_CCR4_H_ + +#include + +class Register_TIM_CCR4 : public Register { +public: + Register_TIM_CCR4() + : Register("TIM", "CCR4", 16, 0) + {} + uint32_t operator = (uint32_t arg); +}; + +#endif//_REGISTER_TIM_CCR4_H_ diff --git a/stm32/emulator/inc/Register_TIM_CR1.h b/stm32/emulator/inc/Register_TIM_CR1.h new file mode 100644 index 0000000..5cd7f10 --- /dev/null +++ b/stm32/emulator/inc/Register_TIM_CR1.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _REGISTER_TIM_CR1_H_ +#define _REGISTER_TIM_CR1_H_ + +#include + +class Register_TIM_CR1 : public Register { +public: + Register_TIM_CR1() + : Register("TIM", "CR1", 16, 0) + {} + uint32_t operator = (uint32_t arg); +}; + +#endif//_REGISTER_TIM_CR1_H_ diff --git a/stm32/emulator/inc/Register_TIM_CR2.h b/stm32/emulator/inc/Register_TIM_CR2.h new file mode 100644 index 0000000..44b09d8 --- /dev/null +++ b/stm32/emulator/inc/Register_TIM_CR2.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _REGISTER_TIM_CR2_H_ +#define _REGISTER_TIM_CR2_H_ + +#include + +class Register_TIM_CR2 : public Register { +public: + Register_TIM_CR2() + : Register("TIM", "CR2", 16, 0) + {} + uint32_t operator = (uint32_t arg); +}; + +#endif//_REGISTER_TIM_CR2_H_ diff --git a/stm32/emulator/inc/Register_TIM_DIER.h b/stm32/emulator/inc/Register_TIM_DIER.h new file mode 100644 index 0000000..4ac2c23 --- /dev/null +++ b/stm32/emulator/inc/Register_TIM_DIER.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _REGISTER_TIM_DIER_H_ +#define _REGISTER_TIM_DIER_H_ + +#include + +class Register_TIM_DIER : public Register { +public: + Register_TIM_DIER() + : Register("TIM", "DIER", 16, 0) + {} + uint32_t operator = (uint32_t arg); +}; + +#endif//_REGISTER_TIM_DIER_H_ diff --git a/stm32/emulator/inc/Register_TIM_PSC.h b/stm32/emulator/inc/Register_TIM_PSC.h new file mode 100644 index 0000000..378a879 --- /dev/null +++ b/stm32/emulator/inc/Register_TIM_PSC.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _REGISTER_TIM_PSC_H_ +#define _REGISTER_TIM_PSC_H_ + +#include + +class Register_TIM_PSC : public Register { +public: + Register_TIM_PSC() + : Register("TIM", "PSC", 16, 0) + {} + uint32_t operator = (uint32_t arg); +}; + +#endif//_REGISTER_TIM_PSC_H_ diff --git a/stm32/emulator/inc/Register_TIM_SMCR.h b/stm32/emulator/inc/Register_TIM_SMCR.h new file mode 100644 index 0000000..b5e48b0 --- /dev/null +++ b/stm32/emulator/inc/Register_TIM_SMCR.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _REGISTER_TIM_SMCR_H_ +#define _REGISTER_TIM_SMCR_H_ + +#include + +class Register_TIM_SMCR : public Register { +public: + Register_TIM_SMCR() + : Register("TIM", "SMCR", 16, 0) + {} + uint32_t operator = (uint32_t arg); +}; + +#endif//_REGISTER_TIM_SMCR_H_ diff --git a/stm32/emulator/inc/Register_USART_BRR.h b/stm32/emulator/inc/Register_USART_BRR.h new file mode 100644 index 0000000..334e83a --- /dev/null +++ b/stm32/emulator/inc/Register_USART_BRR.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _REGISTER_USART_BRR_H_ +#define _REGISTER_USART_BRR_H_ + +#include + +class Register_USART_BRR : public Register { +public: + Register_USART_BRR(uint8_t val) + : Register("USART", "BRR", val, 0) + {} + uint32_t operator = (uint32_t arg); +}; + +#endif//_REGISTER_USART_BRR_H_ diff --git a/stm32/emulator/inc/Register_USART_CR1.h b/stm32/emulator/inc/Register_USART_CR1.h new file mode 100644 index 0000000..7169b4b --- /dev/null +++ b/stm32/emulator/inc/Register_USART_CR1.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _REGISTER_USART_CR1_H_ +#define _REGISTER_USART_CR1_H_ + +#include + +class Register_USART_CR1 : public Register { +public: + Register_USART_CR1(uint8_t val) + : Register("USART", "CR1", val, 0) + {} + uint32_t operator = (uint32_t arg); +}; + +#endif//_REGISTER_USART_CR1_H_ diff --git a/stm32/emulator/inc/Register_USART_CR2.h b/stm32/emulator/inc/Register_USART_CR2.h new file mode 100644 index 0000000..a694965 --- /dev/null +++ b/stm32/emulator/inc/Register_USART_CR2.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _REGISTER_USART_CR2_H_ +#define _REGISTER_USART_CR2_H_ + +#include + +class Register_USART_CR2 : public Register { +public: + Register_USART_CR2(uint8_t val) + : Register("USART", "CR2", val, 0) + {} + uint32_t operator = (uint32_t arg); +}; + +#endif//_REGISTER_USART_CR2_H_ diff --git a/stm32/emulator/inc/Register_USART_CR3.h b/stm32/emulator/inc/Register_USART_CR3.h new file mode 100644 index 0000000..be7d4c0 --- /dev/null +++ b/stm32/emulator/inc/Register_USART_CR3.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _REGISTER_USART_CR3_H_ +#define _REGISTER_USART_CR3_H_ + +#include + +class Register_USART_CR3 : public Register { +public: + Register_USART_CR3(uint8_t val) + : Register("USART", "CR3", val, 0) + {} + uint32_t operator = (uint32_t arg); +}; + +#endif//_REGISTER_USART_CR3_H_ diff --git a/stm32/emulator/inc/Register_USART_DR.h b/stm32/emulator/inc/Register_USART_DR.h new file mode 100644 index 0000000..ea083b8 --- /dev/null +++ b/stm32/emulator/inc/Register_USART_DR.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _REGISTER_USART_DR_H_ +#define _REGISTER_USART_DR_H_ + +#include + +class Register_USART_DR : public Register { +public: + Register_USART_DR() + : Register("USART", "DR", 16, 0) + {} + uint32_t operator = (uint32_t arg); +}; + +#endif \ No newline at end of file diff --git a/stm32/emulator/inc/Register_USART_GTPR.h b/stm32/emulator/inc/Register_USART_GTPR.h new file mode 100644 index 0000000..daa6e8c --- /dev/null +++ b/stm32/emulator/inc/Register_USART_GTPR.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _REGISTER_USART_GTPR_H_ +#define _REGISTER_USART_GTPR_H_ + +#include + +class Register_USART_GTPR : public Register { +public: + Register_USART_GTPR(uint8_t val) + : Register("USART", "GTPR", val, 0) + {} + uint32_t operator = (uint32_t arg); + +}; + +#endif//_REGISTER_USART_GTPR_H_ diff --git a/stm32/emulator/inc/Register_USART_ICR.h b/stm32/emulator/inc/Register_USART_ICR.h new file mode 100644 index 0000000..8328502 --- /dev/null +++ b/stm32/emulator/inc/Register_USART_ICR.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _REGISTER_USART_ICR_H_ +#define _REGISTER_USART_ICR_H_ + +#include + +class Register_USART_ICR : public Register { +public: + Register_USART_ICR() + : Register("USART", "ICR", 32, 0) + {} + uint32_t operator = (uint32_t arg); +}; + +#endif//_REGISTER_USART_ICR_H_ diff --git a/stm32/emulator/inc/Register_USART_ISR.h b/stm32/emulator/inc/Register_USART_ISR.h new file mode 100644 index 0000000..47408e9 --- /dev/null +++ b/stm32/emulator/inc/Register_USART_ISR.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _REGISTER_USART_ISR_H_ +#define _REGISTER_USART_ISR_H_ + +#include + +class Register_USART_ISR : public Register { +public: + Register_USART_ISR(uint32_t val) + : Register("USART", "ISR", 32, val) + {} + uint32_t operator = (uint32_t arg); +}; + +#endif//_REGISTER_USART_ISR_H_ diff --git a/stm32/emulator/inc/Register_USART_RDR.h b/stm32/emulator/inc/Register_USART_RDR.h new file mode 100644 index 0000000..f8ad9e1 --- /dev/null +++ b/stm32/emulator/inc/Register_USART_RDR.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _REGISTER_USART_RDR_H_ +#define _REGISTER_USART_RDR_H_ + +#include + +class Register_USART_RDR : public Register { +public: + Register_USART_RDR() + : Register("USART", "RDR", 16, 0) + {} + uint32_t operator = (uint32_t arg); +}; + +#endif//_REGISTER_USART_RDR_H_ diff --git a/stm32/emulator/inc/Register_USART_RQR.h b/stm32/emulator/inc/Register_USART_RQR.h new file mode 100644 index 0000000..4eb88ba --- /dev/null +++ b/stm32/emulator/inc/Register_USART_RQR.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _REGISTER_USART_RQR_H_ +#define _REGISTER_USART_RQR_H_ + +#include + +class Register_USART_RQR : public Register { +public: + Register_USART_RQR() + : Register("USART", "RQR", 16, 0) + {} + uint32_t operator = (uint32_t arg); +}; + +#endif//_REGISTER_USART_RQR_H_ diff --git a/stm32/emulator/inc/Register_USART_RTOR.h b/stm32/emulator/inc/Register_USART_RTOR.h new file mode 100644 index 0000000..5006075 --- /dev/null +++ b/stm32/emulator/inc/Register_USART_RTOR.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _REGISTER_USART_RTOR_H_ +#define _REGISTER_USART_RTOR_H_ + +#include + +class Register_USART_RTOR : public Register { +public: + Register_USART_RTOR() + : Register("USART", "RTOR", 32, 0) + {} + uint32_t operator = (uint32_t arg); +}; + +#endif//_REGISTER_USART_RTOR_H_ diff --git a/stm32/emulator/inc/Register_USART_SR.h b/stm32/emulator/inc/Register_USART_SR.h new file mode 100644 index 0000000..81aff21 --- /dev/null +++ b/stm32/emulator/inc/Register_USART_SR.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _REGISTER_USART_SR_H_ +#define _REGISTER_USART_SR_H_ + +#include + +class Register_USART_SR : public Register { +public: + Register_USART_SR(uint16_t val) + : Register("USART", "SR", 16, val) + {} + uint32_t operator = (uint32_t arg); +}; + +#endif//_REGISTER_USART_SR_H_ diff --git a/stm32/emulator/inc/Register_USART_TDR.h b/stm32/emulator/inc/Register_USART_TDR.h new file mode 100644 index 0000000..db5dec0 --- /dev/null +++ b/stm32/emulator/inc/Register_USART_TDR.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#ifndef _REGISTER_USART_TDR_H_ +#define _REGISTER_USART_TDR_H_ + +#include + +class Register_USART_TDR : public Register { +public: + Register_USART_TDR() + : Register("USART", "TDR", 16, 0) + {} + uint32_t operator = (uint32_t arg); +}; + +#endif//_REGISTER_USART_TDR_H_ diff --git a/stm32/emulator/inc/SCB.h b/stm32/emulator/inc/SCB.h index c226f24..197fd32 100644 --- a/stm32/emulator/inc/SCB.h +++ b/stm32/emulator/inc/SCB.h @@ -17,23 +17,46 @@ * along with ELL-i software. If not, see . */ +/** + * @author Pekka Nikander 2014 + */ + #ifndef _SCB_H_ #define _SCB_H_ #include +#if defined(__STM32F407__) || defined(__STM32F334__) +# include +# include +# include +#endif class SystemControlBlock { public: #if defined(__STM32F407__) || defined(__STM32F334__) /* XXX Set to reset value */ - DEFINE_REGISTER(32, SCB, CPUID, 0x410FC241); - DEFINE_REGISTER(32, SCB, ICSR, 0x00000000); - DEFINE_REGISTER(32, SCB, VTOR, 0x00000000); + //DEFINE_REGISTER(32, SCB, CPUID, 0x410FC241); + //DEFINE_REGISTER(32, SCB, ICSR, 0x00000000); + //DEFINE_REGISTER(32, SCB, VTOR, 0x00000000); + Register_SCB_CPUID CPUID; + Register_SCB_ICSR ICSR; + Register_SCB_VTOR VTOR; #endif protected: - SystemControlBlock() {} + SystemControlBlock() +#if defined(__STM32F407__) || defined(__STM32F334__) + : CPUID(0x410FC241) + , ICSR(0x00000000) + , VTOR(0x00000000) +#endif + {} public: static SystemControlBlock SCB; +#if defined(__STM32F407__) || defined(__STM32F334__) + void SCB_CPUID_VALUES( SystemControlBlock *const scb, CALLBACK(SCB_CPUID_CALLBACK) ); + void SCB_ICSR_VALUES( SystemControlBlock *const scb, CALLBACK(SCB_ICSR_CALLBACK) ); + void SCB_VTOR_VALUES( SystemControlBlock *const scb, CALLBACK(SCB_VTOR_CALLBACK) ); +#endif }; SystemControlBlock *const SCB = &SystemControlBlock::SCB; diff --git a/stm32/emulator/inc/SPIemu.h b/stm32/emulator/inc/SPIemu.h index b5bf4c7..ec3b47c 100644 --- a/stm32/emulator/inc/SPIemu.h +++ b/stm32/emulator/inc/SPIemu.h @@ -24,14 +24,18 @@ #ifndef _SPI_H_ # define _SPI_H_ -# include -# include -# include +#include +#include +#include +#include +#include class SerialPeripheralInterface { public: - DEFINE_REGISTER(16, SPI, CR1, 0); - DEFINE_REGISTER(16, SPI, CR2, 0); + //DEFINE_REGISTER(16, SPI, CR1, 0); + //DEFINE_REGISTER(16, SPI, CR2, 0); + Register_SPI_CR1 CR1; + Register_SPI_CR2 CR2; Register_SPI_SR SR; Register_SPI_DR DR; protected: diff --git a/stm32/emulator/inc/TIM.h b/stm32/emulator/inc/TIM.h index 8b05222..0699867 100644 --- a/stm32/emulator/inc/TIM.h +++ b/stm32/emulator/inc/TIM.h @@ -21,23 +21,52 @@ #define _TIM_H_ #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include class Timer { public: - DEFINE_REGISTER(16, TIM, CR1, 0x00000000); - DEFINE_REGISTER(16, TIM, CR2, 0x00000000); - DEFINE_REGISTER(16, TIM, SMCR, 0x00000000); - DEFINE_REGISTER(16, TIM, DIER, 0x00000000); - DEFINE_REGISTER(16, TIM, CCMR1, 0x00000000); - DEFINE_REGISTER(16, TIM, CCMR2, 0x00000000); - DEFINE_REGISTER(16, TIM, CCER, 0x00000000); - DEFINE_REGISTER(16, TIM, BDTR, 0x00000000); - DEFINE_REGISTER(16, TIM, PSC, 0x00000000); - DEFINE_REGISTER(32, TIM, ARR, 0x00000000); - DEFINE_REGISTER(32, TIM, CCR1, 0x00000000); - DEFINE_REGISTER(32, TIM, CCR2, 0x00000000); - DEFINE_REGISTER(32, TIM, CCR3, 0x00000000); - DEFINE_REGISTER(32, TIM, CCR4, 0x00000000); + //DEFINE_REGISTER(16, TIM, CR1, 0x00000000); + //DEFINE_REGISTER(16, TIM, CR2, 0x00000000); + //DEFINE_REGISTER(16, TIM, SMCR, 0x00000000); + //DEFINE_REGISTER(16, TIM, DIER, 0x00000000); + //DEFINE_REGISTER(16, TIM, CCMR1, 0x00000000); + //DEFINE_REGISTER(16, TIM, CCMR2, 0x00000000); + //DEFINE_REGISTER(16, TIM, CCER, 0x00000000); + //DEFINE_REGISTER(16, TIM, BDTR, 0x00000000); + //DEFINE_REGISTER(16, TIM, PSC, 0x00000000); + //DEFINE_REGISTER(32, TIM, ARR, 0x00000000); + //DEFINE_REGISTER(32, TIM, CCR1, 0x00000000); + //DEFINE_REGISTER(32, TIM, CCR2, 0x00000000); + //DEFINE_REGISTER(32, TIM, CCR3, 0x00000000); + //DEFINE_REGISTER(32, TIM, CCR4, 0x00000000); + Register_TIM_CR1 CR1; + Register_TIM_CR2 CR2; + Register_TIM_SMCR SMCR; + Register_TIM_DIER DIER; + Register_TIM_CCMR1 CCMR1; + Register_TIM_CCMR2 CCMR2; + Register_TIM_CCER CCER; + Register_TIM_BDTR BDTR; + Register_TIM_PSC PSC; + Register_TIM_ARR ARR; + Register_TIM_CCR1 CCR1; + Register_TIM_CCR2 CCR2; + Register_TIM_CCR3 CCR3; + Register_TIM_CCR4 CCR4; + protected: Timer() {} public: @@ -58,6 +87,21 @@ class Timer { static Timer TIM15; static Timer TIM16; static Timer TIM17; + + void TIM_CR1_VALUES( Timer *const tim, CALLBACK(TIM_CR1_CALLBACK) ); + void TIM_CR2_VALUES( Timer *const tim, CALLBACK(TIM_CR2_CALLBACK) ); + void TIM_SMCR_VALUES( Timer *const tim, CALLBACK(TIM_SMCR_CALLBACK) ); + void TIM_DIER_VALUES( Timer *const tim, CALLBACK(TIM_DIER_CALLBACK) ); + void TIM_CCMR1_VALUES( Timer *const tim, CALLBACK(TIM_CCMR1_CALLBACK) ); + void TIM_CCMR2_VALUES( Timer *const tim, CALLBACK(TIM_CCMR2_CALLBACK) ); + void TIM_CCER_VALUES( Timer *const tim, CALLBACK(TIM_CCER_CALLBACK) ); + void TIM_BDTR_VALUES( Timer *const tim, CALLBACK(TIM_BDTR_CALLBACK) ); + void TIM_PSC_VALUES( Timer *const tim, CALLBACK(TIM_PSC_CALLBACK) ); + void TIM_ARR_VALUES( Timer *const tim, CALLBACK(TIM_ARR_CALLBACK) ); + void TIM_CCR1_VALUES( Timer *const tim, CALLBACK(TIM_CCR1_CALLBACK) ); + void TIM_CCR2_VALUES( Timer *const tim, CALLBACK(TIM_CCR2_CALLBACK) ); + void TIM_CCR3_VALUES( Timer *const tim, CALLBACK(TIM_CCR3_CALLBACK) ); + void TIM_CCR4_VALUES( Timer *const tim, CALLBACK(TIM_CCR4_CALLBACK) ); }; Timer *const TIM1 = &Timer::TIM1; @@ -78,4 +122,24 @@ Timer *const TIM15 = &Timer::TIM15; Timer *const TIM16 = &Timer::TIM16; Timer *const TIM17 = &Timer::TIM17; +Timer *const TIM[] = { TIM1 + , TIM2 + , TIM3 + , TIM4 + , TIM5 + , TIM6 + , TIM7 + , TIM8 + , TIM9 + , TIM10 + , TIM11 + , TIM12 + , TIM13 + , TIM14 + , TIM15 + , TIM16 + , TIM17 +}; + + #endif //_TIM_H_ diff --git a/stm32/emulator/inc/USART.h b/stm32/emulator/inc/USART.h index 264af75..f0315ae 100644 --- a/stm32/emulator/inc/USART.h +++ b/stm32/emulator/inc/USART.h @@ -25,6 +25,29 @@ #define _USART_H_ #include +#if defined(__STM32F407__) +# include +# include +# include +# include +# include +# include +# include +#elif defined(__STM32F051__) || defined(__STM32F334__) +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +#else +# error "Unknown MCU die. Please define." +#endif #if defined(__STM32F051__) # include @@ -39,34 +62,76 @@ class UniversalSynchronousAsynchronousReceiverTransmitter { public: #if defined(__STM32F407__) - DEFINE_REGISTER(16, USART, SR, USART_SR_TXE); - DEFINE_REGISTER(16, USART, DR, 0); - DEFINE_REGISTER(16, USART, BRR, 0); - DEFINE_REGISTER(16, USART, CR1, 0); - DEFINE_REGISTER(16, USART, CR2, 0); - DEFINE_REGISTER(16, USART, CR3, 0); - DEFINE_REGISTER(16, USART, GTPR, 0); + Register_USART_SR SR; + Register_USART_DR DR; + Register_USART_BRR BRR; + Register_USART_CR1 CR1; + Register_USART_CR2 CR2; + Register_USART_CR3 CR3; + Register_USART_GTPR GTPR; #elif defined(__STM32F051__) || defined(__STM32F334__) - DEFINE_REGISTER(32, USART, CR1, 0); - DEFINE_REGISTER(32, USART, CR2, 0); - DEFINE_REGISTER(32, USART, CR3, 0); - DEFINE_REGISTER(16, USART, BRR, 0); - DEFINE_REGISTER(16, USART, GTPR, 0); - DEFINE_REGISTER(32, USART, RTOR, 0); - DEFINE_REGISTER(16, USART, RQR, 0); - DEFINE_REGISTER(32, USART, ISR, USART_ISR_TXE); - DEFINE_REGISTER(32, USART, ICR, 0); - DEFINE_REGISTER(16, USART, RDR, 0); - DEFINE_REGISTER(16, USART, TDR, 0); + Register_USART_CR1 CR1; + Register_USART_CR2 CR2; + Register_USART_CR3 CR3; + Register_USART_BRR BRR; + Register_USART_GTPR GTPR; + Register_USART_RTOR RTOR; + Register_USART_RQR RQR; + Register_USART_ISR ISR; + Register_USART_ICR ICR; + Register_USART_RDR RDR; + Register_USART_TDR TDR; #else # error "Unknown MCU die. Please define." #endif protected: - UniversalSynchronousAsynchronousReceiverTransmitter() {} + UniversalSynchronousAsynchronousReceiverTransmitter() +#if defined(__STM32F407__) + : SR(USART_SR_TXE) + , BRR(16) + , CR1(16) + , CR2(16) + , CR3(16) + , GTPR(16) +#elif defined(__STM32F051__) || defined(__STM32F334__) + : CR1(32) + , CR2(32) + , CR3(32) + , BRR(32) + , GTPR(32) + , ISR(0x00000080) +#else +# error "Unknown MCU die. Please define." +#endif + {} public: static UniversalSynchronousAsynchronousReceiverTransmitter USART1; static UniversalSynchronousAsynchronousReceiverTransmitter USART2; static UniversalSynchronousAsynchronousReceiverTransmitter USART3; + +#if defined(__STM32F407__) + void USART_SR_VALUES( UniversalSynchronousAsynchronousReceiverTransmitter *const usartPort, CALLBACK(USART_SR_CALLBACK) ); + void USART_DR_VALUES( UniversalSynchronousAsynchronousReceiverTransmitter *const usartPort, CALLBACK(USART_DR_CALLBACK) ); + void USART_BRR_VALUES( UniversalSynchronousAsynchronousReceiverTransmitter *const usartPort, CALLBACK(USART_BRR_CALLBACK) ); + void USART_CR1_VALUES( UniversalSynchronousAsynchronousReceiverTransmitter *const usartPort, CALLBACK(USART_CR1_CALLBACK) ); + void USART_CR2_VALUES( UniversalSynchronousAsynchronousReceiverTransmitter *const usartPort, CALLBACK(USART_CR2_CALLBACK) ); + void USART_CR3_VALUES( UniversalSynchronousAsynchronousReceiverTransmitter *const usartPort, CALLBACK(USART_CR3_CALLBACK) ); + void USART_GTPR_VALUES( UniversalSynchronousAsynchronousReceiverTransmitter *const usartPort, CALLBACK(USART_GTPR_CALLBACK) ); +#elif defined(__STM32F051__) || defined(__STM32F334__) + void USART_BRR_VALUES( UniversalSynchronousAsynchronousReceiverTransmitter *const usartPort, CALLBACK(USART_BRR_CALLBACK) ); + void USART_CR1_VALUES( UniversalSynchronousAsynchronousReceiverTransmitter *const usartPort, CALLBACK(USART_CR1_CALLBACK) ); + void USART_CR2_VALUES( UniversalSynchronousAsynchronousReceiverTransmitter *const usartPort, CALLBACK(USART_CR2_CALLBACK) ); + void USART_CR3_VALUES( UniversalSynchronousAsynchronousReceiverTransmitter *const usartPort, CALLBACK(USART_CR3_CALLBACK) ); + void USART_GTPR_VALUES( UniversalSynchronousAsynchronousReceiverTransmitter *const usartPort, CALLBACK(USART_GTPR_CALLBACK) ); + void USART_RTOR_VALUES( UniversalSynchronousAsynchronousReceiverTransmitter *const usartPort, CALLBACK(USART_RTOR_CALLBACK) ); + void USART_RQR_VALUES( UniversalSynchronousAsynchronousReceiverTransmitter *const usartPort, CALLBACK(USART_RQR_CALLBACK) ); + void USART_ISR_VALUES( UniversalSynchronousAsynchronousReceiverTransmitter *const usartPort, CALLBACK(USART_ISR_CALLBACK) ); + void USART_ICR_VALUES( UniversalSynchronousAsynchronousReceiverTransmitter *const usartPort, CALLBACK(USART_ICR_CALLBACK) ); + void USART_RDR_VALUES( UniversalSynchronousAsynchronousReceiverTransmitter *const usartPort, CALLBACK(USART_RDR_CALLBACK) ); + void USART_TDR_VALUES( UniversalSynchronousAsynchronousReceiverTransmitter *const usartPort, CALLBACK(USART_TDR_CALLBACK) ); +#else +# error "Unknown MCU die. Please define." +#endif }; UniversalSynchronousAsynchronousReceiverTransmitter *const USART1 = @@ -75,5 +140,14 @@ UniversalSynchronousAsynchronousReceiverTransmitter *const USART2 = &UniversalSynchronousAsynchronousReceiverTransmitter::USART2; UniversalSynchronousAsynchronousReceiverTransmitter *const USART3 = &UniversalSynchronousAsynchronousReceiverTransmitter::USART2; +#if defined(__STM32F407__) + UniversalSynchronousAsynchronousReceiverTransmitter *const STM32F4DiscoveryUsartArray[] = { USART1, USART2 }; +#elif defined(__STM32F334__) + UniversalSynchronousAsynchronousReceiverTransmitter *const STM32F334NucleoUsartArray[] = { USART1, USART2, USART3 }; +#elif defined(__STM32F051__) + UniversalSynchronousAsynchronousReceiverTransmitter *const EllduinoUsartArray[] = { USART2, USART1 }; +#else +# error "Unknown MCU die. Please define." +#endif #endif //_USART_H_ diff --git a/stm32/emulator/src/FLASH.cpp b/stm32/emulator/src/FLASH.cpp index 22b3a4c..3e5d38f 100644 --- a/stm32/emulator/src/FLASH.cpp +++ b/stm32/emulator/src/FLASH.cpp @@ -17,7 +17,50 @@ * along with ELL-i software. If not, see . */ +/** + * @author Asif Sardar 2014 + */ + #include Flash Flash::FLASH; +void Flash::FLASH_ACR_VALUES( Flash *const flash, CALLBACK(FLASH_ACR_CALLBACK) ) { + FLASH_ACR_CALLBACK( flash->ACR.registerPeriph().c_str() + , flash->ACR.registerName().c_str() + , flash->ACR.registerValue() + , flash->ACR.registerOpStr().c_str() + ); +} + +void Flash::FLASH_KEYR_VALUES( Flash *const flash, CALLBACK(FLASH_KEYR_CALLBACK) ) { + FLASH_KEYR_CALLBACK( flash->KEYR.registerPeriph().c_str() + , flash->KEYR.registerName().c_str() + , flash->KEYR.registerValue() + , flash->KEYR.registerOpStr().c_str() + ); +} + +void Flash::FLASH_OPTKEYR_VALUES( Flash *const flash, CALLBACK(FLASH_OPTKEYR_CALLBACK) ) { + FLASH_OPTKEYR_CALLBACK( flash->OPTKEYR.registerPeriph().c_str() + , flash->OPTKEYR.registerName().c_str() + , flash->OPTKEYR.registerValue() + , flash->OPTKEYR.registerOpStr().c_str() + ); +} + +void Flash::FLASH_SR_VALUES( Flash *const flash, CALLBACK(FLASH_SR_CALLBACK) ) { + FLASH_SR_CALLBACK( flash->SR.registerPeriph().c_str() + , flash->SR.registerName().c_str() + , flash->SR.registerValue() + , flash->SR.registerOpStr().c_str() + ); +} + +void Flash::FLASH_CR_VALUES( Flash *const flash, CALLBACK(FLASH_CR_CALLBACK) ) { + FLASH_CR_CALLBACK( flash->CR.registerPeriph().c_str() + , flash->CR.registerName().c_str() + , flash->CR.registerValue() + , flash->CR.registerOpStr().c_str() + ); +} diff --git a/stm32/emulator/src/GPIO.cpp b/stm32/emulator/src/GPIO.cpp index a0fbda7..1a5ef6d 100644 --- a/stm32/emulator/src/GPIO.cpp +++ b/stm32/emulator/src/GPIO.cpp @@ -35,3 +35,105 @@ GeneralPurposeInputOutput GeneralPurposeInputOutput::GPIOG; GeneralPurposeInputOutput GeneralPurposeInputOutput::GPIOH; GeneralPurposeInputOutput GeneralPurposeInputOutput::GPIOI; +void GeneralPurposeInputOutput::GPIO_MODER_VALUES( GeneralPurposeInputOutput *const gpioPort + , CALLBACK(GPIO_MODER_CALLBACK) ) { + GPIO_MODER_CALLBACK( gpioPort->MODER.registerPeriph().c_str() + , gpioPort->MODER.registerName().c_str() + , gpioPort->MODER.registerValue() + , gpioPort->MODER.registerOpStr().c_str() + ); +} + +void GeneralPurposeInputOutput::GPIO_PUPDR_VALUES( GeneralPurposeInputOutput *const gpioPort + , CALLBACK(GPIO_PUPDR_CALLBACK) ) { + GPIO_PUPDR_CALLBACK( gpioPort->PUPDR.registerPeriph().c_str() + , gpioPort->PUPDR.registerName().c_str() + , gpioPort->PUPDR.registerValue() + , gpioPort->PUPDR.registerOpStr().c_str() + ); +} + +void GeneralPurposeInputOutput::GPIO_ODR_VALUES( GeneralPurposeInputOutput *const gpioPort + , CALLBACK(GPIO_ODR_CALLBACK) ) { + GPIO_ODR_CALLBACK( gpioPort->ODR.registerPeriph().c_str() + , gpioPort->ODR.registerName().c_str() + , gpioPort->ODR.registerValue() + , gpioPort->ODR.registerOpStr().c_str() + ); +} + +void GeneralPurposeInputOutput::GPIO_IDR_VALUES( GeneralPurposeInputOutput *const gpioPort + , CALLBACK(GPIO_IDR_CALLBACK) ) { + GPIO_IDR_CALLBACK( gpioPort->IDR.registerPeriph().c_str() + , gpioPort->IDR.registerName().c_str() + , gpioPort->IDR.registerValue() + , gpioPort->IDR.registerOpStr().c_str() + ); +} +#if defined(__STM32F407__) || defined(__STM32F334__) +void GeneralPurposeInputOutput::GPIO_BSRRL_VALUES( GeneralPurposeInputOutput *const gpioPort + , CALLBACK(GPIO_BSRRL_CALLBACK) ) { + GPIO_BSRRL_CALLBACK( gpioPort->BSRRL.registerPeriph().c_str() + , gpioPort->BSRRL.registerName().c_str() + , gpioPort->BSRRL.registerValue() + , gpioPort->BSRRL.registerOpStr().c_str() + ); +} + +void GeneralPurposeInputOutput::GPIO_AFR_VALUES( GeneralPurposeInputOutput *const gpioPort + , CALLBACK(GPIO_AFR_CALLBACK) ) { + GPIO_AFR_CALLBACK( gpioPort->AFR[0].registerPeriph().c_str() + , gpioPort->AFR[0].registerName().c_str() + , gpioPort->AFR[0].registerValue() + , gpioPort->AFR[0].registerOpStr().c_str() + ); + GPIO_AFR_CALLBACK( gpioPort->AFR[1].registerPeriph().c_str() + , gpioPort->AFR[1].registerName().c_str() + , gpioPort->AFR[1].registerValue() + , gpioPort->AFR[1].registerOpStr().c_str() + ); +} + +void GeneralPurposeInputOutput::GPIO_BSRRH_VALUES( GeneralPurposeInputOutput *const gpioPort + , CALLBACK(GPIO_BSRRH_CALLBACK) ) { + GPIO_BSRRH_CALLBACK( gpioPort->BSRRH.registerPeriph().c_str() + , gpioPort->BSRRH.registerName().c_str() + , gpioPort->BSRRH.registerValue() + , gpioPort->BSRRH.registerOpStr().c_str() + ); +} +#elif defined(__STM32F051__) +void GeneralPurposeInputOutput::GPIO_BSRR_VALUES( GeneralPurposeInputOutput *const gpioPort + , CALLBACK(GPIO_BSRR_CALLBACK) ) { + GPIO_BSRR_CALLBACK( gpioPort->BSRR.registerPeriph().c_str() + , gpioPort->BSRR.registerName().c_str() + , gpioPort->BSRR.registerValue() + , gpioPort->BSRR.registerOpStr().c_str() + ); +} + +void GeneralPurposeInputOutput::GPIO_AFR_VALUES( GeneralPurposeInputOutput *const gpioPort + , CALLBACK(GPIO_AFR_CALLBACK) ) { + GPIO_AFR_CALLBACK( gpioPort->AFR[0].registerPeriph().c_str() + , gpioPort->AFR[0].registerName().c_str() + , gpioPort->AFR[0].registerValue() + , gpioPort->AFR[0].registerOpStr().c_str() + ); + GPIO_AFR_CALLBACK( gpioPort->AFR[1].registerPeriph().c_str() + , gpioPort->AFR[1].registerName().c_str() + , gpioPort->AFR[1].registerValue() + , gpioPort->AFR[1].registerOpStr().c_str() + ); +} + +void GeneralPurposeInputOutput::GPIO_BRR_VALUES( GeneralPurposeInputOutput *const gpioPort + , CALLBACK(GPIO_BRR_CALLBACK) ) { + GPIO_BRR_CALLBACK( gpioPort->BRR.registerPeriph().c_str() + , gpioPort->BRR.registerName().c_str() + , gpioPort->BRR.registerValue() + , gpioPort->BRR.registerOpStr().c_str() + ); +} +#else +# error "Unknown MCU die. Please define." +#endif diff --git a/stm32/emulator/src/PWR.cpp b/stm32/emulator/src/PWR.cpp index 91712ff..360744a 100644 --- a/stm32/emulator/src/PWR.cpp +++ b/stm32/emulator/src/PWR.cpp @@ -17,7 +17,20 @@ * along with ELL-i software. If not, see . */ +/** + * @author Asif Sardar 2014 + */ + #include PowerController PowerController::PWR; +#if defined(__STM32F407__) +void PowerController::PWR_CR_VALUES( PowerController *const pwr, CALLBACK(PWR_CR_CALLBACK) ) { + PWR_CR_CALLBACK( pwr->CR.registerPeriph().c_str() + , pwr->CR.registerName().c_str() + , pwr->CR.registerValue() + , pwr->CR.registerOpStr().c_str() + ); +} +#endif \ No newline at end of file diff --git a/stm32/emulator/src/RCC.cpp b/stm32/emulator/src/RCC.cpp index e0b5efb..51ac6a8 100644 --- a/stm32/emulator/src/RCC.cpp +++ b/stm32/emulator/src/RCC.cpp @@ -17,7 +17,144 @@ * along with ELL-i software. If not, see . */ +/** + * @author Asif Sardar 2014 + */ + #include ResetClockControl ResetClockControl::RCC; +void ResetClockControl::RCC_CR_VALUES( ResetClockControl *const rcc, CALLBACK(RCC_CR_CALLBACK) ) { + RCC_CR_CALLBACK( rcc->CR.registerPeriph().c_str() + , rcc->CR.registerName().c_str() + , rcc->CR.registerValue() + , rcc->CR.registerOpStr().c_str() + ); +} + +#if defined(__STM32F407__) +void ResetClockControl::RCC_PLLCFGR_VALUES( ResetClockControl *const rcc, CALLBACK(RCC_PLLCFGR_CALLBACK) ) { + RCC_PLLCFGR_CALLBACK( rcc->PLLCFGR.registerPeriph().c_str() + , rcc->PLLCFGR.registerName().c_str() + , rcc->PLLCFGR.registerValue() + , rcc->PLLCFGR.registerOpStr().c_str() + ); +} +#endif + +void ResetClockControl::RCC_CFGR_VALUES( ResetClockControl *const rcc, CALLBACK(RCC_CFGR_CALLBACK) ) { + RCC_CFGR_CALLBACK( rcc->CFGR.registerPeriph().c_str() + , rcc->CFGR.registerName().c_str() + , rcc->CFGR.registerValue() + , rcc->CFGR.registerOpStr().c_str() + ); +} + +void ResetClockControl::RCC_CIR_VALUES( ResetClockControl *const rcc, CALLBACK(RCC_CIR_CALLBACK) ) { + RCC_CIR_CALLBACK( rcc->CIR.registerPeriph().c_str() + , rcc->CIR.registerName().c_str() + , rcc->CIR.registerValue() + , rcc->CIR.registerOpStr().c_str() + ); +} + +void ResetClockControl::RCC_APB1RSTR_VALUES( ResetClockControl *const rcc, CALLBACK(RCC_APB1RSTR_CALLBACK) ) { + RCC_APB1RSTR_CALLBACK( rcc->APB1RSTR.registerPeriph().c_str() + , rcc->APB1RSTR.registerName().c_str() + , rcc->APB1RSTR.registerValue() + , rcc->APB1RSTR.registerOpStr().c_str() + ); +} + +#if defined(__STM32F407__) +void ResetClockControl::RCC_AHB1ENR_VALUES( ResetClockControl *const rcc, CALLBACK(RCC_AHB1ENR_CALLBACK) ) { + RCC_AHB1ENR_CALLBACK( rcc->AHB1ENR.registerPeriph().c_str() + , rcc->AHB1ENR.registerName().c_str() + , rcc->AHB1ENR.registerValue() + , rcc->AHB1ENR.registerOpStr().c_str() + ); +} +#elif defined(__STM32F051__) || defined(__STM32F334__) +void ResetClockControl::RCC_AHBENR_VALUES( ResetClockControl *const rcc, CALLBACK(RCC_AHBENR_CALLBACK) ) { + RCC_AHBENR_CALLBACK( rcc->AHBENR.registerPeriph().c_str() + , rcc->AHBENR.registerName().c_str() + , rcc->AHBENR.registerValue() + , rcc->AHBENR.registerOpStr().c_str() + ); +} +#else +# error "Unknown MCU die. Please define." +#endif + +void ResetClockControl::RCC_APB2ENR_VALUES( ResetClockControl *const rcc, CALLBACK(RCC_APB2ENR_CALLBACK) ) { + RCC_APB2ENR_CALLBACK( rcc->APB2ENR.registerPeriph().c_str() + , rcc->APB2ENR.registerName().c_str() + , rcc->APB2ENR.registerValue() + , rcc->APB2ENR.registerOpStr().c_str() + ); +} + +void ResetClockControl::RCC_APB1ENR_VALUES( ResetClockControl *const rcc, CALLBACK(RCC_APB1ENR_CALLBACK) ) { + RCC_APB1ENR_CALLBACK( rcc->APB1ENR.registerPeriph().c_str() + , rcc->APB1ENR.registerName().c_str() + , rcc->APB1ENR.registerValue() + , rcc->APB1ENR.registerOpStr().c_str() + ); +} + +void ResetClockControl::RCC_APB2RSTR_VALUES( ResetClockControl *const rcc, CALLBACK(RCC_APB2RSTR_CALLBACK) ) { + RCC_APB2RSTR_CALLBACK( rcc->APB2RSTR.registerPeriph().c_str() + , rcc->APB2RSTR.registerName().c_str() + , rcc->APB2RSTR.registerValue() + , rcc->APB2RSTR.registerOpStr().c_str() + ); +} + +void ResetClockControl::RCC_BDCR_VALUES( ResetClockControl *const rcc, CALLBACK(RCC_BDCR_CALLBACK) ) { + RCC_BDCR_CALLBACK( rcc->BDCR.registerPeriph().c_str() + , rcc->BDCR.registerName().c_str() + , rcc->BDCR.registerValue() + , rcc->BDCR.registerOpStr().c_str() + ); +} + +void ResetClockControl::RCC_CSR_VALUES( ResetClockControl *const rcc, CALLBACK(RCC_CSR_CALLBACK) ) { + RCC_CSR_CALLBACK( rcc->CSR.registerPeriph().c_str() + , rcc->CSR.registerName().c_str() + , rcc->CSR.registerValue() + , rcc->CSR.registerOpStr().c_str() + ); +} + +void ResetClockControl::RCC_AHBRSTR_VALUES( ResetClockControl *const rcc, CALLBACK(RCC_AHBRSTR_CALLBACK) ) { + RCC_AHBRSTR_CALLBACK( rcc->AHBRSTR.registerPeriph().c_str() + , rcc->AHBRSTR.registerName().c_str() + , rcc->AHBRSTR.registerValue() + , rcc->AHBRSTR.registerOpStr().c_str() + ); +} + +void ResetClockControl::RCC_CFGR2_VALUES( ResetClockControl *const rcc, CALLBACK(RCC_CFGR2_CALLBACK) ) { + RCC_CFGR2_CALLBACK( rcc->CFGR2.registerPeriph().c_str() + , rcc->CFGR2.registerName().c_str() + , rcc->CFGR2.registerValue() + , rcc->CFGR2.registerOpStr().c_str() + ); +} + +void ResetClockControl::RCC_CFGR3_VALUES( ResetClockControl *const rcc, CALLBACK(RCC_CFGR3_CALLBACK) ) { + RCC_CFGR3_CALLBACK( rcc->CFGR3.registerPeriph().c_str() + , rcc->CFGR3.registerName().c_str() + , rcc->CFGR3.registerValue() + , rcc->CFGR3.registerOpStr().c_str() + ); +} + +void ResetClockControl::RCC_CR2_VALUES( ResetClockControl *const rcc, CALLBACK(RCC_CR2_CALLBACK) ) { + RCC_CR2_CALLBACK( rcc->CR2.registerPeriph().c_str() + , rcc->CR2.registerName().c_str() + , rcc->CR2.registerValue() + , rcc->CR2.registerOpStr().c_str() + ); +} diff --git a/stm32/emulator/src/Register.cpp b/stm32/emulator/src/Register.cpp index 9da652c..427730b 100644 --- a/stm32/emulator/src/Register.cpp +++ b/stm32/emulator/src/Register.cpp @@ -17,15 +17,25 @@ * along with ELL-i software. If not, see . */ +#include "pythonCallback.c" + #include -void Register::printout(const std::string opStr, uint32_t result) const { +void Register::printout(const std::string opStr, uint32_t result) { + opStr_ = opStr; std::cout << std::setbase(16) << periph_ << ':' << name_ << ':' << "value=" << value_ << " -> " << opStr << result << std::endl; + + PyGILState_STATE gilState = PyGILState_Ensure(); + PyObject *mod = PyImport_ImportModule("pythonCallback"); + PyObject *func = PyObject_GetAttrString(mod, (char*)"callback_python"); + PyObject *arglist = Py_BuildValue("ssiis", periph_.c_str(), name_.c_str(), value_, result, opStr.c_str()); + PyObject_CallObject(func, arglist); + PyGILState_Release(gilState); } uint32_t Register::operator = (uint32_t arg) volatile { @@ -48,12 +58,28 @@ uint32_t Register::operator &= (uint32_t arg) { return value_ &= arg; } -uint32_t Register::operator & (uint32_t arg) const { +uint32_t Register::operator & (uint32_t arg) { printout("&", value_ & arg); return value_ & arg; } -uint16_t Register::operator & (uint16_t arg) const { +uint16_t Register::operator & (uint16_t arg) { printout("&(16b)", value_ & arg); return value_ & arg; } + +uint32_t Register::registerValue() const { + return value_; +} + +const std::string Register::registerPeriph() const { + return periph_; +} + +const std::string Register::registerName() const { + return name_; +} + +std::string Register::registerOpStr() const { + return opStr_; +} diff --git a/stm32/emulator/src/Register_FLASH_ACR.cpp b/stm32/emulator/src/Register_FLASH_ACR.cpp new file mode 100644 index 0000000..2b0d498 --- /dev/null +++ b/stm32/emulator/src/Register_FLASH_ACR.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_FLASH_ACR::operator = (uint32_t arg) { + printout("=", arg); + return value_; +} diff --git a/stm32/emulator/src/Register_FLASH_CR.cpp b/stm32/emulator/src/Register_FLASH_CR.cpp new file mode 100644 index 0000000..ca42c2c --- /dev/null +++ b/stm32/emulator/src/Register_FLASH_CR.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_FLASH_CR::operator = (uint32_t arg) { + printout("=", arg); + return value_; +} diff --git a/stm32/emulator/src/Register_FLASH_KEYR.cpp b/stm32/emulator/src/Register_FLASH_KEYR.cpp new file mode 100644 index 0000000..0d20b51 --- /dev/null +++ b/stm32/emulator/src/Register_FLASH_KEYR.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_FLASH_KEYR::operator = (uint32_t arg) { + printout("=", arg); + return value_; +} diff --git a/stm32/emulator/src/Register_FLASH_OPTKEYR.cpp b/stm32/emulator/src/Register_FLASH_OPTKEYR.cpp new file mode 100644 index 0000000..c067e8c --- /dev/null +++ b/stm32/emulator/src/Register_FLASH_OPTKEYR.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_FLASH_OPTKEYR::operator = (uint32_t arg) { + printout("=", arg); + return value_; +} diff --git a/stm32/emulator/src/Register_FLASH_SR.cpp b/stm32/emulator/src/Register_FLASH_SR.cpp new file mode 100644 index 0000000..8c0b25c --- /dev/null +++ b/stm32/emulator/src/Register_FLASH_SR.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_FLASH_SR::operator = (uint32_t arg) { + printout("=", arg); + return value_; +} diff --git a/stm32/emulator/src/Register_PWR_CR.cpp b/stm32/emulator/src/Register_PWR_CR.cpp new file mode 100644 index 0000000..701c929 --- /dev/null +++ b/stm32/emulator/src/Register_PWR_CR.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_PWR_CR::operator = (uint32_t arg) { + printout("=", arg); + return value_; +} diff --git a/stm32/emulator/src/Register_RCC_AHB1ENR.cpp b/stm32/emulator/src/Register_RCC_AHB1ENR.cpp new file mode 100644 index 0000000..2fc7938 --- /dev/null +++ b/stm32/emulator/src/Register_RCC_AHB1ENR.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_RCC_AHB1ENR::operator = (uint32_t arg) { + printout("=", arg); + return value_; +} diff --git a/stm32/emulator/src/Register_RCC_AHBENR.cpp b/stm32/emulator/src/Register_RCC_AHBENR.cpp new file mode 100644 index 0000000..0c937e6 --- /dev/null +++ b/stm32/emulator/src/Register_RCC_AHBENR.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_RCC_AHBENR::operator = (uint32_t arg) { + printout("=", arg); + return value_; +} diff --git a/stm32/emulator/src/Register_RCC_AHBRSTR.cpp b/stm32/emulator/src/Register_RCC_AHBRSTR.cpp new file mode 100644 index 0000000..c11fe1d --- /dev/null +++ b/stm32/emulator/src/Register_RCC_AHBRSTR.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_RCC_AHBRSTR::operator = (uint32_t arg) { + printout("=", arg); + return value_; +} diff --git a/stm32/emulator/src/Register_RCC_APB1ENR.cpp b/stm32/emulator/src/Register_RCC_APB1ENR.cpp new file mode 100644 index 0000000..a352d6e --- /dev/null +++ b/stm32/emulator/src/Register_RCC_APB1ENR.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_RCC_APB1ENR::operator = (uint32_t arg) { + printout("=", arg); + return value_; +} diff --git a/stm32/emulator/src/Register_RCC_APB1RSTR.cpp b/stm32/emulator/src/Register_RCC_APB1RSTR.cpp new file mode 100644 index 0000000..29c771e --- /dev/null +++ b/stm32/emulator/src/Register_RCC_APB1RSTR.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_RCC_APB1RSTR::operator = (uint32_t arg) { + printout("=", arg); + return value_; +} diff --git a/stm32/emulator/src/Register_RCC_APB2ENR.cpp b/stm32/emulator/src/Register_RCC_APB2ENR.cpp new file mode 100644 index 0000000..26ab6b0 --- /dev/null +++ b/stm32/emulator/src/Register_RCC_APB2ENR.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_RCC_APB2ENR::operator = (uint32_t arg) { + printout("=", arg); + return value_; +} diff --git a/stm32/emulator/src/Register_RCC_APB2RSTR.cpp b/stm32/emulator/src/Register_RCC_APB2RSTR.cpp new file mode 100644 index 0000000..3a896e4 --- /dev/null +++ b/stm32/emulator/src/Register_RCC_APB2RSTR.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_RCC_APB2RSTR::operator = (uint32_t arg) { + printout("=", arg); + return value_; +} diff --git a/stm32/emulator/src/Register_RCC_BDCR.cpp b/stm32/emulator/src/Register_RCC_BDCR.cpp new file mode 100644 index 0000000..4f9b437 --- /dev/null +++ b/stm32/emulator/src/Register_RCC_BDCR.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_RCC_BDCR::operator = (uint32_t arg) { + printout("=", arg); + return value_; +} diff --git a/stm32/emulator/src/Register_RCC_CFGR2.cpp b/stm32/emulator/src/Register_RCC_CFGR2.cpp new file mode 100644 index 0000000..790c602 --- /dev/null +++ b/stm32/emulator/src/Register_RCC_CFGR2.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_RCC_CFGR2::operator = (uint32_t arg) { + printout("=", arg); + return value_; +} diff --git a/stm32/emulator/src/Register_RCC_CFGR3.cpp b/stm32/emulator/src/Register_RCC_CFGR3.cpp new file mode 100644 index 0000000..50be9a9 --- /dev/null +++ b/stm32/emulator/src/Register_RCC_CFGR3.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_RCC_CFGR3::operator = (uint32_t arg) { + printout("=", arg); + return value_; +} diff --git a/stm32/emulator/src/Register_RCC_CIR.cpp b/stm32/emulator/src/Register_RCC_CIR.cpp new file mode 100644 index 0000000..e571f96 --- /dev/null +++ b/stm32/emulator/src/Register_RCC_CIR.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_RCC_CIR::operator = (uint32_t arg) { + printout("=", arg); + return value_; +} diff --git a/stm32/emulator/src/Register_RCC_CR.cpp b/stm32/emulator/src/Register_RCC_CR.cpp new file mode 100644 index 0000000..ea4e481 --- /dev/null +++ b/stm32/emulator/src/Register_RCC_CR.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_RCC_CR::operator = (uint32_t arg) { + printout("=", arg); + return value_; +} diff --git a/stm32/emulator/src/Register_RCC_CR2.cpp b/stm32/emulator/src/Register_RCC_CR2.cpp new file mode 100644 index 0000000..a997f3c --- /dev/null +++ b/stm32/emulator/src/Register_RCC_CR2.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_RCC_CR2::operator = (uint32_t arg) { + printout("=", arg); + return value_; +} diff --git a/stm32/emulator/src/Register_RCC_CSR.cpp b/stm32/emulator/src/Register_RCC_CSR.cpp new file mode 100644 index 0000000..c133b4c --- /dev/null +++ b/stm32/emulator/src/Register_RCC_CSR.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_RCC_CSR::operator = (uint32_t arg) { + printout("=", arg); + return value_; +} diff --git a/stm32/emulator/src/Register_RCC_PLLCFGR.cpp b/stm32/emulator/src/Register_RCC_PLLCFGR.cpp new file mode 100644 index 0000000..8ae0da3 --- /dev/null +++ b/stm32/emulator/src/Register_RCC_PLLCFGR.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_RCC_PLLCFGR::operator = (uint32_t arg) { + printout("=", arg); + return value_; +} diff --git a/stm32/emulator/src/Register_SCB_CPUID.cpp b/stm32/emulator/src/Register_SCB_CPUID.cpp new file mode 100644 index 0000000..78701b7 --- /dev/null +++ b/stm32/emulator/src/Register_SCB_CPUID.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_SCB_CPUID::operator = (uint32_t arg) { + printout("=", arg); + return value_; +} diff --git a/stm32/emulator/src/Register_SCB_ICSR.cpp b/stm32/emulator/src/Register_SCB_ICSR.cpp new file mode 100644 index 0000000..1665f5f --- /dev/null +++ b/stm32/emulator/src/Register_SCB_ICSR.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_SCB_ICSR::operator = (uint32_t arg) { + printout("=", arg); + return value_; +} diff --git a/stm32/emulator/src/Register_SCB_VTOR.cpp b/stm32/emulator/src/Register_SCB_VTOR.cpp new file mode 100644 index 0000000..827e02c --- /dev/null +++ b/stm32/emulator/src/Register_SCB_VTOR.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_SCB_VTOR::operator = (uint32_t arg) { + printout("=", arg); + return value_; +} diff --git a/stm32/emulator/src/Register_SPI_CR1.cpp b/stm32/emulator/src/Register_SPI_CR1.cpp new file mode 100644 index 0000000..ca9de7b --- /dev/null +++ b/stm32/emulator/src/Register_SPI_CR1.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_SPI_CR1::operator = (uint32_t arg) { + printout("=", arg); + return value_; +} diff --git a/stm32/emulator/src/Register_SPI_CR2.cpp b/stm32/emulator/src/Register_SPI_CR2.cpp new file mode 100644 index 0000000..d09486d --- /dev/null +++ b/stm32/emulator/src/Register_SPI_CR2.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_SPI_CR2::operator = (uint32_t arg) { + printout("=", arg); + return value_; +} diff --git a/stm32/emulator/src/Register_SPI_SR.cpp b/stm32/emulator/src/Register_SPI_SR.cpp index 435b2f0..03edb7b 100644 --- a/stm32/emulator/src/Register_SPI_SR.cpp +++ b/stm32/emulator/src/Register_SPI_SR.cpp @@ -34,7 +34,7 @@ uint32_t Register_SPI_SR::operator = (uint32_t arg) { return value_; } -uint16_t Register_SPI_SR::operator & (uint16_t arg) const { +uint16_t Register_SPI_SR::operator & (uint16_t arg) { dr_.printout("=", dr_.value_); printout("&(16b)", value_ & arg); // XXX SPI_SR_FRLVL should probably be part of value_, @@ -47,7 +47,7 @@ uint16_t Register_SPI_SR::operator & (uint16_t arg) const { return v & arg; } -uint16_t Register_SPI_SR::operator & (uint32_t arg) const { +uint16_t Register_SPI_SR::operator & (uint32_t arg) { dr_.printout("=", dr_.value_); printout("&", value_ & arg); // XXX SPI_SR_FRLVL should probably be part of value_, diff --git a/stm32/emulator/src/Register_TIM_ARR.cpp b/stm32/emulator/src/Register_TIM_ARR.cpp new file mode 100644 index 0000000..76dd42f --- /dev/null +++ b/stm32/emulator/src/Register_TIM_ARR.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_TIM_ARR::operator = (uint32_t arg) { + printout("=", arg); + return value_ = arg; +} diff --git a/stm32/emulator/src/Register_TIM_BDTR.cpp b/stm32/emulator/src/Register_TIM_BDTR.cpp new file mode 100644 index 0000000..2096b4b --- /dev/null +++ b/stm32/emulator/src/Register_TIM_BDTR.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_TIM_BDTR::operator = (uint32_t arg) { + printout("=", arg); + return value_ = arg; +} diff --git a/stm32/emulator/src/Register_TIM_CCER.cpp b/stm32/emulator/src/Register_TIM_CCER.cpp new file mode 100644 index 0000000..8b62133 --- /dev/null +++ b/stm32/emulator/src/Register_TIM_CCER.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_TIM_CCER::operator = (uint32_t arg) { + printout("=", arg); + return value_ = arg; +} diff --git a/stm32/emulator/src/Register_TIM_CCMR1.cpp b/stm32/emulator/src/Register_TIM_CCMR1.cpp new file mode 100644 index 0000000..c7c0745 --- /dev/null +++ b/stm32/emulator/src/Register_TIM_CCMR1.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_TIM_CCMR1::operator = (uint32_t arg) { + printout("=", arg); + return value_ = arg; +} diff --git a/stm32/emulator/src/Register_TIM_CCMR2.cpp b/stm32/emulator/src/Register_TIM_CCMR2.cpp new file mode 100644 index 0000000..50bba10 --- /dev/null +++ b/stm32/emulator/src/Register_TIM_CCMR2.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_TIM_CCMR2::operator = (uint32_t arg) { + printout("=", arg); + return value_ = arg; +} diff --git a/stm32/emulator/src/Register_TIM_CCR1.cpp b/stm32/emulator/src/Register_TIM_CCR1.cpp new file mode 100644 index 0000000..15c3f3d --- /dev/null +++ b/stm32/emulator/src/Register_TIM_CCR1.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_TIM_CCR1::operator = (uint32_t arg) { + printout("=", arg); + return value_ = arg; +} diff --git a/stm32/emulator/src/Register_TIM_CCR2.cpp b/stm32/emulator/src/Register_TIM_CCR2.cpp new file mode 100644 index 0000000..46ecd4f --- /dev/null +++ b/stm32/emulator/src/Register_TIM_CCR2.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_TIM_CCR2::operator = (uint32_t arg) { + printout("=", arg); + return value_ = arg; +} diff --git a/stm32/emulator/src/Register_TIM_CCR3.cpp b/stm32/emulator/src/Register_TIM_CCR3.cpp new file mode 100644 index 0000000..b0a2f59 --- /dev/null +++ b/stm32/emulator/src/Register_TIM_CCR3.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_TIM_CCR3::operator = (uint32_t arg) { + printout("=", arg); + return value_ = arg; +} diff --git a/stm32/emulator/src/Register_TIM_CCR4.cpp b/stm32/emulator/src/Register_TIM_CCR4.cpp new file mode 100644 index 0000000..9112c0b --- /dev/null +++ b/stm32/emulator/src/Register_TIM_CCR4.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_TIM_CCR4::operator = (uint32_t arg) { + printout("=", arg); + return value_ = arg; +} diff --git a/stm32/emulator/src/Register_TIM_CR1.cpp b/stm32/emulator/src/Register_TIM_CR1.cpp new file mode 100644 index 0000000..362efe8 --- /dev/null +++ b/stm32/emulator/src/Register_TIM_CR1.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_TIM_CR1::operator = (uint32_t arg) { + printout("=", arg); + return value_ = arg; +} diff --git a/stm32/emulator/src/Register_TIM_CR2.cpp b/stm32/emulator/src/Register_TIM_CR2.cpp new file mode 100644 index 0000000..67a523f --- /dev/null +++ b/stm32/emulator/src/Register_TIM_CR2.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_TIM_CR2::operator = (uint32_t arg) { + printout("=", arg); + return value_ = arg; +} diff --git a/stm32/emulator/src/Register_TIM_DIER.cpp b/stm32/emulator/src/Register_TIM_DIER.cpp new file mode 100644 index 0000000..fee2466 --- /dev/null +++ b/stm32/emulator/src/Register_TIM_DIER.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_TIM_DIER::operator = (uint32_t arg) { + printout("=", arg); + return value_ = arg; +} diff --git a/stm32/emulator/src/Register_TIM_PSC.cpp b/stm32/emulator/src/Register_TIM_PSC.cpp new file mode 100644 index 0000000..eceb48c --- /dev/null +++ b/stm32/emulator/src/Register_TIM_PSC.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_TIM_PSC::operator = (uint32_t arg) { + printout("=", arg); + return value_ = arg; +} diff --git a/stm32/emulator/src/Register_TIM_SMCR.cpp b/stm32/emulator/src/Register_TIM_SMCR.cpp new file mode 100644 index 0000000..0c86d9b --- /dev/null +++ b/stm32/emulator/src/Register_TIM_SMCR.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_TIM_SMCR::operator = (uint32_t arg) { + printout("=", arg); + return value_ = arg; +} diff --git a/stm32/emulator/src/Register_USART_BRR.cpp b/stm32/emulator/src/Register_USART_BRR.cpp new file mode 100644 index 0000000..5ae7ca0 --- /dev/null +++ b/stm32/emulator/src/Register_USART_BRR.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_USART_BRR::operator = (uint32_t arg) { + printout("=", arg); + return value_ = arg; +} diff --git a/stm32/emulator/src/Register_USART_CR1.cpp b/stm32/emulator/src/Register_USART_CR1.cpp new file mode 100644 index 0000000..8bda506 --- /dev/null +++ b/stm32/emulator/src/Register_USART_CR1.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_USART_CR1::operator = (uint32_t arg) { + printout("=", arg); + return value_= arg; +} diff --git a/stm32/emulator/src/Register_USART_CR2.cpp b/stm32/emulator/src/Register_USART_CR2.cpp new file mode 100644 index 0000000..40409a2 --- /dev/null +++ b/stm32/emulator/src/Register_USART_CR2.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_USART_CR2::operator = (uint32_t arg) { + printout("=", arg); + return value_= arg; +} diff --git a/stm32/emulator/src/Register_USART_CR3.cpp b/stm32/emulator/src/Register_USART_CR3.cpp new file mode 100644 index 0000000..20eeed9 --- /dev/null +++ b/stm32/emulator/src/Register_USART_CR3.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_USART_CR3::operator = (uint32_t arg) { + printout("=", arg); + return value_= arg; +} diff --git a/stm32/emulator/src/Register_USART_DR.cpp b/stm32/emulator/src/Register_USART_DR.cpp new file mode 100644 index 0000000..f11cb11 --- /dev/null +++ b/stm32/emulator/src/Register_USART_DR.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_USART_DR::operator = (uint32_t arg) { + printout("=", arg); + return value_ = arg; +} diff --git a/stm32/emulator/src/Register_USART_GTPR.cpp b/stm32/emulator/src/Register_USART_GTPR.cpp new file mode 100644 index 0000000..03ce9aa --- /dev/null +++ b/stm32/emulator/src/Register_USART_GTPR.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_USART_GTPR::operator = (uint32_t arg) { + printout("=", arg); + return value_ = arg; +} diff --git a/stm32/emulator/src/Register_USART_ICR.cpp b/stm32/emulator/src/Register_USART_ICR.cpp new file mode 100644 index 0000000..5b4d932 --- /dev/null +++ b/stm32/emulator/src/Register_USART_ICR.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_USART_ICR::operator = (uint32_t arg) { + printout("=", arg); + return value_ = arg; +} diff --git a/stm32/emulator/src/Register_USART_ISR.cpp b/stm32/emulator/src/Register_USART_ISR.cpp new file mode 100644 index 0000000..f68843e --- /dev/null +++ b/stm32/emulator/src/Register_USART_ISR.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_USART_ISR::operator = (uint32_t arg) { + printout("=", arg); + return value_ = arg; +} diff --git a/stm32/emulator/src/Register_USART_RDR.cpp b/stm32/emulator/src/Register_USART_RDR.cpp new file mode 100644 index 0000000..b4cfba2 --- /dev/null +++ b/stm32/emulator/src/Register_USART_RDR.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_USART_RDR::operator = (uint32_t arg) { + printout("=", arg); + return value_ = arg; +} diff --git a/stm32/emulator/src/Register_USART_RQR.cpp b/stm32/emulator/src/Register_USART_RQR.cpp new file mode 100644 index 0000000..41326a5 --- /dev/null +++ b/stm32/emulator/src/Register_USART_RQR.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_USART_RQR::operator = (uint32_t arg) { + printout("=", arg); + return value_ = arg; +} diff --git a/stm32/emulator/src/Register_USART_RTOR.cpp b/stm32/emulator/src/Register_USART_RTOR.cpp new file mode 100644 index 0000000..c87364e --- /dev/null +++ b/stm32/emulator/src/Register_USART_RTOR.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_USART_RTOR::operator = (uint32_t arg) { + printout("=", arg); + return value_ = arg; +} diff --git a/stm32/emulator/src/Register_USART_SR.cpp b/stm32/emulator/src/Register_USART_SR.cpp new file mode 100644 index 0000000..1a62bf0 --- /dev/null +++ b/stm32/emulator/src/Register_USART_SR.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_USART_SR::operator = (uint32_t arg) { + printout("=", arg); + return value_ = arg; +} diff --git a/stm32/emulator/src/Register_USART_TDR.cpp b/stm32/emulator/src/Register_USART_TDR.cpp new file mode 100644 index 0000000..aebbc4c --- /dev/null +++ b/stm32/emulator/src/Register_USART_TDR.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Asif Sardar 2014 + */ + +#include + +uint32_t Register_USART_TDR::operator = (uint32_t arg) { + printout("=", arg); + return value_ = arg; +} \ No newline at end of file diff --git a/stm32/emulator/src/SCB.cpp b/stm32/emulator/src/SCB.cpp index c4f0086..21e1e57 100644 --- a/stm32/emulator/src/SCB.cpp +++ b/stm32/emulator/src/SCB.cpp @@ -17,7 +17,36 @@ * along with ELL-i software. If not, see . */ +/** + * @author Asif Sardar 2014 + */ + #include SystemControlBlock SystemControlBlock::SCB; +#if defined(__STM32F407__) || defined(__STM32F334__) +void SystemControlBlock::SCB_CPUID_VALUES( SystemControlBlock *const scb, CALLBACK(SCB_CPUID_CALLBACK) ) { + SCB_CPUID_CALLBACK( scb->CPUID.registerPeriph().c_str() + , scb->CPUID.registerName().c_str() + , scb->CPUID.registerValue() + , scb->CPUID.registerOpStr().c_str() + ); +} + +void SystemControlBlock::SCB_ICSR_VALUES( SystemControlBlock *const scb, CALLBACK(SCB_ICSR_CALLBACK) ) { + SCB_ICSR_CALLBACK( scb->ICSR.registerPeriph().c_str() + , scb->ICSR.registerName().c_str() + , scb->ICSR.registerValue() + , scb->ICSR.registerOpStr().c_str() + ); +} + +void SystemControlBlock::SCB_VTOR_VALUES( SystemControlBlock *const scb, CALLBACK(SCB_VTOR_CALLBACK) ) { + SCB_VTOR_CALLBACK( scb->VTOR.registerPeriph().c_str() + , scb->VTOR.registerName().c_str() + , scb->VTOR.registerValue() + , scb->VTOR.registerOpStr().c_str() + ); +} +#endif diff --git a/stm32/emulator/src/SPI.cpp b/stm32/emulator/src/SPI.cpp index cb8c03d..723a432 100644 --- a/stm32/emulator/src/SPI.cpp +++ b/stm32/emulator/src/SPI.cpp @@ -17,8 +17,11 @@ * along with ELL-i software. If not, see . */ +/** + * @author Pekka Nikander 2014 + */ + #include SerialPeripheralInterface SerialPeripheralInterface::SPI1; SerialPeripheralInterface SerialPeripheralInterface::SPI2; - diff --git a/stm32/emulator/src/TIM.cpp b/stm32/emulator/src/TIM.cpp index 46895b3..cda62d8 100644 --- a/stm32/emulator/src/TIM.cpp +++ b/stm32/emulator/src/TIM.cpp @@ -37,3 +37,114 @@ Timer Timer::TIM15; Timer Timer::TIM16; Timer Timer::TIM17; +void Timer::TIM_CR1_VALUES( Timer *const tim, CALLBACK(TIM_CR1_CALLBACK) ) { + TIM_CR1_CALLBACK( tim->CR1.registerPeriph().c_str() + , tim->CR1.registerName().c_str() + , tim->CR1.registerValue() + , tim->CR1.registerOpStr().c_str() + ); +} + +void Timer::TIM_CR2_VALUES( Timer *const tim, CALLBACK(TIM_CR2_CALLBACK) ) { + TIM_CR2_CALLBACK( tim->CR2.registerPeriph().c_str() + , tim->CR2.registerName().c_str() + , tim->CR2.registerValue() + , tim->CR2.registerOpStr().c_str() + ); +} + +void Timer::TIM_SMCR_VALUES( Timer *const tim, CALLBACK(TIM_SMCR_CALLBACK) ) { + TIM_SMCR_CALLBACK( tim->SMCR.registerPeriph().c_str() + , tim->SMCR.registerName().c_str() + , tim->SMCR.registerValue() + , tim->SMCR.registerOpStr().c_str() + ); +} + +void Timer::TIM_DIER_VALUES( Timer *const tim, CALLBACK(TIM_DIER_CALLBACK) ) { + TIM_DIER_CALLBACK( tim->DIER.registerPeriph().c_str() + , tim->DIER.registerName().c_str() + , tim->DIER.registerValue() + , tim->DIER.registerOpStr().c_str() + ); +} + +void Timer::TIM_CCMR1_VALUES( Timer *const tim, CALLBACK(TIM_CCMR1_CALLBACK) ) { + TIM_CCMR1_CALLBACK( tim->CCMR1.registerPeriph().c_str() + , tim->CCMR1.registerName().c_str() + , tim->CCMR1.registerValue() + , tim->CCMR1.registerOpStr().c_str() + ); +} + +void Timer::TIM_CCMR2_VALUES( Timer *const tim, CALLBACK(TIM_CCMR2_CALLBACK) ) { + TIM_CCMR2_CALLBACK( tim->CCMR2.registerPeriph().c_str() + , tim->CCMR2.registerName().c_str() + , tim->CCMR2.registerValue() + , tim->CCMR2.registerOpStr().c_str() + ); +} + +void Timer::TIM_CCER_VALUES( Timer *const tim, CALLBACK(TIM_CCER_CALLBACK) ) { + TIM_CCER_CALLBACK( tim->CCER.registerPeriph().c_str() + , tim->CCER.registerName().c_str() + , tim->CCER.registerValue() + , tim->CCER.registerOpStr().c_str() + ); +} + +void Timer::TIM_BDTR_VALUES( Timer *const tim, CALLBACK(TIM_BDTR_CALLBACK) ) { + TIM_BDTR_CALLBACK( tim->BDTR.registerPeriph().c_str() + , tim->BDTR.registerName().c_str() + , tim->BDTR.registerValue() + , tim->BDTR.registerOpStr().c_str() + ); +} + +void Timer::TIM_PSC_VALUES( Timer *const tim, CALLBACK(TIM_PSC_CALLBACK) ) { + TIM_PSC_CALLBACK( tim->PSC.registerPeriph().c_str() + , tim->PSC.registerName().c_str() + , tim->PSC.registerValue() + , tim->PSC.registerOpStr().c_str() + ); +} + +void Timer::TIM_ARR_VALUES( Timer *const tim, CALLBACK(TIM_ARR_CALLBACK) ) { + TIM_ARR_CALLBACK( tim->ARR.registerPeriph().c_str() + , tim->ARR.registerName().c_str() + , tim->ARR.registerValue() + , tim->ARR.registerOpStr().c_str() + ); +} + +void Timer::TIM_CCR1_VALUES( Timer *const tim, CALLBACK(TIM_CCR1_CALLBACK) ) { + TIM_CCR1_CALLBACK( tim->CCR1.registerPeriph().c_str() + , tim->CCR1.registerName().c_str() + , tim->CCR1.registerValue() + , tim->CCR1.registerOpStr().c_str() + ); +} + +void Timer::TIM_CCR2_VALUES( Timer *const tim, CALLBACK(TIM_CCR2_CALLBACK) ) { + TIM_CCR2_CALLBACK( tim->CCR2.registerPeriph().c_str() + , tim->CCR2.registerName().c_str() + , tim->CCR2.registerValue() + , tim->CCR2.registerOpStr().c_str() + ); +} + +void Timer::TIM_CCR3_VALUES( Timer *const tim, CALLBACK(TIM_CCR3_CALLBACK) ) { + TIM_CCR3_CALLBACK( tim->CCR3.registerPeriph().c_str() + , tim->CCR3.registerName().c_str() + , tim->CCR3.registerValue() + , tim->CCR3.registerOpStr().c_str() + ); +} + +void Timer::TIM_CCR4_VALUES( Timer *const tim, CALLBACK(TIM_CCR4_CALLBACK) ) { + TIM_CCR4_CALLBACK( tim->CCR4.registerPeriph().c_str() + , tim->CCR4.registerName().c_str() + , tim->CCR4.registerValue() + , tim->CCR4.registerOpStr().c_str() + ); +} diff --git a/stm32/emulator/src/USART.cpp b/stm32/emulator/src/USART.cpp index eade775..3e2db60 100644 --- a/stm32/emulator/src/USART.cpp +++ b/stm32/emulator/src/USART.cpp @@ -17,6 +17,10 @@ * along with ELL-i software. If not, see . */ +/** + * @author Asif Sardar 2014 + */ + #include UniversalSynchronousAsynchronousReceiverTransmitter @@ -26,3 +30,168 @@ UniversalSynchronousAsynchronousReceiverTransmitter::USART2; UniversalSynchronousAsynchronousReceiverTransmitter UniversalSynchronousAsynchronousReceiverTransmitter::USART3; +#if defined(__STM32F407__) +void UniversalSynchronousAsynchronousReceiverTransmitter::USART_SR_VALUES( + UniversalSynchronousAsynchronousReceiverTransmitter *const usartPort, CALLBACK(USART_SR_CALLBACK) ) { + USART_SR_CALLBACK( usartPort->SR.registerPeriph().c_str() + , usartPort->SR.registerName().c_str() + , usartPort->SR.registerValue() + , usartPort->SR.registerOpStr().c_str() + ); +} + +void UniversalSynchronousAsynchronousReceiverTransmitter::USART_DR_VALUES( + UniversalSynchronousAsynchronousReceiverTransmitter *const usartPort, CALLBACK(USART_DR_CALLBACK) ) { + USART_DR_CALLBACK( usartPort->DR.registerPeriph().c_str() + , usartPort->DR.registerName().c_str() + , usartPort->DR.registerValue() + , usartPort->DR.registerOpStr().c_str() + ); +} + +void UniversalSynchronousAsynchronousReceiverTransmitter::USART_BRR_VALUES( + UniversalSynchronousAsynchronousReceiverTransmitter *const usartPort, CALLBACK(USART_BRR_CALLBACK) ) { + USART_BRR_CALLBACK( usartPort->BRR.registerPeriph().c_str() + , usartPort->BRR.registerName().c_str() + , usartPort->BRR.registerValue() + , usartPort->BRR.registerOpStr().c_str() + ); +} + +void UniversalSynchronousAsynchronousReceiverTransmitter::USART_CR1_VALUES( + UniversalSynchronousAsynchronousReceiverTransmitter *const usartPort, CALLBACK(USART_CR1_CALLBACK) ) { + USART_CR1_CALLBACK( usartPort->CR1.registerPeriph().c_str() + , usartPort->CR1.registerName().c_str() + , usartPort->CR1.registerValue() + , usartPort->CR1.registerOpStr().c_str() + ); +} + +void UniversalSynchronousAsynchronousReceiverTransmitter::USART_CR2_VALUES( + UniversalSynchronousAsynchronousReceiverTransmitter *const usartPort, CALLBACK(USART_CR2_CALLBACK) ) { + USART_CR2_CALLBACK( usartPort->CR2.registerPeriph().c_str() + , usartPort->CR2.registerName().c_str() + , usartPort->CR2.registerValue() + , usartPort->CR2.registerOpStr().c_str() + ); +} + +void UniversalSynchronousAsynchronousReceiverTransmitter::USART_CR3_VALUES( + UniversalSynchronousAsynchronousReceiverTransmitter *const usartPort, CALLBACK(USART_CR3_CALLBACK) ) { + USART_CR3_CALLBACK( usartPort->CR3.registerPeriph().c_str() + , usartPort->CR3.registerName().c_str() + , usartPort->CR3.registerValue() + , usartPort->CR3.registerOpStr().c_str() + ); +} + +void UniversalSynchronousAsynchronousReceiverTransmitter::USART_GTPR_VALUES( + UniversalSynchronousAsynchronousReceiverTransmitter *const usartPort, CALLBACK(USART_GTPR_CALLBACK) ) { + USART_GTPR_CALLBACK( usartPort->GTPR.registerPeriph().c_str() + , usartPort->GTPR.registerName().c_str() + , usartPort->GTPR.registerValue() + , usartPort->GTPR.registerOpStr().c_str() + ); +} +#elif defined(__STM32F051__) || defined(__STM32F334__) +void UniversalSynchronousAsynchronousReceiverTransmitter::USART_BRR_VALUES( + UniversalSynchronousAsynchronousReceiverTransmitter *const usartPort, CALLBACK(USART_BRR_CALLBACK) ) { + USART_BRR_CALLBACK( usartPort->BRR.registerPeriph().c_str() + , usartPort->BRR.registerName().c_str() + , usartPort->BRR.registerValue() + , usartPort->BRR.registerOpStr().c_str() + ); +} + +void UniversalSynchronousAsynchronousReceiverTransmitter::USART_CR1_VALUES( + UniversalSynchronousAsynchronousReceiverTransmitter *const usartPort, CALLBACK(USART_CR1_CALLBACK) ) { + USART_CR1_CALLBACK( usartPort->CR1.registerPeriph().c_str() + , usartPort->CR1.registerName().c_str() + , usartPort->CR1.registerValue() + , usartPort->CR1.registerOpStr().c_str() + ); +} + +void UniversalSynchronousAsynchronousReceiverTransmitter::USART_CR2_VALUES( + UniversalSynchronousAsynchronousReceiverTransmitter *const usartPort, CALLBACK(USART_CR2_CALLBACK) ) { + USART_CR2_CALLBACK( usartPort->CR2.registerPeriph().c_str() + , usartPort->CR2.registerName().c_str() + , usartPort->CR2.registerValue() + , usartPort->CR2.registerOpStr().c_str() + ); +} + +void UniversalSynchronousAsynchronousReceiverTransmitter::USART_CR3_VALUES( + UniversalSynchronousAsynchronousReceiverTransmitter *const usartPort, CALLBACK(USART_CR3_CALLBACK) ) { + USART_CR3_CALLBACK( usartPort->CR3.registerPeriph().c_str() + , usartPort->CR3.registerName().c_str() + , usartPort->CR3.registerValue() + , usartPort->CR3.registerOpStr().c_str() + ); +} + +void UniversalSynchronousAsynchronousReceiverTransmitter::USART_GTPR_VALUES( + UniversalSynchronousAsynchronousReceiverTransmitter *const usartPort, CALLBACK(USART_GTPR_CALLBACK) ) { + USART_GTPR_CALLBACK( usartPort->GTPR.registerPeriph().c_str() + , usartPort->GTPR.registerName().c_str() + , usartPort->GTPR.registerValue() + , usartPort->GTPR.registerOpStr().c_str() + ); +} + +void UniversalSynchronousAsynchronousReceiverTransmitter::USART_RTOR_VALUES( + UniversalSynchronousAsynchronousReceiverTransmitter *const usartPort, CALLBACK(USART_RTOR_CALLBACK) ) { + USART_RTOR_CALLBACK( usartPort->RTOR.registerPeriph().c_str() + , usartPort->RTOR.registerName().c_str() + , usartPort->RTOR.registerValue() + , usartPort->RTOR.registerOpStr().c_str() + ); +} + +void UniversalSynchronousAsynchronousReceiverTransmitter::USART_RQR_VALUES( + UniversalSynchronousAsynchronousReceiverTransmitter *const usartPort, CALLBACK(USART_RQR_CALLBACK) ) { + USART_RQR_CALLBACK( usartPort->RQR.registerPeriph().c_str() + , usartPort->RQR.registerName().c_str() + , usartPort->RQR.registerValue() + , usartPort->RQR.registerOpStr().c_str() + ); +} + +void UniversalSynchronousAsynchronousReceiverTransmitter::USART_ISR_VALUES( + UniversalSynchronousAsynchronousReceiverTransmitter *const usartPort, CALLBACK(USART_ISR_CALLBACK) ) { + USART_ISR_CALLBACK( usartPort->ISR.registerPeriph().c_str() + , usartPort->ISR.registerName().c_str() + , usartPort->ISR.registerValue() + , usartPort->ISR.registerOpStr().c_str() + ); +} + +void UniversalSynchronousAsynchronousReceiverTransmitter::USART_ICR_VALUES( + UniversalSynchronousAsynchronousReceiverTransmitter *const usartPort, CALLBACK(USART_ICR_CALLBACK) ) { + USART_ICR_CALLBACK( usartPort->ICR.registerPeriph().c_str() + , usartPort->ICR.registerName().c_str() + , usartPort->ICR.registerValue() + , usartPort->ICR.registerOpStr().c_str() + ); +} + +void UniversalSynchronousAsynchronousReceiverTransmitter::USART_RDR_VALUES( + UniversalSynchronousAsynchronousReceiverTransmitter *const usartPort, CALLBACK(USART_RDR_CALLBACK) ) { + USART_RDR_CALLBACK( usartPort->RDR.registerPeriph().c_str() + , usartPort->RDR.registerName().c_str() + , usartPort->RDR.registerValue() + , usartPort->RDR.registerOpStr().c_str() + ); +} + +void UniversalSynchronousAsynchronousReceiverTransmitter::USART_TDR_VALUES( + UniversalSynchronousAsynchronousReceiverTransmitter *const usartPort, CALLBACK(USART_TDR_CALLBACK) ) { + USART_TDR_CALLBACK( usartPort->TDR.registerPeriph().c_str() + , usartPort->TDR.registerName().c_str() + , usartPort->TDR.registerValue() + , usartPort->TDR.registerOpStr().c_str() + ); +} +#else +# error "Unknown MCU die. Please define." +#endif diff --git a/stm32/emulator/src/pythonCallback.c b/stm32/emulator/src/pythonCallback.c new file mode 100644 index 0000000..57684e6 --- /dev/null +++ b/stm32/emulator/src/pythonCallback.c @@ -0,0 +1,50 @@ +#include + +static PyObject *my_callback = NULL; + +static PyObject *set_python_callback_reference(PyObject *dummy, PyObject *args) +{ + PyObject *result = NULL; + PyObject *temp; + + if (PyArg_ParseTuple(args, "O:REGISTER_VALUES_CALLBACK", &temp)) { + if (!PyCallable_Check(temp)) { + PyErr_SetString(PyExc_TypeError, "parameter must be callable"); + return NULL; + } + Py_XINCREF(temp); + Py_XDECREF(my_callback); + my_callback = temp; + Py_INCREF(Py_None); + result = Py_None; + } + return result; +} + +static PyObject *callback_python(PyObject *dummy, PyObject *arglist) { + PyObject *result = PyObject_CallObject(my_callback, arglist); + Py_DECREF(arglist); + if (result == NULL) { + return NULL; + } + Py_DECREF(result); + Py_INCREF(Py_None); + result = Py_None; + return result; +} + +static char set_python_callback_reference_docs[] = "Set python callback function reference from python to C call."; +static char callback_python_docs[] = "Call python callback function from C to python through python callback reference."; + +static PyMethodDef pythonCallback_methods[] = { + {"set_python_callback_reference", (PyCFunction)set_python_callback_reference, METH_VARARGS, \ + set_python_callback_reference_docs}, + {"callback_python", (PyCFunction)callback_python, METH_VARARGS, callback_python_docs}, + {NULL, NULL, 0, NULL} +}; + +PyMODINIT_FUNC +initpythonCallback(void) +{ + (void) Py_InitModule3("pythonCallback", pythonCallback_methods, "Extension module for C-to-from-python callbacks"); +} diff --git a/stm32/libraries/CoAP/Makefile b/stm32/libraries/CoAP/Makefile new file mode 100644 index 0000000..44cadba --- /dev/null +++ b/stm32/libraries/CoAP/Makefile @@ -0,0 +1,64 @@ +# +# Copyright (c) 2014 ELL-i co-operative +# +# This is part of ELL-i software +# +# ELL-i software is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ELL-i software is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with ELL-i software. If not, see . +# +# Compile and assemble the Arduino CoAP library +# + +TOP ?= ../../ + +MAKEDIR ?= $(TOP)make/ + +# +# Define the variant to build for +# +PLATFORM ?= arduino +VARIANT ?= ellduino + +# +# Define the library name, if not coming from the calling make +# + +LIB ?= libCoAP.a + +# +# Define source directories +# + +D := $(TOP)libraries/CoAP/src/ + +vpath %.cpp $(D) $(D)coap $(D)encX24j600 $(D)netinet +vpath %.c $(D) $(D)coap $(D)encX24j600 $(D)netinet + +EXTRA_CFLAGS += -I$(TOP)libraries/SPI/src + +# +# Define app library objects. Add new objects here. +# + +LIB_OBJS := eth_input.o arp_input.o +LIB_OBJS += ip_input.o ip_output.o icmp_input.o ip_checksum.o +LIB_OBJS += udp.o coap_input.o coap_handle.o +LIB_OBJS += ethernet_output.o + +# +# Set up the compilation environment, identical to the Arduino IDE, +# for Arduino lib building. +# +LOCAL_RULES := TRUE + +include $(MAKEDIR)lib.mk diff --git a/stm32/libraries/CoAP/TODO b/stm32/libraries/CoAP/TODO new file mode 100644 index 0000000..b6980c5 --- /dev/null +++ b/stm32/libraries/CoAP/TODO @@ -0,0 +1,22 @@ +CLEAN UP ETHERNET HEADER DEFINITION! See ethernet.h + +Move MAC address handling to the driver, add an API + +Refactor the code so that it gets compiled and optimised as a large single object: + +In the overall.c file, define the packet structure, similar to the test case + +include all the stuff there + +eth_input is a real function, called from enc28j60 code +- even it could be inlined but one function overhead is not that bad + +inline ip_input, udp_input, and icmp_input + +udp socket handlers are again separate functions, called through pointers + +udp_output is a real function, called from CoAP + +make sure ip_output is called via a tail call from udp_output and icmp +- make static and tail called, allowing optimised call passing + diff --git a/stm32/libraries/CoAP/src/CoAP.h b/stm32/libraries/CoAP/src/CoAP.h new file mode 100644 index 0000000..5f82f1f --- /dev/null +++ b/stm32/libraries/CoAP/src/CoAP.h @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * Compile-time-allocation based API for CoAP + * + * @author: Pekka Nikander 2014 + */ +#ifndef _ETHERNET_COAP_API_H +# define _ETHERNET_COAP_API_H + +# include +# include // Define size_t +# include + +# include + +# include // XXX Define in_addr_t, IP_MSS, to be removed +# include // XXX Define ether_header, to be removed + +# include +# include + + +# ifdef __cplusplus +# if 0 +# include +# else +# include +# endif +# endif + +// Define the semantics for the return value +typedef int (*coap_callback)( + const struct coap_options * input_options, + const uint8_t *input_buffer, size_t input_length, + uint8_t *output_buffer, size_t *output_buffer_length); + +/* + * Note that we *must* align the IP header (and subsequent headers) at + * 4 byte boundary. However, the Ethernet header is 6+6+2=14 bytes + * long. Consequently, we have to align the Ethernet header at + * two-byte boundary. Bowing slightly to potential future 64-bit + * version and IPv6 compatibility, we align the IP header at a 8-byte + * boundary, leaving two bytes at the beginning of the buffer + */ +#define ALIGNMENT_OFFSET 2 + +typedef struct CoAPClass { + // XXX Move to some other header, buffer.h? + // XXX And define properly + uint8_t packet_buffer_[ + ALIGNMENT_OFFSET + + sizeof(struct ether_header) + + IP_MSS] + __attribute__((aligned(8))); +#define PACKET_BUFFER_SIZE (sizeof(packet_buffer_) - ALIGNMENT_OFFSET) +#define PACKET_BUFFER_START (packet_buffer_ + ALIGNMENT_OFFSET) +#define PACKET_BUFFER_ETHER ((struct ether_header *)PACKET_BUFFER_START) + +# ifdef __cplusplus +public: + void begin(in_addr_t ip_address = IP_ADDRESS_UNSPECIFIED) { + assert(((uint32_t)PACKET_BUFFER_ETHER) % 4 == 2); + // XXX ETHERNET.begin(ether_local_address); + ETHERNET.begin(); + } + void loop(void) { + if (ETHERNET.availablePackets()) { + ETHERNET.receivePacket(PACKET_BUFFER_START, PACKET_BUFFER_SIZE); + eth_input(PACKET_BUFFER_ETHER); + } + } +# endif +} CoAPClass; + +extern CoAPClass CoAP; + +typedef struct { + const coap_callback coap_url_get_callback; + const coap_callback coap_url_put_callback; + const char * coap_url_path; + const uint8_t coap_url_path_length; +} __attribute__((aligned(SYSTEM_INIT_ALIGNMENT))) CoAPURL; + +# ifdef __MACH__ +# define COAP_URL_SECTION(name) ".text,.coapurl" +# else +# define COAP_URL_SECTION(name) ".coap.url." # name +# endif + + +# define DEFINE_COAP_URL(name, path, get_callback, put_callback) \ + extern const CoAPURL __coap_url ## name \ + __attribute__((section(COAP_URL_SECTION(name)))); \ + const CoAPURL __coap_url ## name \ + = { \ + IF(coap_url_get_callback) get_callback, \ + IF(coap_url_put_callback) put_callback, \ + IF(coap_url_path) path, \ + IF(coap_url_path_length) sizeof(path) - 1, \ + } \ + +extern const CoAPURL __coap_urls[]; +extern const CoAPURL __coap_urls_end[]; + +#endif //_ETHERNET_COAP_API_H diff --git a/stm32/libraries/CoAP/src/assert.h b/stm32/libraries/CoAP/src/assert.h new file mode 100644 index 0000000..7d22c58 --- /dev/null +++ b/stm32/libraries/CoAP/src/assert.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * Assert-related macros, by default relying on Arduino APIs + * + * @author: Pekka Nikander 2014 + */ + +#ifndef _ASSERT_H_ +# define _ASSERT_H_ + +# ifdef _ASSERT_DEBUG_PIN_ +# include "wiring_digital.h" +#endif + +# ifdef __cplusplus +extern "C" { +# endif + +static inline void abort(void) __attribute__((noreturn)); + +# ifdef __cplusplus +} // extern "C" +# endif + +static inline void assert(int a) { + if (!a) abort(); +} + +static inline void abort(void) { + +# ifdef _ASSERT_DEBUG_PIN_ + + volatile int i; + pinMode(_ASSERT_DEBUG_PIN_, OUTPUT); + + while (1) { + + digitalWrite(_ASSERT_DEBUG_PIN_, 1); + + for (i=0; i<1000; i++) + ; + + digitalWrite(_ASSERT_DEBUG_PIN_, 0); + + for (i=0; i<1000; i++) + ; + + } +# endif //_ASSERT_DEBUG_PIN_ + for (;;) + ; +} + +#endif //_ASSERT_H_ diff --git a/stm32/libraries/CoAP/src/coap/coap_codes.h b/stm32/libraries/CoAP/src/coap/coap_codes.h new file mode 100644 index 0000000..5883e4c --- /dev/null +++ b/stm32/libraries/CoAP/src/coap/coap_codes.h @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * Minimal CoAP + * + * @author: Pekka Nikander 2014 + */ + +#ifndef _COAP_CODES_H +# define _COAP_CODES_H + +# define DEFINE_COAP_CODE(h, l) (((h) & 0x7) << 5 | ((l) & 0x1f)) + +# define COAP_CODE_CLASS_REQUEST DEFINE_COAP_CODE(0, 0) +# define COAP_CODE_CLASS_SUCCESS DEFINE_COAP_CODE(2, 0) +# define COAP_CODE_CLASS_C_ERROR DEFINE_COAP_CODE(4, 0) +# define COAP_CODE_CLASS_S_ERROR DEFINE_COAP_CODE(5, 0) +# define COAP_CODE_CLASS_MASK DEFINE_COAP_CODE(~0,0) + +# define COAP_CODE_EMPTY DEFINE_COAP_CODE(0, 00) +# define COAP_CODE_GET DEFINE_COAP_CODE(0, 01) +# define COAP_CODE_POST DEFINE_COAP_CODE(0, 02) +# define COAP_CODE_PUT DEFINE_COAP_CODE(0, 03) +# define COAP_CODE_DELETE DEFINE_COAP_CODE(0, 04) + +# define COAP_CODE_CREATED DEFINE_COAP_CODE(2, 01) +# define COAP_CODE_DELETED DEFINE_COAP_CODE(2, 02) +# define COAP_CODE_VALID DEFINE_COAP_CODE(2, 03) +# define COAP_CODE_CHANGED DEFINE_COAP_CODE(2, 04) +# define COAP_CODE_CONTENT DEFINE_COAP_CODE(2, 05) + +# define COAP_CODE_BAD_REQUEST DEFINE_COAP_CODE(4, 00) +# define COAP_CODE_UNAUTHORIZED DEFINE_COAP_CODE(4, 01) +# define COAP_CODE_BAD_OPTION DEFINE_COAP_CODE(4, 02) +# define COAP_CODE_FORBIDDEN DEFINE_COAP_CODE(4, 03) +# define COAP_CODE_NOT_FOUND DEFINE_COAP_CODE(4, 04) +# define COAP_CODE_NOT_ALLOWED DEFINE_COAP_CODE(4, 05) +# define COAP_CODE_NOT_ACCEPTABLE DEFINE_COAP_CODE(4, 06) +# define COAP_CODE_PRECOND_FAILED DEFINE_COAP_CODE(4, 12) +# define COAP_CODE_TOO_LARGE DEFINE_COAP_CODE(4, 13) +# define COAP_CODE_UNSUPP_FORMAT DEFINE_COAP_CODE(4, 15) + +# define COAP_CODE_SERVER_ERROR DEFINE_COAP_CODE(5, 00) +# define COAP_CODE_NOT_IMPLEMENTED DEFINE_COAP_CODE(5, 01) +# define COAP_CODE_BAD_GATEWAY DEFINE_COAP_CODE(5, 02) +# define COAP_CODE_SERV_UNAVAIL DEFINE_COAP_CODE(5, 03) +# define COAP_CODE_GATEWAY_TIMEOUT DEFINE_COAP_CODE(5, 04) +# define COAP_CODE_PROXY_NOT_SUPP DEFINE_COAP_CODE(5, 05) + +#endif //_COAP_CODES_H diff --git a/stm32/libraries/CoAP/src/coap/coap_handle.c b/stm32/libraries/CoAP/src/coap/coap_handle.c new file mode 100644 index 0000000..abca15a --- /dev/null +++ b/stm32/libraries/CoAP/src/coap/coap_handle.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * Minimal CoAP + * + * @author: Pekka Nikander 2014 + */ + +#include +#include +#include + +/** + * XXX + */ +int coap_handle_request( + uint8_t coap_code, + const struct coap_options *const options, + const uint8_t *const payload, + size_t payload_length, + uint8_t *reply_content_buffer, + size_t *reply_content_buffer_length) { + + // XXX Replace the linear search with a binary one; see CoAP.h + for (const CoAPURL *coap_url = __coap_urls; + coap_url < __coap_urls_end; + coap_url++) { + + if (options->uri_path.option_len == coap_url->coap_url_path_length && + 0 == memcmp(options->uri_path.option_value, coap_url->coap_url_path, + options->uri_path.option_len)) { + + switch (coap_code) { + case COAP_CODE_GET: + if (NULL == coap_url->coap_url_get_callback) + return COAP_CODE_NOT_ALLOWED; + return coap_url->coap_url_get_callback(options, + payload, + payload_length, + reply_content_buffer, + reply_content_buffer_length); + case COAP_CODE_PUT: + if (NULL == coap_url->coap_url_put_callback) + return COAP_CODE_NOT_ALLOWED; + return coap_url->coap_url_put_callback(options, + payload, + payload_length, + reply_content_buffer, + reply_content_buffer_length); + } + *reply_content_buffer_length = 0; + return COAP_CODE_NOT_IMPLEMENTED; + } + } + *reply_content_buffer_length = 0; + return COAP_CODE_NOT_FOUND; // Send reply +} diff --git a/stm32/libraries/CoAP/src/coap/coap_input.c b/stm32/libraries/CoAP/src/coap/coap_input.c new file mode 100644 index 0000000..917b5fe --- /dev/null +++ b/stm32/libraries/CoAP/src/coap/coap_input.c @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * Minimal CoAP + * + * @author: Pekka Nikander 2014 + */ + +#include +#include +#include +#include +#include + +CoAPClass CoAP; + +/** + * XXX + */ + +void coap_input(uint8_t coap_data[], uint16_t coap_data_len) { + struct coap *const coap = (struct coap *)coap_data; + register struct coap_hdr *coap_hdr = &coap->coap_hdr; + register uint8_t *const packet_end = &coap_hdr->coap_vttkl + coap_data_len; + uint32_t tkl = (coap_hdr->coap_vttkl & COAP_TKL_MASK); + uint8_t *content_start = coap->coap_token + tkl; + uint8_t is_confirmable = 0; + uint8_t coap_error_code; + + switch (coap_hdr->coap_vttkl & COAP_VT_MASK) { + case COAP_VT_CONFIRMABLE: + is_confirmable = 1; + /* Fall through */ + case COAP_VT_NON_CONFIRMABLE: + break; // Handle the message + case COAP_VT_ACKNOWLEDGEMENT: + net_error("CoAP: Ignoring an acknowledgement.\n"); + case COAP_VT_RESET: + return; // Ignore the message + } + + if (tkl > COAP_TKL_MAX) + goto send_reset; + + { + struct coap_options options = COAP_OPTIONS_INITIALISATION; + uint32_t option_number = 0; + uint8_t *option_bytes = content_start; + + while (option_bytes < packet_end && option_bytes[0] != COAP_OPTION_PAYLOAD) { + uint8_t option_byte = option_bytes[0]; + int32_t option_delta = coap_option_dl_value(option_byte >> 4, &option_bytes); + int32_t option_length = coap_option_dl_value(option_byte & 0xF, &option_bytes); + + if (option_delta < 0 || option_length < 0) { + goto send_reset; // Message format error + } + + uint8_t *option_value = ++option_bytes; + option_bytes += option_length; + option_number += option_delta; + + net_debug("CoAP: Found option %d (len=%d).\n", option_number, option_length); + + switch (option_number) { + case COAP_OPTION_URI_PATH: + options.uri_path.option_len = option_length; + options.uri_path.option_value = option_value; + break; + case COAP_OPTION_CONTENT_FORMAT: + options.content_format.option_len = option_length; + options.content_format.option_value = option_value; + break; + case COAP_OPTION_URI_QUERY: + options.uri_query.option_len = option_length; + options.uri_query.option_value = option_value; + break; + case COAP_OPTION_ACCEPT: + options.accept.option_len = option_length; + options.accept.option_value = option_value; + break; + + case COAP_OPTION_IF_MATCH: + case COAP_OPTION_URI_HOST: + case COAP_OPTION_ETAG: + case COAP_OPTION_IF_NONE: + case COAP_OPTION_URI_PORT: + case COAP_OPTION_LOCATION_PATH: + case COAP_OPTION_MAX_AGE: + case COAP_OPTION_LOCATION_QUERY: + case COAP_OPTION_PROXY_URI: + case COAP_OPTION_PROXY_SCHEME: + case COAP_OPTION_SIZE1: + default: + if (!(option_number & COAP_OPTION_CRITICAL)) + break; // Silently ignored + if (is_confirmable) { + // XXX diagnostic payload as per section 5.5.2 + coap_error_code = COAP_CODE_BAD_OPTION; + goto send_error; + } + goto send_reset; + } + } + + switch (coap_hdr->coap_code) { + case COAP_CODE_EMPTY: + case COAP_CODE_POST: + case COAP_CODE_DELETE: + goto send_reset; + case COAP_CODE_GET: + case COAP_CODE_PUT: + break; // Handle the message + } +#ifndef XXX_LENGTH +#define XXX_LENGTH 256 /* XXX */ +#endif + + /* Handle GET and PUT requests */ + size_t reply_content_length = XXX_LENGTH; // Total buffer length + int reply = coap_handle_request(coap_hdr->coap_code, &options, + option_bytes /*payload*/, packet_end - option_bytes, + content_start, &reply_content_length); + coap_hdr->coap_code = reply; + if (reply != COAP_CODE_EMPTY) { + udp_output(coap, sizeof(struct coap_hdr) + tkl + reply_content_length); + } + return; + } + +send_error: + net_debug("CoAP: Sending a reset on error.\n"); + //XXX; + +send_reset: + net_debug("CoAP: Sending a reset.\n"); + coap_hdr->coap_code = COAP_CODE_EMPTY; + udp_output(coap, sizeof(struct coap_hdr) + tkl); +} + +DEFINE_UDP_SOCKET(UDP_PORT_COAP, coap_input); + diff --git a/stm32/libraries/CoAP/src/coap/coap_internal.h b/stm32/libraries/CoAP/src/coap/coap_internal.h new file mode 100644 index 0000000..5b5abb0 --- /dev/null +++ b/stm32/libraries/CoAP/src/coap/coap_internal.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * Minimal CoAP + * + * @author: Pekka Nikander 2014 + */ + +#ifndef _COAP_INTERNAL_H +# define _COAP_INTERNAL_H + +# include +# include +# include + +# define UDP_PORT_COAP 5683 + +struct coap_hdr { + uint8_t coap_vttkl; + uint8_t coap_code; + uint16_t coap_id; +}; + +struct coap { + union { + struct coap_hdr coap_hdr; + uint32_t coap_hdr_long; + }; + uint8_t coap_token[0]; +}; + +# define DEFINE_COAP_VT(v, t) (((v) & 0x3) << 6 | ((t) & 0x3) << 4) + +# define COAP_VT_CONFIRMABLE DEFINE_COAP_VT(1, 0) +# define COAP_VT_NON_CONFIRMABLE DEFINE_COAP_VT(1, 1) +# define COAP_VT_ACKNOWLEDGEMENT DEFINE_COAP_VT(1, 2) +# define COAP_VT_RESET DEFINE_COAP_VT(1, 3) +# define COAP_VT_MASK DEFINE_COAP_VT(~0,~0) + +# define COAP_TKL_MIN 0x00 +# define COAP_TKL_MAX 0x08 +# define COAP_TKL_MASK 0x0f + +# ifdef __cplusplus +extern "C" { +# endif +extern void coap_input(uint8_t data[], uint16_t coap_data_len); +extern int coap_handle_request(uint8_t coap_code, const struct coap_options *options, + const uint8_t *payload, size_t payload_length, + uint8_t *reply_content, size_t *reply_content_length); +# ifdef __cplusplus +} +# endif + +#endif //_COAP_INTERNAL_H diff --git a/stm32/libraries/CoAP/src/coap/coap_options.h b/stm32/libraries/CoAP/src/coap/coap_options.h new file mode 100644 index 0000000..d7ed3c6 --- /dev/null +++ b/stm32/libraries/CoAP/src/coap/coap_options.h @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * Minimal CoAP + * + * @author: Pekka Nikander 2014 + */ + +#ifndef _COAP_OPTIONS_H +# define _COAP_OPTIONS_H + +struct coap_option { + uint8_t option_len; + uint8_t *option_value; +}; + +struct coap_options { + struct coap_option uri_path; + struct coap_option uri_query; + struct coap_option content_format; + struct coap_option accept; +}; + +# define COAP_OPTIONS_INITIALISATION { { 0, NULL }, { 0, NULL }, { 0, NULL }, { 0, NULL } } + +# define COAP_OPTION_DELTA(b) (((b) >> 4) & 0x0f) +# define COAP_OPTION_LENGTH(b) (((b) >> 0) & 0x0f) +# define COAP_OPTION_DL_EXT1 13 +# define COAP_OPTION_DL_EXT2 14 +# define COAP_OPTION_DL_PAYLOAD 15 + +# define COAP_OPTION_PAYLOAD 0xff + +# define COAP_OPTION_IF_MATCH 1 +# define COAP_OPTION_URI_HOST 3 +# define COAP_OPTION_ETAG 4 +# define COAP_OPTION_IF_NONE 5 +# define COAP_OPTION_URI_PORT 7 +# define COAP_OPTION_LOCATION_PATH 8 +# define COAP_OPTION_URI_PATH 11 +# define COAP_OPTION_CONTENT_FORMAT 12 +# define COAP_OPTION_MAX_AGE 14 +# define COAP_OPTION_URI_QUERY 15 +# define COAP_OPTION_ACCEPT 17 +# define COAP_OPTION_LOCATION_QUERY 20 +# define COAP_OPTION_PROXY_URI 35 +# define COAP_OPTION_PROXY_SCHEME 39 +# define COAP_OPTION_SIZE1 60 + +# define COAP_OPTION_CRITICAL 0x01 + +# define COAP_FORMAT_TEXT_PLAIN 0 +# define COAP_FORMAT_APPLICATION_LINK 40 +# define COAP_FORMAT_APPLICATION_XML 41 +# define COAP_FORMAT_APPLICATION_STREAM 42 +# define COAP_FORMAT_APPLICATION_EXI 47 +# define COAP_FORMAT_APPLICATION_JSON 50 + +/** + * XXX + * @param v option delta or length, must be 0-15 + * @param p pointer to a pointer to the next byte, may get incremented + * @return -1 if a payload marker is detected + */ +static inline int32_t coap_option_dl_value(const uint8_t v, uint8_t ** p) { + const uint16_t *const ext2 = (const uint16_t *)(*p); + switch (v) { + case COAP_OPTION_DL_EXT1: (*p)++; return **p - 13; + case COAP_OPTION_DL_EXT2: (*p) += 2; return *ext2 - 269; + case COAP_OPTION_DL_PAYLOAD: return -1; + default: return v; + } +} + +#endif //_COAP_OPTIONS_H + diff --git a/stm32/libraries/CoAP/src/enc28j60/ENC28J60.h b/stm32/libraries/CoAP/src/enc28j60/ENC28J60.h new file mode 100644 index 0000000..ecd2e7a --- /dev/null +++ b/stm32/libraries/CoAP/src/enc28j60/ENC28J60.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2014 ELL-i co-operative + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +#include +#if defined(ELLI_STM32F051_ELLDUINO) +# include // XXX To be placed into the variant.h! +#elif defined(ELLI_STM32F407_DISCOVERY) +# include +#elif defined(ELLI_STM32F334_NUCLEO) +# include +#else +# error "The ENC28J60 library is not yet supported with this board." +#endif + diff --git a/stm32/libraries/CoAP/src/enc28j60/ENC28J60Class.h b/stm32/libraries/CoAP/src/enc28j60/ENC28J60Class.h new file mode 100644 index 0000000..aa855f2 --- /dev/null +++ b/stm32/libraries/CoAP/src/enc28j60/ENC28J60Class.h @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * ENC28J60 interface through the Arduino SPI library + * + * @author: Pekka Nikander 2014 + */ + +#ifndef _ENC28J60_CLASS_H_ +# define _ENC28J60_CLASS_H_ + +# include +# include + +class ENC28J60Class { +public: + // XXX Currently we have to define this here as _static_ for constant + // propagation to work correctly. Must try again later with better gcc / LLVM. + // ss_pin_ should be const non-static, set from the constructor. + const static pin_t ss_pin_ = ENC28J60_CS_PIN; // Must allow constant propagration! + + const uint8_t *const mac_address_; + + const static uint32_t spiCR1value = SPI_CR1_DEFAULT_INIT_VALUE; + + constexpr ENC28J60Class( + const struct SPI &spi_dummy, // XXX FIXME define the SPI device here + pin_t ss_pin_dummy, + const uint8_t mac_address[ETH_ADDRESS_LEN]) + // : ss_pin_(ss_pin), ... XXX FIXME add variable initialisation here + : mac_address_(mac_address) + {}; + + void begin() const; + int availablePackets(void) const; + + int receivePacket(uint8_t *buffer, size_t len) const; + void sendPacket (uint8_t *buffer, size_t len) const; + + // XXX For debugging purposes + bool checkBegin(const uint8_t mac_address[ETH_ADDRESS_LEN]) const; + void getHeader(enc_rx_packet_header_t *rx_header) const; + + static const struct enc28j60_register_init_static_8bit enc28j60_init[]; + static const size_t enc28j60_init_size; + static enc_rx_packet_header_t rx_header; + +private: + + uint8_t spi_command(uint8_t cmd, uint8_t value, bool third_byte) const; + void spi_transfer_send(uint8_t *buffer, uint16_t len) const __attribute__((always_inline)); + void spi_transfer (uint8_t *buffer, uint16_t len) const __attribute__((always_inline)); + + void set_bank(int bank) const; //XXX to prevent casting differnt enums enc_bank_t + int phy_get(enc_reg_t reg) const; + void phy_set(enc_reg_t reg, int value, bool nowait) const; + + int reg_get(enc_reg_t reg) const __attribute__((always_inline)); + void reg_set(enc_reg_t reg, int value) const __attribute__((always_inline)); + void reg_set_inner(enc_reg_t reg, int value) const; + void reg_bitop(enc_spi_op_t op, enc_reg_t reg, int mask) const __attribute__((always_inline)); + +}; + +inline uint8_t +ENC28J60Class::spi_command(uint8_t cmd, uint8_t value, bool third_byte) const { + uint8_t buffer[4]; + size_t len; + + buffer[0] = cmd; + buffer[1] = value; + + len = 2; + if (third_byte) len = 3; + + spi_transfer(buffer, len); + + return (third_byte)? buffer[2]: buffer[1]; +} + +inline void +ENC28J60Class::spi_transfer_send(uint8_t *buffer, uint16_t len) const { + spi_master_activate(ss_pin_); + ::spi_transfer_raw(&ENC28J60_SPI, spiCR1value, buffer, len, 0); + spi_master_deactivate(ss_pin_); +} + +inline void +ENC28J60Class::spi_transfer(uint8_t *buffer, uint16_t len) const { + spi_master_activate(ss_pin_); + ::spi_transfer_raw(&ENC28J60_SPI, spiCR1value, buffer, len, 1); + spi_master_deactivate(ss_pin_); +} + +# include +# include +# include + +#endif//_ENC28J60_CLASS_H_ diff --git a/stm32/libraries/CoAP/src/enc28j60/enc28j60_conf.h b/stm32/libraries/CoAP/src/enc28j60/enc28j60_conf.h new file mode 100644 index 0000000..a0b5e86 --- /dev/null +++ b/stm32/libraries/CoAP/src/enc28j60/enc28j60_conf.h @@ -0,0 +1,337 @@ +/* + * Copyright 2014 Pekka Nikander. See NOTICE for licensing information. + */ + +#ifndef _ENC28J60_CONF_H +# define _ENC28J60_CONF_H + +# include +# include + +/* + * ENC28J60 RX/TX buffer assignment + * + * The RX buffer should start at zero. See Rev. B4 Silicon Errata. + * + * Leave one Ethernet packet worth for the TX buffer, 0x600 = 1536 bytes + */ +# define MAX_PACKET_SIZE 0x0600 + +# define RX_BUFFER_START (ENC_BUFFER_START) +# define RX_BUFFER_END (TX_BUFFER_START - 1) +# define TX_BUFFER_START (ENC_BUFFER_START + ENC_BUFFER_SIZE - MAX_PACKET_SIZE) +# define TX_BUFFER_END (ENC_BUFFER_START + ENC_BUFFER_SIZE) + +# define ETH_ADDRESS_LEN 6 + +# define ENC_BUFFER_START 0x0000 +# define ENC_BUFFER_SIZE 0x2000 + +enum enc_bank_t { +# define ENC_BANK_SHIFT 5 + ENC_BANK0 = 0x00, + ENC_BANK1 = 0x20, + ENC_BANK2 = 0x40, + ENC_BANK3 = 0x60, + ENC_BANK_FLAG0 = 0x80, + ENC_BANK_GEN = ENC_BANK_FLAG0 | ENC_BANK0, + ENC_BANK2_MREG = ENC_BANK_FLAG0 | ENC_BANK2, + ENC_BANK3_MREG = ENC_BANK_FLAG0 | ENC_BANK3, + ENC_BANK_MASK = ENC_BANK0 | ENC_BANK1 | ENC_BANK2 | ENC_BANK3, + /* 16-bit constants for 16-bit registers */ + ENC_BANK_PHY = 0x100, + ENC_TYPE_LONG = 0x200, /* NB. Not in TYPE_MASK! */ + ENC_TYPE_MASK = ENC_BANK_PHY | ENC_BANK_FLAG0 | ENC_BANK_MASK, +}; + +# define ENC_REG_MASK 0x1F + +# define ENC_GEN_REG(number) (ENC_BANK_GEN | (number)) +# define ENC_BANK0__REG(number) (ENC_BANK0 | (number)) +# define ENC_BANK0_LREG(number) (ENC_BANK0 | (number) | ENC_TYPE_LONG) +# define ENC_BANK1__REG(number) (ENC_BANK1 | (number)) +# define ENC_BANK1_LREG(number) (ENC_BANK1 | (number) | ENC_TYPE_LONG) +# define ENC_BANK2__REG(number) (ENC_BANK2 | (number)) +# define ENC_BANK2_MREG(number) (ENC_BANK2_MREG | (number)) +# define ENC_BANK2LMREG(number) (ENC_BANK2_MREG | (number) | ENC_TYPE_LONG) +# define ENC_BANK3__REG(number) (ENC_BANK3 | (number)) +# define ENC_BANK3_MREG(number) (ENC_BANK3_MREG | (number)) +# define ENC_BANK3LMREG(number) (ENC_BANK3_MREG | (number) | ENC_TYPE_LONG) +# define ENC_PHY_REG(number) (ENC_BANK_PHY | (number)) + +enum enc_reg_t { + E_INT_ENA = ENC_GEN_REG(0x1B), +# define E_INT_ENA_INT 0x80 +# define E_INT_ENA_PKT 0x40 +# define E_INT_ENA_DMA 0x20 +# define E_INT_ENA_LINK 0x10 +# define E_INT_ENA_TX 0x08 +# define E_INT_ENA_WOL 0x04 +# define E_INT_ENA_TX_ERR 0x02 +# define E_INT_ENA_RX_ERR 0x01 + + E_INT_REQ = ENC_GEN_REG(0x1C), +# define E_INT_REQ_PKT 0x40 +# define E_INT_REQ_DMA 0x20 +# define E_INT_REQ_LINK 0x10 +# define E_INT_REQ_TX 0x08 +# define E_INT_REQ_WOL 0x04 +# define E_INT_REQ_TX_ERR 0x02 +# define E_INT_REQ_RX_ERR 0x01 + + E_STAT = ENC_GEN_REG(0x1D), +# define E_STAT_INT 0x80 +# define E_STAT_LATE_COL 0x10 +# define E_STAT_RX_BUSY 0x04 +# define E_STAT_TX_ABORT 0x02 +# define E_STAT_CLOCK_READY 0x01 + + E_CON2 = ENC_GEN_REG(0x1E), +# define E_CON2_AUTO_INC 0x80 +# define E_CON2_PKT_DEC 0x40 +# define E_CON2_POWER_SAVE 0x20 +# define E_CON2_VR_POWER_SAVE 0x08 + E_CON1 = ENC_GEN_REG(0x1F), +# define E_CON1_TX_RESET 0x80 +# define E_CON1_RX_RESET 0x40 +# define E_CON1_DMA_START 0x20 +# define E_CON1_CSUM_ENABLE 0x10 +# define E_CON1_TX_REQUEST 0x08 +# define E_CON1_RX_ENABLE 0x04 +# define E_CON1_B_SEL1 0x02 +# define E_CON1_B_SEL0 0x01 + + E_RD_PTR = ENC_BANK0_LREG(0x00), + E_RD_PTR_L = ENC_BANK0__REG(0x00), + E_RD_PTR_H = ENC_BANK0__REG(0x01), + E_WR_PTR = ENC_BANK0_LREG(0x02), + E_WR_PTR_L = ENC_BANK0__REG(0x02), + E_WR_PTR_H = ENC_BANK0__REG(0x03), + E_TX_STA = ENC_BANK0_LREG(0x04), + E_TX_STA_L = ENC_BANK0__REG(0x04), + E_TX_STA_H = ENC_BANK0__REG(0x05), + E_TX_END = ENC_BANK0_LREG(0x06), + E_TX_END_L = ENC_BANK0__REG(0x06), + E_TX_END_H = ENC_BANK0__REG(0x07), + E_RX_STA = ENC_BANK0_LREG(0x08), + E_RX_STA_L = ENC_BANK0__REG(0x08), + E_RX_STA_H = ENC_BANK0__REG(0x09), + E_RX_END = ENC_BANK0_LREG(0x0A), + E_RX_END_L = ENC_BANK0__REG(0x0A), + E_RX_END_H = ENC_BANK0__REG(0x0B), + E_RX_RD_PTR = ENC_BANK0_LREG(0x0C), + E_RX_RD_PTR_L = ENC_BANK0__REG(0x0C), + E_RX_RD_PTR_H = ENC_BANK0__REG(0x0D), + E_RX_WR_PTR = ENC_BANK0_LREG(0x0E), + E_RX_WR_PTR_L = ENC_BANK0__REG(0x0E), + E_RX_WR_PTR_H = ENC_BANK0__REG(0x0F), + E_DMA_STA = ENC_BANK0_LREG(0x10), + E_DMA_STA_L = ENC_BANK0__REG(0x10), + E_DMA_STA_H = ENC_BANK0__REG(0x11), + E_DMA_END = ENC_BANK0_LREG(0x12), + E_DMA_END_L = ENC_BANK0__REG(0x12), + E_DMA_END_H = ENC_BANK0__REG(0x13), + E_DMA_DST = ENC_BANK0_LREG(0x14), + E_DMA_DST_L = ENC_BANK0__REG(0x14), + E_DMA_DST_H = ENC_BANK0__REG(0x15), + E_DMA_CS = ENC_BANK0_LREG(0x16), + E_DMA_CS_L = ENC_BANK0__REG(0x16), + E_DMA_CS_H = ENC_BANK0__REG(0x17), + + E_HT0 = ENC_BANK1__REG(0x00), + E_HT1 = ENC_BANK1__REG(0x01), + E_HT2 = ENC_BANK1__REG(0x02), + E_HT3 = ENC_BANK1__REG(0x03), + E_HT4 = ENC_BANK1__REG(0x04), + E_HT5 = ENC_BANK1__REG(0x05), + E_HT6 = ENC_BANK1__REG(0x06), + E_HT7 = ENC_BANK1__REG(0x07), + E_PM_M0 = ENC_BANK1__REG(0x08), + E_PM_M1 = ENC_BANK1__REG(0x09), + E_PM_M2 = ENC_BANK1__REG(0x0A), + E_PM_M3 = ENC_BANK1__REG(0x0B), + E_PM_M4 = ENC_BANK1__REG(0x0C), + E_PM_M5 = ENC_BANK1__REG(0x0D), + E_PM_M6 = ENC_BANK1__REG(0x0E), + E_PM_M7 = ENC_BANK1__REG(0x0F), + E_PM_CHSUM = ENC_BANK1_LREG(0x10), + E_PM_CHSUM_L = ENC_BANK1__REG(0x10), + E_PM_CHSUM_H = ENC_BANK1__REG(0x11), + E_PM_OFF = ENC_BANK1_LREG(0x14), + E_PM_OFF_L = ENC_BANK1__REG(0x14), + E_PM_OFF_H = ENC_BANK1__REG(0x15), + E_WOL_IE = ENC_BANK1__REG(0x16), + E_WOL_IR = ENC_BANK1__REG(0x17), + E_RX_FCOND = ENC_BANK1__REG(0x18), +# define E_RX_FCOND_UC_EN 0x80 +# define E_RX_FCOND_AND_OR 0x40 +# define E_RX_FCOND_CRC_EN 0x20 +# define E_RX_FCOND_PM_EN 0x10 +# define E_RX_FCOND_MP_EN 0x08 +# define E_RX_FCOND_HT_EN 0x04 +# define E_RX_FCOND_MC_EN 0x02 +# define E_RX_FCOND_BC_EN 0x01 + E_PKT_CNT = ENC_BANK1__REG(0x19), + + MAC_CON1 = ENC_BANK2_MREG(0x00), +# define MAC_CON1_LOOP_BACK 0x10 +# define MAC_CON1_TX_PAUSE 0x08 +# define MAC_CON1_RX_PAUSE 0x04 +# define MAC_CON1_PASS_ALL 0x02 +# define MAC_CON1_RX_EN 0x01 + MAC_CON2 = ENC_BANK2_MREG(0x01), +# define MAC_CON2_MAC_RST 0x80 +# define MAC_CON2_RND_RST 0x40 +# define MAC_CON2_RX_RST 0x08 +# define MAC_CON2_RX_FUN_RST 0x04 +# define MAC_CON2_TX_RST 0x02 +# define MAC_CON2_TX_FUN_RST 0x01 + MAC_CON3 = ENC_BANK2_MREG(0x02), +# define MAC_CON3_PAD_CRC_2 0x80 +# define MAC_CON3_PAD_CRC_1 0x40 +# define MAC_CON3_PAD_CRC_0 0x20 +# define MAC_CON3_TX_CRC_EN 0x10 +# define MAC_CON3_PHDR_LEN 0x08 +# define MAC_CON3_HUGE_FRAMES 0x04 +# define MAC_CON3_FR_LEN_CHK 0x02 +# define MAC_CON3_FULL_DPX 0x01 + MAC_CON4 = ENC_BANK2_MREG(0x03), +# define MAC_CON4_DEFER 0x40 +# define MAC_CON4_BP_EN 0x20 +# define MAC_CON4_NO_BKOFF 0x10 +# define MAC_CON4_LONG_PRE 0x02 +# define MAC_CON4_PURE_PRE 0x01 + MAC_BBIP_GAP = ENC_BANK2_MREG(0x04), + MAC_IP_GAP = ENC_BANK2LMREG(0x06), + MAC_IP_GAP_L = ENC_BANK2_MREG(0x06), + MAC_IP_GAP_H = ENC_BANK2_MREG(0x07), + MAC_COL_CON1 = ENC_BANK2_MREG(0x08), + MAC_COL_CON2 = ENC_BANK2_MREG(0x09), + MAC_MAX_FRAME = ENC_BANK2LMREG(0x0A), + MAC_MAX_FRAME_L = ENC_BANK2_MREG(0x0A), + MAC_MAX_FRAME_H = ENC_BANK2_MREG(0x0B), + MAC_PHY_SUP = ENC_BANK2_MREG(0x0D), +# define MAC_PHY_SUP_RSTINTFC 0x80 +# define MAC_PHY_SUP_RSTRMII 0x40 + + MII_CON = ENC_BANK2_MREG(0x11), + MII_CMD = ENC_BANK2_MREG(0x12), +# define MII_CMD_SCAN 0x02 +# define MII_CMD_READ 0x01 + MII_REG_ADR = ENC_BANK2_MREG(0x14), + MII_WR = ENC_BANK2LMREG(0x16), + MII_WR_L = ENC_BANK2_MREG(0x16), + MII_WR_H = ENC_BANK2_MREG(0x17), + MII_RD = ENC_BANK2LMREG(0x18), + MII_RD_L = ENC_BANK2_MREG(0x18), + MII_RD_H = ENC_BANK2_MREG(0x19), + + /* NB. Note the peciular order. */ + MAC_ADR1 = ENC_BANK3_MREG(0x00), + MAC_ADR0 = ENC_BANK3_MREG(0x01), + MAC_ADR3 = ENC_BANK3_MREG(0x02), + MAC_ADR2 = ENC_BANK3_MREG(0x03), + MAC_ADR5 = ENC_BANK3_MREG(0x04), + MAC_ADR4 = ENC_BANK3_MREG(0x05), + + E_BSTSD = ENC_BANK3__REG(0x06), + E_BSTCON = ENC_BANK3__REG(0x07), + E_BSTCSL = ENC_BANK3__REG(0x08), + E_BSTCSH = ENC_BANK3__REG(0x09), + + MII_STAT = ENC_BANK3_MREG(0x0A), +# define MII_STAT_NVALID 0x04 +# define MII_STAT_SCAN 0x02 +# define MII_STAT_BUSY 0x01 + + E_REVID = ENC_BANK3__REG(0x12), + E_COCON = ENC_BANK3__REG(0x15), + E_FLOCON = ENC_BANK3__REG(0x17), + E_PAUSL = ENC_BANK3__REG(0x18), + E_PAUSH = ENC_BANK3__REG(0x19), + + PHY_CON1 = ENC_PHY_REG(0x00), +# define PHY_CON1_PRST 0x8000 +# define PHY_CON1_PLOOPBK 0x4000 +# define PHY_CON1_PPWRSV 0x0800 +# define PHY_CON1_PDPXMD 0x0100 + + PHY_STAT1 = ENC_PHY_REG(0x01), +# define PHY_STAT1_PFDPX 0x1000 +# define PHY_STAT1_PHDPX 0x0800 +# define PHY_STAT1_LLSTAT 0x0004 +# define PHY_STAT1_JBSTAT 0x0002 + + PHY_HID1 = ENC_PHY_REG(0x02), + PHY_HID2 = ENC_PHY_REG(0x03), + PHY_CON2 = ENC_PHY_REG(0x10), +# define PHY_CON2_FRCLINK 0x4000 +# define PHY_CON2_TXDIS 0x2000 +# define PHY_CON2_JABBER 0x0400 +# define PHY_CON2_HDLDIS 0x0100 + PHY_STAT2 = ENC_PHY_REG(0x11), + PHY_IE = ENC_PHY_REG(0x12), + PHY_IR = ENC_PHY_REG(0x13), + PHY_LCON = ENC_PHY_REG(0x14), +}; + +enum enc_spi_op_t { + ENC_SPI_READ_REG = 0x00, + ENC_SPI_READ_MEM = 0x3A, + ENC_SPI_WRITE_REG = 0x40, + ENC_SPI_WRITE_MEM = 0x7A, + ENC_SPI_SET_BF = 0x80, + ENC_SPI_CLR_BF = 0xA0, + ENC_SPI_RESET = 0xFF, +}; + +typedef uint8_t enc_reg_value_t, enc_buf_value_t; +typedef size_t enc_buf_len_t; +typedef uint16_t enc_phy_value_t; + +enum enc_rx_packet_status_t { + ENC_RX_STATUS_LONG_DROP = 0x0001, + ENC_RX_STATUS_CARRIER_SEEN = 0x0004, + ENC_RX_STATUS_CEC_ERROR = 0x0010, + ENC_RX_STATUS_LENGTH_ERROR = 0x0020, + ENC_RX_STATUS_LONG_TYPE = 0x0040, + ENC_RX_STATUS_RECEIVE_OK = 0x0080, + ENC_RX_STATUS_MULTICAST = 0x0100, + ENC_RX_STATUS_BROADCAST = 0x0200, + ENC_RX_STATUS_DRIBBLE = 0x0400, + ENC_RX_STATUS_CONTROL_FRAME = 0x0800, + ENC_RX_STATUS_PAUSE_FRAME = 0x1000, + ENC_RX_STATUS_UNKNOWN_OPCODE = 0x2000, + ENC_RX_STATUS_VLAN_FRAME = 0x4000, +}; + +/** + * ENC28J60 internal RX packet header. + * + * Transferred over SPI, see Data Sheet page 33-34 + */ + +typedef struct enc28j60_register_init_static_8bit { + enc_reg_t reg; + enc_reg_value_t value; +} device_register_init_static_8bit_t; + +//XXX This is no longer used, needs to be removed, for reference meanwhile +# ifdef __cplusplus +extern "C" { +# endif + +//XXX packed to prevent any padding +typedef struct __attribute__((__packed__)) enc_rx_packet_header { + uint8_t rx_cmd; + uint16_t rx_next; + uint16_t rx_length; /* Length of the received frame */ + uint16_t rx_status; +} enc_rx_packet_header_t; + + +# ifdef __cplusplus +} // extern "C" +# endif + +#endif //_ENC28J60_CONF_H diff --git a/stm32/libraries/CoAP/src/enc28j60/enc28j60_init.cpp b/stm32/libraries/CoAP/src/enc28j60/enc28j60_init.cpp new file mode 100644 index 0000000..c68231f --- /dev/null +++ b/stm32/libraries/CoAP/src/enc28j60/enc28j60_init.cpp @@ -0,0 +1,190 @@ +/* + * Copyright (c) 2014 ELL-i co-operative + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Pekka Nikander 2014 + * @author Ivan Raul 2014 + * + * @brief ENC28J60 ethernet interface + */ + +#include + +#define D8(r, v) { .reg = (r), .value = (v) } + +#define D16(r, v) \ + D8(r ## _L, (v) & 0xff), \ + D8(r ## _H, (v) >> 8) + + +const struct enc28j60_register_init_static_8bit ENC28J60Class::enc28j60_init[] = { + + /********************************** + * Bank0: RX and TX buffers, DMA + **********************************/ + + /* Buffer transfer */ + D16(E_RD_PTR, RX_BUFFER_START), + D16(E_WR_PTR, TX_BUFFER_START), + /* TX buffer */ + D16(E_TX_STA, TX_BUFFER_START), + D16(E_TX_END, TX_BUFFER_END), + /* RX buffer */ + D16(E_RX_STA, RX_BUFFER_START), + D16(E_RX_END, RX_BUFFER_END), + D16(E_RX_RD_PTR, RX_BUFFER_START), + // E_RX_WR_PTR is read only + /* DMA: not used in this application */ + + /********************************** + * Bank1: Packet filtering + **********************************/ + + /* + * Hash-table not used + */ + /* + * Pattern matching broadcast packet filter for ARP + */ + D8 (E_PM_M0, 0x3F), /* Match destination Ethernet address (6 bytes) */ + D8 (E_PM_M1, 0x30), /* Match ARP Ethertype 0x0608 */ + // All the rest of E_PM_M0 in their reset values */ + D16(E_PM_CHSUM, 0xf7f9), /* IP checksum for ff ff ff ff ff ff 06 08 */ + D16(E_PM_OFF, 0x0000), /* Match from the beginning of the packet */ + /* + * Wake-on-LAN + */ +#ifdef XXX + XXX +#endif + /* + * Filtering configuration. + */ + D8(E_RX_FCOND, + 0 + | E_RX_FCOND_UC_EN /* 1: Unicast without our MAC discarded */ + | ! E_RX_FCOND_AND_OR /* 0: User OR filtering */ + | E_RX_FCOND_CRC_EN /* 1: Enablve post-filter CRC check */ + | E_RX_FCOND_PM_EN /* 1: Pattern match filter enabled for ARP */ + | ! E_RX_FCOND_MP_EN /* 0: Magic packet filter disabled */ + | ! E_RX_FCOND_HT_EN /* 0: Hash-table filter disabled */ + | ! E_RX_FCOND_MC_EN /* 0: Multicast disabled */ + | E_RX_FCOND_BC_EN /* 1: Broadcast enabled */ + ), + + /********************************** + * Bank3: MAC & MII + **********************************/ + D8(MAC_CON1, + 0 + | ! MAC_CON1_LOOP_BACK /* 0: No loopback */ + | MAC_CON1_TX_PAUSE /* 1: Allow sending pause control frames */ + | MAC_CON1_RX_PAUSE /* 1: Adhere received pause control frames */ + | ! MAC_CON1_PASS_ALL /* 0: Don't pass control frames to host */ + | MAC_CON1_RX_EN /* 1: Enable the MAC */ + ), + D8(MAC_CON2, + 0 + | ! MAC_CON2_MAC_RST /* 0: Enable MAC */ + | ! MAC_CON2_RND_RST /* 0: Enable MAC random number generator */ + | ! MAC_CON2_RX_RST /* 0: Enable MAC receive logic */ + | ! MAC_CON2_RX_FUN_RST /* 0: Enable MAC packet receive */ + | ! MAC_CON2_TX_RST /* 0: Enable MAC transmit logic */ + | ! MAC_CON2_TX_FUN_RST /* 0: Enable MAC packet transmit */ + ), + D8(MAC_CON3, + 0 + | ! MAC_CON3_PAD_CRC_2 /* 001: Pad to 60 bytes and add CRC */ + | ! MAC_CON3_PAD_CRC_1 + | MAC_CON3_PAD_CRC_0 + | MAC_CON3_TX_CRC_EN /* 1: Enable CRC for Transmit */ + | ! MAC_CON3_PHDR_LEN /* 0: No proprietary header */ + | ! MAC_CON3_HUGE_FRAMES /* 0: No proprietary header */ + | MAC_CON3_FR_LEN_CHK /* 1: Check frame lengths */ + | ! MAC_CON3_FULL_DPX /* 0: No full duplex (yet) XXX */ + ), + D8(MAC_CON4, + 0 + | ! MAC_CON4_DEFER /* 0: Abort after excessive wait */ + | ! MAC_CON4_BP_EN /* 0: Use binary backoff algorithm */ + | ! MAC_CON4_NO_BKOFF /* 0: Use binary backoff algorithm */ + | ! MAC_CON4_LONG_PRE /* 0: Long preambles allowed */ + | ! MAC_CON4_PURE_PRE /* 0: Don't check preable contents */ + ), + D8(MAC_BBIP_GAP, 0x12), /* Recommended back-to-back gap for half duplex XXX */ + D16(MAC_IP_GAP, 0x0C12), /* As recommended in the data sheet */ + // Collision control default values as per data sheet + D16(MAC_MAX_FRAME, 1518),/* As recommended in the data shaat */ + // MAC-PHY Support not changed as per data sheet + + // MII Control register not changed as per data sheet + // MII Command, status, MII reg address and data registers + // used for MII communication, not initialised. + + /********************************** + * Bank3: MAC address and misc + **********************************/ + +#if 0 + MISTAT + EREVID + ECOCON + EFLOCON + EPAUS +#endif + + /********************************** + * Cross-bank registers + **********************************/ + D8(E_INT_ENA, + 0 + | E_INT_ENA_INT /* 1: Enable INT pin */ + | E_INT_ENA_PKT /* 1: Interrupt on pending packets */ + | ! E_INT_ENA_DMA /* 0: Disable DMA interrupt */ + | E_INT_ENA_LINK /* 1: Interrupt on link status change */ + | E_INT_ENA_TX /* 1: Interrupt on transmit ready */ + | E_INT_ENA_WOL /* 1: Enable WOL pin */ + | ! E_INT_ENA_TX_ERR /* 1: Disable transmit error interrupts */ + | E_INT_ENA_RX_ERR /* 1: Disable receive error interrupts */ + ), +#ifdef DONT_INIT_RESET_TIME_VALUE + D8(E_CON2, + 0 + | E_CON2_AUTOINC /* 1: Autoinc; reset-time value */ + | ! E_CON2_PKTDEC /* 0: Command, not used during initialisation */ + | ! E_CON2_PWRSV /* 0: No MAC/PHY power save; reset-time value */ + | ! E_CON2_VRPS /* 0: No voltage regu power save; reset-time value */ + ), +#endif + D8(E_CON1, + 0 + | ! E_CON1_TX_RESET /* 0: Transmit logic enabled */ + | ! E_CON1_RX_RESET /* 0: Receive logic enabled */ + | ! E_CON1_DMA_START /* 0: Don't use DMA now */ + | ! E_CON1_CSUM_ENABLE /* 0: N/A, we are not using the DMA */ + | ! E_CON1_TX_REQUEST /* 0: Don't transmit yet */ + | E_CON1_RX_ENABLE /* 1: Enable Receiving */ + | E_CON1_B_SEL1 /* 11: Stay in bank 3 */ + | E_CON1_B_SEL0 + ), +}; + +const size_t ENC28J60Class::enc28j60_init_size = COUNT_OF(ENC28J60Class::enc28j60_init); + +enc_rx_packet_header_t ENC28J60Class::rx_header; diff --git a/stm32/libraries/CoAP/src/enc28j60/enc28j60_init.h b/stm32/libraries/CoAP/src/enc28j60/enc28j60_init.h new file mode 100644 index 0000000..2019035 --- /dev/null +++ b/stm32/libraries/CoAP/src/enc28j60/enc28j60_init.h @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * ENC28J60 interface through the Arduino SPI library + * + * @author: Pekka Nikander 2014 + */ + +#ifndef _ENC28J60_INIT_H_ +# define _ENC28J60_INIT_H_ + +inline void +ENC28J60Class::begin() const { + const device_register_init_static_8bit_t *p; + + spi_master_begin(&ENC28J60_SPI, ss_pin_); + + // XXX reset the device + + while ((reg_get(E_STAT) & E_STAT_CLOCK_READY) == 0) { + ; + } + + // XXX CHECK ORDER! + reg_set(MAC_ADR0, mac_address_[5]); + reg_set(MAC_ADR1, mac_address_[4]); + reg_set(MAC_ADR2, mac_address_[3]); + reg_set(MAC_ADR3, mac_address_[2]); + reg_set(MAC_ADR4, mac_address_[1]); + reg_set(MAC_ADR5, mac_address_[0]); + + for (p = enc28j60_init; p < enc28j60_init + enc28j60_init_size; p++) { + reg_set(p->reg, p->value); + } + + while (reg_get(PHY_CON1) & PHY_CON1_PRST) + ; + + reg_set(PHY_CON2, PHY_CON2_HDLDIS); + + enc_buf_value_t b[2] = { ENC_SPI_WRITE_MEM, 0 }; + + spi_transfer(b, sizeof(b)); + +} + +// XXX For debugging purposes +inline bool +ENC28J60Class::checkBegin(const uint8_t mac_address[ETH_ADDRESS_LEN]) const { + const device_register_init_static_8bit_t *p; + + if(reg_get(MAC_ADR0) != mac_address[5]) return false; + if(reg_get(MAC_ADR1) != mac_address[4]) return false; + if(reg_get(MAC_ADR2) != mac_address[3]) return false; + if(reg_get(MAC_ADR3) != mac_address[2]) return false; + if(reg_get(MAC_ADR4) != mac_address[1]) return false; + if(reg_get(MAC_ADR5) != mac_address[0]) return false; + + for (p = enc28j60_init + 14; //skip buffer pointers + p < enc28j60_init + enc28j60_init_size - 1; //skip ECON1 + p++) { + if (reg_get(p->reg) != p->value) return false; + } + + return true; +} + +#endif // _ENC28J60_INIT_H_ diff --git a/stm32/libraries/CoAP/src/enc28j60/enc28j60_packet.h b/stm32/libraries/CoAP/src/enc28j60/enc28j60_packet.h new file mode 100644 index 0000000..84dabb2 --- /dev/null +++ b/stm32/libraries/CoAP/src/enc28j60/enc28j60_packet.h @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author: Pekka Nikander 2014 + * @author Ivan Raul 2014 + * + * @brief ENC28J60 ethernet interface + */ + +#ifndef _ENC28J60_PACKET_H_ +# define _ENC28J60_PACKET_H_ + +# include +# include + +inline int +ENC28J60Class::availablePackets(void) const { + return reg_get(E_PKT_CNT); +} + +inline int +ENC28J60Class::receivePacket(uint8_t *buffer, size_t maxlen) const { + + rx_header.rx_cmd = ENC_SPI_READ_MEM; + spi_transfer((unsigned char *)&rx_header, sizeof(enc_rx_packet_header_t)); + + register unsigned int plen = rx_header.rx_length; + register unsigned int next = rx_header.rx_next; + + if (plen > maxlen) + plen = maxlen; + + /* Assumed buffer has extra space at the + * beginning for the command + */ + *(buffer - 1) = ENC_SPI_READ_MEM; + spi_transfer(buffer-1, plen+1); + + /* + * Go to the beginning of the next packet. + * + * NB. It might be possible to avoid this call if len == + * rx_header.rx_length, but that would need to be tested, as + * it is not clear from the data sheet. + */ + reg_set(E_RD_PTR, next); + + /* + * Free the ENC28J60 buffer memory for the next packets. + * See Errata #14. + */ + reg_set(E_RX_RD_PTR, next == RX_BUFFER_START? RX_BUFFER_END: next-1); + + /* Decrement the packet count */ + reg_bitop(ENC_SPI_SET_BF, E_CON2, E_CON2_PKT_DEC); + + return plen; + +} + +inline void +ENC28J60Class::getHeader(enc_rx_packet_header_t *rx_header) const { + rx_header->rx_cmd = ENC_SPI_READ_MEM; + + spi_transfer((unsigned char *)rx_header, sizeof(enc_rx_packet_header_t)); + + register unsigned int next = rx_header->rx_next; + + /* + * Go to the beginning of the next packet. + */ + reg_set(E_RD_PTR, next); + + /* + * Free the ENC28J60 buffer memory for the next packets. + * See Errata #14. + */ + reg_set(E_RX_RD_PTR, next == RX_BUFFER_START? RX_BUFFER_END: next-1); + + /* Decrement the packet count */ + reg_bitop(ENC_SPI_SET_BF, E_CON2, E_CON2_PKT_DEC); +} + + +inline void +ENC28J60Class::sendPacket(uint8_t *buffer, size_t len) const { + /* + * Wait until the previous packet has been sent. + */ + // DEBUG_SET_LED0(1); + while ((reg_get(E_CON1) & E_CON1_TX_REQUEST)) { + // DEBUG_SET_LED1(1); + /* + * Reset the transmit logic if it has been stalled + * as per Errata #12. + * + * The current implementation below (with #if 0s) + * is copied from the example implementation, and + * seems to work. The errata seems to indicate + * otherwise. As far as I (Pekka) understand, this + * implementation is bad and may lead to some packets + * being partial or lost. Return to here. + * + * XXX FIXME + */ +# if 0 + if ((reg_get(E_INT_REQ) & E_INT_REQ_TX_ERR)) { +# endif + // DEBUG_SET_LED2(1); + /* Reset the transmit logic */ + reg_bitop(ENC_SPI_SET_BF, E_CON1, E_CON1_TX_RESET); + reg_bitop(ENC_SPI_CLR_BF, E_CON1, E_CON1_TX_RESET); +# if 0 + /* XXX: The example code doesn't do the following + while the data sheet tells to do so. */ + reg_bitop(ENC_SPI_CLR_BF, E_INT_REQ, E_INT_REQ_TX_ERR); +# endif + // DEBUG_SET_LED2(0); +# if 0 + } else { + ; // XXX: Allow other threads to run + } +# endif + // DEBUG_SET_LED1(0); + } + + /* + * Write the packet to the ENC28J60 packet buffer. + * + * NB. The per-packet control byte is there already + * at TX_BUFFER_START. It was written there at + * enc_init(). + */ + reg_set(E_WR_PTR, TX_BUFFER_START + 1); + + *(buffer - 1) = ENC_SPI_WRITE_MEM; + spi_transfer_send(buffer-1, len+1); + + /* + * Set the packet start and end. + */ + reg_set(E_TX_STA, TX_BUFFER_START); + reg_set(E_TX_END, TX_BUFFER_START + 1 + len); + + /* + * Request transmission. + */ + reg_bitop(ENC_SPI_SET_BF, E_CON1, E_CON1_TX_REQUEST); + // DEBUG_SET_LED0(0); +} + +#endif //_ENC28J60_PACKET_H_ diff --git a/stm32/libraries/CoAP/src/enc28j60/enc28j60_reg.h b/stm32/libraries/CoAP/src/enc28j60/enc28j60_reg.h new file mode 100644 index 0000000..3ff7c4c --- /dev/null +++ b/stm32/libraries/CoAP/src/enc28j60/enc28j60_reg.h @@ -0,0 +1,187 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author: Pekka Nikander 2014 + * @author Ivan Raul 2014 + * + * @brief ENC28J60 ethernet interface + */ + +#ifndef _ENC28J60_REG_H_ +# define _ENC28J60_REG_H_ + + +# define SPI_XFER_RX(op, reg, xtra) spi_command((op) | ((reg) & ENC_REG_MASK), 0, (xtra)) +# define SPI_XFER_TX(op, reg, value) spi_command((op) | ((reg) & ENC_REG_MASK), (value), 0) + +inline int +ENC28J60Class::reg_get(enc_reg_t reg) const { + int xfer_3rd_byte = 0; + int value = 0; + + spi_master_activate(ss_pin_); + + switch (reg & ENC_TYPE_MASK) { + case ENC_BANK2_MREG: + case ENC_BANK3_MREG: + xfer_3rd_byte = 1; + /* FALLTHROUGH */ + case ENC_BANK0: + case ENC_BANK1: + case ENC_BANK2: + case ENC_BANK3: + set_bank(reg & ENC_BANK_MASK); + /* FALLTHROUGH */ + case ENC_BANK_GEN: + value = SPI_XFER_RX(ENC_SPI_READ_REG, reg, xfer_3rd_byte); + if (reg & ENC_TYPE_LONG) { + value |= SPI_XFER_RX(ENC_SPI_READ_REG, reg+1, xfer_3rd_byte) << 8; + } + break; + case ENC_BANK_PHY: + value = phy_get(static_cast(reg & ENC_REG_MASK)); + break; + default: + abort(); + } + + spi_master_deactivate(ss_pin_); + + return value; +} + +inline void +ENC28J60Class::reg_set_inner(enc_reg_t reg, int value) const { + switch (reg & ENC_TYPE_MASK) { + case ENC_BANK2_MREG: + case ENC_BANK3_MREG: + case ENC_BANK0: + case ENC_BANK1: + case ENC_BANK2: + case ENC_BANK3: + set_bank(reg & ENC_BANK_MASK); + /* FALLTHROUGH */ + case ENC_BANK_GEN: + SPI_XFER_TX(ENC_SPI_WRITE_REG, reg, value); + if (reg & ENC_TYPE_LONG) + SPI_XFER_TX(ENC_SPI_WRITE_REG, reg+1, value >> 8); + break; + case ENC_BANK_PHY: + phy_set(static_cast(reg & ENC_REG_MASK), value, 0); + break; + default: + abort(); + } +} + +inline void +ENC28J60Class::reg_set(enc_reg_t reg, int value) const { + spi_master_activate(ss_pin_); + reg_set_inner(reg, value); + spi_master_deactivate(ss_pin_); +} + +inline void +ENC28J60Class::reg_bitop(enc_spi_op_t bitop, enc_reg_t reg, int mask) const { + //assert(bitop == ENC_SPI_SET_BF || bitop == ENC_SPI_CLR_BF); + + spi_master_activate(ss_pin_); + + switch (reg & ENC_TYPE_MASK) { + case ENC_BANK0: + case ENC_BANK1: + case ENC_BANK2: + case ENC_BANK3: + set_bank(reg & ENC_BANK_MASK); + /* FALLTHROUGH */ + case ENC_BANK_GEN: + SPI_XFER_TX(bitop, reg, mask); + if (reg & ENC_TYPE_LONG) + SPI_XFER_TX(bitop, reg, mask >> 8); + break; + case ENC_BANK2_MREG: + case ENC_BANK3_MREG: + case ENC_BANK_PHY: + default: + abort(); + } + + spi_master_deactivate(ss_pin_); +} + +/** + * Switches to the right register bank + * if not there already + */ +inline void +ENC28J60Class::set_bank(int bank) const { + static uint8_t curr = ENC_BANK0; /* Current bank */ + + bank &= ENC_BANK_MASK; + + if (curr == bank || bank == ENC_BANK_GEN) + return; + + register int bank_index = (bank & ENC_BANK_MASK) >> ENC_BANK_SHIFT; + register int curr_index = (curr & ENC_BANK_MASK) >> ENC_BANK_SHIFT; + + register const int bits_to_clr = (curr_index & ~bank_index); + if (bits_to_clr != 0) + SPI_XFER_TX(ENC_SPI_CLR_BF, E_CON1, bits_to_clr); + + register const int bits_to_set = (~curr_index & bank_index); + if (bits_to_set != 0) + SPI_XFER_TX(ENC_SPI_SET_BF, E_CON1, bits_to_set); + + curr = bank; +} + +inline int +ENC28J60Class::phy_get(enc_reg_t reg) const { + set_bank(MII_REG_ADR); + /* Write address and start read */ + SPI_XFER_TX(ENC_SPI_WRITE_REG, MII_REG_ADR, reg & ENC_REG_MASK); + SPI_XFER_TX(ENC_SPI_WRITE_REG, MII_CMD, MII_CMD_READ); + set_bank(MII_STAT); + /* Wait until ready */ + while (SPI_XFER_RX(ENC_SPI_READ_REG, MII_STAT, 1) & MII_STAT_BUSY) + ; + set_bank(MII_CMD); + /* Clear the read command; XXX is this needed? */ + SPI_XFER_TX(ENC_SPI_WRITE_REG, MII_CMD, 0); + /* Read the value */ + return (SPI_XFER_RX(ENC_SPI_READ_REG, MII_RD_H, 1) << 8) | + SPI_XFER_RX(ENC_SPI_READ_REG, MII_RD_L, 1); +} + +inline void +ENC28J60Class::phy_set(enc_reg_t reg, int value, bool nowait) const { + set_bank(MII_REG_ADR); + SPI_XFER_TX(ENC_SPI_WRITE_REG, MII_REG_ADR, reg & ENC_REG_MASK); + SPI_XFER_TX(ENC_SPI_WRITE_REG, MII_WR_L, value); + SPI_XFER_TX(ENC_SPI_WRITE_REG, MII_WR_H, value >> 8); + if (nowait) + return; + set_bank(MII_STAT); + while (SPI_XFER_RX(ENC_SPI_READ_REG, MII_STAT, 1) & MII_STAT_BUSY) + ; +} + +#endif //_ENC28J60_REG_H_ diff --git a/stm32/libraries/CoAP/src/enc28j60/ethernet_output.cpp b/stm32/libraries/CoAP/src/enc28j60/ethernet_output.cpp new file mode 100644 index 0000000..6f5b9d3 --- /dev/null +++ b/stm32/libraries/CoAP/src/enc28j60/ethernet_output.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author: Pekka Nikander 2014 + * @author Ivan Raul 2014 + * + * @brief ENC28J60 ethernet interface + */ + +#include +#include + +void eth_output(const void *payload, uint16_t payload_len) { + /* + * XXX + * + * This implementation assumes there is free space before the + * Ethernet Header start to store the command. + */ + ENC28J60.sendPacket((uint8_t *) payload - ETHER_HEADER_LEN, payload_len + ETHER_HEADER_LEN); +} diff --git a/stm32/libraries/CoAP/src/encX24j600/ENCX24J600.h b/stm32/libraries/CoAP/src/encX24j600/ENCX24J600.h new file mode 100644 index 0000000..1aeec79 --- /dev/null +++ b/stm32/libraries/CoAP/src/encX24j600/ENCX24J600.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2014 ELL-i co-operative + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +#include +#if defined(ELLI_STM32F051_ELLDUINO) +# include // XXX To be placed into the variant.h! +#elif defined(ELLI_STM32F407_DISCOVERY) +# include +#elif defined(ELLI_STM32F334_NUCLEO) +# include +#else +# error "Board not supported by the ENCX24J600 library." +#endif diff --git a/stm32/libraries/CoAP/src/encX24j600/ENCX24J600Class.h b/stm32/libraries/CoAP/src/encX24j600/ENCX24J600Class.h new file mode 100644 index 0000000..5860c49 --- /dev/null +++ b/stm32/libraries/CoAP/src/encX24j600/ENCX24J600Class.h @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * ENCX24J600 interface through the Arduino SPI library + * + * @author: Pekka Nikander 2014 + */ + +#ifndef _ENCX24J600_CLASS_H_ +# define _ENCX24J600_CLASS_H_ + +#if 0 +# include +# include +//# include // XXX To be placed into the variant.h! +#else +# include +#endif +# include + +class ENCX24J600Class { +public: + // XXX Currently we have to define this here as _static_ for constant + // propagation to work correctly. Must try again later with better gcc / LLVM. + // ss_pin_ should be const non-static, set from the constructor. + const static pin_t ss_pin_ = ENCX24J600_CS_PIN; // XXX Must allow constant propagration. + const static pin_t int_pin_ = ENCX24J600_INT_PIN; // XXX Must allow constant propagration. + + const static uint32_t spiCR1value = SPI_CR1_DEFAULT_INIT_VALUE; + + constexpr ENCX24J600Class( + const struct SPI &spi_dummy, // XXX FIXME define the SPI device here + pin_t ss_pin_dummy) // XXX FIXME define the SPI slave select pin here + // : ss_pin_(ss_pin), ... XXX FIXME add variable initialisation here + {}; + + void begin() const; + int availablePackets(void) const; + + int receivePacket(uint8_t *buffer, size_t len) const; + void sendPacket (uint8_t *buffer, size_t len) const; + + void readEthernetAddr(uint8_t *buffer) const; + + void enableInterrupt(const enum E_INT_ENA mask) const; + void disableInterrupt(const enum E_INT_ENA mask) const; + void clearInterrupt(const enum E_INT_ENA mask) const; + + void enableGlobalInterrupts(void) const; + void disableGlobalInterrupts(void) const; + + static const struct encX24j600_register_init_static_16bit encX24j600_init[]; + static const size_t encX24j600_init_size; + +private: + + void spi_send_single_byte(enc_spi_op_t op) const + __attribute__((always_inline)); + uint8_t spi_transfer_3bytes(uint8_t cmd, uint8_t address, uint8_t value) const; + uint16_t spi_transfer_4bytes(uint8_t cmd, uint8_t address, uint16_t value) const; + void spi_transfer_send(uint8_t *buffer, uint16_t len) const + __attribute__((always_inline)); + void spi_transfer (uint8_t *buffer, uint16_t len) const /// XXX rename + __attribute__((always_inline)); + + int phy_get(uint8_t reg) const; + void phy_set(uint8_t reg, int value, bool nowait) const; + + int reg_get(enc_reg_t reg) const __attribute__((always_inline)); + void reg_set(enc_reg_t reg, int value) const __attribute__((always_inline)); + void reg_clr_bits(enc_reg_t reg, int mask) const __attribute__((always_inline)); + void reg_set_bits(enc_reg_t reg, int mask) const __attribute__((always_inline)); + +}; + +inline void +ENCX24J600Class::spi_send_single_byte(enc_spi_op_t cmd) const { + uint8_t buffer[1]; + buffer[0] = cmd; + spi_transfer(buffer, 1); +} + +inline uint8_t +ENCX24J600Class::spi_transfer_3bytes(uint8_t cmd, uint8_t address, uint8_t value) const { + uint8_t buffer[3]; + + buffer[0] = cmd; + buffer[1] = address; + buffer[2] = value; + + spi_transfer(buffer, 3); + + return buffer[2]; +} + +inline uint16_t +ENCX24J600Class::spi_transfer_4bytes(uint8_t cmd, uint8_t address, uint16_t value) const { + uint8_t buffer[4]; + + buffer[0] = cmd; + buffer[1] = address; + buffer[2] = value; // NB. C/C++ truncates by default + buffer[3] = value >> 8; + + spi_transfer(buffer, 4); + + return buffer[2] | (buffer[3] << 8); +} + +inline void +ENCX24J600Class::spi_transfer_send(uint8_t *buffer, uint16_t len) const { + spi_master_activate(ss_pin_); + ::spi_transfer_raw(&ENCX24J600_SPI, spiCR1value, buffer, len, 0); + spi_master_deactivate(ss_pin_); +} + +inline void +ENCX24J600Class::spi_transfer(uint8_t *buffer, uint16_t len) const { + spi_master_activate(ss_pin_); + ::spi_transfer_raw(&ENCX24J600_SPI, spiCR1value, buffer, len, 1); + spi_master_deactivate(ss_pin_); +} + +# include +# include +# include +# include + +#endif//_ENCX24J600_CLASS_H_ diff --git a/stm32/libraries/CoAP/src/encX24j600/encX24j600_begin.h b/stm32/libraries/CoAP/src/encX24j600/encX24j600_begin.h new file mode 100644 index 0000000..81acfb9 --- /dev/null +++ b/stm32/libraries/CoAP/src/encX24j600/encX24j600_begin.h @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * ENC28J60 interface through the Arduino SPI library + * + * @author: Pekka Nikander 2014 + */ + +#ifndef _ENCX24J600_INIT_H_ +# define _ENCX24J600_INIT_H_ + +#if 1 +#include +#endif + +inline void +ENCX24J600Class::begin() const { + + spi_master_begin(&ENCX24J600_SPI, ss_pin_); + + /* Set the interrupt line pin to input mode */ + pinMode(int_pin_, INPUT); + + /* Reset routine, see Section 8.1 of the Data shsset (39935c.pdf) */ + +#if 1 +# define DEBUG_PIN 3 + pinMode(DEBUG_PIN, OUTPUT); + digitalWrite(DEBUG_PIN, 1); +#endif + /* + * Steps 1-2: Write 1234h to EUDAST. Read EUDAST to see if it now + * equals 1234h. If it does not, the SPI/PSP interface may not be + * ready yet, so return to step 1 and try again. + */ + do { + reg_set(E_UDA_START, 0x1234); +#if 1 + static int c = 0; + + if (c++ > 10000) { + if (digitalRead(DEBUG_PIN)) { + digitalWrite(DEBUG_PIN, 0); + } else { + digitalWrite(DEBUG_PIN, 1); + } + c = 0; + } +#endif + } while (reg_get(E_UDA_START) != 0x1234); + + digitalWrite(DEBUG_PIN, 0); + + /* Step 3. Poll CLKRDY (ESTAT<12>) and wait for it to become set. */ + while ((reg_get(E_STAT) & CLOCK_READY) == 0) + ; + + /* Step 4. Issue a System Reset command by setting ETHRST (ECON2<4>). */ + spi_send_single_byte(ENC_SPI_RESET); + + /* + * Step 5. In software, wait at least 25us for the Reset to take + * place and the SPI/PSP interface to begin operating again. + */ + // XXX Replace with something better + for (volatile int i = 0; i < 25 * 48; i++) + ; + + /* + * Step 6. Read EUDAST to confirm that the System Reset took + * place. EUDAST should have reverted back to its Reset default of + * 0000h. + */ + if (reg_get(E_UDA_START) != 0x0000) + /* XXX fail? */; + + + /* + * Initialize all non-phy registers to their desired values + */ + + for ( const device_register_init_static_8bit_t *p = encX24j600_init; + p < encX24j600_init + encX24j600_init_size; + p++) { + reg_set(p->reg, p->value); + } + + /* + * Wait until the PHY is no longer in reset. We do this instead of + * Step 7. Wait at least 256us for the PHY registers and PHY + * status bits to become available. + */ + + while (reg_get(PHY_CON1) & PHY_CON1_PRST) + ; + + /* + * Initialise the PHY + */ + // XXX no-op at the moment + + /* + * Disable all interrupts + */ + reg_set(E_INT_ENA,0); + + digitalWrite(DEBUG_PIN, 1); +} + +inline void +ENCX24J600Class::readEthernetAddr(uint8_t *buffer) const { + + uint16_t *addr = (uint16_t *) buffer; + addr[0] = reg_get(MAC_ADDR1); + addr[1] = reg_get(MAC_ADDR2); + addr[2] = reg_get(MAC_ADDR3); + +} +#endif // _ENCX24J600_INIT_H_ diff --git a/stm32/libraries/CoAP/src/encX24j600/encX24j600_conf.h b/stm32/libraries/CoAP/src/encX24j600/encX24j600_conf.h new file mode 100644 index 0000000..971a7b0 --- /dev/null +++ b/stm32/libraries/CoAP/src/encX24j600/encX24j600_conf.h @@ -0,0 +1,338 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * ENCx24J600 driver + * + * @author: Pekka Nikander 2014 + */ + +#ifndef _ENCX24J600_CONF_H +# define _ENCX24J600_CONF_H + +# include +# include + +/* + * ENCX24J600 RX/TX buffer assignment + * + * ENCx24J600 can use a TX buffer from anywhere; the RX buffer is + * at the end of memory, by default at 0x5340, see Section 3.5.2. + * + * Use larger than standard Ethernet packet worths for the RX/TX buffer, 0x600 = 1536 bytes + */ + +# define MAX_PACKET_SIZE 1536 + +# define ENC_BUFFER_START 0x0000 +# define ENC_BUFFER_SIZE 0x6000 +# define ENC_BUFFER_END 0x5FFF + +# define RX_BUFFER_START (0x5340) /* Default value */ +# define RX_BUFFER_END (ENC_BUFFER_END) +# define TX_BUFFER_LEN (0x2000) +# define TX_BUFFER_END (RX_BUFFER_START) +# define TX_BUFFER_START (TX_BUFFER_END - TX_BUFFER_LEN) + +/* Offset added to physical register addresses to fold them into the same address space */ +# define ENC_PHY_OFFSET 0xA0 /* See Table 3-1 on page 20. 0x9F is the last SPI SFR */ + +# define ENC_SFR_REG(number) ((number)) +# define ENC_PHY_REG(number) ((number) + ENC_PHY_OFFSET) +# define ENC_IS_PHY_REG(number) ((number) >= ENC_PHY_OFFSET) + +enum enc_reg_t { + E_TX_START = ENC_SFR_REG(0x00), + E_TX_LEN = ENC_SFR_REG(0x02), + E_RX_START = ENC_SFR_REG(0x04), + E_RX_TAIL = ENC_SFR_REG(0x06), + E_RX_HEAD = ENC_SFR_REG(0x08), + E_DMA_START = ENC_SFR_REG(0x0A), + E_DMA_LEN = ENC_SFR_REG(0x0C), + E_DMA_DST = ENC_SFR_REG(0x0E), + E_DMA_CS = ENC_SFR_REG(0x10), + E_TX_STAT = ENC_SFR_REG(0x12), + E_TX_WIRE = ENC_SFR_REG(0x14), + E_UDA_START = ENC_SFR_REG(0x16), + E_UDA_END = ENC_SFR_REG(0x18), + E_STAT = ENC_SFR_REG(0x1A), + E_IR = ENC_SFR_REG(0x1C), + E_CON1 = ENC_SFR_REG(0x1E), + + E_HT1 = ENC_SFR_REG(0x20), + E_HT2 = ENC_SFR_REG(0x22), + E_HT3 = ENC_SFR_REG(0x24), + E_HT4 = ENC_SFR_REG(0x26), + E_PM_M1 = ENC_SFR_REG(0x28), + E_PM_M2 = ENC_SFR_REG(0x2A), + E_PM_M3 = ENC_SFR_REG(0x2C), + E_PM_M4 = ENC_SFR_REG(0x2E), + E_PM_CKSUM = ENC_SFR_REG(0x30), + E_PM_OFF = ENC_SFR_REG(0x32), + E_RX_FCOND = ENC_SFR_REG(0x34), + + MAC_CON1 = ENC_SFR_REG(0x40), + MAC_CON2 = ENC_SFR_REG(0x42), + MAC_BBIPG = ENC_SFR_REG(0x44), + MAC_IPG = ENC_SFR_REG(0x46), + MAC_CL_CON = ENC_SFR_REG(0x48), + MAC_MAX_FL = ENC_SFR_REG(0x4A), + + MII_CMD = ENC_SFR_REG(0x52), + MII_REG_ADR = ENC_SFR_REG(0x54), + + MAC_ADDR3 = ENC_SFR_REG(0x60), + MAC_ADDR2 = ENC_SFR_REG(0x62), + MAC_ADDR1 = ENC_SFR_REG(0x64), + MII_WR = ENC_SFR_REG(0x66), + MII_RD = ENC_SFR_REG(0x68), + MII_STAT = ENC_SFR_REG(0x6A), +# define MII_STAT_NVALID 0x04 +# define MII_STAT_SCAN 0x02 +# define MII_STAT_BUSY 0x01 + E_PAUSE = ENC_SFR_REG(0x6C), + E_CON2 = ENC_SFR_REG(0x6E), + E_RX_WM = ENC_SFR_REG(0x70), + E_INT_ENA = ENC_SFR_REG(0x72), + E_ID_LED = ENC_SFR_REG(0x74), + + E_GP_DATA = ENC_SFR_REG(0x80), /* 8-bit register, ok to access as 16 bits */ + E_RX_DATA = ENC_SFR_REG(0x82), /* 8-bit register, ok to access as 16 bits */ + E_UDA_DATA = ENC_SFR_REG(0x84), /* 8-bit register, ok to access as 16 bits */ + E_GP_RD_PT = ENC_SFR_REG(0x86), + E_GP_WR_PT = ENC_SFR_REG(0x88), + E_RX_RD_PT = ENC_SFR_REG(0x8A), + E_RX_WR_PT = ENC_SFR_REG(0x8C), + E_UDA_RD_PT = ENC_SFR_REG(0x8E), + E_UDA_WR_PT = ENC_SFR_REG(0x90), + + PHY_CON1 = ENC_PHY_REG(0x00), +# define PHY_CON1_PRST 0x8000 +# define PHY_CON1_PLOOPBK 0x4000 +# define PHY_CON1_PPWRSV 0x0800 +# define PHY_CON1_PDPXMD 0x0100 + PHY_STAT1 = ENC_PHY_REG(0x01), +# define PHY_STAT1_PFDPX 0x1000 +# define PHY_STAT1_PHDPX 0x0800 +# define PHY_STAT1_LLSTAT 0x0004 +# define PHY_STAT1_JBSTAT 0x0002 + PHY_AN_A = ENC_PHY_REG(0x04), + PHY_AN_LPA = ENC_PHY_REG(0x05), + PHY_AN_E = ENC_PHY_REG(0x06), + PHY_CON2 = ENC_PHY_REG(0x11), +# define PHY_CON2_FRCLINK 0x4000 +# define PHY_CON2_TXDIS 0x2000 +# define PHY_CON2_JABBER 0x0400 +# define PHY_CON2_HDLDIS 0x0100 + PHY_STAT2 = ENC_PHY_REG(0x1B), + PHY_STAT3 = ENC_PHY_REG(0x1F), +}; + +enum enc_spi_op_t { + ENC_SPI_READ_REG = 0x00, /* 0x00 - 0x1F */ + ENC_SPI_READ_REG_UB = 0x20, + ENC_SPI_WRITE_REG_UB = 0x22, + ENC_SPI_SET_BF_UB = 0x24, + ENC_SPI_CLR_BF_UB = 0x26, + ENC_SPI_READ_MEM = 0x28, /* Through GP */ + ENC_SPI_WRITE_MEM = 0x2A, /* Through GP */ + ENC_SPI_READ_RX = 0x2C, + ENC_SPI_WRITE_RX = 0x2E, + ENC_SPI_READ_UDA = 0x30, + ENC_SPI_WRITE_UDA = 0x32, + ENC_SPI_WRITE_REG = 0x40, /* 0x40 - 0x5F */ + ENC_SPI_WRITE_GP_RDP = 0x60, + ENC_SPI_READ_GP_RDP = 0x62, + ENC_SPI_WRITE_RX_RDP = 0x64, + ENC_SPI_READ_RX_RDP = 0x66, + ENC_SPI_WRITE_UDA_RPT = 0x68, + ENC_SPI_READ_UDA_RPT = 0x6A, + ENC_SPI_WRITE_GP_WRP = 0x6C, + ENC_SPI_READ_GP_WRP = 0x6E, + ENC_SPI_WRITE_RX_WRP = 0x70, + ENC_SPI_READ_RX_WRP = 0x72, + ENC_SPI_WRITE_UDA_WRP = 0x74, + ENC_SPI_READ_UPDA_WRP = 0x76, + ENC_SPI_SET_BF = 0x80, /* 0x80-0x9F */ + ENC_SPI_CLR_BF = 0xA0, /* 0xA0-0xBF */ + ENC_SPI_BANK0_SELECT = 0xC0, + ENC_SPI_BANK1_SELECT = 0xC2, + ENC_SPI_BANK2_SELECT = 0xC4, + ENC_SPI_BANK3_SELECT = 0xC6, + ENC_SPI_BANK_READ = 0xC8, + ENC_SPI_RESET = 0xCA, + ENC_SPI_SET_PKT_DEC = 0xCC, + + ENC_SPI_DMA_STOP = 0xD2, + ENC_SPI_TX_REQUEST = 0xD4, + ENC_SPI_DMA_CKSUM = 0xD8, + ENC_SPI_DMA_CKSUM_S = 0xDA, + ENC_SPI_DMA_COPY = 0xDC, + ENC_SPI_DMA_COPY_S = 0xDE, + ENC_SPI_FC_DISABLE = 0xE0, + ENC_SPI_FC_SINGLE = 0xE2, + ENC_SPI_FC_MULTIPLE = 0xE4, + ENC_SPI_FC_CLEAR = 0xE6, + ENC_SPI_ENABLE_RX = 0xE8, + ENC_SPI_DISABLE_RX = 0xEA, + ENC_SPI_SET_EIE = 0xEC, + ENC_SPI_CLR_EIE = 0xEE, + +// XXX CHECK ABOVE +}; + +enum E_CON1 { + MODEXST = 0x8000, + HASHEN = 0x4000, + HASHOP = 0x2000, + HASHLST = 0x1000, + AESST = 0x0800, + AES_DECRYPT = 0x0400, + AES_ENCRYPT = 0x0200, + AES_INIT = 0x0000, + PKT_DEC = 0x0100, + FC_END = 0x00C0, + FC_ENABLE = 0x0080, + FC_PAUSE = 0x0040, + FC_IDLE = 0x0000, + DMA_START = 0x0020, + DMAST = 0x0020, + DMACPY = 0x0010, + DMACSSD = 0x0008, + DMANOCS = 0x0004, + TX_REQUEST = 0x0002, + RX_ENABLE = 0x0001, + RXEN = 0x0001, +}; + +enum E_CON2 { + ETHEN = 0x8000, + STRCH = 0x4000, + TXMAC = 0x2000, + SHA1MD5 = 0x1000, + COCON_50 = 0x0F00, + COCON_100 = 0x0E00, + COCON_NONE1 = 0x0D00, + COCON_3125 = 0x0C00, + COCON_4000 = 0x0B00, + COCON_5000 = 0x0A00, + COCON_6250 = 0x0900, + COCON_8000 = 0x0800, + COCON_8333 = 0x0700, + COCON_10000 = 0x0600, + COCON_12500 = 0x0500, + COCON_16666 = 0x0400, + COCON_20000 = 0x0300, + COCON_25000 = 0x0200, + COCON_33333 = 0x0100, + COCON_NONE0 = 0x0000, + AUTOFC = 0x0080, + TX_RESET = 0x0040, + RX_RESET = 0x0020, + ETH_RESET = 0x0010, + MODLEN_1024 = 0x0008, + MODLEN_768 = 0x0004, + MODLEN_512 = 0x0000, + AESLEN_256 = 0x0002, + AESLEN_192 = 0x0001, + AESLEN_128 = 0x0000, +}; + +/* ESTAT: Ethernet status register. Page 93. */ +enum E_STAT { + INT_PEND = 0x8000, + FC_STAT_IDLE = 0x4000, + RX_BUSY = 0x2000, + CLOCK_READY = 0x1000, + PHY_DUPLEX = 0x0400, + PHY_LINK = 0x0100, + PKT_CNT_MASK = 0x00ff, +}; + +enum E_RX_FILTER_CON { + HT_EN = 0x8000, + MP_EN = 0x4000, + NOT_PM = 0x1000, + PM_MAGIC = 0x0900, + PM_HASHTABLE = 0x0800, + PM_NOT_BCAST = 0x0700, + PM_IS_BCAST = 0x0600, + PM_NOT_MCAST = 0x0500, + PM_IS_MCAST = 0x0400, + PM_NOT_UCAST = 0x0300, + PM_IS_UCAST = 0x0200, + PM_ALL = 0x0100, + PM_DISABLE = 0x0000, + CRC_E_EN = 0x0080, + CRC_EN = 0x0040, + RUNT_E_EN = 0x0020, + RUNT_EN = 0x0010, + UC_EN = 0x0008, + NOT_ME_EN = 0x0004, + MC_EN = 0x0002, + BC_EN = 0x0001, +}; + +enum E_INT_ENA { + INT_ENABLE = 0x8000, + MODEX_IE = 0x4000, + HASH_IE = 0x2000, + AES_IE = 0x1000, + LINK_IE = 0x0800, + PKT_IE = 0x0040, + DMA_IE = 0x0020, + TX_IE = 0x0008, + TX_ABT_IE = 0x0004, + RX_ABT_IE = 0x0002, + PC_FULL = 0x0001, +}; + +typedef uint16_t enc_reg_value_t; +typedef uint8_t enc_buf_value_t; +typedef size_t enc_buf_len_t; +typedef uint16_t enc_phy_value_t; + +enum enc_rx_packet_status_t { + ENC_RX_STATUS_LONG_DROP = 0x0001, + ENC_RX_STATUS_CARRIER_SEEN = 0x0004, + ENC_RX_STATUS_CEC_ERROR = 0x0010, + ENC_RX_STATUS_LENGTH_ERROR = 0x0020, + ENC_RX_STATUS_LONG_TYPE = 0x0040, + ENC_RX_STATUS_RECEIVE_OK = 0x0080, + ENC_RX_STATUS_MULTICAST = 0x0100, + ENC_RX_STATUS_BROADCAST = 0x0200, + ENC_RX_STATUS_DRIBBLE = 0x0400, + ENC_RX_STATUS_CONTROL_FRAME = 0x0800, + ENC_RX_STATUS_PAUSE_FRAME = 0x1000, + ENC_RX_STATUS_UNKNOWN_OPCODE = 0x2000, + ENC_RX_STATUS_VLAN_FRAME = 0x4000, +}; + +/** + * ENCX24J600 internal RX packet header. + * + * Transferred over SPI, see Data Sheet page 33-34 + */ + +typedef struct encX24j600_register_init_static_16bit { + enc_reg_t reg; + enc_reg_value_t value; +} device_register_init_static_8bit_t; + +#endif //_ENCX24J600_CONF_H diff --git a/stm32/libraries/CoAP/src/encX24j600/encX24j600_init.cpp b/stm32/libraries/CoAP/src/encX24j600/encX24j600_init.cpp new file mode 100644 index 0000000..7855741 --- /dev/null +++ b/stm32/libraries/CoAP/src/encX24j600/encX24j600_init.cpp @@ -0,0 +1,197 @@ +/* + * Copyright (c) 2014 ELL-i co-operative + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author Pekka Nikander 2014 + * @author Ivan Raul 2014 + * + * @brief ENC28J60 ethernet interface + */ + +#if 0 +/* We do want the lower level C API functions inline + here, even when compiling for the emulator. */ +# define ARDUINO_INLINE_API static inline +#endif + +#include +#include + +#define D16(r, v) { .reg = (r), .value = (v) } + +const struct encX24j600_register_init_static_16bit ENCX24J600Class::encX24j600_init[] = { + + /********************************** + * Sestions 8.4 and 8.5: RX and TX buffers + **********************************/ + + /* TX buffer -- not really needed, but we us for backwards compatibility */ + D16(E_TX_START, TX_BUFFER_START), + D16(E_TX_LEN, TX_BUFFER_LEN), + /* RX buffer */ + D16(E_RX_START, RX_BUFFER_START), + D16(E_RX_TAIL, RX_BUFFER_END & ~0x01), // Clear low-order bit for an even address + D16(E_RX_HEAD, RX_BUFFER_START), + D16(E_RX_RD_PT, RX_BUFFER_START), + + /********************************** + * Section 8.5: Packet filtering + **********************************/ + + /* + * Hash-table not used + */ + + /* + * Filtering configuration. + */ + D16(E_RX_FCOND, + 0 + | ! HT_EN /* 0: Hash-table filter disabled */ + | ! MP_EN /* 0: Magic packet filter disabled */ + | ! NOT_PM /* 0: Patterh match checksum match required for a match */ + | PM_DISABLE /* 0: Pattern matching filter disabled */ + | ! CRC_E_EN /* 0: Filter disabled */ + | CRC_EN /* 1: Packets with an invalid CRC will be discarded */ + | ! RUNT_E_EN /* 0: Filter disabled */ + | ! RUNT_EN /* 0: Discard packets that are 64 bytes or smaller */ + | UC_EN /* 1: Unicast with my MAC received */ + | ! NOT_ME_EN /* 0: Unicast without my MAC discarded */ + | ! MC_EN /* 0: Multicast disabled */ + | BC_EN /* 1: Broadcast enabled */ + ), + + /********************************** + * Section 8.6 MAC + **********************************/ + D16(MAC_CON1, + 0 + | ! LOOP_BACK /* 0: No loopback */ + | TX_PAUSE /* 1: Allow sending pause control frames */ + | RX_PAUSE /* 1: Adhere received pause control frames */ + | ! PASS_ALL /* 0: Don't pass control frames to host */ + | RX_EN /* 1: Enable the MAC */ + ), + D16(MAC_CON2, + 0 + | ! DEFER /* 0: Abort after excessive wait */ + | ! BP_EN /* 0: Use binary backoff algorithm */ + | ! NO_BKOFF /* 0: Use binary backoff algorithm */ +// res | ! LONG_PRE /* 0: Long preambles allowed */ +// res | ! PURE_PRE /* 0: Don't check preable contents */ + | PAD_VLAN /* 101: Pad according to VLAN settings and add CRC */ + | TX_CRC_EN /* 1: Enable CRC for Transmit */ + | ! P_HDR_EN /* 0: No proprietary header */ + | ! HUGE_FRM_EN /* 0: No huge frames */ + | FR_LEN_CHK /* 1: Check frame lengths */ + | ! FULL_DUPLEX /* 0: No full duplex (yet) XXX */ + ), +#if 0 + D16(MAC_MAX_FL, 0x05ee), // reset value +#endif + + +#ifdef old + XXX + D8(MAC_BBIP_GAP, 0x12), /* Recommended back-to-back gap for half duplex XXX */ + D16(MAC_IP_GAP, 0x0C12), /* As recommended in the data sheet */ + // Collision control default values as per data sheet + // MAC-PHY Support not changed as per data sheet + + // MII Control register not changed as per data sheet + // MII Command, status, MII reg address and data registers + // used for MII communication, not initialised. +#endif + + /********************************** + * MAC address and misc + **********************************/ + +#if 0 + MISTAT + EREVID + ECOCON + EFLOCON + EPAUS +#endif + +#ifdef notyet + /* XXX */ + D16(E_TX_STAT, XXX), + D16(E_TX_WIRE, XXX), + /* XXX */ + D16(E_UDA_START, 0x0000), // Reset value + D16(E_UDA_END, XXX), + /* XXX */ + D16(E_STAT, XXX), + D16(E_IR, XXX), + D16(E_CON1, XXX), +#endif + + /********************************** + * Control registers + **********************************/ + D16(E_CON2, + 0 + | ETHEN /* 1: Enable Ethernet */ + | STRCH /* 1: Stretch events on LEDs to 50 ms */ + | ! TXMAC /* 0: Do not insert source MAC address to outgoing packets */ + | ! SHA1MD5 /* 1: Use SHA1 in the hashing engine */ + | COCON_4000 /* 1011: 4 MHz */ + /* + * NOTE! Automatic flow control will not work, at least not with + * some more configuration somewhere else. + * + * Pekka tried to enable AUTOFC bit back in September 2014, + * and ended up hunting for the resulting bug for several + * days. The symptom is that the activity LED flashes quickly + * and the packet count in E_STAT does not get updated. + */ + | ! AUTOFC /* 0: Enable automatic flow control */ + | ! TX_RESET /* 0: Normal operation */ + | ! RX_RESET /* 0: Normal operation */ + | ! ETH_RESET /* 0: Normal operation */ + | MODLEN_512 /* 00: 512-bit exponential modulus and operands */ + | AESLEN_128 /* 10: 128-bit AES */ + ), + + + D16(E_INT_ENA, + 0 + | INT_ENABLE /* 1: Enable INT pin */ + | PKT_IE /* 1: Interrupt on pending packets */ + | ! DMA_IE /* 0: Disable DMA interrupt */ + | LINK_IE /* 1: Interrupt on link status change */ + | TX_IE /* 1: Interrupt on transmit ready */ +// XXX | E_INT_ENA_WOL /* 1: Enable WOL pin */ + | ! TX_ABT_IE /* 0: Disable transmit error interrupts */ + | ! RX_ABT_IE /* 0: Disable receive error interrupts */ + ), + + D16(E_CON1, + 0 + | ! DMA_START /* 0: Don't use DMA now */ + | ! TX_REQUEST /* 0: Don't transmit yet */ + | RX_ENABLE /* 1: Enable Receiving */ + ), +}; + +const size_t ENCX24J600Class::encX24j600_init_size = COUNT_OF(ENCX24J600Class::encX24j600_init); + +// enc_rx_packet_header_t ENCX24J600Class::rx_header; diff --git a/stm32/libraries/CoAP/src/encX24j600/encX24j600_int.h b/stm32/libraries/CoAP/src/encX24j600/encX24j600_int.h new file mode 100644 index 0000000..85176a6 --- /dev/null +++ b/stm32/libraries/CoAP/src/encX24j600/encX24j600_int.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author: Pekka Nikander 2014 + * @author Ivan Raul 2014 + * + * @brief ENCX24J600 ethernet interface + */ + +#ifndef _ENCX24J600_INT_H_ +# define _ENCX24J600_INT_H_ + +# include + +inline void +ENCX24J600Class::enableInterrupt(const enum E_INT_ENA mask) const { + reg_set_bits(E_INT_ENA, mask); +} + +inline void +ENCX24J600Class::disableInterrupt(const enum E_INT_ENA mask) const { + reg_clr_bits(E_INT_ENA, mask); +} + +inline void +ENCX24J600Class::clearInterrupt(const enum E_INT_ENA mask) const { + reg_clr_bits(E_IR, mask); +} + +inline void +ENCX24J600Class::enableGlobalInterrupts(void) const { + spi_send_single_byte(ENC_SPI_SET_EIE); +} + +inline void +ENCX24J600Class::disableGlobalInterrupts(void) const { + spi_send_single_byte(ENC_SPI_CLR_EIE); +} + +#endif //_ENCX24J600_INT_H_ diff --git a/stm32/libraries/CoAP/src/encX24j600/encX24j600_mac.h b/stm32/libraries/CoAP/src/encX24j600/encX24j600_mac.h new file mode 100644 index 0000000..8d4b900 --- /dev/null +++ b/stm32/libraries/CoAP/src/encX24j600/encX24j600_mac.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * ENCx24J600 driver + * + * @author: Pekka Nikander 2014 + */ + +#ifndef _ENCX24J600_MAC_H +# define _ENCX24J600_MAC_H + +enum MAC_CON1 { + LOOPBK = 0x10, + LOOP_BACK = 0x10, + TX_PAUSE = 0x08, // Marked as reserved, write as '1' in the data sheet + RXPAU = 0x04, + RX_PAUSE = 0x04, + PASSALL = 0x02, + PASS_ALL = 0x02, + RX_EN = 0x01, // Marked as reserved, write as '1' in the data sheet +}; + +enum MAC_CON2 { + DEFER = 0x4000, + BPEN = 0x2000, + BP_EN = 0x2000, + NOBKOFF = 0x1000, + NO_BKOFF = 0x1000, +// LONG_PRE 0x0200 reserved +// PURE_PRE 0x0100 reserved + + PAD_64 = 0x00E0, + PAD_VLAN = 0x00A0, + // 0x0060 is redunant + PAD_60 = 0x0020, + PAD_NONE = 0x0000, + PADCFG_EN = 0x0020, + + TXCRCEN = 0x0010, + TX_CRC_EN = 0x0010, + PHDREN = 0x0008, + P_HDR_EN = 0x0008, + HFRMEN = 0x0004, + HUGE_FRM_EN = 0x0004, + FR_LEN_CHK = 0x0002, // Reserved, must be written as '1' + FULDPX = 0x0001, + FULL_DUPLEX = 0x0001, +}; + +// XXX TBD +# define MII_CMD_SCAN 0x02 +# define MII_CMD_READ 0x01 + +#endif //_ENCX24J600_MAC_H diff --git a/stm32/libraries/CoAP/src/encX24j600/encX24j600_packet.h b/stm32/libraries/CoAP/src/encX24j600/encX24j600_packet.h new file mode 100644 index 0000000..960d6cb --- /dev/null +++ b/stm32/libraries/CoAP/src/encX24j600/encX24j600_packet.h @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author: Pekka Nikander 2014 + * @author Ivan Raul 2014 + * + * @brief ENCX24J600 ethernet interface + */ + +#ifndef _ENCX24J600_PACKET_H_ +# define _ENCX24J600_PACKET_H_ + +# include +# include + +typedef struct { + uint8_t rx_padding0; + uint8_t rx_cmd; + // Start of the actual RX header + uint16_t rx_next; + uint16_t rx_length; + uint8_t rx_flags[4]; +} enc_rx_packet_header_t; + +inline int +ENCX24J600Class::availablePackets(void) const { + register int value; + + spi_master_activate(ss_pin_); + // Read just the low order 8 bits of E_STAT, the packet count + value = spi_transfer_3bytes(ENC_SPI_READ_REG_UB, E_STAT, 0); + spi_master_deactivate(ss_pin_); + + return value; +} + +inline int +ENCX24J600Class::receivePacket(uint8_t *buffer, size_t maxlen) const { + enc_rx_packet_header_t rx_header; + + rx_header.rx_cmd = ENC_SPI_READ_RX; + spi_transfer((unsigned char *)&rx_header.rx_cmd, + sizeof(enc_rx_packet_header_t) - sizeof(rx_header.rx_padding0)); + + register unsigned int plen = rx_header.rx_length; + register unsigned int next = rx_header.rx_next; + + if (plen > maxlen) + plen = maxlen; + + /* Assumed buffer has extra space at the + * beginning for the command + */ + *(buffer - 1) = ENC_SPI_READ_RX; + spi_transfer(buffer-1, plen+1); + + /* + * Go to the beginning of the next packet. + */ + reg_set(E_RX_RD_PT, next); + + /* + * Set the tail pointer to (next - 2), + * as suggested by the datasheet. + * If E_RX_TAIL points to the same + * address as E_RX_HEAD, the receive + * buffer is considered full, and + * incoming packets are discarded. + * Wrap around if necessary: first + * increase to prevent negative values. + * Example for next = RX_BUFFER_START: + * + * {START-2}{START-1}[ START ][START+1] + * [ END-1 ][ END ]{ END+1 }{ END+2 } + * -2 -1 0 1 + * (next-2) ( next ) + * + * As (START) and the imaginary (END+1) + * are in the same position, they are + * chosen to enable the value conversion + * for the wrap around. + */ + next -= 2; + if (next < RX_BUFFER_START) { + next += RX_BUFFER_END + 1; + next -= RX_BUFFER_START; + } + reg_set(E_RX_TAIL, next); + + /* Decrement the packet count */ + spi_master_activate(ss_pin_); + spi_send_single_byte(ENC_SPI_SET_PKT_DEC); + spi_master_deactivate(ss_pin_); + + return plen; + +} + +inline void +ENCX24J600Class::sendPacket(uint8_t *buffer, size_t len) const { + /* + * Wait until the previous packet has been sent. + */ + // DEBUG_SET_LED0(1); + while ((reg_get(E_CON1) & TX_REQUEST)) + ; + + /* + * Write the packet to the ENCX24J600 packet buffer. + */ + reg_set(E_GP_WR_PT, TX_BUFFER_START); + + *(buffer - 1) = ENC_SPI_WRITE_MEM; + spi_transfer_send(buffer-1, len+1); + + /* + * Set the packet start and end. + */ + reg_set(E_TX_START, TX_BUFFER_START); + reg_set(E_TX_LEN, len); + + /* + * Request transmission. + */ + spi_send_single_byte(ENC_SPI_TX_REQUEST); + // DEBUG_SET_LED0(0); +} + +#endif //_ENCX24J600_PACKET_H_ diff --git a/stm32/libraries/CoAP/src/encX24j600/encX24j600_reg.h b/stm32/libraries/CoAP/src/encX24j600/encX24j600_reg.h new file mode 100644 index 0000000..bd315e5 --- /dev/null +++ b/stm32/libraries/CoAP/src/encX24j600/encX24j600_reg.h @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author: Pekka Nikander 2014 + * @author Ivan Raul 2014 + * + * @brief ENCX24J600 ethernet interface + */ + +#ifndef _ENCX24J600_REG_H_ +# define _ENCX24J600_REG_H_ + + +inline int +ENCX24J600Class::reg_get(enc_reg_t reg) const { + register int value; + + spi_master_activate(ss_pin_); + + if (!ENC_IS_PHY_REG(reg)) { + value = spi_transfer_4bytes(ENC_SPI_READ_REG_UB, reg, 0/*dummy*/); + } else { + value = phy_get(static_cast(reg - ENC_PHY_OFFSET)); + } + + spi_master_deactivate(ss_pin_); + + return value; +} + +inline void +ENCX24J600Class::reg_set(enc_reg_t reg, int value) const { + spi_master_activate(ss_pin_); + + if (!ENC_IS_PHY_REG(reg)) { + spi_transfer_4bytes(ENC_SPI_WRITE_REG_UB, reg, value); + } else { + phy_set(static_cast(reg - ENC_PHY_OFFSET), value, 0); + } + + spi_master_deactivate(ss_pin_); +} + +inline void +ENCX24J600Class::reg_clr_bits(enc_reg_t reg, int mask) const { + spi_master_activate(ss_pin_); + spi_transfer_4bytes(ENC_SPI_CLR_BF_UB, reg, mask); + spi_master_deactivate(ss_pin_); +} + +inline void +ENCX24J600Class::reg_set_bits(enc_reg_t reg, int mask) const { + spi_master_activate(ss_pin_); + spi_transfer_4bytes(ENC_SPI_SET_BF_UB, reg, mask); + spi_master_deactivate(ss_pin_); +} + +inline int +ENCX24J600Class::phy_get(uint8_t reg) const { + // XXX TODO + return 0; +} + +inline void +ENCX24J600Class::phy_set(uint8_t reg, int value, bool nowait) const { + // XXX TODO +#if 0 + OLD CODE + SPI_XFER_TX(ENC_SPI_WRITE_REG, MII_REG_ADR, reg); + SPI_XFER_TX(ENC_SPI_WRITE_REG, MII_WR_L, value); + SPI_XFER_TX(ENC_SPI_WRITE_REG, MII_WR_H, value >> 8); + if (nowait) + return; + set_bank(MII_STAT); + while (SPI_XFER_RX(ENC_SPI_READ_REG, MII_STAT, 1) & MII_STAT_BUSY) + ; +#endif +} + +#endif //_ENCX24J600_REG_H_ diff --git a/stm32/libraries/CoAP/src/encX24j600/ethernet_output.cpp b/stm32/libraries/CoAP/src/encX24j600/ethernet_output.cpp new file mode 100644 index 0000000..d70f09c --- /dev/null +++ b/stm32/libraries/CoAP/src/encX24j600/ethernet_output.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * @author: Pekka Nikander 2014 + * @author Ivan Raul 2014 + * + * @brief ENC28J600 ethernet interface + */ + +#include +#include + +void eth_output(const void *payload, uint16_t payload_len) { + /* + * XXX + * + * This implementation assumes there is free space before the + * Ethernet Header start to store the command. + */ + ENCX24J600.sendPacket((uint8_t *) payload - ETHER_HEADER_LEN, payload_len + ETHER_HEADER_LEN); +} diff --git a/stm32/libraries/CoAP/src/netinet/arp.h b/stm32/libraries/CoAP/src/netinet/arp.h new file mode 100644 index 0000000..d29b8f7 --- /dev/null +++ b/stm32/libraries/CoAP/src/netinet/arp.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * Minimal standalone ARP + * + * @author: Pekka Nikander 2014 + */ + +#ifndef _ARP_H +# define _ARP_H + +# include + +struct arp { + uint16_t arp_hardware_address_space; + uint16_t arp_protocol_address_space; + uint8_t arp_hardware_address_length; + uint8_t arp_protocol_address_length; + uint16_t arp_opcode; + uint8_t arp_src_eth_addr[ETHER_ADDR_LEN]; + in_addr_t arp_src_ip_addr; + uint8_t arp_dst_eth_addr[ETHER_ADDR_LEN]; + in_addr_t arp_dst_ip_addr; +} __attribute__((packed,aligned(2))); + +# define ARP_HARDWARE_ETHERNET 1 + +# define ARP_OPCODE_REQUEST 1 +# define ARP_OPCODE_REPLY 2 + +/** + * XXX + */ +extern void arp_input(struct arp *const arp); + +#endif //_ARP_H diff --git a/stm32/libraries/CoAP/src/netinet/arp_input.c b/stm32/libraries/CoAP/src/netinet/arp_input.c new file mode 100644 index 0000000..168c3dd --- /dev/null +++ b/stm32/libraries/CoAP/src/netinet/arp_input.c @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * Minimal standalone ICMP + * + * @author: Pekka Nikander 2014 + */ + +#include +#include +#include +#include +#include + +#include + +/** + * XXX + */ + +#ifndef DEBUG_WRITE +# if 0 +# define DEBUG_WRITE(...) +# else +# define DEBUG_WRITE debug_write +extern void debug_write(int c); +# endif +#endif + +void arp_input(struct arp *const arp) { +#if 0 + /** + * Verify packet format XXX revise + */ + if (arp->arp_hardware_address_space != ARP_HARDWARE_ETHERNET || + arp->arp_protocol_address_space != ETHERTYPE_IP) + return; +#endif + + DEBUG_WRITE('a'); + + /* + * Switch on opcode + */ + switch (arp->arp_opcode) { + default: + // Ignore replies and all other packets. + net_error("Unknown ARP opcode %d.\n", ntohs(arp->arp_opcode)); + return; + case CONSTEXPR_HTONS(ARP_OPCODE_REQUEST): + DEBUG_WRITE('A'); + if (arp->arp_dst_ip_addr != ip_local_address.s_addr) { + // Not us + return; + } + // The ethernet src and dst have already been swapped + DEBUG_WRITE('R'); + arp->arp_opcode = CONSTEXPR_HTONS(ARP_OPCODE_REPLY); + memcpy(arp->arp_dst_eth_addr, arp->arp_src_eth_addr, sizeof(arp->arp_dst_eth_addr)); + memcpy(arp->arp_src_eth_addr, ether_local_address, sizeof(arp->arp_src_eth_addr)); + arp->arp_dst_ip_addr = arp->arp_src_ip_addr; + arp->arp_src_ip_addr = ip_local_address.s_addr; + eth_output(arp, sizeof(struct arp)); + return; + } +} + diff --git a/stm32/libraries/CoAP/src/netinet/eth_input.c b/stm32/libraries/CoAP/src/netinet/eth_input.c new file mode 100644 index 0000000..147d399 --- /dev/null +++ b/stm32/libraries/CoAP/src/netinet/eth_input.c @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * Minimal Ethernet + * + * @author: Pekka Nikander 2014 + */ + +#include +#include +#include +#include +#include + +#ifndef DEBUG_WRITE +# if 0 +# define DEBUG_WRITE(...) +# else +# define DEBUG_WRITE debug_write +extern void debug_write(int c); +# endif +#endif + +uint8_t ether_local_address[ETHER_ADDR_LEN] = { 0, 0, 0, 0, 0, 0 }; // XXX better default? + +/** + * XXX + */ + +void eth_input(struct ether_header *const ether) { + +#if 0 + /* + * Verify destination address. + */ + XXX; +#endif + + DEBUG_WRITE('e'); + + /* + * Swap source and destination address for return packet. + * + * If the upper layers need the src/dst information, they + * must be written with this swapping in mind. + */ + // XXX Check that the following produces optimal code. Revise if not. + // Write in assembler if needed. + register uint16_t d0 = ether->ether_addrs[0]; + register uint16_t d1 = ether->ether_addrs[1]; + register uint16_t d2 = ether->ether_addrs[2]; + ether->ether_addrs[0] = ether->ether_addrs[3]; + ether->ether_addrs[1] = ether->ether_addrs[4]; + ether->ether_addrs[2] = ether->ether_addrs[5]; + ether->ether_addrs[3] = d0; + ether->ether_addrs[4] = d1; + ether->ether_addrs[5] = d2; + + /* + * Pass to the upper layer + */ + switch (ether->ether_type) { + case CONSTEXPR_HTONS(ETHERTYPE_IP): + DEBUG_WRITE('i'); + ip_input ((struct ip *) ((char *)ether + ETHER_HEADER_LEN)); + return; + case CONSTEXPR_HTONS(ETHERTYPE_ARP): + DEBUG_WRITE('a'); + arp_input((struct arp *)((char *)ether + ETHER_HEADER_LEN)); + return; + default: + DEBUG_WRITE('u'); + net_error("Unknown ethernet protocol %d.\n", ether->ether_type); + return; // Unknown protocol -- dropped silently + } +} + +void eth_set_address(const uint8_t *const address) { + memcpy(ether_local_address, address, ETHER_ADDR_LEN); +} diff --git a/stm32/libraries/CoAP/src/netinet/ethernet.h b/stm32/libraries/CoAP/src/netinet/ethernet.h new file mode 100644 index 0000000..f042ddb --- /dev/null +++ b/stm32/libraries/CoAP/src/netinet/ethernet.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * Minimal standalone UDP + * + * @author: Pekka Nikander 2014 + */ + +#ifndef _ETHERNET_H_ +# define _ETHERNET_H_ + +# include + +# define ETHER_ADDR_LEN 6 + +/** + * Local host Ethernet address. + * + * While it would be more efficient to have a compiled-in ethernet + * address, we cannot support that at the moment. XXX WHY? Explain. + */ +extern uint8_t ether_local_address[ETHER_ADDR_LEN]; + +/// XXXXXXX CLEAN UP THE FOLLOWING + +struct ether_header_real { + uint8_t ether_dhost[ETHER_ADDR_LEN]; + uint8_t ether_shost[ETHER_ADDR_LEN]; + uint16_t ether_type; +} __attribute__((packed)); + +struct ether_header { + union { + struct { + uint8_t ether_dhost[ETHER_ADDR_LEN]; + uint8_t ether_shost[ETHER_ADDR_LEN]; + }; + struct { + uint16_t ether_addrs[2*ETHER_ADDR_LEN/sizeof(uint16_t)]; + }; + }; + uint16_t ether_type; +} __attribute__((packed)); + +# define ETHER_HEADER_LEN (2 * ETHER_ADDR_LEN + sizeof(uint16_t)) + +# define ETHERTYPE_IP 0x0800 +# define ETHERTYPE_ARP 0x0806 +# define ETHERTYPE_IPV6 0x86dd + +# ifdef __cplusplus +extern "C" { +# endif +extern void eth_input(struct ether_header *const eth_packet); +extern void eth_output(const void *payload, uint16_t payload_len); +extern void eth_set_address(const uint8_t *const address); +# ifdef __cplusplus +} +# endif + +#endif //_ETHERNET_H_ diff --git a/stm32/libraries/CoAP/src/netinet/icmp.h b/stm32/libraries/CoAP/src/netinet/icmp.h new file mode 100644 index 0000000..42d3240 --- /dev/null +++ b/stm32/libraries/CoAP/src/netinet/icmp.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * Minimal standalone ICMP + * + * @author: Pekka Nikander 2014 + */ + +#ifndef _ICMP_H +# define _ICMP_H + +struct icmp { + uint8_t icmp_type; + uint8_t icmp_code; + uint16_t icmp_sum; + uint16_t icmp_id; + uint16_t icmp_seqno; + uint8_t icmp_data[0]; +}; + +# define ICMP_TYPE_ECHO_REPLY 0 +# define ICMP_TYPE_ECHO 8 + +/** + * XXX + */ +extern void icmp_input(struct icmp *const icmp_packet, size_t len); + +#endif //_ICMP_H diff --git a/stm32/libraries/CoAP/src/netinet/icmp_input.c b/stm32/libraries/CoAP/src/netinet/icmp_input.c new file mode 100644 index 0000000..72390da --- /dev/null +++ b/stm32/libraries/CoAP/src/netinet/icmp_input.c @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * Minimal standalone ICMP + * + * @author: Pekka Nikander 2014 + */ + +#include +#include +#include + +/** + * XXX + */ +void icmp_input(struct icmp *const icmp, size_t icmp_len) { + net_error("ICMP type %d.\n", icmp->icmp_type); + switch (icmp->icmp_type) { + case ICMP_TYPE_ECHO: + icmp->icmp_type = ICMP_TYPE_ECHO_REPLY; + ip_checksum_update(&icmp->icmp_sum, ICMP_TYPE_ECHO, ICMP_TYPE_ECHO_REPLY); + break; + default: + net_error("Unknown ICMP type %d.\n", icmp->icmp_type); + // Drop silently + return; + } + ip_output(icmp, icmp_len); +} + diff --git a/stm32/libraries/CoAP/src/netinet/ip.h b/stm32/libraries/CoAP/src/netinet/ip.h new file mode 100644 index 0000000..3b7d1e9 --- /dev/null +++ b/stm32/libraries/CoAP/src/netinet/ip.h @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * Minimal standalone IPv4 + * + * @author: Pekka Nikander 2014 + */ + +#ifndef _IP_H_ +# define _IP_H_ + +# include +# include + +# define IPPROTO_ICMP 1 +# define IPPROTO_UDP 17 + +typedef uint32_t in_addr_t; + +static const in_addr_t IP_ADDRESS_UNSPECIFIED = 0; + +struct in_addr { + union { + in_addr_t s_addr; + uint8_t s_bytes[sizeof(in_addr_t)]; + }; +} __attribute__((packed)); + +extern struct in_addr ip_local_address; + +struct ip { + uint8_t ip_vhl; + uint8_t ip_tos; + uint16_t ip_len; + uint16_t ip_id; + union { + uint16_t ip_off; + uint8_t ip_foff[2]; + }; + uint8_t ip_ttl; + uint8_t ip_p; + uint16_t ip_sum; + struct in_addr ip_src; + struct in_addr ip_dst; +} __attribute__((packed,aligned(4))); + +union iph { + struct ip iph; + uint8_t iph_bytes[0]; + uint16_t iph_shorts[0]; + uint32_t iph_longs[0]; +} __attribute__((packed,aligned(4))); + +# define IP_VHL_DEFAULT 0x45 /* IPv4, 4*4 = 20 bytes */ +# define IP_TOS_DEFAULT 0x0 /* XXX define */ +# define IP_OFF_DEFAULT CONSTEXPR_HTONS(0x4000) +# define IP_TTL_DEFAULT 64 /* Default TTL, from RFC1340 */ + +# define IP_MSS 576 /* Default segment size */ + +# ifdef __cplusplus +extern "C" { +# endif + +extern void ip_input( struct ip *const ip); +extern void ip_output(const void *payload, uint16_t payload_len); +extern uint16_t ip_checksum(uint32_t seed, const void *data, size_t data_len); + +/** + * XXX + */ +static inline void ip_checksum_update( + uint16_t *const chksump, uint16_t oldvalue, uint16_t newvalue) { + register uint16_t sum_; // 1's complement of the sum + sum_ = ~(*chksump); // Fetch old sum and complement. + sum_ += -oldvalue + newvalue; + *chksump = ~sum_; // Complement and store new sum. + +} + +# ifdef __cplusplus +} +# endif + +#endif //_IP_H_ diff --git a/stm32/libraries/CoAP/src/netinet/ip_checksum.c b/stm32/libraries/CoAP/src/netinet/ip_checksum.c new file mode 100644 index 0000000..6b87abc --- /dev/null +++ b/stm32/libraries/CoAP/src/netinet/ip_checksum.c @@ -0,0 +1,184 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * Minimal standalone IPv4 + * + * @author: Pekka Nikander 2014 + */ + +#include +#include +#include +#include + +/** + * Incrementally computes IP checksum over the data. + * + * Starting from a partial non-complemented checksum, adds the 16-bit + * words in the 32-bit aligned data to the checksum, carrying data + * over. Returns one's complement of the generated checksum. + * + * The seed may contain two 16-bit values in parallel. + * + * The data buffer must be 32-bits aligned. + * + * For simply computing the checksum over a memory area, call this + * function with the checksum argument as zero. In a more typical + * case, you first compute a pseudo-header checksum to the checksum + * argument, and then call this function with the data buffer. + * + * @param checksum non-complemented checksum seed, two 16-bit words in parallel + * @param data a 32-bit aligned memory area to compute the checksum over + * @param len the length of the memory area, may be of any length + * + */ +uint16_t ip_checksum(register uint32_t checksum, const void *data, size_t len) { + register const uint8_t *dp = (const uint8_t *)data; + register const uint8_t *end = dp + len; + + /* + * The default (if OPTIMIZE_SIZE hasn't been defined) is to first + * compute the checksum in 64-bit chunks, using a 32-bit register + * and ADC (add with carry) instructions; see the assembly code. + * Once there is less than 64 bits left, the remainder is first + * computed using 16-bit additions, and finally adding the lone + * 8-bit byte (if any). + * + * The 'end' variable is not really the end of the buffer, but a + * pseudo-end adjusted so that the comparisons in the while loops + * are simple, generating more compact code. + * + * The default size of this function on Cortex-M0 is 72 bytes, and + * the size-optimized size 46 bytes. The default version runs + * about 3-4 times as fast as the size-optimised one on large buffers. + */ +#define OPTIMIZE_SIZE 1 + +#ifndef OPTIMIZE_SIZE + // Process the data in 64 bit chunks, using LDM and ADC instructions + { + register const uint32_t zero = 0; + + end -= 2 * sizeof(uint32_t) - 1; + + while (dp < end) { +#if defined(__thumb__) +# if defined(__ARM_ARCH_6M__) + XXX DOES NOT WORK, CRASHES. INVESTIGATE. PROBABLY *WAS* ALIGNMENT, TEST. + __asm__ ( + "ldm %[dp]!, {r2,r3}\n\t" + "add %[checksum], r2\n\t" + "adc %[checksum], r3\n\t" + "adc %[checksum], %[zero]" + : [checksum] "+r" (checksum), [dp] "+r" (dp) + : [zero] "r" (zero) + : "r2", "r3" + ); +# else +# error "Not implemented for ARMv7 yet. Please do." +# endif +#else + register const uint16_t *hp = (const uint16_t *)dp; + checksum += *hp++; + checksum += *hp++; + checksum += *hp++; + checksum += *hp++; + dp += 2 * sizeof(uint32_t); +#endif + } + + end += 2 * sizeof(uint32_t) - 1; + } +#endif + + // Add the half words together. This cannot overflow. + { + register uint32_t checksum_high = (checksum >> 16) & 0xFFFF; + checksum = checksum & 0xFFFF; + checksum += checksum_high; + } + + // If there are any remaining 16 bit words, add them. Cannot overflow. + // In the worst case, we get 1fffe + ffff + ffff + ffff = 4fffb + { + end -= 1; + + while (dp < end) { + register uint32_t d = *((uint16_t *)dp); + checksum += d; + dp += sizeof(uint16_t); + } + + end += 1; + } + + // If the is a remaining 8 bit byte, add it. Cannot overflow. + // Note that we can add it directly, as byte swapping will do the right thing. + // In the worst case, we get 4fffx or 5fffx + if (dp < end) { + checksum += *dp; + } + + // Add the half words together again, + // two times for the worst case, e.g. + // 4ffff -> 10003 -> 4 or 5fffd -> 10002 -> 3 + { + register uint32_t checksum_high; + checksum_high = (checksum >> 16) & 0xFFFF; + checksum = checksum & 0xFFFF; + checksum += checksum_high; + + checksum_high = (checksum >> 16) & 0xFFFF; + checksum = checksum & 0xFFFF; + checksum += checksum_high; + } + + // XXX Should we have this complementing here? Or at the caller? + // Return 1's complement + return ~checksum; +} + +#ifdef UNIT_TEST + +#include + +static uint8_t test_vector[] = { + 0xe3, 0x4f, 0x23, 0x96, 0x44, 0x27, 0x99, 0xf3, +}; + +static uint8_t test_vector2[] = { + 0xe3, 0x4f, 0x23, 0x96, 0x44, 0x27, 0x99, 0xf3, 0x01, 0x01, 0x10, +}; + +int main(void) { + uint16_t checksum = ip_checksum(0, test_vector, sizeof(test_vector)); + if (checksum != 0xff1a) { + fprintf(stderr, "%x != 0xff1a\n", checksum); + return 1; + } + checksum = ip_checksum(0, test_vector2, sizeof(test_vector2)); + if (checksum != 0xfe09) { + fprintf(stderr, "%x != 0xfe09\n", checksum); + return 1; + } + return 0; +} + +#endif //UNIT_TEST diff --git a/stm32/libraries/CoAP/src/netinet/ip_input.c b/stm32/libraries/CoAP/src/netinet/ip_input.c new file mode 100644 index 0000000..f04782f --- /dev/null +++ b/stm32/libraries/CoAP/src/netinet/ip_input.c @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * Minimal standalone IPv4 + * + * @author: Pekka Nikander 2014 + */ + +#include +#include +#include +#include + +struct ip_packet { + union iph ip_iph; + union { + struct udp ip_udp; + struct icmp ip_icmp; + }; +}; + +struct in_addr ip_local_address = { .s_bytes = { 10, 0, 0, 2 } }; + +static const union iph ip_header_mask = { + .iph = { + /* First 32-bit word */ + .ip_vhl = (uint8_t)~0, // must match; C++11 requires the cast + .ip_tos = 0, // ignored + .ip_len = 0, // ignored + /* Second 32-bit word */ + .ip_id = 0, // ignored + .ip_foff = { 0x1f, 0xff }, // only offset must match + /* Third 32-bit word */ + .ip_ttl = 0, // ignored + .ip_p = 0, // ignored + .ip_sum = 0, // ignored + /* Fourth and fifth 32-bit words */ + .ip_src = { { 0 } }, // ignored + .ip_dst = { { 0 } }, // not matched + } +}; + +static const union iph ip_header_data = { + .iph = { + .ip_vhl = IP_VHL_DEFAULT, + .ip_tos = 0, // ignored + .ip_len = 0, // ignored + .ip_id = 0, // ignored + .ip_off = 0, // offset must be zero + .ip_ttl = 0, // ignored + .ip_p = 0, // ignored + .ip_sum = 0, // ignored + .ip_src = { { 0 } }, // ignored + .ip_dst = { { 0 } }, // not matched + } +}; + +/** + * XXX + */ + +# ifndef offsetof +# define offsetof(st, m) ((uint32_t)(&((st *)0)->m)) +# endif + +void ip_input(struct ip *const iph) { + + /* + * Verify the packet format. + */ + register const uint16_t *const iphps = (uint16_t *)iph; + register const uint16_t *const iphms = ip_header_mask.iph_shorts; + register const uint16_t *const iphds = ip_header_data.iph_shorts; + + // VHL & TOS + const uint32_t vhl_o2 = offsetof(struct ip,ip_vhl)/2; + if ((iphps[vhl_o2] & iphms[vhl_o2]) != iphds[vhl_o2]) { + net_error("Dropping malformatted packet vhl. %04x & %04x != %04x\n", + iphps[vhl_o2], iphms[vhl_o2], iphds[vhl_o2]); + return; + } + + // Length and ID ignored + + // Offset must be zero, ignore flags + const uint32_t off_o2 = offsetof(struct ip,ip_off)/2; + if ((iphps[off_o2] & iphms[off_o2]) != iphds[off_o2]) { + net_error("Dropping non-zero offset. %04x & %04x != %04x\n", + iphps[off_o2], iphms[off_o2], iphds[off_o2]); + return; // Non-zero offset + } + + // Check TTL + //XXX; + +#if 0 + // Verify checksum, RFC1122 Section 3.2.1.2 + if (ip_checksum(0, iph, sizeof(struct ip)) != 0) + net_error("Dropping bad checksum.\n"); + return; +#endif + + // Verify destination address. + register in_addr_t dst = iph->ip_dst.s_addr; + if (dst != ip_local_address.s_addr) { + // XXX Reply with ICMP destination unreachable? + net_error("Dropping packet with wrong destination address.\n"); + return; // Wrong destiation address -- dropped silently + } + + /* + * Swap source and destination address for return packet. + * + * If the upper layers need the src/dst information, they + * must be written with this swapping in mind. + */ + iph->ip_dst = iph->ip_src; + iph->ip_src.s_addr = dst; + + /* + * Pass to the upper layer + */ + struct ip_packet *const ip_packet = (struct ip_packet *)iph; + const size_t len = ntohs(iph->ip_len) - sizeof(struct ip); + switch (iph->ip_p) { + case IPPROTO_UDP: + udp_input(&ip_packet->ip_udp, len); + return; + case IPPROTO_ICMP: + icmp_input(&ip_packet->ip_icmp, len); + return; + default: + // XXX Reply with a suitable ICMP? + net_error("Dropping packet with unknown protocol %d.\n", iph->ip_p); + return; // Unknown protocol -- dropped silently + } +} + diff --git a/stm32/libraries/CoAP/src/netinet/ip_output.c b/stm32/libraries/CoAP/src/netinet/ip_output.c new file mode 100644 index 0000000..e466ebb --- /dev/null +++ b/stm32/libraries/CoAP/src/netinet/ip_output.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * Minimal standalone IPv4 + * + * @author: Pekka Nikander 2014 + */ + +#include +#include +#include +#include + +/** + * XXX + * + * The pointed packet MUST be a pointer to inside an Ethernet packet, + * containing valid Ethernet fields. + * + * The payload MUST be aligned at a 4 byte boundary, meaning that + * the IP header will also be properly aligned at 4 bytes. + */ +void ip_output(const void *payload, uint16_t payload_len) { + static uint16_t ip_id; + + struct ip *const iph = (struct ip *)((char *)payload - sizeof(struct ip)); + + const uint16_t len = payload_len += sizeof(struct ip); + + // XXX Check that the compiler optimises properly + // XXX Check if passing proto in argument would produce better code + iph->ip_vhl = IP_VHL_DEFAULT; +#if 0 // Reply with whatever TOS there was + iph->ip_tos = IP_TOS_DEFAULT; +#endif + iph->ip_len = htons(len); + iph->ip_id = ip_id++; + iph->ip_off = IP_OFF_DEFAULT; // We don't support fragments + iph->ip_ttl = IP_TTL_DEFAULT; // Always reply with default TTL + // Proto MUST be set when calling + iph->ip_sum = 0; + iph->ip_src.s_addr = ip_local_address.s_addr; + // Dst MUST be set when calling + + iph->ip_sum = ip_checksum(0, iph, sizeof(struct ip)); + + /* + * Pass to lower layer. NB. Tail call. + */ + eth_output(iph, len); +} diff --git a/stm32/libraries/CoAP/src/netinet/net_debug.h b/stm32/libraries/CoAP/src/netinet/net_debug.h new file mode 100644 index 0000000..bae79c7 --- /dev/null +++ b/stm32/libraries/CoAP/src/netinet/net_debug.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * Debugging macros for the IP stack + * + * @author: Pekka Nikander 2014 + */ + +#ifndef _NET_DEBUG_H +# define _NET_DEBUG_H + +# ifdef EMULATOR +# include +# define net_error(...) fprintf(stderr, __VA_ARGS__) +# define net_debug(...) fprintf(stderr, __VA_ARGS__) +# else +# define net_error(...) +# define net_debug(...) +# endif + +#endif //_NET_DEBUG_H diff --git a/stm32/libraries/CoAP/src/netinet/net_packet.h b/stm32/libraries/CoAP/src/netinet/net_packet.h new file mode 100644 index 0000000..41f6438 --- /dev/null +++ b/stm32/libraries/CoAP/src/netinet/net_packet.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * The complete packet structure handled by the Ell-i stack. + * + * XXX Add here more documentation how the Ell-i stack handles + * packets. + * + * @author: Pekka Nikander 2014 + */ + +#ifndef _NET_PACKET_H +# define _NET_PACKET_H + +#include +#include +#include +#include +#include +// #include + +struct net_packet { + uint16_t np_padding; // For aligning the ip header correctly + struct ether_header np_ether; + union { + struct arp np_arp; + struct { + struct ip np_ip; // Must be 4 bytes aligned + union { + struct udp np_udp; + struct icmp np_icmp; + }; + }; + }; +} __attribute__((packed)); + +#endif //_NET_PACKET_H + diff --git a/stm32/libraries/CoAP/src/netinet/udp.c b/stm32/libraries/CoAP/src/netinet/udp.c new file mode 100644 index 0000000..5e0b965 --- /dev/null +++ b/stm32/libraries/CoAP/src/netinet/udp.c @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * Minimal standalone UDP + * + * @author: Pekka Nikander 2014 + */ + +#include +#include +#include + +/** + * XXX + */ + +void udp_input(struct udp *const udp_packet, size_t len) { +#if 0 + /* + * Verify UDP checksum + */ + XXX; +#endif + + /* Swap ports */ + register uint16_t dport = udp_packet->udp_dport; + udp_packet->udp_dport = udp_packet->udp_sport; + udp_packet->udp_sport = dport; + + /* Find upper layer handler, if any */ + for (const struct udp_socket *socket = __udp_sockets; + socket < __udp_sockets_end; + socket++ /* XXX */) { + if (socket->udp_port == dport) { + /* XXX Update statistics */ + const uint16_t payload_len = ntohs(udp_packet->udp_len) - sizeof(struct udp); + socket->udp_socket_handler(udp_packet->udp_data, payload_len); + return; + } + } + net_error("Packet to unbound UDP socket %d\n", dport); +} + +/** + * Compute the UDP checksum, taking the addresses for the pseudo + * header from the IP header. + * + * @param ip IP header for the IP addresses in the UDP pseudo header + * @param udp UDP header, followed with the payload + * @param len UDP length, passed in register to save memory access + */ +static inline uint16_t +udp_checksum( + const struct ip *const ip, const struct udp *const udp, const size_t len) { + + /* + * Phase 1: Compute the pseudo-header checksum, using + * parallel 16-bit words in a 32-bit register. + */ + + // Initialize pseudo-header from the end, the UDP length + register uint32_t checksum = len; + + // Assign a register with the pseudo-header constant value, for + // using as a register in the ADC instruction below +# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +# define UDP_ZEROES_PROTOCOL_SHORT ((IPPROTO_UDP << 8) | 0) +# else +# define UDP_ZEROES_PROTOCOL_SHORT ((0 << 8) | IPPROTO_UDP) +# endif + register const uint32_t zeroes_protocol = UDP_ZEROES_PROTOCOL_SHORT; + +#if defined(__thumb__) && 0//XXX remove zero here once works +# if defined(__ARM_ARCH_6M__) + // Add IP addresses, as 32-bit entities, using ADC + register const uint32_t *srcp = &ip->ip_src.s_addr; + __asm__ ( + XXX DOES NOT WORK, CRASHES. INVESTIGATE. + "ldm %[srcp]!, {r2, r3}\n\t" + "add %[checksum], r2\n\t" + "adc %[checksum], r3\n\t" + "adc %[checksum], %[zeroes_protocol]" + : [checksum] "+r" (checksum), [srcp] "+r" (srcp) + : [zeroes_protocol] "r" (zeroes_protocol) + : "r2", "r3" + ); +# else +# error "Not implemented for ARMv7 yet. Please do." +# endif +#else + checksum += (ip->ip_src.s_addr >> 16) & 0xFFFF; + checksum += (ip->ip_src.s_addr ) & 0xFFFF; + checksum += (ip->ip_dst.s_addr >> 16) & 0xFFFF; + checksum += (ip->ip_dst.s_addr ) & 0xFFFF; + checksum += zeroes_protocol; +#endif + + /* + * Part 2: Compute the checksum over the UDP header and data. + * ip_checksum() accepts two parallel 16-bit words in its + * first argument. + */ + checksum = ip_checksum(checksum, udp, len); + if (checksum == 0) + checksum = ~0; + return checksum; +} + +/** + * XXX + */ + +void udp_output(const void *payload, size_t payload_len) { + struct udp *const udp = (struct udp *)((const char *)payload - sizeof(struct udp)); + const uint16_t udp_len = payload_len + sizeof(struct udp); + + udp->udp_len = htons(udp_len); + udp->udp_sum = 0; + + /* + * Clear the checksum, for now + */ + udp->udp_sum = 0; // udp_checksum(ip, udp, udp_len); + /* + * Pass to lower layer. + */ + ip_output(udp, udp_len); +} + +void udp_echo(uint8_t udp_payload[], uint16_t udp_payload_len) { + udp_output(udp_payload, udp_payload_len); +} + +DEFINE_UDP_SOCKET(UDP_PORT_ECHO, udp_echo); diff --git a/stm32/libraries/CoAP/src/netinet/udp.h b/stm32/libraries/CoAP/src/netinet/udp.h new file mode 100644 index 0000000..fe2103d --- /dev/null +++ b/stm32/libraries/CoAP/src/netinet/udp.h @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * Minimal standalone UDP + * + * @author: Pekka Nikander 2014 + */ + +#ifndef _UDP_H +# define _UDP_H + +# include +# include + +typedef uint16_t udp_port_t; + +# define UDP_PORT_ECHO 7 + +struct udp { + udp_port_t udp_sport; + udp_port_t udp_dport; + uint16_t udp_len; + uint16_t udp_sum; + uint8_t udp_data[0]; +}; + + +/** + * A compile-time allocated const data structure describing an UDP socket. + * + * @see DEFINE_UDP_SOCKET + */ + +struct udp_socket { + void (*udp_socket_handler)(uint8_t data[], uint16_t data_len); + const uint16_t udp_port; + /* XXX Add pointer to statistics, in RAM */ +} __attribute__((aligned(SYSTEM_INIT_ALIGNMENT))); + +# ifdef __MACH__ +# define UDP_SOCKET_SECTION(port) ".text,.socket" +# else +# define UDP_SOCKET_SECTION(port) ".socket.udp." # port +# endif + +# define __EXPAND_SOCKET_NAME(port) __udp_socket ## port + +# define DECLARE_UDP_SOCKET(port) \ + extern const struct udp_socket __EXPAND_SOCKET_NAME(port) \ + __attribute__((section(UDP_SOCKET_SECTION(port)))) + +/** + * Defines an UDP socket. + * + * To define a UDP socket at compile time, use the DEFINE_UDP_SOCKET + * macro to XXX. + */ + +# define DEFINE_UDP_SOCKET(port, handler) \ + DECLARE_UDP_SOCKET(port); \ + const struct udp_socket __EXPAND_SOCKET_NAME(port) \ + __attribute__((section(UDP_SOCKET_SECTION(port)))) \ + = { \ + IF(udp_socket_handler) handler, \ + IF(udp_port) CONSTEXPR_HTONS(port), \ + } + +extern const struct udp_socket __attribute__((section(UDP_SOCKET_SECTION()))) __udp_sockets[]; +extern const struct udp_socket __attribute__((section(UDP_SOCKET_SECTION()))) __udp_sockets_end[]; + +# ifdef __cplusplus +extern "C" { +# endif +extern void udp_input(struct udp *const udp_packet, size_t len); +extern void udp_output(const void * payload, size_t payload_len); +# ifdef __cplusplus +} +# endif + +#endif //_UDP_H diff --git a/stm32/libraries/CoAP/src/netinet/util.h b/stm32/libraries/CoAP/src/netinet/util.h new file mode 100644 index 0000000..c0bf2df --- /dev/null +++ b/stm32/libraries/CoAP/src/netinet/util.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +/** + * ARM CMSIS optimised hton{s,l} and ntoh{s,l} + * + * @author: Pekka Nikander 2014 + */ + +#ifndef _UTIL_STM32_H_ +# define _UTIL_STM32_H_ + +# include + +# if defined(STM32F0XX) +# include // Declare __REV16() and __REV() +# elif defined(STM32F40_41xxx) +# include +# elif defined(STM32F334x8) +# include +# else +# error "Unsupported MCU." +# endif + +/* Compile time */ +# define CONSTEXPR_HTONS(s) ((((s) >> 8) & 0xff) | (((s) << 8) & 0xff00)) +# define CONSTEXPR_NTOHS(s) ((((s) >> 8) & 0xff) | (((s) << 8) & 0xff00)) + +# ifndef EMULATOR + +/* Runtime */ +static inline int htons(uint16_t s) { return __REV16(s); }; +static inline int ntohs(uint16_t s) { return __REV16(s); }; +static inline int htonl(uint32_t l) { return __REV(l); }; +static inline int ntohl(uint32_t l) { return __REV(l); }; + +# else //EMULATOR + +/* Defined already in the emulator header files, don't redefine here. */ + +# endif //EMULATOR + +#endif //_UTIL_STM32_H_ diff --git a/stm32/libraries/CoAP/src/variants/ellduino_enc28j60.h b/stm32/libraries/CoAP/src/variants/ellduino_enc28j60.h new file mode 100644 index 0000000..6b51884 --- /dev/null +++ b/stm32/libraries/CoAP/src/variants/ellduino_enc28j60.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see + * . + */ + +/* + * Authors: Pekka Nikander 2014 + */ + +#ifndef _ELLDUINO_ENC28J60_H_ +# define _ELLDUINO_ENC28J60_H_ + +# define ENC28J60_SPI SPI2struct +# define ENC28J60_CS_PIN 40 + +# include + +// XXX +const uint8_t temp_eth_address[6] = { 0, 0, 0, 0, 0, 0 }; + + +static const ENC28J60Class ENC28J60(ENC28J60_SPI, ENC28J60_CS_PIN, temp_eth_address); + +#endif//_ELLDUINO_ENC28J60_H_ diff --git a/stm32/libraries/CoAP/src/variants/ellduino_encX24j600.h b/stm32/libraries/CoAP/src/variants/ellduino_encX24j600.h new file mode 100644 index 0000000..44937c2 --- /dev/null +++ b/stm32/libraries/CoAP/src/variants/ellduino_encX24j600.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see + * . + */ + +/* + * Authors: Pekka Nikander 2014 + */ + +#ifndef _ELLDUINO_ENCX24J600_H_ +# define _ELLDUINO_ENCX24J600_H_ + +# define ENCX24J600_SPI SPI1struct /* XXX Move to the constructor */ +# define ENCX24J600_CS_PIN 2 +# define ENCX24J600_INT_PIN 22 /* XXX Modify with correct value */ + +# include + +/* NB. Shall be evaluated at compile time, no runtime static C++ constructors allowed */ +static const ENCX24J600Class ENCX24J600(ENCX24J600_SPI, /* XXX FIXME */ + ENCX24J600_CS_PIN /* Slave select XXX currently dummy FIXME */); + +#endif//_ELLDUINO_ENCX24J600_H_ diff --git a/stm32/libraries/CoAP/src/variants/stm32f334nucleo_enc28j60.h b/stm32/libraries/CoAP/src/variants/stm32f334nucleo_enc28j60.h new file mode 100644 index 0000000..ecc27fb --- /dev/null +++ b/stm32/libraries/CoAP/src/variants/stm32f334nucleo_enc28j60.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see + * . + */ + +/* + * Authors: Pekka Nikander 2014 + */ + +#ifndef _STM32F334NUCLEO_ENC28J60_H_ +# define _STM32F334NUCLEO_ENC28J60_H_ + +# define ENC28J60_SPI SPI1struct +# define ENC28J60_CS_PIN 2 + +# include + +const uint8_t temp_eth_address[6] = { 0, 0, 0, 0, 0, 0 }; + +static const ENC28J60Class ENC28J60(ENC28J60_SPI, ENC28J60_CS_PIN, temp_eth_address); + +#endif//_STM32F334NUCLEO_ENC28J60_H_ diff --git a/stm32/libraries/CoAP/src/variants/stm32f334nucleo_encX24j600.h b/stm32/libraries/CoAP/src/variants/stm32f334nucleo_encX24j600.h new file mode 100644 index 0000000..d04bdd4 --- /dev/null +++ b/stm32/libraries/CoAP/src/variants/stm32f334nucleo_encX24j600.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see + * . + */ + +/* + * Authors: Pekka Nikander 2014 + */ + +#ifndef _STM32F334NUCLEO_ENCX24J600_H_ +# define _STM32F334NUCLEO_ENCX24J600_H_ + +# define ENCX24J600_SPI SPI1struct /* XXX Move to the constructor */ +# define ENCX24J600_CS_PIN 2 +# define ENCX24J600_INT_PIN 22 + +# include + +/* NB. Shall be evaluated at compile time, no runtime static C++ constructors allowed */ +static const ENCX24J600Class ENCX24J600(ENCX24J600_SPI, /* XXX FIXME */ + ENCX24J600_CS_PIN /* Slave select XXX currently dummy FIXME */); + +#endif//_STM32F334NUCLEO_ENCX24J600_H_ diff --git a/stm32/libraries/CoAP/src/variants/stm32f4discovery_enc28j60.h b/stm32/libraries/CoAP/src/variants/stm32f4discovery_enc28j60.h new file mode 100644 index 0000000..385072d --- /dev/null +++ b/stm32/libraries/CoAP/src/variants/stm32f4discovery_enc28j60.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see + * . + */ + +/* + * Authors: Pekka Nikander 2014 + */ + +#ifndef _STM32F4DISCOVERY_ENC28J60_H_ +# define _STM32F4DISCOVERY_ENC28J60_H_ + +# define ENC28J60_SPI SPI2struct +# define ENC28J60_CS_PIN 40 + +# include + +# warning "For a functional STM32F4discovery system, more work is needed. Will not work." + +const uint8_t temp_eth_address[6] = { 0, 0, 0, 0, 0, 0 }; + +static const ENC28J60Class ENC28J60(ENC28J60_SPI, ENC28J60_CS_PIN, temp_eth_address); + +#endif//_STM32F4DISCOVERY_ENC28J60_H_ diff --git a/stm32/libraries/CoAP/src/variants/stm32f4discovery_encX24j600.h b/stm32/libraries/CoAP/src/variants/stm32f4discovery_encX24j600.h new file mode 100644 index 0000000..c67a637 --- /dev/null +++ b/stm32/libraries/CoAP/src/variants/stm32f4discovery_encX24j600.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2014 ELL-i co-operative. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see + * . + */ + +/* + * Authors: Pekka Nikander 2014 + */ + +#ifndef _STM32F4DISCOVERY_ENCX24J600_H_ +# define _STM32F4DISCOVERY_ENCX24J600_H_ + +# define ENCX24J600_SPI SPI1struct /* XXX Move to the constructor */ +# define ENCX24J600_CS_PIN 2 +# define ENCX24J600_INT_PIN 22 /* XXX Modify with correct value */ + +# include + +/* NB. Shall be evaluated at compile time, no runtime static C++ constructors allowed */ +static const ENCX24J600Class ENCX24J600(ENCX24J600_SPI, /* XXX FIXME */ + ENCX24J600_CS_PIN /* Slave select XXX currently dummy FIXME */); + +#endif//_STM32F4DISCOVERY_ENCX24J600_H_ diff --git a/stm32/make/app.mk b/stm32/make/app.mk index 63e8b70..553cc60 100644 --- a/stm32/make/app.mk +++ b/stm32/make/app.mk @@ -72,12 +72,15 @@ endif ifeq ($(PLATFORM),emulator) -all: $(APP) lib$(APP).so +all: $(APP) lib$(APP).so pythonCallback.so clean:: rm -f $(PRE_OBJS) rm -f $(POST_OBJS) rm -f lib$(APP).so + rm -f pythonCallback.so + rm -f python.o + rm -f ./-lpython2.7 $(APP): $(APP_OBJS) libsystem_$(VARIANT).a $(LIBES_LIBS) $(PRE_OBJS) $(POST_OBJS) $(LD) $(LDFLAGS) -o $@ $(PRE_OBJS) $(APP_OBJS) $(LIBS) $(POST_OBJS) @@ -86,6 +89,10 @@ lib$(APP).so: $(APP_OBJS) libsystem_$(VARIANT).a $(LIBES_LIBS) $(PRE_OBJS) $(POS $(LD) $(LDFLAGS) $(SHAREDFLAGS) -o $@ $(PRE_OBJS) $(APP_OBJS) $(LIB_OBJS) \ $(LIBS) $(POST_OBJS) $(HOST_LIBS) +pythonCallback.so: $(APP_OBJS) libsystem_$(VARIANT).a $(LIBES_LIBS) $(PRE_OBJS) $(POST_OBJS) + $(LD) $(LDFLAGS) $(SHAREDFLAGS) -o $@ $(PRE_OBJS) $(APP_OBJS) $(LIB_OBJS) \ + $(LIBS) $(POST_OBJS) $(HOST_LIBS) + libsystem_$(VARIANT).a: @make TOP=$(TOP) -f $(TOP)make/system_lib.mk all diff --git a/stm32/make/emulator.mk b/stm32/make/emulator.mk index 1aa927f..85dd10b 100644 --- a/stm32/make/emulator.mk +++ b/stm32/make/emulator.mk @@ -42,7 +42,7 @@ else CC := g++ CXX := g++ LD := g++ -m32 -march=i386 -LD_SCRIPT := -Xlinker -T -Xlinker $(LD_LINKER_FILE) +LD_SCRIPT := -Xlinker -export-dynamic endif AR := ar ELF2HEX := : @@ -61,6 +61,18 @@ $(eval LIBS := \ $(subst -lstm32f3,-lsystem_$(VARIANT), \ $(call expand,compiler.cmd.ld.libs))))) + + +#The Cflags and LIBS are used for cpython extension module and cpython API in emulator +#Currently, the support is added for Linux only. +UNAME_S := $(shell uname -s) +ifeq ($(UNAME_S),Linux) +EXTRA_CFLAGS += -I/usr/include/python2.7/ -I/lib/i386-linux-gnu/ +EXTRA_CFLAGS += -pthread -fno-strict-aliasing -fwrapv -Wall -fPIC +LIBS += -L/usr/lib/python2.7/ -L/lib/i386-linux-gnu/ -L/lib32 -L/usr/lib32 +LIBS += -lpython2.7 -lpthread -ldl -lutil -lm +endif + CFLAGS += $(EXTRA_CFLAGS) CXXFLAGS += $(EXTRA_CFLAGS) @@ -74,11 +86,13 @@ POST_OBJS := emulator_post.o SHAREDFLAGS := -Wl,-dylib -Wl,-macosx_version_min -Wl,10.8 LDFLAGS := -m32 -Wl,-arch -Wl,i386 $(LD_SCRIPT) else -LDFLAGS := -m32 -march=i386 $(LD_SCRIPT) +LDFLAGS := -m32 -march=i386 $(LD_SCRIPT) SHAREDFLAGS := -shared -Xlinker --export-dynamic DYLD = $(LD) endif + + # # C++ standard library # @@ -89,11 +103,61 @@ LIBS += -lstdc++ # Additional system objects # -SYSTEM_OBJS := emulator.o Register.o GPIO.o TIM.o USART.o SPI.o -SYSTEM_OBJS += PWR.o SCB.o RCC.o FLASH.o -SYSTEM_OBJS += Register_RCC_CFGR.o +#Emulator Object File +SYSTEM_OBJS := emulator.o + +#Emulator Python Callback Module Object File +SYSTEM_OBJS += pythonCallback.o + +#Emulator Register Object File +SYSTEM_OBJS += Register.o + +#Emulator FLASH Object Files +SYSTEM_OBJS += FLASH.o +SYSTEM_OBJS += Register_FLASH_ACR.o Register_FLASH_KEYR.o Register_FLASH_OPTKEYR.o +SYSTEM_OBJS += Register_FLASH_SR.o Register_FLASH_CR.o + +#Emulator PWR Object Files +SYSTEM_OBJS += PWR.o +SYSTEM_OBJS += Register_PWR_CR.o + +#Emulator SCB Object Files +SYSTEM_OBJS += SCB.o +SYSTEM_OBJS += Register_SCB_CPUID.o Register_SCB_ICSR.o Register_SCB_VTOR.o + +#Emulator TIM Object Files +SYSTEM_OBJS += TIM.o +SYSTEM_OBJS += Register_TIM_CR1.o Register_TIM_CR2.o Register_TIM_SMCR.o +SYSTEM_OBJS += Register_TIM_DIER.o Register_TIM_CCMR1.o Register_TIM_CCMR2.o +SYSTEM_OBJS += Register_TIM_CCER.o Register_TIM_BDTR.o Register_TIM_PSC.o +SYSTEM_OBJS += Register_TIM_ARR.o Register_TIM_CCR1.o Register_TIM_CCR2.o +SYSTEM_OBJS += Register_TIM_CCR3.o Register_TIM_CCR4.o + +#Emulator RCC Object Files +SYSTEM_OBJS += RCC.o +SYSTEM_OBJS += Register_RCC_CR.o Register_RCC_PLLCFGR.o Register_RCC_CFGR.o +SYSTEM_OBJS += Register_RCC_CFGR.o Register_RCC_CIR.o Register_RCC_APB1RSTR.o +SYSTEM_OBJS += Register_RCC_AHB1ENR.o Register_RCC_AHBENR.o +SYSTEM_OBJS += Register_RCC_APB2ENR.o Register_RCC_APB1ENR.o +SYSTEM_OBJS += Register_RCC_APB2RSTR.o Register_RCC_BDCR.o +SYSTEM_OBJS += Register_RCC_CSR.o Register_RCC_AHBRSTR.o +SYSTEM_OBJS += Register_RCC_CFGR2.o Register_RCC_CFGR3.o Register_RCC_CR2.o + +#Emulator GPIO Object Files +SYSTEM_OBJS += GPIO.o SYSTEM_OBJS += Register_GPIO_PUPDR.o Register_GPIO_MODER.o Register_GPIO_IDR.o SYSTEM_OBJS += Register_GPIO_ODR.o Register_GPIO_BSRR.o Register_GPIO_AFR.o Register_GPIO_BRR.o SYSTEM_OBJS += Register_GPIO_BSRRL.o Register_GPIO_BSRRH.o -SYSTEM_OBJS += Register_SPI_SR.o Register_SPI_DR.o + +#Emulator USART Object Files +SYSTEM_OBJS += USART.o +SYSTEM_OBJS += Register_USART_BRR.o Register_USART_CR1.o Register_USART_CR2.o Register_USART_CR3.o +SYSTEM_OBJS += Register_USART_GTPR.o Register_USART_SR.o Register_USART_DR.o +SYSTEM_OBJS += Register_USART_ICR.o Register_USART_RTOR.o Register_USART_RQR.o +SYSTEM_OBJS += Register_USART_ISR.o Register_USART_RDR.o Register_USART_TDR.o + +#Emulator SPI Object Files +SYSTEM_OBJS += SPI.o +SYSTEM_OBJS += Register_SPI_CR1.o Register_SPI_CR2.o Register_SPI_SR.o Register_SPI_DR.o + VPATH += $(TOP)emulator/src diff --git a/stm32/make/system_lib.mk b/stm32/make/system_lib.mk index 99c4d98..97eebe4 100644 --- a/stm32/make/system_lib.mk +++ b/stm32/make/system_lib.mk @@ -59,6 +59,7 @@ endif SYSTEM_OBJS += \ system_init.o \ + memory.o \ $(VARIANT)_gpio.o \ $(VARIANT)_timer.o \ $(VARIANT)_usart.o \ diff --git a/stm32/system/stm32/src/memory.c b/stm32/system/stm32/src/memory.c new file mode 100644 index 0000000..8e64512 --- /dev/null +++ b/stm32/system/stm32/src/memory.c @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2013-2014 ELL-i co-operative. + * + * This file is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +#include + +inline +void *memcpy(void *dst, const void *src, size_t size) { + char *d = (char *)dst; + const char *s = (const char *)src; + while (size--) { + *d++ = *s++; + } + return dst; +} + +inline +void *memset(void *dst, int c, size_t size) { + char *d = (char *)dst; + while (size--) { + *d++ = c; + } + return dst; +} + +inline +int memcmp(const void *str1, const void *str2, size_t size) { + const char *s1 = (const char *)str1; + const char *s2 = (const char *)str2; + + while (size--) { + int d = *s1++ - *s2++; + if (d != 0) + return d; + } + return 0; +} diff --git a/stm32/tests/robot_library/Makefile b/stm32/tests/robot_library/Makefile index e9ea995..0c6045a 100644 --- a/stm32/tests/robot_library/Makefile +++ b/stm32/tests/robot_library/Makefile @@ -25,6 +25,7 @@ APP_OBJS := $(APP).o $(VARIANT).o EXTRA_CFLAGS += \ -I$(TOP)libraries/SPI/src/variants \ + -I$(TOP)emulator/inc \ include $(TOP)make/app.mk diff --git a/stm32/tests/robot_library/robot_library.cpp b/stm32/tests/robot_library/robot_library.cpp index e93f505..750a4cf 100644 --- a/stm32/tests/robot_library/robot_library.cpp +++ b/stm32/tests/robot_library/robot_library.cpp @@ -17,8 +17,15 @@ * along with ELL-i software. If not, see . */ +/** + * @author Asif Sardar 2014 + */ + #include #include +//#include +//#include +//#include /** * C test wrappers for calling our APIs from Robot Framework Python code @@ -42,6 +49,9 @@ extern "C" { return 0; } +//######################################################################################################// +// Arduino Fuctions Interface +//-------------------------------------------------------------------------------------------------------- /* * C interface for the Arduino Digital API calls */ @@ -54,7 +64,9 @@ extern "C" { void t_digitalWrite(pin_t pin, uint32_t val) { digitalWrite(pin, val); } +//-------------------------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------------------------- /* * C interface for the Arduino Analog API calls */ @@ -64,19 +76,49 @@ extern "C" { void t_noAnalogWrite(pin_t pin) { noAnalogWrite(pin); } +//-------------------------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------------------------- /* - * C interface for the Arduino Serial object + * C interface for the Arduino Serial API calls */ - void t_SerialBegin(uint32_t baudrate) { - Serial.begin(baudrate); +#if defined(__STM32F407__) + ARDUINO_GLOBAL_IMMUTABLE class SerialClass STM32F4DiscoverySerialArray[] = { Serial1, Serial2 }; +#elif defined(__STM32F334__) + ARDUINO_GLOBAL_IMMUTABLE class SerialClass STM32F334NucleoSerialArray[] = { Serial1, Serial2, Serial3 }; +#elif defined(__STM32F051__) + ARDUINO_GLOBAL_IMMUTABLE class SerialClass EllduinoSerialArray[] = { Serial1, Serial }; +#else +# error "Unknown MCU die. Please define." +#endif + + void t_SerialBegin(uint32_t baudrate, int usartNum) { +#if defined(__STM32F407__) + STM32F4DiscoverySerialArray[usartNum-1].begin(baudrate); +#elif defined(__STM32F334__) + STM32F334NucleoSerialArray[usartNum-1].begin(baudrate); +#elif defined(__STM32F051__) + EllduinoSerialArray[usartNum-1].begin(baudrate); +#else +# error "Unknown MCU die. Please define." +#endif } - void t_SerialWrite(uint8_t c) { - Serial.write(c); + void t_SerialWrite(uint8_t c, int usartNum) { +#if defined(__STM32F407__) + STM32F4DiscoverySerialArray[usartNum-1].write(c); +#elif defined(__STM32F334__) + STM32F334NucleoSerialArray[usartNum-1].write(c); +#elif defined(__STM32F051__) + EllduinoSerialArray[usartNum-1].write(c); +#else +# error "Unknown MCU die. Please define." +#endif } +//-------------------------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------------------------- /* - * C interface for the Arduino SPI library + * C interface for the Arduino SPI library API calls */ void t_SPI_begin(const uint8_t ss_pin) { SPI.begin(ss_pin); @@ -99,4 +141,410 @@ extern "C" { uint8_t t_SPI_transfer(uint8_t ss_pin, uint8_t data) { return SPI.transfer(ss_pin, data); } +//-------------------------------------------------------------------------------------------------------- + +//######################################################################################################// + +//######################################################################################################// +// Callback Fuctions Interface +//-------------------------------------------------------------------------------------------------------- + /* + * C interface for General Purpose Input Output (GPIO) python callback functions + */ + void t_GPIO_MODER( const char *port, CALLBACK(GPIO_MODER_CALLBACK) ) { + GPIOPORT[IDX(port)]->GPIO_MODER_VALUES( GPIOPORT[IDX(port)], GPIO_MODER_CALLBACK ); + } + void t_GPIO_PUPDR( const char *port, CALLBACK(GPIO_PUPDR_CALLBACK) ) { + GPIOPORT[IDX(port)]->GPIO_PUPDR_VALUES( GPIOPORT[IDX(port)], GPIO_PUPDR_CALLBACK ); + } + void t_GPIO_ODR( const char *port, CALLBACK(GPIO_ODR_CALLBACK) ) { + GPIOPORT[IDX(port)]->GPIO_ODR_VALUES( GPIOPORT[IDX(port)], GPIO_ODR_CALLBACK ); + } + void t_GPIO_IDR( const char *port, CALLBACK(GPIO_IDR_CALLBACK) ) { + GPIOPORT[IDX(port)]->GPIO_IDR_VALUES( GPIOPORT[IDX(port)], GPIO_IDR_CALLBACK ); + + } +#if defined(__STM32F407__) || defined(__STM32F334__) + void t_GPIO_BSRRL( const char *port, CALLBACK(GPIO_BSRRL_CALLBACK) ) { + GPIOPORT[IDX(port)]->GPIO_BSRRL_VALUES( GPIOPORT[IDX(port)], GPIO_BSRRL_CALLBACK ); + } + void t_GPIO_AFR( const char *port, CALLBACK(GPIO_AFR_CALLBACK) ) { + GPIOPORT[IDX(port)]->GPIO_AFR_VALUES( GPIOPORT[IDX(port)], GPIO_AFR_CALLBACK ); + } + void t_GPIO_BSRRH( const char *port, CALLBACK(GPIO_BSRRH_CALLBACK) ) { + GPIOPORT[IDX(port)]->GPIO_BSRRH_VALUES( GPIOPORT[IDX(port)], GPIO_BSRRH_CALLBACK ); + } +#elif defined(__STM32F051__) + void t_GPIO_BSRR( const char *port, CALLBACK(GPIO_BSRR_CALLBACK) ) { + GPIOPORT[IDX(port)]->GPIO_BSRR_VALUES( GPIOPORT[IDX(port)], GPIO_BSRR_CALLBACK ); + } + void t_GPIO_AFR( const char *port, CALLBACK(GPIO_AFR_CALLBACK) ) { + GPIOPORT[IDX(port)]->GPIO_AFR_VALUES( GPIOPORT[IDX(port)], GPIO_AFR_CALLBACK ); + } + void t_GPIO_BRR( const char *port, CALLBACK(GPIO_BRR_CALLBACK) ) { + GPIOPORT[IDX(port)]->GPIO_BRR_VALUES( GPIOPORT[IDX(port)], GPIO_BRR_CALLBACK ); + } +#else +# error "Unknown MCU die. Please define." +#endif + +//-------------------------------------------------------------------------------------------------------- + +//-------------------------------------------------------------------------------------------------------- + /* + * C interface for Universal Synchronous Asynchronous Reciever Transmitter (USART) python + * callback functions + */ +#if defined(__STM32F407__) + void t_USART_SR( int usartNum, CALLBACK(USART_SR_CALLBACK) ) { + STM32F4DiscoveryUsartArray[usartNum-1]->USART_SR_VALUES + ( STM32F4DiscoveryUsartArray[usartNum-1] + , USART_SR_CALLBACK + ); + } + void t_USART_DR( int usartNum, CALLBACK(USART_DR_CALLBACK) ) { + STM32F4DiscoveryUsartArray[usartNum-1]->USART_DR_VALUES + ( STM32F4DiscoveryUsartArray[usartNum-1] + , USART_DR_CALLBACK + ); + } + void t_USART_BRR( int usartNum, CALLBACK(USART_BRR_CALLBACK) ) { + STM32F4DiscoveryUsartArray[usartNum-1]->USART_BRR_VALUES + ( STM32F4DiscoveryUsartArray[usartNum-1] + , USART_BRR_CALLBACK + ); + } + void t_USART_CR1( int usartNum, CALLBACK(USART_CR1_CALLBACK) ) { + STM32F4DiscoveryUsartArray[usartNum-1]->USART_CR1_VALUES + ( STM32F4DiscoveryUsartArray[usartNum-1] + , USART_CR1_CALLBACK + ); + } + void t_USART_CR2( int usartNum, CALLBACK(USART_CR2_CALLBACK) ) { + STM32F4DiscoveryUsartArray[usartNum-1]->USART_CR2_VALUES + ( STM32F4DiscoveryUsartArray[usartNum-1] + , USART_CR2_CALLBACK + ); + } + void t_USART_CR3( int usartNum, CALLBACK(USART_CR3_CALLBACK) ) { + STM32F4DiscoveryUsartArray[usartNum-1]->USART_CR3_VALUES + ( STM32F4DiscoveryUsartArray[usartNum-1] + , USART_CR3_CALLBACK + ); + } + void t_USART_GTPR( int usartNum, CALLBACK(USART_GTPR_CALLBACK) ) { + STM32F4DiscoveryUsartArray[usartNum-1]->USART_GTPR_VALUES + ( STM32F4DiscoveryUsartArray[usartNum-1] + , USART_GTPR_CALLBACK + ); + } +#elif defined(__STM32F051__) || defined(__STM32F334__) + void t_USART_BRR( int usartNum, CALLBACK(USART_BRR_CALLBACK) ) { +#if defined(__STM32F051__) + EllduinoSerialArray[usartNum-1].usart_.usart_->USART_BRR_VALUES + ( EllduinoSerialArray[usartNum-1].usart_.usart_ + , USART_BRR_CALLBACK + ); +#elif defined(__STM32F334__) + STM32F334NucleoSerialArray[usartNum-1].usart_.usart_->USART_BRR_VALUES + ( STM32F334NucleoSerialArray[usartNum-1].usart_.usart_ + , USART_BRR_CALLBACK + ); +#endif + } + void t_USART_CR1( int usartNum, CALLBACK(USART_CR1_CALLBACK) ) { +#if defined(__STM32F051__) + EllduinoSerialArray[usartNum-1].usart_.usart_->USART_CR1_VALUES + ( EllduinoSerialArray[usartNum-1].usart_.usart_ + , USART_CR1_CALLBACK + ); +#elif defined(__STM32F334__) + STM32F334NucleoSerialArray[usartNum-1].usart_.usart_->USART_CR1_VALUES + ( STM32F334NucleoSerialArray[usartNum-1].usart_.usart_ + , USART_CR1_CALLBACK + ); +#endif + } + void t_USART_CR2( int usartNum, CALLBACK(USART_CR2_CALLBACK) ) { +#if defined(__STM32F051__) + EllduinoSerialArray[usartNum-1].usart_.usart_->USART_CR2_VALUES + ( EllduinoSerialArray[usartNum-1].usart_.usart_ + , USART_CR2_CALLBACK + ); +#elif defined(__STM32F334__) + STM32F334NucleoSerialArray[usartNum-1].usart_.usart_->USART_CR2_VALUES + ( STM32F334NucleoSerialArray[usartNum-1].usart_.usart_ + , USART_CR2_CALLBACK + ); +#endif + } + void t_USART_CR3( int usartNum, CALLBACK(USART_CR3_CALLBACK) ) { +#if defined(__STM32F051__) + EllduinoSerialArray[usartNum-1].usart_.usart_->USART_CR3_VALUES + ( EllduinoSerialArray[usartNum-1].usart_.usart_ + , USART_CR3_CALLBACK + ); +#elif defined(__STM32F334__) + STM32F334NucleoSerialArray[usartNum-1].usart_.usart_->USART_CR3_VALUES + ( STM32F334NucleoSerialArray[usartNum-1].usart_.usart_ + , USART_CR3_CALLBACK + ); +#endif + } + void t_USART_GTPR( int usartNum, CALLBACK(USART_GTPR_CALLBACK) ) { +#if defined(__STM32F051__) + EllduinoSerialArray[usartNum-1].usart_.usart_->USART_GTPR_VALUES + ( EllduinoSerialArray[usartNum-1].usart_.usart_ + , USART_GTPR_CALLBACK + ); +#elif defined(__STM32F334__) + STM32F334NucleoSerialArray[usartNum-1].usart_.usart_->USART_GTPR_VALUES + ( STM32F334NucleoSerialArray[usartNum-1].usart_.usart_ + , USART_GTPR_CALLBACK + ); +#endif + } + void t_USART_RTOR( int usartNum, CALLBACK(USART_RTOR_CALLBACK) ) { +#if defined(__STM32F051__) + EllduinoSerialArray[usartNum-1].usart_.usart_->USART_RTOR_VALUES + ( EllduinoSerialArray[usartNum-1].usart_.usart_ + , USART_RTOR_CALLBACK + ); +#elif defined(__STM32F334__) + STM32F334NucleoSerialArray[usartNum-1].usart_.usart_->USART_RTOR_VALUES + ( STM32F334NucleoSerialArray[usartNum-1].usart_.usart_ + , USART_RTOR_CALLBACK + ); +#endif + } + void t_USART_RQR( int usartNum, CALLBACK(USART_RQR_CALLBACK) ) { +#if defined(__STM32F051__) + EllduinoSerialArray[usartNum-1].usart_.usart_->USART_RQR_VALUES + ( EllduinoSerialArray[usartNum-1].usart_.usart_ + , USART_RQR_CALLBACK + ); +#elif defined(__STM32F334__) + STM32F334NucleoSerialArray[usartNum-1].usart_.usart_->USART_RQR_VALUES + ( STM32F334NucleoSerialArray[usartNum-1].usart_.usart_ + , USART_RQR_CALLBACK + ); +#endif + } + void t_USART_ISR( int usartNum, CALLBACK(USART_ISR_CALLBACK) ) { +#if defined(__STM32F051__) + EllduinoSerialArray[usartNum-1].usart_.usart_->USART_ISR_VALUES + ( EllduinoSerialArray[usartNum-1].usart_.usart_ + , USART_ISR_CALLBACK + ); +#elif defined(__STM32F334__) + STM32F334NucleoSerialArray[usartNum-1].usart_.usart_->USART_ISR_VALUES + ( STM32F334NucleoSerialArray[usartNum-1].usart_.usart_ + , USART_ISR_CALLBACK + ); +#endif + } + void t_USART_ICR( int usartNum, CALLBACK(USART_ICR_CALLBACK) ) { +#if defined(__STM32F051__) + EllduinoSerialArray[usartNum-1].usart_.usart_->USART_ICR_VALUES + ( EllduinoSerialArray[usartNum-1].usart_.usart_ + , USART_ICR_CALLBACK + ); +#elif defined(__STM32F334__) + STM32F334NucleoSerialArray[usartNum-1].usart_.usart_->USART_ICR_VALUES + ( STM32F334NucleoSerialArray[usartNum-1].usart_.usart_ + , USART_ICR_CALLBACK + ); +#endif + } + void t_USART_RDR( int usartNum, CALLBACK(USART_RDR_CALLBACK) ) { +#if defined(__STM32F051__) + EllduinoSerialArray[usartNum-1].usart_.usart_->USART_RDR_VALUES + ( EllduinoSerialArray[usartNum-1].usart_.usart_ + , USART_RDR_CALLBACK + ); +#elif defined(__STM32F334__) + STM32F334NucleoSerialArray[usartNum-1].usart_.usart_->USART_RDR_VALUES + ( STM32F334NucleoSerialArray[usartNum-1].usart_.usart_ + , USART_RDR_CALLBACK + ); +#endif + } + void t_USART_TDR( int usartNum, CALLBACK(USART_TDR_CALLBACK) ) { +#if defined(__STM32F051__) + EllduinoSerialArray[usartNum-1].usart_.usart_->USART_TDR_VALUES + ( EllduinoSerialArray[usartNum-1].usart_.usart_ + , USART_TDR_CALLBACK + ); +#elif defined(__STM32F334__) + STM32F334NucleoSerialArray[usartNum-1].usart_.usart_->USART_TDR_VALUES + ( STM32F334NucleoSerialArray[usartNum-1].usart_.usart_ + , USART_TDR_CALLBACK + ); +#endif + } +#else +# error "Unknown MCU die. Please define." +#endif +//-------------------------------------------------------------------------------------------------------- + +//-------------------------------------------------------------------------------------------------------- + /* + * C interface for System Control Block (SCB) python callback functions + */ +#if defined(__STM32F407__) || defined(__STM32F334__) + void t_SCB_CPUID( CALLBACK(SCB_CPUID_CALLBACK) ) { + SCB->SCB_CPUID_VALUES(SCB, SCB_CPUID_CALLBACK); + } + void t_SCB_ICSR( CALLBACK(SCB_ICSR_CALLBACK) ) { + SCB->SCB_ICSR_VALUES(SCB, SCB_ICSR_CALLBACK); + } + void t_SCB_VTOR( CALLBACK(SCB_VTOR_CALLBACK) ) { + SCB->SCB_VTOR_VALUES(SCB, SCB_VTOR_CALLBACK); + } +#endif +//-------------------------------------------------------------------------------------------------------- + +//-------------------------------------------------------------------------------------------------------- + /* + * C interface for Power Control (PWR) python callback functions + */ +#if defined(__STM32F407__) + void t_PWR_CR( CALLBACK(PWR_CR_CALLBACK) ) { + PWR->PWR_CR_VALUES(PWR, PWR_CR_CALLBACK); + } +#endif +//-------------------------------------------------------------------------------------------------------- + +//-------------------------------------------------------------------------------------------------------- + /* + * C interface for Power Control (PWR) python callback functions + */ + void t_FLASH_ACR( CALLBACK(FLASH_ACR_CALLBACK) ) { + FLASH->FLASH_ACR_VALUES(FLASH, FLASH_ACR_CALLBACK); + } + void t_FLASH_KEYR( CALLBACK(FLASH_KEYR_CALLBACK) ) { + FLASH->FLASH_KEYR_VALUES(FLASH, FLASH_KEYR_CALLBACK); + } + void t_FLASH_OPTKEYR( CALLBACK(FLASH_OPTKEYR_CALLBACK) ) { + FLASH->FLASH_OPTKEYR_VALUES(FLASH, FLASH_OPTKEYR_CALLBACK); + } + void t_FLASH_SR( CALLBACK(FLASH_SR_CALLBACK) ) { + FLASH->FLASH_SR_VALUES(FLASH, FLASH_SR_CALLBACK); + } + void t_FLASH_CR( CALLBACK(FLASH_CR_CALLBACK) ) { + FLASH->FLASH_CR_VALUES(FLASH, FLASH_CR_CALLBACK); + } +//-------------------------------------------------------------------------------------------------------- + +//-------------------------------------------------------------------------------------------------------- + /* + * C interface for Reset Clock Control (RCC) python callback functions + */ + void t_RCC_CR( CALLBACK(RCC_CR_CALLBACK) ) { + RCC->RCC_CR_VALUES(RCC, RCC_CR_CALLBACK); + } +#if defined(__STM32F407__) + void t_RCC_PLLCFGR( CALLBACK(RCC_PLLCFGR_CALLBACK) ) { + RCC->RCC_PLLCFGR_VALUES(RCC, RCC_PLLCFGR_CALLBACK); + } +#endif + void t_RCC_CFGR( CALLBACK(RCC_CFGR_CALLBACK) ) { + RCC->RCC_CFGR_VALUES(RCC, RCC_CFGR_CALLBACK); + } + void t_RCC_CIR( CALLBACK(RCC_CIR_CALLBACK) ) { + RCC->RCC_CIR_VALUES(RCC, RCC_CIR_CALLBACK); + } + void t_RCC_APB1RSTR( CALLBACK(RCC_APB1RSTR_CALLBACK) ) { + RCC->RCC_APB1RSTR_VALUES(RCC, RCC_APB1RSTR_CALLBACK); + } +#if defined(__STM32F407__) + void t_RCC_AHB1ENR( CALLBACK(RCC_AHB1ENR_CALLBACK) ) { + RCC->RCC_AHB1ENR_VALUES(RCC, RCC_AHB1ENR_CALLBACK); + } +#elif defined(__STM32F051__) || defined(__STM32F334__) + void t_RCC_AHBENR( CALLBACK(RCC_AHBENR_CALLBACK) ) { + RCC->RCC_AHBENR_VALUES(RCC, RCC_AHBENR_CALLBACK); + } +#else +# error "Unknown MCU die. Please define." +#endif + void t_RCC_APB2ENR( CALLBACK(RCC_APB2ENR_CALLBACK) ) { + RCC->RCC_APB2ENR_VALUES(RCC, RCC_APB2ENR_CALLBACK); + } + void t_RCC_APB1ENR( CALLBACK(RCC_APB1ENR_CALLBACK) ) { + RCC->RCC_APB1ENR_VALUES(RCC, RCC_APB1ENR_CALLBACK); + } + void t_RCC_APB2RSTR( CALLBACK(RCC_APB2RSTR_CALLBACK) ) { + RCC->RCC_APB2RSTR_VALUES(RCC, RCC_APB2RSTR_CALLBACK); + } + void t_RCC_BDCR( CALLBACK(RCC_BDCR_CALLBACK) ) { + RCC->RCC_BDCR_VALUES(RCC, RCC_BDCR_CALLBACK); + } + void t_RCC_CSR( CALLBACK(RCC_CSR_CALLBACK) ) { + RCC->RCC_CSR_VALUES(RCC, RCC_CSR_CALLBACK); + } + void t_RCC_AHBRSTR( CALLBACK(RCC_AHBRSTR_CALLBACK) ) { + RCC->RCC_AHBRSTR_VALUES(RCC, RCC_AHBRSTR_CALLBACK); + } + void t_RCC_CFGR2( CALLBACK(RCC_CFGR2_CALLBACK) ) { + RCC->RCC_CFGR2_VALUES(RCC, RCC_CFGR2_CALLBACK); + } + void t_RCC_CFGR3( CALLBACK(RCC_CFGR3_CALLBACK) ) { + RCC->RCC_CFGR3_VALUES(RCC, RCC_CFGR3_CALLBACK); + } + void t_RCC_CR2( CALLBACK(RCC_CR2_CALLBACK) ) { + RCC->RCC_CR2_VALUES(RCC, RCC_CR2_CALLBACK); + } +//-------------------------------------------------------------------------------------------------------- + +//-------------------------------------------------------------------------------------------------------- + /* + * C interface for Timers (TIM) python callback functions + */ + void t_TIM_CR1( int timNum, CALLBACK(TIM_CR1_CALLBACK) ) { + TIM[timNum-1]->TIM_CR1_VALUES(TIM[timNum-1], TIM_CR1_CALLBACK); + } + void t_TIM_CR2( int timNum, CALLBACK(TIM_CR2_CALLBACK) ) { + TIM[timNum-1]->TIM_CR2_VALUES(TIM[timNum-1], TIM_CR2_CALLBACK); + } + void t_TIM_SMCR( int timNum, CALLBACK(TIM_SMCR_CALLBACK) ) { + TIM[timNum-1]->TIM_SMCR_VALUES(TIM[timNum-1], TIM_SMCR_CALLBACK); + } + void t_TIM_DIER( int timNum, CALLBACK(TIM_DIER_CALLBACK) ) { + TIM[timNum-1]->TIM_DIER_VALUES(TIM[timNum-1], TIM_DIER_CALLBACK); + } + void t_TIM_CCMR1( int timNum, CALLBACK(TIM_CCMR1_CALLBACK) ) { + TIM[timNum-1]->TIM_CCMR1_VALUES(TIM[timNum-1], TIM_CCMR1_CALLBACK); + } + void t_TIM_CCMR2( int timNum, CALLBACK(TIM_CCMR2_CALLBACK) ) { + TIM[timNum-1]->TIM_CCMR2_VALUES(TIM[timNum-1], TIM_CCMR2_CALLBACK); + } + void t_TIM_CCER( int timNum, CALLBACK(TIM_CCER_CALLBACK) ) { + TIM[timNum-1]->TIM_CCER_VALUES(TIM[timNum-1], TIM_CCER_CALLBACK); + } + void t_TIM_BDTR( int timNum, CALLBACK(TIM_BDTR_CALLBACK) ) { + TIM[timNum-1]->TIM_BDTR_VALUES(TIM[timNum-1], TIM_BDTR_CALLBACK); + } + void t_TIM_PSC( int timNum, CALLBACK(TIM_PSC_CALLBACK) ) { + TIM[timNum-1]->TIM_PSC_VALUES(TIM[timNum-1], TIM_PSC_CALLBACK); + } + void t_TIM_ARR( int timNum, CALLBACK(TIM_ARR_CALLBACK) ) { + TIM[timNum-1]->TIM_ARR_VALUES(TIM[timNum-1], TIM_ARR_CALLBACK); + } + void t_TIM_CCR1( int timNum, CALLBACK(TIM_CCR1_CALLBACK) ) { + TIM[timNum-1]->TIM_CCR1_VALUES(TIM[timNum-1], TIM_CCR1_CALLBACK); + } + void t_TIM_CCR2( int timNum, CALLBACK(TIM_CCR2_CALLBACK) ) { + TIM[timNum-1]->TIM_CCR2_VALUES(TIM[timNum-1], TIM_CCR2_CALLBACK); + } + void t_TIM_CCR3( int timNum, CALLBACK(TIM_CCR3_CALLBACK) ) { + TIM[timNum-1]->TIM_CCR3_VALUES(TIM[timNum-1], TIM_CCR3_CALLBACK); + } + void t_TIM_CCR4( int timNum, CALLBACK(TIM_CCR4_CALLBACK) ) { + TIM[timNum-1]->TIM_CCR4_VALUES(TIM[timNum-1], TIM_CCR4_CALLBACK); + } +//-------------------------------------------------------------------------------------------------------- + +//######################################################################################################// + }; diff --git a/stm32/tests/test_CoAP_interrupt/Makefile b/stm32/tests/test_CoAP_interrupt/Makefile new file mode 100644 index 0000000..302a88f --- /dev/null +++ b/stm32/tests/test_CoAP_interrupt/Makefile @@ -0,0 +1,28 @@ +# +# Copyright (c) 2013-2014 ELL-i co-operative +# +# Compile and link an application +# + +TOP ?= $(shell pwd)/../../ +MAKEDIR ?= $(TOP)make/ + +APP := test_CoAP_interrupt + +APP_OBJS ?= main.o coap_input.o $(APP).o $(VARIANT).o encX24j600_init.o + +EXTRA_CFLAGS += -DETHERNET=ENCX24J600 -DDEBUG_WRITE=debug_write + +include $(TOP)make/app.mk + +VPATH += ../../libraries/CoAP/src/coap \ + $(TOP)libraries/CoAP/src/encX24j600 \ + $(PWD) + +CXXFLAGS += \ + -I$(TOP)libraries/CoAP/src/coap \ + -I$(TOP)libraries/CoAP/src/netinet \ + -I$(TOP)libraries/CoAP/src/encX24J600 \ + -I$(TOP)libraries/CoAP/src \ + -I$(TOP)libraries/SPI/src \ + diff --git a/stm32/tests/test_CoAP_interrupt/test_CoAP_interrupt.cpp b/stm32/tests/test_CoAP_interrupt/test_CoAP_interrupt.cpp new file mode 100644 index 0000000..5e935cd --- /dev/null +++ b/stm32/tests/test_CoAP_interrupt/test_CoAP_interrupt.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2014 ELL-i co-op. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define DEBUG_LED 4 + +uint8_t address[ETHER_ADDR_LEN]; +uint8_t buffer[2048 + 8/*XXX*/] __attribute__((aligned(8))); +struct ether_header *const ether_header = (struct ether_header *)(buffer+8); + +extern "C" void debug_write(int c) { + Serial.write(c); +} + +void setup() { + pinMode(DEBUG_LED, OUTPUT); + Serial.begin(57600); + Serial.write('B'); + ETHERNET.begin(); + ETHERNET.readEthernetAddr(address); + eth_set_address(address); + ETHERNET.enableInterrupt(PKT_IE); + ETHERNET.enableGlobalInterrupts(); + Serial.write('s'); + Serial.write('\r'); + Serial.write('\n'); +} + +void loop() { + Serial.write('w'); + while (digitalRead(ETHERNET.int_pin_)) + ; + + Serial.write('r'); + digitalWrite(DEBUG_LED, 1); + ETHERNET.receivePacket(&buffer[8], sizeof(buffer) - 8); + Serial.write('.'); + eth_input(ether_header); + digitalWrite(DEBUG_LED, 0); + Serial.write('\r'); + Serial.write('\n'); + +#ifdef EMULATOR + _exit(0); +#endif +} + +#include + +#define HELLO_WORLD "Hello, World!" + +int test_get_callback( + const struct coap_options *input_options, + const uint8_t *input_buffer, size_t input_length, + uint8_t *output_buffer, size_t *output_buffer_length) { + *output_buffer++ = COAP_OPTION_PAYLOAD; + memcpy(output_buffer, HELLO_WORLD, sizeof(HELLO_WORLD)); + *output_buffer_length = sizeof(HELLO_WORLD); // Excludes NUL + return 0; // XXX semantics not fixed yet +} + + +DEFINE_COAP_URL(test, "test", test_get_callback, NULL); diff --git a/stm32/tests/test_CoAP_no_threads/Makefile b/stm32/tests/test_CoAP_no_threads/Makefile new file mode 100644 index 0000000..2e6f6fe --- /dev/null +++ b/stm32/tests/test_CoAP_no_threads/Makefile @@ -0,0 +1,28 @@ +# +# Copyright (c) 2013-2014 ELL-i co-operative +# +# Compile and link an application +# + +TOP ?= $(shell pwd)/../../ +MAKEDIR ?= $(TOP)make/ + +APP := test_CoAP_no_threads + +APP_OBJS ?= main.o coap_input.o $(APP).o $(VARIANT).o encX24j600_init.o + +EXTRA_CFLAGS += -DETHERNET=ENCX24J600 -DDEBUG_WRITE=debug_write + +include $(TOP)make/app.mk + +VPATH += ../../libraries/CoAP/src/coap \ + $(TOP)libraries/CoAP/src/encX24j600 \ + $(PWD) + +CXXFLAGS += \ + -I$(TOP)libraries/CoAP/src/coap \ + -I$(TOP)libraries/CoAP/src/netinet \ + -I$(TOP)libraries/CoAP/src/encX24J600 \ + -I$(TOP)libraries/CoAP/src \ + -I$(TOP)libraries/SPI/src \ + diff --git a/stm32/tests/test_CoAP_no_threads/test_CoAP_no_threads.cpp b/stm32/tests/test_CoAP_no_threads/test_CoAP_no_threads.cpp new file mode 100644 index 0000000..87f3fc4 --- /dev/null +++ b/stm32/tests/test_CoAP_no_threads/test_CoAP_no_threads.cpp @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2014 ELL-i co-op. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define DEBUG_LED 4 + +uint8_t address[ETHER_ADDR_LEN]; +uint8_t buffer[2048 + 8/*XXX*/] __attribute__((aligned(8))); +struct ether_header *const ether_header = (struct ether_header *)(buffer+8); + +extern "C" void debug_write(int c) { + Serial.write(c); +} + +void setup() { + pinMode(DEBUG_LED, OUTPUT); + Serial.begin(57600); + Serial.write('B'); + ETHERNET.begin(); + ETHERNET.readEthernetAddr(address); + eth_set_address(address); + Serial.write('s'); +} + +void loop() { + Serial.write('w'); + while (!(ETHERNET.availablePackets())) + ; + + Serial.write('r'); + digitalWrite(DEBUG_LED, 1); + ETHERNET.receivePacket(&buffer[8], sizeof(buffer) - 8); + Serial.write('.'); + eth_input(ether_header); + digitalWrite(DEBUG_LED, 0); + + +#ifdef EMULATOR + _exit(0); +#endif +} + +#include + +#define HELLO_WORLD "Hello, World!" + +int test_get_callback( + const struct coap_options *input_options, + const uint8_t *input_buffer, size_t input_length, + uint8_t *output_buffer, size_t *output_buffer_length) { + *output_buffer++ = COAP_OPTION_PAYLOAD; + memcpy(output_buffer, HELLO_WORLD, sizeof(HELLO_WORLD)); + *output_buffer_length = sizeof(HELLO_WORLD); // Excludes NUL + return 0; // XXX semantics not fixed yet +} + + +DEFINE_COAP_URL(test, "test", test_get_callback, NULL); diff --git a/stm32/tests/test_ENCX24J600_begin/Makefile b/stm32/tests/test_ENCX24J600_begin/Makefile new file mode 100644 index 0000000..38297f0 --- /dev/null +++ b/stm32/tests/test_ENCX24J600_begin/Makefile @@ -0,0 +1,25 @@ +# +# Copyright (c) 2014 ELL-i co-operative +# +# Compile and link an application +# + +TOP ?= $(shell pwd)/../../ +MAKEDIR ?= $(TOP)make/ + +APP := test_ENCX24J600_begin + +APP_OBJS ?= main.o $(APP).o $(VARIANT).o encX24j600_init.o + +include $(TOP)make/app.mk + +VPATH += \ + $(TOP)libraries/CoAP/src/coap \ + $(TOP)libraries/CoAP/src/encX24j600 \ + $(PWD) + +CXXFLAGS += \ + -I$(TOP)libraries/CoAP/src/encX24J600 \ + -I$(TOP)libraries/CoAP/src \ + -I$(TOP)libraries/SPI/src \ + diff --git a/stm32/tests/test_ENCX24J600_begin/test_ENCX24J600_begin.cpp b/stm32/tests/test_ENCX24J600_begin/test_ENCX24J600_begin.cpp new file mode 100644 index 0000000..c5075cc --- /dev/null +++ b/stm32/tests/test_ENCX24J600_begin/test_ENCX24J600_begin.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2014 ELL-i co-op. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +#include +#include + +#ifdef EMULATOR +#include +#endif + +#define DEBUG 4 + +void setup() { + pinMode(DEBUG, OUTPUT); + digitalWrite(DEBUG, 0); + Serial.begin(57600); + ENCX24J600.begin(); +} + +void loop() { + digitalWrite(DEBUG, 1); +#ifdef EMULATOR + _exit(0); +#endif +} diff --git a/stm32/tests/test_ENCX24J600_receive/Makefile b/stm32/tests/test_ENCX24J600_receive/Makefile new file mode 100644 index 0000000..ef2568d --- /dev/null +++ b/stm32/tests/test_ENCX24J600_receive/Makefile @@ -0,0 +1,26 @@ +# +# Copyright (c) 2014 ELL-i co-operative +# +# Compile and link an application +# + +TOP ?= $(shell pwd)/../../ +MAKEDIR ?= $(TOP)make/ + +APP := test_ENCX24J600_receive + +APP_OBJS ?= main.o $(APP).o $(VARIANT).o encX24j600_init.o + +include $(TOP)make/app.mk + +VPATH += \ + $(TOP)libraries/CoAP/src/coap \ + $(TOP)libraries/CoAP/src/encX24j600 \ + $(PWD) + +CXXFLAGS += \ + -I$(TOP)libraries/CoAP/src/netinet \ + -I$(TOP)libraries/CoAP/src/encX24J600 \ + -I$(TOP)libraries/CoAP/src \ + -I$(TOP)libraries/SPI/src \ + diff --git a/stm32/tests/test_ENCX24J600_receive/test_ENCX24J600_receive.cpp b/stm32/tests/test_ENCX24J600_receive/test_ENCX24J600_receive.cpp new file mode 100644 index 0000000..1e25537 --- /dev/null +++ b/stm32/tests/test_ENCX24J600_receive/test_ENCX24J600_receive.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2014 ELL-i co-op. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +#include +#include + +#ifdef EMULATOR +#include +#endif + +#include +#include +#include + +uint8_t buffer[2048 + 8/*XXX*/] __attribute__((aligned(8))); + +#define DEBUG 4 + +void setup() { + pinMode(DEBUG, OUTPUT); + digitalWrite(DEBUG, 1); + Serial.begin(57600); + Serial.write('B'); + ENCX24J600.begin(); + digitalWrite(DEBUG, 0); +} + +void loop() { + while (ENCX24J600.availablePackets() <= 0) + ; + digitalWrite(DEBUG, 1); + Serial.write('r'); + ENCX24J600.receivePacket(buffer + 8, sizeof(buffer) - 8); + Serial.write('o'); + digitalWrite(DEBUG, 0); +#ifdef EMULATOR + _exit(0); +#endif +} diff --git a/stm32/tests/test_ENCX24J600_send/Makefile b/stm32/tests/test_ENCX24J600_send/Makefile new file mode 100644 index 0000000..5d0bf65 --- /dev/null +++ b/stm32/tests/test_ENCX24J600_send/Makefile @@ -0,0 +1,26 @@ +# +# Copyright (c) 2014 ELL-i co-operative +# +# Compile and link an application +# + +TOP ?= $(shell pwd)/../../ +MAKEDIR ?= $(TOP)make/ + +APP := test_ENCX24J600_send + +APP_OBJS ?= main.o $(APP).o $(VARIANT).o encX24j600_init.o + +include $(TOP)make/app.mk + +VPATH += \ + $(TOP)libraries/CoAP/src/coap \ + $(TOP)libraries/CoAP/src/encX24j600 \ + $(PWD) + +CXXFLAGS += \ + -I$(TOP)libraries/CoAP/src/netinet \ + -I$(TOP)libraries/CoAP/src/encX24J600 \ + -I$(TOP)libraries/CoAP/src \ + -I$(TOP)libraries/SPI/src \ + diff --git a/stm32/tests/test_ENCX24J600_send/test_ENCX24J600_send.cpp b/stm32/tests/test_ENCX24J600_send/test_ENCX24J600_send.cpp new file mode 100644 index 0000000..1ddbb45 --- /dev/null +++ b/stm32/tests/test_ENCX24J600_send/test_ENCX24J600_send.cpp @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2014 ELL-i co-op. + * + * This is part of ELL-i software. + * + * ELL-i software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ELL-i software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ELL-i software. If not, see . + */ + +#include +#include + +#ifdef EMULATOR +#include +#endif + +#include +#include +#include + +struct { + char extra_space[2]; + struct ether_header_real eth; + struct ip ip; + struct udp udp; +} __attribute__((packed)) _mockup_packet = { + IF(extra_space) { '\0', '\0' }, + IF(eth) { + IF(ether_dhost) { 1, 2, 3, 4, 5, 6 }, // XXX TBD + IF(ether_shost) { 10, 11, 12, 13, 14, 15 }, + IF(ether_type ) CONSTEXPR_HTONS(ETHERTYPE_IP), + }, + IF(ip) { + IF(ip_vhl ) IP_VHL_DEFAULT, + IF(ip_tos ) 0, + IF(ip_len ) CONSTEXPR_HTONS(sizeof(ip) + sizeof(udp)), + IF(ip_id ) CONSTEXPR_HTONS(0x4321), + { IF(ip_off ) 0, }, + IF(ip_ttl ) 1, + IF(ip_p ) IPPROTO_UDP, + IF(ip_sum ) CONSTEXPR_HTONS(0x62ae), + IF(ip_src ) { { IF(s_bytes) { 10, 0, 0, 1 } } }, + IF(ip_dst ) { { IF(s_bytes) { 10, 0, 0, 2 } } }, + }, + IF(udp) { + IF(udp_sport) CONSTEXPR_HTONS('s'), + IF(udp_dport) CONSTEXPR_HTONS(UDP_PORT_ECHO), + IF(udp_len ) CONSTEXPR_HTONS(sizeof(udp)), + IF(udp_sum ) 0, + }, +}; + +uint8_t *const mockup_packet = (unsigned char *)&(_mockup_packet.eth); +const uint16_t mockup_packet_size = sizeof(_mockup_packet) - sizeof(_mockup_packet.extra_space); + +void setup() { + Serial.begin(57600); + ENCX24J600.begin(); +} + +void loop() { + ENCX24J600.sendPacket(mockup_packet, mockup_packet_size); +#ifdef EMULATOR + _exit(0); +#endif +} diff --git a/stm32/variants/stm32f334nucleo/ld/flash.ld b/stm32/variants/stm32f334nucleo/ld/flash.ld index e1d9df3..b819dd6 100644 --- a/stm32/variants/stm32f334nucleo/ld/flash.ld +++ b/stm32/variants/stm32f334nucleo/ld/flash.ld @@ -61,6 +61,22 @@ SECTIONS KEEP (*(SORT(.peripheral.*))) /* Read-only peripheral initialisation data */ __peripheral_end = .; + /* + * XXX + */ + . = ALIGN(16); + __udp_sockets = .; + KEEP (*(.socket.udp.*)) /* Read-only UDP socket data structures */ + __udp_sockets_end = .; + + /* + * XXX + */ + . = ALIGN(16); + __coap_urls = .; + KEEP (*(.coap.url*)) /* Read-only UDP socket data structures */ + __coap_urls_end = .; + /* * The following sections are needed to jump from ARM code to Thumb * ocde and vice versa. They are not needed in Cortex-M0, but they diff --git a/stm32/variants/stm32f334nucleo/stm32f334nucleo_gpio.h b/stm32/variants/stm32f334nucleo/stm32f334nucleo_gpio.h index 510b286..20d7157 100644 --- a/stm32/variants/stm32f334nucleo/stm32f334nucleo_gpio.h +++ b/stm32/variants/stm32f334nucleo/stm32f334nucleo_gpio.h @@ -155,7 +155,7 @@ DEFINE_GPIO_PIN_DUMMY(F, 15); static const struct GPIO GPIOPIN[] = { DEFINE_GPIO_PIN(A, 3), /* 0 PA3 D0 RX2 */ DEFINE_GPIO_PIN(A, 2), /* 1 PA2 D1 TX2 */ - DEFINE_GPIO_PIN(A, 10), /* 2 PA10 D2 */ + DEFINE_GPIO_PIN(C, 10), /* 2 PA10 D2 */ DEFINE_GPIO_PIN(B, 3), /* 3 PB3 D3 TIM2_CH2 */ DEFINE_GPIO_PIN(B, 5), /* 4 PB5 D4 */ DEFINE_GPIO_PIN(B, 4), /* 5 PB3 D5 TIM3_CH1 */ @@ -181,6 +181,7 @@ static const struct GPIO GPIOPIN[] = { DEFINE_GPIO_PIN(C, 1), /* 58 PC1 A4 ADC1_7*/ DEFINE_GPIO_PIN(C, 0), /* 59 PC0 A5 ADC1_6 */ #endif + DEFINE_GPIO_PIN(D, 2), /* 22 PD2 PoElli ENCX24J600 INT */ }; #endif //_STM32F334NUCLEO_GPIO_H_ diff --git a/stm32/variants/stm32f4discovery/stm32f4discovery_gpio.h b/stm32/variants/stm32f4discovery/stm32f4discovery_gpio.h index 457e5a8..655ae07 100644 --- a/stm32/variants/stm32f4discovery/stm32f4discovery_gpio.h +++ b/stm32/variants/stm32f4discovery/stm32f4discovery_gpio.h @@ -250,6 +250,7 @@ static const struct GPIO GPIOPIN[] = { DEFINE_GPIO_PIN(C, 1), /* 58 PC1 A4 ADC1_11*/ DEFINE_GPIO_PIN(C, 0), /* 59 PC0 A5 ADC1_10 */ #endif + DEFINE_GPIO_PIN(C, 11), /* XXX Modify with real value / PoElli ENCX24J600 INT */ }; #endif //_STM32F4DISCOVERY_GPIO_H_