Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#237 - remove all non inline and template code from headers. #245

Merged
merged 7 commits into from
Sep 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ set(H_FILES

set(MK404_SOURCES
parts/Board.cpp
parts/I2CPeripheral.cpp
parts/boards/EinsyRambo.cpp
parts/boards/MiniRambo.cpp
parts/boards/MM_Control_01.cpp
Expand All @@ -153,6 +154,7 @@ set(MK404_SOURCES
parts/components/Button.cpp
parts/components/EEPROM.cpp
parts/components/Fan.cpp
parts/components/GLHelper.cpp
parts/components/GCodeSniffer.cpp
parts/components/HC595.cpp
parts/components/HD44780.cpp
Expand All @@ -162,6 +164,7 @@ set(MK404_SOURCES
parts/components/LED.cpp
parts/components/MMU1.cpp
parts/components/MMU2.cpp
parts/components/PAT9125.cpp
parts/components/PINDA.cpp
parts/components/RotaryEncoder.cpp
parts/components/SDCard.cpp
Expand All @@ -177,16 +180,27 @@ set(MK404_SOURCES
parts/printers/Prusa_MK25_13.cpp
parts/printers/Prusa_MK25S_13.cpp
parts/printers/Prusa_MK2MMU_13.cpp
parts/printers/Prusa_MK3.cpp
parts/printers/Prusa_MK3MMU2.cpp
parts/printers/Prusa_MK3S.cpp
parts/printers/Prusa_MK3SMMU2.cpp
parts/printers/Test_Printer.cpp
parts/IScriptable.cpp
parts/Printer.cpp
parts/PrinterFactory.cpp
parts/Scriptable.cpp
parts/ScriptHost.cpp
parts/SoftPWMable.cpp
parts/TelemetryHost.cpp
utility/MK3S_Bear.cpp
utility/MK3S_Full.cpp
utility/MK3S_Lite.cpp
utility/MK3SGL.cpp
utility/GLObj.cpp
utility/FatImage.cpp
utility/GLPrint.cpp
utility/Color.cpp
utility/OBJCollection.cpp
utility/SerialPipe.cpp
3rdParty/arcball/Camera.cpp
parts/IKeyClient.cpp
Expand Down Expand Up @@ -232,6 +246,17 @@ ExternalProject_Add(simavr

)

add_custom_target(clean-simavr
COMMAND cd ${PROJECT_SOURCE_DIR}/3rdParty/simavr && make clean
)

add_custom_target(clean-all
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND make clean
DEPENDS clean-simavr
)


add_dependencies(MK404 simavr)

set (LIBSIMAVR ${PROJECT_SOURCE_DIR}/3rdParty/simavr/simavr/obj-${SIMAVR_BIN_DIR}/libsimavr.a)
Expand Down
2 changes: 1 addition & 1 deletion MK404.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void timerCB(int i)
{
glutReshapeWindow(iWinW, iWinH);
}
glutTimerFunc(50, timerCB, i);
glutTimerFunc(25, timerCB, i);
glutPostRedisplay();
}

Expand Down
2 changes: 1 addition & 1 deletion parts/ADCPeripheral.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ADCPeripheral: public BasePeripheral
{
protected:
// Returns the current mux number for this peripheral
uint8_t GetMuxNumber() { return m_uiMux; }
inline uint8_t GetMuxNumber() { return m_uiMux; }

// Override this with your own ADC implementation. You don't need to worry abouy
// verifying you are the current ADC channel.
Expand Down
186 changes: 186 additions & 0 deletions parts/Board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,101 @@
*/

#include "Board.h"
#include "KeyController.h" // for KeyController
#include "ScriptHost.h" // for ScriptHost
#include "TelemetryHost.h"
#include "Util.h" // for CXXDemangle
#include "avr_extint.h" // for avr_extint_set_strict_lvl_trig
#include "avr_uart.h"
#include "gsl-lite.hpp"
#include "sim_avr_types.h" // for avr_regbit_t
#include "sim_elf.h" // for avr_load_firmware, elf_firmware_t, elf_read_fir...
#include "sim_gdb.h" // for avr_gdb_init
#include "sim_hex.h" // for read_ihex_file
#include "sim_io.h" // for avr_io_getirq
#include "sim_regbit.h" // for avr_regbit_get, avr_regbit_set
#include "uart_pty.h" // for uart_pty
#include <cstdint>
#include <cstdlib> // for exit, free
#include <cstring> // for memcpy, NULL
#include <fstream> // IWYU pragma: keep
#include <iomanip> // for operator<<, setw
#include <iostream>
#include <memory>
#include <typeinfo> // for type_info
#include <unistd.h> // for usleep

namespace Boards {
using string = std::string;

Board::Board(const Wirings::Wiring &wiring,uint32_t uiFreqHz):Scriptable("Board"),m_wiring(wiring),m_uiFreq(uiFreqHz)
{
RegisterActionAndMenu("Quit", "Sends the quit signal to the AVR",ScriptAction::Quit);
RegisterActionAndMenu("Reset","Resets the board by resetting the AVR.", ScriptAction::Reset);
RegisterActionAndMenu("Pause","Pauses the simulated AVR execution.", ScriptAction::Pause);
RegisterActionAndMenu("Resume","Resumes simulated AVR execution.", ScriptAction::Unpause);
RegisterAction("WaitMs","Waits the specified number of milliseconds (in AVR-clock time)", ScriptAction::Wait,{ArgType::Int});

RegisterKeyHandler('r', "Resets the AVR/board");
RegisterKeyHandler('z', "Pauses/resumes AVR execution");
RegisterKeyHandler('q', "Shuts down the board and exits");

}

Board::~Board()
{
if (m_thread) std::cerr << "PROGRAMMING ERROR: " << m_strBoard << " THREAD NOT STOPPED BEFORE DESTRUCTION.\n";
}

void Board::AddSerialPty(uart_pty *UART, const char chrNum)
{
UART->Init(m_pAVR);
UART->Connect(chrNum);
}

bool Board::TryConnect(avr_irq_t *src, PinNames::Pin ePin)
{
if (m_wiring.IsPin(ePin))
{
avr_connect_irq(src, m_wiring.DIRQLU(m_pAVR,ePin));
return true;
}
return _PinNotConnectedMsg(ePin);
}

avr_irq_t* Board::GetDIRQ(PinNames::Pin ePin)
{
if (m_wiring.IsPin(ePin))
{
return m_wiring.DIRQLU(m_pAVR,ePin);
}
return nullptr;
}

Board::MCUPin Board::GetPinNumber(PinNames::Pin ePin)
{
if (m_wiring.IsPin(ePin))
{
return m_wiring.GetPin(ePin);
}
return -1;
}

avr_irq_t* Board::GetPWMIRQ(PinNames::Pin ePin)
{
if (m_wiring.IsPin(ePin))
{
return m_wiring.DPWMLU(m_pAVR,ePin);
}
return nullptr;
}

bool Board::_PinNotConnectedMsg(PinNames::Pin ePin)
{
std:: cout << "Requested connection w/ Digital pin " << ePin << " on " << m_strBoard << ", but it is not defined!\n";;
return false;
}

void Board::CreateAVR()
{
m_pAVR = avr_make_mcu_by_name(m_wiring.GetMCUName().c_str());
Expand Down Expand Up @@ -233,4 +311,112 @@ namespace Boards {
}
return 0;
}

void Board::DisableInterruptLevelPoll(uint8_t uiNumIntLins)
{
for (int i=0; i<uiNumIntLins; i++)
{
avr_extint_set_strict_lvl_trig(m_pAVR,i,false);
}

}

IScriptable::LineStatus Board::ProcessAction(unsigned int ID, const std::vector<std::string> &vArgs)
{
switch (ID)
{
case Quit:
SetQuitFlag();
return LineStatus::Finished;
case Reset:
SetResetFlag();
return LineStatus::Finished;
case Wait:
if (m_uiWtCycleCount >0)
{
if (--m_uiWtCycleCount==0)
{
return LineStatus::Finished;
}
else
{
return LineStatus::Waiting;
}
}
else
{
m_uiWtCycleCount = (m_uiFreq/1000)*stoi(vArgs.at(0));
return LineStatus::Waiting;
}
break;
case Pause:
std::cout << "Pause\n";
m_bPaused.store(true);
return LineStatus::Finished;
case Unpause:
m_bPaused.store(false);
return LineStatus::Finished;
}
return LineStatus::Unhandled;
}


void* Board::RunAVR()
{
avr_regbit_t MCUSR = m_pAVR->reset_flags.porf;
MCUSR.mask =0xFF;
MCUSR.bit = 0;
std::cout << "Starting " << m_wiring.GetMCUName() << " execution...\n";
int state = cpu_Running;
while ((state != cpu_Done) && (state != cpu_Crashed) && !m_bQuit){
// Re init the special workarounds we need after a reset.
if (m_bIsPrimary) // Only one board should be scripting.
{
ScriptHost::DispatchMenuCB();
KeyController::GetController().OnAVRCycle(); // Handle/dispatch any pressed keys.
}
if (m_bIsPrimary && ScriptHost::IsInitialized())
{
ScriptHost::OnAVRCycle();
}
if (m_bPaused)
{
usleep(100000);
continue;
}
int8_t uiMCUSR = avr_regbit_get(m_pAVR,MCUSR);
if (uiMCUSR != m_uiLastMCUSR)
{
std::cout << "MCUSR: " << std::setw(2) << std::hex << (m_uiLastMCUSR = uiMCUSR) << '\n';
if (uiMCUSR) // only run on change and not changed to 0
{
OnAVRReset();
}
}
OnAVRCycle();

if (m_bReset)
{
m_bReset = false;
avr_reset(m_pAVR);
avr_regbit_set(m_pAVR, m_pAVR->reset_flags.extrf);
}
state = avr_run(m_pAVR);
}
std::cout << m_wiring.GetMCUName() << "finished (" << state << ").\n";
avr_terminate(m_pAVR);
return nullptr;
};


std::string Board::GetStorageFileName(const std::string &strType)
{
std::string strFN {CXXDemangle(typeid(*this).name())};//= m_strBoard;
//strFN.append("_").append(m_wiring.GetMCUName()).append("_").append(strType).append(".bin");
strFN.append("_").append(strType).append(".bin");
#ifdef TEST_MODE // Creates special files in test mode that don't clobber your existing stuff.
strFN.append("_test");
#endif
return strFN;
}
}; // namespace Boards
Loading