1 /* 2 * SPDX-License-Identifier: BSD-3-Clause 3 * SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors 4 * 5 */ 6 7 8 #include "tfm_plat_test.h" 9 #include "hardware/timer.h" 10 #include "hardware/irq.h" 11 12 #define TIMER0_IRQ0_NUM 0 13 #define TIMER_MS 1000 14 #define TIMER_DELAY_US (500 * TIMER_MS) 15 16 extern void TFM_TIMER0_IRQ_Handler(void); 17 18 #ifdef TFM_PARTITION_SLIH_TEST 19 TFM_LINK_SET_RO_IN_PARTITION_SECTION("TFM_SP_SLIH_TEST", "APP-ROT") 20 #elif defined(TFM_PARTITION_FLIH_TEST) 21 TFM_LINK_SET_RO_IN_PARTITION_SECTION("TFM_SP_FLIH_TEST", "APP-ROT") 22 #endif tfm_plat_test_secure_timer_set_alarm_in_us(uint32_t delay_us)23void tfm_plat_test_secure_timer_set_alarm_in_us(uint32_t delay_us) 24 { 25 /* Load timer */ 26 uint64_t target = timer0_hw->timerawl + delay_us; 27 28 /* Write the lower 32 bits of the target time to the alarm which will 29 arm it */ 30 timer0_hw->alarm[TIMER0_IRQ0_NUM] = (uint32_t) target; 31 } 32 tfm_plat_test_secure_timer_irq_handler(void)33void tfm_plat_test_secure_timer_irq_handler(void) 34 { 35 TFM_TIMER0_IRQ_Handler(); 36 tfm_plat_test_secure_timer_set_alarm_in_us(TIMER_DELAY_US); 37 } 38 tfm_plat_test_secure_timer_start(void)39void tfm_plat_test_secure_timer_start(void) 40 { 41 /* Enable Timer0_0 interrupt */ 42 hw_set_bits(&timer0_hw->inte, 1u << TIMER0_IRQ0_NUM); 43 tfm_plat_test_secure_timer_set_alarm_in_us(TIMER_DELAY_US); 44 } 45 tfm_plat_test_secure_timer_clear_intr(void)46void tfm_plat_test_secure_timer_clear_intr(void) 47 { 48 hw_clear_bits(&timer0_hw->intr, 1u << TIMER0_IRQ0_NUM); 49 } 50 tfm_plat_test_secure_timer_stop(void)51void tfm_plat_test_secure_timer_stop(void) 52 { 53 /* Disable Timer0_0 interrupt */ 54 hw_clear_bits(&timer0_hw->inte, 1u << TIMER0_IRQ0_NUM); 55 } 56 tfm_plat_test_non_secure_timer_start(void)57void tfm_plat_test_non_secure_timer_start(void) 58 { 59 } 60 tfm_plat_test_non_secure_timer_stop(void)61void tfm_plat_test_non_secure_timer_stop(void) 62 { 63 } 64