Beschreibung
This commit is contained in:
parent
aa5aeff9d1
commit
c09e5b5b48
30
control/examples/register2/Makefile
Normal file
30
control/examples/register2/Makefile
Normal file
|
@ -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 $@
|
40
control/examples/register2/main.cpp
Normal file
40
control/examples/register2/main.cpp
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
#include <b15f/b15f.h>
|
||||||
|
#include <b15f/plottyfile.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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<size_t>(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;
|
||||||
|
|
||||||
|
}
|
|
@ -508,6 +508,22 @@ uint8_t B15F::getRegister(volatile uint8_t* adr)
|
||||||
return getMem8(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<uint8_t *>(&aw), 0, sizeof(aw));
|
||||||
|
return reinterpret_cast<uint16_t*>(aw);
|
||||||
|
}
|
||||||
|
|
||||||
/*************************/
|
/*************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -229,7 +229,6 @@ public:
|
||||||
* \param adr Speicheradresse
|
* \param adr Speicheradresse
|
||||||
* \param val Neuer Wert für die Zelle
|
* \param val Neuer Wert für die Zelle
|
||||||
* \return true, falls Vorgang erfolgreich
|
* \return true, falls Vorgang erfolgreich
|
||||||
* \throws DriverException
|
|
||||||
*/
|
*/
|
||||||
bool setMem8(volatile uint8_t* adr, uint8_t val);
|
bool setMem8(volatile uint8_t* adr, uint8_t val);
|
||||||
|
|
||||||
|
@ -238,7 +237,6 @@ public:
|
||||||
* Diese kann ein Register oder RAM-Daten sein.
|
* Diese kann ein Register oder RAM-Daten sein.
|
||||||
* \param adr Speicheradresse
|
* \param adr Speicheradresse
|
||||||
* \return Wert der Speicherzelle
|
* \return Wert der Speicherzelle
|
||||||
* \throws DriverException
|
|
||||||
*/
|
*/
|
||||||
uint8_t getMem8(volatile uint8_t* adr);
|
uint8_t getMem8(volatile uint8_t* adr);
|
||||||
|
|
||||||
|
@ -249,7 +247,6 @@ public:
|
||||||
* \param adr Speicheradresse
|
* \param adr Speicheradresse
|
||||||
* \param val Neuer Wert für die Zelle
|
* \param val Neuer Wert für die Zelle
|
||||||
* \return true, falls Vorgang erfolgreich
|
* \return true, falls Vorgang erfolgreich
|
||||||
* \throws DriverException
|
|
||||||
*/
|
*/
|
||||||
bool setMem16(volatile uint16_t* adr, uint16_t val);
|
bool setMem16(volatile uint16_t* adr, uint16_t val);
|
||||||
|
|
||||||
|
@ -258,7 +255,6 @@ public:
|
||||||
* Diese kann ein Register oder RAM-Daten sein.
|
* Diese kann ein Register oder RAM-Daten sein.
|
||||||
* \param adr Speicheradresse
|
* \param adr Speicheradresse
|
||||||
* \return Wert der Speicherzelle
|
* \return Wert der Speicherzelle
|
||||||
* \throws DriverException
|
|
||||||
*/
|
*/
|
||||||
uint16_t getMem16(volatile uint16_t* adr);
|
uint16_t getMem16(volatile uint16_t* adr);
|
||||||
|
|
||||||
|
@ -268,7 +264,6 @@ public:
|
||||||
* \param adr Speicheradresse
|
* \param adr Speicheradresse
|
||||||
* \param val Neuer Wert für das Register
|
* \param val Neuer Wert für das Register
|
||||||
* \return true, falls Vorgang erfolgreich
|
* \return true, falls Vorgang erfolgreich
|
||||||
* \throws DriverException
|
|
||||||
*/
|
*/
|
||||||
bool setRegister(volatile uint8_t* adr, uint8_t val);
|
bool setRegister(volatile uint8_t* adr, uint8_t val);
|
||||||
|
|
||||||
|
@ -276,9 +271,14 @@ public:
|
||||||
* Diese Funktion ist ein Alias für getMem8().
|
* Diese Funktion ist ein Alias für getMem8().
|
||||||
* \param adr Speicheradresse
|
* \param adr Speicheradresse
|
||||||
* \return Wert des Registers
|
* \return Wert des Registers
|
||||||
* \throws DriverException
|
|
||||||
*/
|
*/
|
||||||
uint8_t getRegister(volatile uint8_t* adr);
|
uint8_t getRegister(volatile uint8_t* adr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Liefert die Adresse des ersten Interrupt Counters (BASISR).
|
||||||
|
* \return Adresse (in der MCU)
|
||||||
|
*/
|
||||||
|
uint16_t* getInterruptCounterOffset(void);
|
||||||
|
|
||||||
/*************************/
|
/*************************/
|
||||||
|
|
||||||
|
|
|
@ -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_GET_MEM_8 = 17;
|
||||||
constexpr static uint8_t RQ_SET_MEM_16 = 18;
|
constexpr static uint8_t RQ_SET_MEM_16 = 18;
|
||||||
constexpr static uint8_t RQ_GET_MEM_16 = 19;
|
constexpr static uint8_t RQ_GET_MEM_16 = 19;
|
||||||
|
constexpr static uint8_t RQ_COUNTER_OFFSET = 20;
|
||||||
|
|
||||||
uint8_t const rq_len[] = {
|
uint8_t const rq_len[] = {
|
||||||
1 /* RQ_DISCARD */,
|
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_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_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_GET_MEM_16 */ + 1 /* memory address low */ + 1 /* memory address high */,
|
||||||
|
1 /* RQ_COUNTER_OFFSET */,
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // REQUESTS_H
|
#endif // REQUESTS_H
|
||||||
|
|
Loading…
Reference in a new issue