From c09e5b5b48175f57d08cb41606c8fb09c2790a40 Mon Sep 17 00:00:00 2001 From: Tristan Krause Date: Tue, 25 Jun 2019 11:02:08 +0200 Subject: [PATCH] Beschreibung --- control/examples/register2/Makefile | 30 ++++++++++++++++++++++ control/examples/register2/main.cpp | 40 +++++++++++++++++++++++++++++ control/src/drv/b15f.cpp | 16 ++++++++++++ control/src/drv/b15f.h | 12 ++++----- control/src/drv/requests.h | 2 ++ 5 files changed, 94 insertions(+), 6 deletions(-) create mode 100644 control/examples/register2/Makefile create mode 100644 control/examples/register2/main.cpp diff --git a/control/examples/register2/Makefile b/control/examples/register2/Makefile new file mode 100644 index 0000000..8000d6e --- /dev/null +++ b/control/examples/register2/Makefile @@ -0,0 +1,30 @@ +# Name: Makefile +# Project: B15F (board15 Famulus Edition) +# Author: Tristan Krause +# Creation Date: 2019-05-15 + +# Environment +COMPILER_PATH = g++ + +# Options +CFLAGS = -std=c++17 -O3 -Wall -Wextra +LDFLAGS = -lb15fdrv +OBJECTS = main.o +OUT = main.elf + +COMPILE = $(COMPILER_PATH) $(CFLAGS) + +main: $(OBJECTS) + $(COMPILE) $(OBJECTS) -o $(OUT) $(LDFLAGS) + +help: + @echo "This Makefile has the following targets:" + @echo "make main .... to compile" + @echo "make clean ... to delete objects and executables" + +clean: + @echo "Cleaning..." + rm -f $(OBJECTS) $(OUT) *.bin gnuplotscript.gp + +.cpp.o: + $(COMPILE) -c $< -o $@ diff --git a/control/examples/register2/main.cpp b/control/examples/register2/main.cpp new file mode 100644 index 0000000..4ac1f91 --- /dev/null +++ b/control/examples/register2/main.cpp @@ -0,0 +1,40 @@ +#include +#include + +/* + * Dieses Beispiel liest ein par Interrupt Counter aus. + * Die Counter sind 16-Bit groß und in einem Feld. + * Die Vector Nummer ist gleich die Counter-Nummer im Feld. + * Ausname: Vector 0 (Reset). Dieser ist im Feld stattdessen der BADISR-Interrupt + */ +int main() +{ + uint8_t tmp; + B15F& drv = B15F::getInstance(); + + // INT2 für falling edge + tmp = drv.getRegister(&EICRA); + tmp |= _BV(ISC21); + drv.setRegister(&EICRA, tmp); + + // aktiviere INT2 + tmp = drv.getRegister(&EIMSK); + tmp |= _BV(INT2); + drv.setRegister(&EIMSK, tmp); + + // ab jetzt sollte kann man INT2 mit einem Pullup/Pulldown Widerstand betreiben. + // Nachdem man eine Flanke auf INT2 gegeben hat und dieses Programm erneut aufruft, siehtman wie counter[INT2] hochzählt. + + // Erhalte Adress-Offset zum ersten Counter. + uint16_t* cnt = drv.getInterruptCounterOffset(); + std::cout << "mem offset: " << reinterpret_cast(cnt) << std::endl; + + // gib beispielhaft ein par Counter aus: + std::cout << "counter[BADISR]: " << (int) drv.getMem16(cnt) << std::endl; + std::cout << "counter[INT0]: " << (int) drv.getMem16(cnt + 1) << std::endl; + std::cout << "counter[INT1]: " << (int) drv.getMem16(cnt + 2) << std::endl; + std::cout << "counter[INT2]: " << (int) drv.getMem16(cnt + 3) << std::endl; + std::cout << "counter[ANALOG_COMP]: " << (int) drv.getMem16(cnt + 23) << std::endl; + std::cout << "counter[TIMER3_OVF]: " << (int) drv.getMem16(cnt + 34) << std::endl; + +} diff --git a/control/src/drv/b15f.cpp b/control/src/drv/b15f.cpp index b2c7c77..a4f522d 100644 --- a/control/src/drv/b15f.cpp +++ b/control/src/drv/b15f.cpp @@ -508,6 +508,22 @@ uint8_t B15F::getRegister(volatile uint8_t* adr) return getMem8(adr); } +uint16_t* B15F::getInterruptCounterOffset() +{ + usart.clearInputBuffer(); + + uint8_t rq[] = + { + RQ_COUNTER_OFFSET + }; + + usart.transmit(&rq[0], 0, sizeof(rq)); + + uint16_t aw; + usart.receive(reinterpret_cast(&aw), 0, sizeof(aw)); + return reinterpret_cast(aw); +} + /*************************/ diff --git a/control/src/drv/b15f.h b/control/src/drv/b15f.h index 99ce192..1a03701 100644 --- a/control/src/drv/b15f.h +++ b/control/src/drv/b15f.h @@ -229,7 +229,6 @@ public: * \param adr Speicheradresse * \param val Neuer Wert für die Zelle * \return true, falls Vorgang erfolgreich - * \throws DriverException */ bool setMem8(volatile uint8_t* adr, uint8_t val); @@ -238,7 +237,6 @@ public: * Diese kann ein Register oder RAM-Daten sein. * \param adr Speicheradresse * \return Wert der Speicherzelle - * \throws DriverException */ uint8_t getMem8(volatile uint8_t* adr); @@ -249,7 +247,6 @@ public: * \param adr Speicheradresse * \param val Neuer Wert für die Zelle * \return true, falls Vorgang erfolgreich - * \throws DriverException */ bool setMem16(volatile uint16_t* adr, uint16_t val); @@ -258,7 +255,6 @@ public: * Diese kann ein Register oder RAM-Daten sein. * \param adr Speicheradresse * \return Wert der Speicherzelle - * \throws DriverException */ uint16_t getMem16(volatile uint16_t* adr); @@ -268,7 +264,6 @@ public: * \param adr Speicheradresse * \param val Neuer Wert für das Register * \return true, falls Vorgang erfolgreich - * \throws DriverException */ bool setRegister(volatile uint8_t* adr, uint8_t val); @@ -276,9 +271,14 @@ public: * Diese Funktion ist ein Alias für getMem8(). * \param adr Speicheradresse * \return Wert des Registers - * \throws DriverException */ uint8_t getRegister(volatile uint8_t* adr); + + /** + * Liefert die Adresse des ersten Interrupt Counters (BASISR). + * \return Adresse (in der MCU) + */ + uint16_t* getInterruptCounterOffset(void); /*************************/ diff --git a/control/src/drv/requests.h b/control/src/drv/requests.h index 3a6beb4..24a2dc4 100644 --- a/control/src/drv/requests.h +++ b/control/src/drv/requests.h @@ -21,6 +21,7 @@ constexpr static uint8_t RQ_SET_MEM_8 = 16; constexpr static uint8_t RQ_GET_MEM_8 = 17; constexpr static uint8_t RQ_SET_MEM_16 = 18; constexpr static uint8_t RQ_GET_MEM_16 = 19; +constexpr static uint8_t RQ_COUNTER_OFFSET = 20; uint8_t const rq_len[] = { 1 /* RQ_DISCARD */, @@ -43,6 +44,7 @@ uint8_t const rq_len[] = { 1 /* RQ_GET_MEM_8 */ + 1 /* memory address low */ + 1 /* memory address high */, 1 /* RQ_SET_MEM_16 */ + 1 /* memory address low */ + 1 /* memory address high */ + 1 /* memory value low */ + 1 /* memory value high */, 1 /* RQ_GET_MEM_16 */ + 1 /* memory address low */ + 1 /* memory address high */, + 1 /* RQ_COUNTER_OFFSET */, }; #endif // REQUESTS_H