Skip to content

Commit

Permalink
Fixes HwInit after API changes. (#540)
Browse files Browse the repository at this point in the history
  • Loading branch information
balazsracz authored May 8, 2021
1 parent d4f1835 commit f3f1882
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 11 deletions.
29 changes: 23 additions & 6 deletions boards/ti-bracz-cs-123/HwInit.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,33 @@ const size_t EEPROMEmulation::SECTOR_SIZE = (4*1024);

static TivaEEPROMEmulation eeprom("/dev/eeprom", 2000);

// Bit storing whether our dcc output is enabled or not.
static bool g_dcc_on = false;

uint32_t feedback_sample_overflow_count = 0;
// If 1, enabled spread spectrum randomization of the DCC timings.
uint8_t spreadSpectrum = 0;

TivaRailcomDriver<RailcomDefs> railcom_driver("/dev/railcom");
TivaDCC<DccHwDefs> dcc_hw("/dev/mainline", &railcom_driver);


DccOutput* get_dcc_output(DccOutput::Type type) {
switch (type)
{
case DccOutput::TRACK:
return DccOutputImpl<DccHwDefs::Output>::instance();
case DccOutput::PGM:
return DccOutputImpl<DccHwDefs::Output2>::instance();
case DccOutput::LCC:
return DccOutputImpl<DccHwDefs::Output3>::instance();
}
return nullptr;
}

extern "C" {

void hw_set_to_safe(void)
{
dcc_hw.disable_output();
DccHwDefs::Output::set_disable_reason(
DccOutput::DisableReason::INITIALIZATION_PENDING);
}

void timer1a_interrupt_handler(void)
Expand Down Expand Up @@ -193,6 +207,7 @@ void set_gpio_puinput(uint32_t port, uint32_t pin) {
MAP_GPIOPadConfigSet(port, pin, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
}

/*
void enable_dcc() {
g_dcc_on = true;
MAP_GPIOPinWrite(LED_BLUE, 0xff);
Expand All @@ -214,6 +229,7 @@ void setshorted_dcc() {
bool query_dcc() {
return g_dcc_on;
}
*/

/** Initialize the processor hardware.
*/
Expand All @@ -232,8 +248,9 @@ void hw_preinit(void)
// These pins are parallel-connected to the outputs.
set_gpio_extinput(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1);
/* Initialize the DCC Timers and GPIO outputs */
dcc_hw.hw_init();
disable_dcc();
dcc_hw.hw_preinit();
DccHwDefs::Output::set_disable_reason(
DccOutput::DisableReason::INITIALIZATION_PENDING);

/* Setup the system clock. */
MAP_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
Expand Down
28 changes: 23 additions & 5 deletions boards/ti-bracz-cs-connected/HwInit.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,26 @@ static TivaUart uart2("/dev/ser0", UART2_BASE, INT_RESOLVE(INT_UART2_, 0));
/** CAN 0 CAN driver instance */
static TivaCan can0("/dev/can0", CAN0_BASE, INT_RESOLVE(INT_CAN0_, 0));

// Bit storing whether our dcc output is enabled or not.
static bool g_dcc_on = false;
uint32_t feedback_sample_overflow_count = 0;
// If 1, enabled spread spectrum randomization of the DCC timings.
uint8_t spreadSpectrum = 0;

TivaRailcomDriver<RailcomDefs> railcom_driver("/dev/railcom");
TivaDCC<DccHwDefs> dcc_hw("/dev/mainline", &railcom_driver);

DccOutput* get_dcc_output(DccOutput::Type type) {
switch (type)
{
case DccOutput::TRACK:
return DccOutputImpl<DccHwDefs::Output>::instance();
case DccOutput::PGM:
return DccOutputImpl<DccHwDefs::Output2>::instance();
case DccOutput::LCC:
return DccOutputImpl<DccHwDefs::Output3>::instance();
}
return nullptr;
}

extern "C" {
/** Timer interrupt for DCC packet handling.
*/
Expand All @@ -138,7 +152,8 @@ void uart2_interrupt_handler(void)

void hw_set_to_safe(void)
{
dcc_hw.disable_output();
DccHwDefs::Output::set_disable_reason(
DccOutput::DisableReason::INITIALIZATION_PENDING);
AccHwDefs::ACC_ENABLE_Pin::hw_set_to_safe();
}

Expand Down Expand Up @@ -221,6 +236,7 @@ void set_gpio_puinput(uint32_t port, uint32_t pin) {
MAP_GPIOPadConfigSet(port, pin, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
}

/*
void enable_dcc() {
g_dcc_on = true;
io::TrackOnLed::set(true);
Expand All @@ -242,6 +258,7 @@ void setshorted_dcc() {
bool query_dcc() {
return g_dcc_on;
}
*/

/** Initialize the processor hardware.
*/
Expand Down Expand Up @@ -270,8 +287,9 @@ void hw_preinit(void)
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

dcc_hw.hw_init();
disable_dcc();
dcc_hw.hw_preinit();
DccHwDefs::Output::set_disable_reason(
DccOutput::DisableReason::INITIALIZATION_PENDING);
RC_DEBUG_Pin::hw_init();

// controls the accessory bus.
Expand Down

0 comments on commit f3f1882

Please sign in to comment.