Brian Silverman | 04fac62 | 2014-01-26 18:32:15 -0800 | [diff] [blame^] | 1 | #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 | |
| 11 | namespace bbb { |
| 12 | |
| 13 | CapeManager::CapeManager() |
| 14 | : uart_(750000), reset_(2, 5, true), custom_bootloader_(2, 3, false) {} |
| 15 | |
| 16 | void 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 | |
| 24 | void 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 |