Hello, I have this struct that tells me what kind of interrupt numbers are valid.
InterruptVectorTable.hpp
struct ValidIRQTypes
{
ValueType m_size;
ValueType m_ValidTypes[];
inline ValueType size() { return m_size; };
/**
* @brief Binary search to check if the given index is valid.
*
* @param InterruptNumber
* @return true
* @return false
*/
bool IsValidIRQType(const ValueType InterruptNumber) const
{
/**
* @brief Binary search
*/
ValueType i = 0;
ValueType j = m_size - 1;
if (InterruptNumber == m_ValidTypes[i] || InterruptNumber == m_ValidTypes[j])
return true;
else if (InterruptNumber < m_ValidTypes[i] || m_ValidTypes[j] < InterruptNumber)
return false;
ValueType mid = 0;
ValueType midValue = 0;
while (i < j)
{
mid = i + (j - i) / 2;
midValue = m_ValidTypes[mid];
if (InterruptNumber <= midValue)
j = mid - 1;
else
i = mid + 1;
}
return InterruptNumber == midValue;
}
};
class InterruptVectorTable
{
/**
* @brief
* Singleton design pattern:
* https://stackoverflow.com/questions/1008019/c-singleton-design-pattern
*/
private:
/**
* @brief Construct a new Interrupt Vector Table object
*/
InterruptVectorTable();
/**
* @brief Destroy the Interrupt Vector Table object
*/
~InterruptVectorTable();
/**
* @brief This vector pointer needs to point to the Vector Table.
* The vector Table needs to have the explicit size of VectorsCount of the ValueType.
* The behaviour is undefined if the vector is accessed from with offsets that are not within the
* range [0:VectorsCount]
*/
ValueType* m_VectorTable;
/**
* @brief Checks whether the given IRQNumber is valid.
*
* @param InterruptNumber
* @return true Is valid
* @return false Is not valid
*/
public:
enum IRQTypes : ValueType; // forward declaration of enums with type/size specification.
const static ValidIRQTypes s_ValidIRQTypes;
bool IsValidIRQType(const ValueType IRQNumber) { return s_ValidIRQTypes.IsValidIRQType(IRQNumber); };
/**
* @brief Deleted copy constructor
*/
InterruptVectorTable(InterruptVectorTable const&) = delete;
/**
* @brief Deleted asignment operator
*/
void operator=(InterruptVectorTable const&) = delete;
/**
* @brief Get the Singleton instance
* Aftr this instance has ben created, interrupts are enabled by default.
*
* @return InterruptVectorTable&
*/
static InterruptVectorTable& getInstance()
{
static InterruptVectorTable instance; // Guaranteed to be destroyed.
// Instantiated on first use.
return instance;
}
/**
* @brief
*
* @param InterruptNumber
* @param Callback Function to be called, when the Interrupt is
*/
bool setCallback(ValueType InterruptNumber, void (*Callback)(void));
/**
* @brief Enables interrupts globally
*/
void enableIRQ();
/**
* @brief Disables Interrupts globally.
*/
void disableIRQ();
/**
* @brief Disable interrupt at given InterruptNumber
*
* @param InterruptNumber interrupt InterruptNumber, as defined in the manuals: >= 0
*/
void enableISR(ValueType InterruptNumber);
/**
* @brief Disable an interrupt / interrupt service routine
*
* @param InterruptNumber Is the InterruptNumber of the interrupt within the interrupt vctor table.
* Should be a ValueType greater than or equal to 0.
*/
void disableISR(ValueType InterruptNumber);
/**
* @brief Triggers a software interrupt request
*
* @param InterruptNumber
*/
void triggerIRQ(ValueType InterruptNumber);
};
Depending on the target a different InterruptVectorTable.cpp is compiled.
The LPC1768 has this here:
#include "LPC17xx.h"
#include "InterruptTypes.hpp"
#include <hal/InterruptVectorTable.hpp>
#include <cstring>
const ValidIRQTypes InterruptVectorTable::s_ValidIRQTypes = {
35,
{
0, 1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12, 13,
14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27,
28, 29, 30, 31, 32, 33, 34
}
};
...
The STM32F407VG has this implementation:
#include "stm32f4xx.h"
#include <hal/InterruptVectorTable.hpp>
#include <cstring>
#include "InterruptTypes.hpp"
const ValidIRQTypes InterruptVectorTable::s_ValidIRQTypes = {
82,
{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 24, 25, 26, 27,
28, 29, 30, 31, 32, 33, 34, 35, 36,
37, 38, 39, 40, 41, 42, 43, 44, 45,
46, 47, 48, 49, 50, 51, 52, 53, 54,
55, 56, 57, 58, 59, 60, 61, 62, 63,
64, 65, 66, 67, 68, 69, 70, 71, 72,
73, 74, 75, 76, 77, 78, 79, 80, 81
}
};
...
and the ATmega328p has basically the same initializer list:
#include <string.h>
#include <hal/InterruptVectorTable.hpp>
#include "InterruptTypes.hpp"
/**
* @brief List of valid IRQ Index numbers
*
*/
const ValidIRQTypes InterruptVectorTable::s_ValidIRQTypes = {
25,
{
1, 2, 3, 4, 5,
6, 7, 8, 9, 10,
11, 12, 13, 14, 15,
16, 17, 18, 19, 20,
21, 22, 23, 24, 25
}
};
...
except that it does not compile and seems to not properly deduce the correct size
src/target/MYAVR_BOARD_MK2/InterruptVectorTable.cpp:20:1: error: too many initializers for 'ValueType [0] {aka unsigned char [0]}'
It basically tells me that the deduced size is 0.
Does anyone know, how one would fix this on AVR-GCC?