mirror of
https://github.com/google/pebble.git
synced 2025-05-20 10:24:58 +00:00
Import of the watch repository from Pebble
This commit is contained in:
commit
3b92768480
10334 changed files with 2564465 additions and 0 deletions
80
platform/tintin/boot/src/boot_tests.c
Normal file
80
platform/tintin/boot/src/boot_tests.c
Normal file
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright 2024 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "boot_tests.h"
|
||||
|
||||
#include "board/board.h"
|
||||
#include "drivers/button.h"
|
||||
#include "drivers/dbgserial.h"
|
||||
#include "drivers/flash.h"
|
||||
#include "system/bootbits.h"
|
||||
#include "system/rtc_registers.h"
|
||||
#include "util/misc.h"
|
||||
|
||||
#include "stm32f2xx.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
static const int STUCK_BUTTON_THRESHOLD = 5;
|
||||
|
||||
bool is_button_stuck(void) {
|
||||
// We store how many times each button has been pressed on previous boots in this
|
||||
// rtc backup register. Every time when we boot without that button pressed that
|
||||
// counter gets cleared. If the byte reaches 5, return a failure.
|
||||
|
||||
uint32_t button_counter_register = RTC_ReadBackupRegister(STUCK_BUTTON_REGISTER);
|
||||
uint8_t* button_counter = (uint8_t*) (&button_counter_register);
|
||||
bool result = false;
|
||||
|
||||
for (int button_id = 0; button_id < NUM_BUTTONS; button_id++) {
|
||||
if (!button_is_pressed(button_id)) {
|
||||
button_counter[button_id] = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (button_counter[button_id] >= STUCK_BUTTON_THRESHOLD) {
|
||||
dbgserial_putstr("Stuck button register is invalid, clearing.");
|
||||
dbgserial_print_hex(button_counter_register);
|
||||
|
||||
RTC_WriteBackupRegister(STUCK_BUTTON_REGISTER, 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
button_counter[button_id] += 1;
|
||||
|
||||
if (button_counter[button_id] >= STUCK_BUTTON_THRESHOLD) {
|
||||
dbgserial_print("Button id ");
|
||||
dbgserial_print_hex(button_id);
|
||||
dbgserial_putstr("is stuck!");
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (button_counter_register != 0) {
|
||||
dbgserial_print("Button was pushed on boot. Button counter: ");
|
||||
dbgserial_print_hex(button_counter_register);
|
||||
dbgserial_newline();
|
||||
}
|
||||
|
||||
RTC_WriteBackupRegister(STUCK_BUTTON_REGISTER, button_counter_register);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool is_flash_broken(void) {
|
||||
return !flash_sanity_check();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue