blob: d9b1e280493d1353b3baf9dad399ae774e06ffc7 [file] [log] [blame]
Brian Silverman04fac622014-01-26 18:32:15 -08001#include "bbb/cape_manager.h"
2
3#include <string.h>
4#include <errno.h>
5
6#include "aos/common/time.h"
7
8#include "bbb/cape_flasher.h"
9#include "bbb/hex_byte_reader.h"
10
11namespace bbb {
12
13CapeManager::CapeManager()
14 : uart_(750000), reset_(2, 5, true), custom_bootloader_(2, 3, false) {}
15
16void CapeManager::DownloadHex(const ::std::string &filename) {
17 HexByteReader file(filename);
18 CapeFlasher flasher(&uart_);
19 DoReset(true);
20 flasher.Download(&file);
21 DoReset(false);
22}
23
24void CapeManager::DoReset(bool bootloader) {
25 static constexpr ::aos::time::Time kTimeout =
26 ::aos::time::Time::InSeconds(0.1);
27 reset_.Set(false);
28 ::aos::time::SleepFor(kTimeout);
29 custom_bootloader_.Set(bootloader);
30 ::aos::time::SleepFor(kTimeout);
31 reset_.Set(true);
32 ::aos::time::SleepFor(kTimeout);
33}
34
35} // namespace bbb