Implement basic tsb protocol for information command
This commit is contained in:
parent
8386d55813
commit
4348759652
12
.gitmodules
vendored
Normal file
12
.gitmodules
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
[submodule "tsb/io"]
|
||||||
|
path = tsb/io
|
||||||
|
url = git@git.blackmark.me:avr/io.git
|
||||||
|
[submodule "tsb/flash"]
|
||||||
|
path = tsb/flash
|
||||||
|
url = git@git.blackmark.me:avr/flash.git
|
||||||
|
[submodule "tsb/uart"]
|
||||||
|
path = tsb/uart
|
||||||
|
url = git@git.blackmark.me:avr/uart.git
|
||||||
|
[submodule "tsb/type"]
|
||||||
|
path = tsb/type
|
||||||
|
url = git@git.blackmark.me:avr/type.git
|
1
tsb/flash
Submodule
1
tsb/flash
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 6edb2e5a21e0ce58ff2df936caee8b84e240a46b
|
1
tsb/io
Submodule
1
tsb/io
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 80de36ee7ee3e6b0842d5eaee81d54062cb496b2
|
96
tsb/main.cpp
96
tsb/main.cpp
@ -1,6 +1,102 @@
|
|||||||
#include "clock.hpp"
|
#include "clock.hpp"
|
||||||
|
|
||||||
|
#include "uart/uart.hpp"
|
||||||
|
|
||||||
|
constexpr auto READ_FLASH_CMD = 'f';
|
||||||
|
constexpr auto WRITE_FLASH_CMD = 'F';
|
||||||
|
constexpr auto READ_EEPROM_CMD = 'e';
|
||||||
|
constexpr auto WRITE_EEPROM_CMD = 'E';
|
||||||
|
constexpr auto READ_USERDATA_CMD = 'c';
|
||||||
|
constexpr auto WRITE_USERDATA_CMD = 'C';
|
||||||
|
constexpr auto REQUEST_CMD = '?';
|
||||||
|
constexpr auto CONFIRM_CMD = '!';
|
||||||
|
constexpr auto AUTO_BAUDING_CMD = '@';
|
||||||
|
|
||||||
|
using uart_interface = uart::Hardware0<uart::Config<38400>, uart::Driven::BLOCKING>;
|
||||||
|
|
||||||
|
enum class State {
|
||||||
|
WAITING,
|
||||||
|
ACTIVE,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct DeviceInfo {
|
||||||
|
char name[3] = {'T', 'S', 'B'};
|
||||||
|
uint8_t date[2] = {0x1a, 0x1f};
|
||||||
|
uint8_t status = 0xf0;
|
||||||
|
uint8_t signature[3] = {0x1e, 0x95, 0x0f};
|
||||||
|
uint8_t pageSize = 0x40;
|
||||||
|
uint16_t flashSize = 0x3ec0;
|
||||||
|
uint16_t eepromSize = 0x03ff;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UserData {
|
||||||
|
uint16_t jumpAddress = 0xAAAA;
|
||||||
|
uint8_t timeout = 0x21;
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline void sendDeviceInfo()
|
||||||
|
{
|
||||||
|
uart::Uart<uart_interface> serial;
|
||||||
|
|
||||||
|
constexpr DeviceInfo deviceInfo;
|
||||||
|
constexpr UserData userData;
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i < sizeof(deviceInfo); ++i) {
|
||||||
|
serial.txByte(*(reinterpret_cast<const uint8_t *>(&deviceInfo) + i));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i < sizeof(userData); ++i) {
|
||||||
|
serial.txByte(*(reinterpret_cast<const uint8_t *>(&userData) + i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint8_t g_lastPage[128] = {};
|
||||||
|
|
||||||
|
static inline void sendUserData()
|
||||||
|
{
|
||||||
|
uart::Uart<uart_interface> serial;
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i < sizeof(g_lastPage); ++i) {
|
||||||
|
serial.txByte(*(reinterpret_cast<const uint8_t *>(&g_lastPage) + i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void sendConfirm()
|
||||||
|
{
|
||||||
|
uart::Uart<uart_interface> serial;
|
||||||
|
serial.txByte(CONFIRM_CMD);
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
uart::Uart<uart_interface> serial;
|
||||||
|
serial.init();
|
||||||
|
|
||||||
|
State state = State::WAITING;
|
||||||
|
|
||||||
|
uint8_t receivedByte = 0;
|
||||||
|
uint8_t autoBaudingCounter = 0;
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
if (serial.rxByte(receivedByte)) {
|
||||||
|
if (state == State::WAITING) {
|
||||||
|
if (receivedByte == AUTO_BAUDING_CMD) {
|
||||||
|
++autoBaudingCounter;
|
||||||
|
}
|
||||||
|
if (autoBaudingCounter == 3) {
|
||||||
|
autoBaudingCounter = 0;
|
||||||
|
state = State::ACTIVE;
|
||||||
|
sendDeviceInfo();
|
||||||
|
}
|
||||||
|
} else if (state == State::ACTIVE) {
|
||||||
|
if (receivedByte == READ_USERDATA_CMD) {
|
||||||
|
sendUserData();
|
||||||
|
sendConfirm();
|
||||||
|
state = State::WAITING;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -215,9 +215,42 @@
|
|||||||
<Compile Include="clock.hpp">
|
<Compile Include="clock.hpp">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="flash\flash.hpp">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="io\io.hpp">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
<Compile Include="main.cpp">
|
<Compile Include="main.cpp">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="type\type.hpp">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="uart\config.hpp">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="uart\hardware.hpp">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="uart\hardware0.hpp">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="uart\hardware1.hpp">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="uart\software.hpp">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="uart\uart.hpp">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="flash" />
|
||||||
|
<Folder Include="io" />
|
||||||
|
<Folder Include="uart" />
|
||||||
|
<Folder Include="type" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
|
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
|
||||||
</Project>
|
</Project>
|
1
tsb/type
Submodule
1
tsb/type
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit ce31ef017f738baaca6f0cbf99dac9d59b5e6811
|
1
tsb/uart
Submodule
1
tsb/uart
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit ae03c8d43e46dfbd396a052f71670727b293ac76
|
Loading…
Reference in New Issue
Block a user