|
| 1 | +/* cc26x2.c |
| 2 | + * |
| 3 | + * Copyright (C) 2018 wolfSSL Inc. |
| 4 | + * |
| 5 | + * This file is part of wolfBoot. |
| 6 | + * |
| 7 | + * wolfBoot is free software; you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU General Public License as published by |
| 9 | + * the Free Software Foundation; either version 2 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * wolfBoot is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License |
| 18 | + * along with this program; if not, write to the Free Software |
| 19 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA |
| 20 | + */ |
| 21 | + |
| 22 | +#include <stdint.h> |
| 23 | + |
| 24 | +#include "oscillators.h" |
| 25 | +#include "ti-lib.h" |
| 26 | + |
| 27 | +#include "target.h" /* For WOLFBOOT_SECTOR_SIZE */ |
| 28 | +extern void clock_init(void); |
| 29 | + |
| 30 | +char uart_read(void) |
| 31 | +{ |
| 32 | + return (char)UARTCharGet(UART0_BASE); |
| 33 | +} |
| 34 | + |
| 35 | +int uart_read_nonblock(char *c) |
| 36 | +{ |
| 37 | + int ret = UARTCharGetNonBlocking(UART0_BASE); |
| 38 | + if (ret == -1) |
| 39 | + return 0; |
| 40 | + *c = (char)ret; |
| 41 | + return 1; |
| 42 | +} |
| 43 | + |
| 44 | + |
| 45 | +int hal_flash_write(uint32_t address, const uint8_t *data, int len) |
| 46 | +{ |
| 47 | + FlashProgram(data, address, len); |
| 48 | + while(FlashCheckFsmForReady() != FAPI_STATUS_FSM_READY) |
| 49 | + ; |
| 50 | + return 0; |
| 51 | +} |
| 52 | + |
| 53 | +void hal_flash_unlock(void) |
| 54 | +{ |
| 55 | +} |
| 56 | + |
| 57 | +void hal_flash_lock(void) |
| 58 | +{ |
| 59 | +} |
| 60 | + |
| 61 | + |
| 62 | +int hal_flash_erase(uint32_t address, int len) |
| 63 | +{ |
| 64 | + int i = 0; |
| 65 | + while (len > 0) { |
| 66 | + FlashSectorErase(address + (WOLFBOOT_SECTOR_SIZE * i++)); |
| 67 | + while(FlashCheckFsmForReady() != FAPI_STATUS_FSM_READY) |
| 68 | + ; |
| 69 | + |
| 70 | + if (len <= WOLFBOOT_SECTOR_SIZE) |
| 71 | + break; |
| 72 | + len -= WOLFBOOT_SECTOR_SIZE; |
| 73 | + } |
| 74 | + return 0; |
| 75 | +} |
| 76 | + |
| 77 | +void hal_init(void) |
| 78 | +{ |
| 79 | + /* Enable flash cache and prefetch. */ |
| 80 | + ti_lib_vims_mode_set(VIMS_BASE, VIMS_MODE_ENABLED); |
| 81 | + ti_lib_vims_configure(VIMS_BASE, true, true); |
| 82 | + |
| 83 | + ti_lib_int_master_disable(); |
| 84 | + |
| 85 | + ti_lib_prcm_power_domain_on(PRCM_DOMAIN_PERIPH); |
| 86 | + while((ti_lib_prcm_power_domain_status(PRCM_DOMAIN_PERIPH) |
| 87 | + != PRCM_DOMAIN_POWER_ON)) |
| 88 | + ; |
| 89 | + |
| 90 | + ti_lib_prcm_power_domain_on(PRCM_DOMAIN_SERIAL); |
| 91 | + while ((ti_lib_prcm_power_domain_status(PRCM_DOMAIN_SERIAL)) != PRCM_DOMAIN_POWER_ON) |
| 92 | + ; |
| 93 | + |
| 94 | + ti_lib_prcm_peripheral_run_enable(PRCM_PERIPH_GPIO); |
| 95 | + ti_lib_prcm_load_set(); |
| 96 | + while(!ti_lib_prcm_load_get()) |
| 97 | + ; |
| 98 | + ti_lib_prcm_peripheral_run_enable(PRCM_PERIPH_UART0); |
| 99 | + |
| 100 | + ti_lib_prcm_load_set(); |
| 101 | + while(!ti_lib_prcm_load_get()) |
| 102 | + ; |
| 103 | + |
| 104 | + ti_lib_int_master_enable(); |
| 105 | + |
| 106 | + clock_init(); |
| 107 | +} |
| 108 | + |
| 109 | +void hal_prepare_boot(void) |
| 110 | +{ |
| 111 | +} |
| 112 | + |
0 commit comments