Specifications
Remote Control and Receiver-Transceiver Specifications and Requirements
for Windows Media Center in Windows Operating Systems
119
Bootloader Example Pseudo-Code
This example assumes the same registry format used by the Wake Firmware Registry Example
section.
void handleSysCommand() {
byte b = getNextByteFromHost();
switch (b) {
case CMD_GETPORTSTATUS: handleGetPortStaus(); break;
case CMD_GETWAKESOURCE: handleGetWakeSource(); break;
case CMD_RESET: handleReset(); break;
// add code here to handle all the other PORT_SYS commands.
default:
// any other commands are errors
illegalCommand();
}
}
void handleReset() {
// Reset write authorization before entering the bootloader
writeAuth = 0;
// on reset, run the bootloader
runBootLoaderLoop();
// Reset write authorization after exiting the bootloader
writeAuth = 0;
// then reset the device once we exit the bootloader
resetDevice();
}
void runBootLoaderLoop() {
while (true) {
byte b = getNextByteFromHost();
switch (b) {
case CMD_BOOT_EXIT: return;
case CMD_BOOT_GETVERSION: handleBootGetVersion(); break;
case CMD_BOOT_WRITEAUTH:handleBootWriteAuth(); break;
case CMD_BOOT_WRITEBLOCK: handleBootWriteBlock(); break;
case CMD_BOOT_SETWAKEPATTERN:handleBootSetWakePattern(); break;
default: break;
}
}
void handleBootGetVersion() {
// send the wake version to the host
sendToHost(RSP_BOOT_VERSION,1);
}
void handleBootWriteAuth() {
// get the write authorization from the host and save it for later.
writeAuth = (getNextByteFromSource() << 24) +
(getNextByteFromSource() << 16) +
(getNextByteFromSource() << 8) +
getNextByteFromSource();
}
void handleBootWriteBlock() {
byte checksum = 0;
byte data[8];
// In our scheme, first 16 bytes are the destination address.
uint address = (getNextByteFromSource() << 16) +
getNextByteFromSource();
// Next 8 bytes are firmware










