I have a Firmware project, developed in C++, where all driver are made with a class and there isn't a simply way to modify them.
the drivers are for internal peripheral of the uP and are implemented by a global instance of the class; now I must modify that function and allow a " re init" of the driver in a exception case or similar.
tha initialization of the driver is made in the constructor of the driver (is implemented in this way and I can't modify it) and there isn't an explicit way (a specific method or similar) to re call that funtions. So I need to force to recall the constructor of the class. It is not a problem to lose all information of the instance, so it is possible to delete the instance and remake it.
for example a part of the code is similar to that (from Mbed library):
class SPI {
public:
SPI(PinName mosi, PinName miso, PinName sclk, PinName ssel=NC);
void format(int bits, int mode = 0);
[.....]
~SPI()
}
in other part of the code there is a global instance of that:
SPI SPI_Master(P0_9, P0_8, P0_7);
void funcA(int b){
}
so there is a way in a function to do something similar:
void SPIException(){
delete SPI_Master;
SPI_Master = new SPI (P0_9, P0_8, P0_7);
}
So to force constructor to be recalled?
and a little clarification:
SPI SPI_Master(P0_9, P0_8, P0_7);
is perfect identical to:
SPI SPI_Master = new SPI(P0_9, P0_8, P0_7);
?