1 /* 2 * Copyright (c) 2019 Elliot Berman 3 * 4 * Use of this source code is governed by a MIT-style 5 * license that can be found in the LICENSE file or at 6 * https://opensource.org/licenses/MIT 7 */ 8 9 #include <target.h> 10 #include <arch/arch_ops.h> 11 #include <platform/sifive.h> 12 13 // NOTE: set to 0 if trying to boot on qemu 14 #define ENABLE_DEBUG_LED 1 15 16 static volatile struct { 17 volatile uint32_t pwmcfg; 18 volatile uint32_t res0; 19 volatile uint32_t pwmcount; 20 volatile uint32_t res1; 21 volatile uint32_t pwms; 22 volatile uint32_t res2[3]; 23 volatile uint32_t pwmcmp[4]; 24 } *const pwm0_base = (void*)PWM0_BASE; 25 target_early_init(void)26void target_early_init(void) { 27 if (ENABLE_DEBUG_LED) { 28 pwm0_base->pwmcfg = 0x100f; // enable always and max scaling 29 target_set_debug_led(0, false); 30 target_set_debug_led(1, false); 31 target_set_debug_led(2, false); 32 target_set_debug_led(3, false); 33 } 34 } 35 target_init(void)36void target_init(void) { 37 } 38 target_set_debug_led(unsigned int led,bool on)39void target_set_debug_led(unsigned int led, bool on) { 40 if (ENABLE_DEBUG_LED) { 41 if(led > 3) 42 return; 43 pwm0_base->pwmcmp[led] = (0xffff + on) & 0xffff; 44 } 45 } 46