blob: cf32971756fc27d90b91918c284012acba74c52e [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()
Brian Silvermanfac5c292014-02-17 15:26:57 -080014 : uart_(750000),
15 reset_(2, 5, true),
16 custom_bootloader_(2, 3, true),
17 bootloader_(2, 2, false) {}
Brian Silverman04fac622014-01-26 18:32:15 -080018
19void CapeManager::DownloadHex(const ::std::string &filename) {
20 HexByteReader file(filename);
21 CapeFlasher flasher(&uart_);
22 DoReset(true);
23 flasher.Download(&file);
24 DoReset(false);
25}
26
27void CapeManager::DoReset(bool bootloader) {
Brian Silvermane364e382014-02-08 21:51:33 -080028 static constexpr ::aos::time::Time kWaitTime =
Brian Silverman04fac622014-01-26 18:32:15 -080029 ::aos::time::Time::InSeconds(0.1);
Brian Silvermane364e382014-02-08 21:51:33 -080030 custom_bootloader_.Set(!bootloader);
Brian Silverman8dc9fd42014-02-10 13:35:43 -080031 reset_.Set(false);
Brian Silvermane364e382014-02-08 21:51:33 -080032 ::aos::time::SleepFor(kWaitTime);
Brian Silverman04fac622014-01-26 18:32:15 -080033 reset_.Set(true);
Brian Silvermane364e382014-02-08 21:51:33 -080034 ::aos::time::SleepFor(kWaitTime);
Brian Silverman04fac622014-01-26 18:32:15 -080035}
36
37} // namespace bbb