Skip to content

Commit

Permalink
Merge pull request #104 from juribeparada/master
Browse files Browse the repository at this point in the history
Adding watchdog to host serial port
  • Loading branch information
g4klx committed Aug 20, 2017
2 parents 1cee9e1 + 17007dd commit 5b1075f
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 24 deletions.
5 changes: 5 additions & 0 deletions IO.cpp
Expand Up @@ -389,6 +389,11 @@ void CIO::resetWatchdog()
m_watchdog = 0U;
}

uint32_t CIO::getWatchdog()
{
return m_watchdog;
}

bool CIO::hasLockout() const
{
return m_lockout;
Expand Down
1 change: 1 addition & 0 deletions IO.h
Expand Up @@ -52,6 +52,7 @@ class CIO {
bool hasLockout() const;

void resetWatchdog();
uint32_t getWatchdog();

private:
bool m_started;
Expand Down
2 changes: 1 addition & 1 deletion IOSTM.cpp
Expand Up @@ -355,7 +355,7 @@ void CIO::initInt()
{
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_StructInit(&GPIO_InitStruct);
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Speed = GPIO_Fast_Speed;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_DOWN;

Expand Down
47 changes: 28 additions & 19 deletions SerialPort.cpp
Expand Up @@ -423,6 +423,10 @@ void CSerialPort::process()
m_ptr = 1U;
m_len = 0U;
}
else {
m_ptr = 0U;
m_len = 0U;
}
} else if (m_ptr == 1U) {
// Handle the frame length
m_len = m_buffer[m_ptr] = c;
Expand Down Expand Up @@ -647,9 +651,9 @@ void CSerialPort::process()

#if defined(SERIAL_REPEATER)
case MMDVM_SERIAL: {
for (uint8_t i = 3U; i < m_len; i++)
m_repeat.put(m_buffer[i]);
}
for (uint8_t i = 3U; i < m_len; i++)
m_repeat.put(m_buffer[i]);
}
break;
#endif

Expand All @@ -665,23 +669,28 @@ void CSerialPort::process()
}
}

if (io.getWatchdog() >= 48000U) {
m_ptr = 0U;
m_len = 0U;
}

#if defined(SERIAL_REPEATER)
// Write any outgoing serial data
uint16_t space = m_repeat.getData();
if (space > 0U) {
int avail = availableForWriteInt(3U);
if (avail < space)
space = avail;

for (uint16_t i = 0U; i < space; i++) {
uint8_t c = m_repeat.get();
writeInt(3U, &c, 1U);
}
}

// Read any incoming serial data
while (availableInt(3U))
readInt(3U);
// Write any outgoing serial data
uint16_t space = m_repeat.getData();
if (space > 0U) {
int avail = availableForWriteInt(3U);
if (avail < space)
space = avail;

for (uint16_t i = 0U; i < space; i++) {
uint8_t c = m_repeat.get();
writeInt(3U, &c, 1U);
}
}

// Read any incoming serial data
while (availableInt(3U))
readInt(3U);
#endif
}

Expand Down
8 changes: 4 additions & 4 deletions SerialSTM.cpp
Expand Up @@ -184,7 +184,7 @@ void InitUSART1(int speed)
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10; // Tx | Rx
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Speed = GPIO_Fast_Speed;
GPIO_Init(GPIOA, &GPIO_InitStructure);

// Configure USART baud rate
Expand Down Expand Up @@ -375,7 +375,7 @@ void InitUSART2(int speed)
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3; // Tx | Rx
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Speed = GPIO_Fast_Speed;
GPIO_Init(GPIOA, &GPIO_InitStructure);

// Configure USART baud rate
Expand Down Expand Up @@ -566,7 +566,7 @@ void InitUSART3(int speed)
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11; // Tx | Rx
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Speed = GPIO_Fast_Speed;
GPIO_Init(GPIOC, &GPIO_InitStructure);

// Configure USART baud rate
Expand Down Expand Up @@ -758,7 +758,7 @@ void InitUART5(int speed)
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; // Tx
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Speed = GPIO_Fast_Speed;
GPIO_Init(GPIOC, &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; // Rx
Expand Down

0 comments on commit 5b1075f

Please sign in to comment.