MCPcopy Create free account
hub / github.com/kiibohd/controller / main

Function main

LoadFile/teensy_loader_cli.c:87–188  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

85/****************************************************************/
86
87int main(int argc, char **argv)
88{
89 unsigned char buf[2048];
90 int num, addr, r, write_size=block_size+2;
91 int first_block=1, waited=0;
92
93 // parse command line arguments
94 parse_options(argc, argv);
95 if (!filename) {
96 fprintf(stderr, "Filename must be specified\n\n");
97 usage();
98 }
99 if (!code_size) {
100 fprintf(stderr, "MCU type must be specified\n\n");
101 usage();
102 }
103 printf_verbose("Teensy Loader, Command Line, Version 2.0, Kiibohd-Mods\n");
104
105 // read the intel hex file
106 // this is done first so any error is reported before using USB
107 num = read_intel_hex(filename);
108 if (num < 0) die("error reading intel hex file \"%s\"", filename);
109 printf_verbose("Read \"%s\": %d bytes, %.1f%% usage\n",
110 filename, num, (double)num / (double)code_size * 100.0);
111
112 // open the USB device
113 while (1) {
114 if (teensy_open()) break;
115 if (hard_reboot_device) {
116 if (!hard_reboot()) die("Unable to find rebootor\n");
117 printf_verbose("Hard Reboot performed\n");
118 hard_reboot_device = 0; // only hard reboot once
119 wait_for_device_to_appear = 1;
120 }
121 if (!wait_for_device_to_appear) die("Unable to open device\n");
122 if (!waited) {
123 printf_verbose("Waiting for Teensy device...\n");
124 printf_verbose(" (hint: press the reset button)\n");
125 waited = 1;
126 }
127 delay(0.25);
128 }
129 printf_verbose("Found HalfKay Bootloader\n");
130
131 // if we waited for the device, read the hex file again
132 // perhaps it changed while we were waiting?
133 if (waited) {
134 num = read_intel_hex(filename);
135 if (num < 0) die("error reading intel hex file \"%s\"", filename);
136 printf_verbose("Read \"%s\": %d bytes, %.1f%% usage\n",
137 filename, num, (double)num / (double)code_size * 100.0);
138 }
139
140 // program the data
141 printf_verbose("Programming");
142 fflush(stdout);
143 for (addr = 0; addr < code_size; addr += block_size) {
144 if (!first_block && !ihex_bytes_within_range(addr, addr + block_size - 1)) {

Callers 3

ResetHandlerFunction · 0.50
ResetHandlerFunction · 0.50
ResetHandlerFunction · 0.50

Calls 14

parse_optionsFunction · 0.85
usageFunction · 0.85
printf_verboseFunction · 0.85
read_intel_hexFunction · 0.85
dieFunction · 0.85
teensy_openFunction · 0.85
hard_rebootFunction · 0.85
delayFunction · 0.85
ihex_bytes_within_rangeFunction · 0.85
memory_is_blankFunction · 0.85
ihex_get_dataFunction · 0.85
teensy_writeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…