TivaC Implementation
***
This is an implementation for the TivaC board.
For now it models the system control block, the general purpose I/O, the general purpose timers, the watchdog timers and the usart module.
The code is available at https://github.com/moesay/qemu_TivaC.git
***
Mohamed ElSayed (8):
the tivac machine def initial commit
tivac usart module implementation
tivac gpio module implementation
tivac system control implementation
tivac general purpose timers implementation
tivac watchdog timers implementation
editing the meson and KConfig files to add tivac to qemu build system code style fixes
.gitignore | 1 + README.rst | 150 +--- configs/devices/arm-softmmu/default.mak | 1 + hw/arm/Kconfig | 13 + hw/arm/meson.build | 3 + hw/arm/tivac.c | 56 ++ hw/arm/tm4c123gh6pm_soc.c | 276 +++++++ hw/char/Kconfig | 3 + hw/char/meson.build | 1 + hw/char/tm4c123_usart.c | 383 +++++++++ hw/char/trace-events | 4 + hw/gpio/Kconfig | 3 + hw/gpio/meson.build | 1 + hw/gpio/tm4c123_gpio.c | 372 +++++++++ hw/gpio/trace-events | 4 + hw/misc/Kconfig | 3 + hw/misc/meson.build | 1 + hw/misc/tm4c123_sysctl.c | 989 ++++++++++++++++++++++++ hw/misc/trace-events | 5 + hw/timer/Kconfig | 3 + hw/timer/meson.build | 1 + hw/timer/tm4c123_gptm.c | 495 ++++++++++++ hw/timer/trace-events | 5 + hw/watchdog/Kconfig | 3 + hw/watchdog/meson.build | 1 + hw/watchdog/tm4c123_watchdog.c | 297 +++++++ hw/watchdog/trace-events | 3 + include/hw/arm/tm4c123gh6pm_soc.h | 71 ++ include/hw/char/tm4c123_usart.h | 124 +++ include/hw/gpio/tm4c123_gpio.h | 127 +++ include/hw/misc/tm4c123_sysctl.h | 307 ++++++++ include/hw/timer/tm4c123_gptm.h | 131 ++++ include/hw/watchdog/tm4c123_watchdog.h | 97 +++ 33 files changed, 3797 insertions(+), 137 deletions(-) create mode 100644 hw/arm/tivac.c create mode 100644 hw/arm/tm4c123gh6pm_soc.c create mode 100644 hw/char/tm4c123_usart.c create mode 100644 hw/gpio/tm4c123_gpio.c create mode 100644 hw/misc/tm4c123_sysctl.c create mode 100644 hw/timer/tm4c123_gptm.c create mode 100644 hw/watchdog/tm4c123_watchdog.c create mode 100644 include/hw/arm/tm4c123gh6pm_soc.h create mode 100644 include/hw/char/tm4c123_usart.h create mode 100644 include/hw/gpio/tm4c123_gpio.h create mode 100644 include/hw/misc/tm4c123_sysctl.h create mode 100644 include/hw/timer/tm4c123_gptm.h create mode 100644 include/hw/watchdog/tm4c123_watchdog.h
--
2.34.1
[PULL 1/8] the tivac machine def init commit
--- hw/arm/tivac.c | 56 ++++++ hw/arm/tm4c123gh6pm_soc.c | 274 ++++++++++++++++++++++++++++++ include/hw/arm/tm4c123gh6pm_soc.h | 71 ++++++++ 3 files changed, 401 insertions(+) create mode 100644 hw/arm/tivac.c create mode 100644 hw/arm/tm4c123gh6pm_soc.c create mode 100644 include/hw/arm/tm4c123gh6pm_soc.h
hw/arm/tivac.c new file +56 -0
@@ -0,0 +1,56 @@ +/* +* TivaC Board Implementation +* +* Copyright (c) 2023 Mohamed ElSayed <[email protected]> +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "hw/boards.h" +#include "hw/qdev-properties.h" +#include "hw/qdev-clock.h" +#include "qemu/error-report.h" +#include "hw/arm/tm4c123gh6pm_soc.h" +#include "hw/arm/boot.h" + + +/* Main SYSCLK frequency in Hz (24MHz) */ +#define SYSCLK_FRQ 24000000ULL + +static void tivac_init (MachineState *machine) +{ +DeviceState *dev; + dev =qdev_new (TYPE_TM4C123GH6PM_SOC ); + +qdev_prop_set_string (dev,"cpu-type" ,ARM_CPU_TYPE_NAME ("cortex-m4" )); +sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal); + +armv7m_load_kernel (ARM_CPU (first_cpu), + machine->kernel_filename, +0 ,FLASH_SIZE ); +} + +static void tivac_machine_init (MachineClass *mc) +{ + mc->desc ="Tiva C (Cortex-M4)" ; + mc->init = tivac_init; +} +DEFINE_MACHINE ("tivac" , tivac_machine_init)
hw/arm/tm4c123gh6pm_soc.c new file +274 -0
274 lines not on this page · raw message
include/hw/arm/tm4c123gh6pm_soc.h new file +71 -0
71 lines not on this page · raw message
--
2.34.1
[PULL 5/8] tivac general purpose timers implementation
In reply to Mohamed ElSayed--- hw/timer/tm4c123_gptm.c | 529 ++++++++++++++++++++++++++++++++ include/hw/timer/tm4c123_gptm.h | 131 ++++++++ 2 files changed, 660 insertions(+) create mode 100644 hw/timer/tm4c123_gptm.c create mode 100644 include/hw/timer/tm4c123_gptm.h
hw/timer/tm4c123_gptm.c new file +529 -0
@@ -0,0 +1,529 @@ +/* +* TM4C123 General purpose timers +* +* Copyright (c) 2023 Mohamed ElSayed <[email protected]> +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +#include "hw/timer/tm4c123_gptm.h" +#include "hw/irq.h" +#include "trace.h" +#include "qemu/timer.h" +#include <time.h> + +#define LOG(fmt, args...) qemu_log("%s: " fmt, __func__, ## args) +#define READONLY LOG("0x%"HWADDR_PRIx" is a readonly field\n.", addr) + +static uint64_t ns_to_ticks (void *opaque,uint64_t ns,uint32_t prescaler) +{ +TM4C123GPTMState *s = opaque; + +uint32_t freq =clock_get_hz (s->clk) / prescaler; +float sec = (float )ns / (float )NANOSECONDS_PER_SECOND ; +return sec * freq; +} + +static unsigned long ticks_to_time_ns (void *opaque,uint64_t ticks,uint32_t prescaler) +{ +TM4C123GPTMState *s = opaque; +uint32_t freq =clock_get_hz (s->clk) / prescaler; +return (((float )ticks / (float )freq) *NANOSECONDS_PER_SECOND ); +} + +static void log_message (const char *message) +{ +uint64_t ns =qemu_clock_get_ns (QEMU_CLOCK_REALTIME ); +time_t seconds = ns /1000000000 ; +struct tm *timeinfo =localtime (&seconds); +char buffer[80 ]; +strftime (buffer,sizeof (buffer),"%Y-%m-%d %H:%M:%S" , timeinfo); +LOG ("[%s] %s\n" , buffer, message); +} + +static uint16_t get_timer_width (void *opaque) +{ +TM4C123GPTMState *s = opaque; +switch (s->mmio.addr) { + case TIMER0_32...TIMER5_32: +return TIMER_WIDTH_32 ; + case TIMER0_64...TIMER5_64: +return TIMER_WIDTH_64 ; + } +return 0 ; +} + +static uint64_t build_interval_value (void *opaque) +{ +TM4C123GPTMState *s = opaque; +uint16_t timer_width =get_timer_width (s); +uint64_t interval_value =0 ; +if (timer_width ==TIMER_WIDTH_32 ) { +/* timer is in 32 bit mode or 32bit rtc*/ +uint16_t upper16 =extract32 (s->gptm_talir,16 ,16 ); +uint16_t lower16 =extract32 (s->gptm_tblir,0 ,16 ); + interval_value = ((uint32_t )lower16 <<16 ) + upper16; + } +else if (timer_width ==TIMER_WIDTH_64 ) { + interval_value = ((uint64_t )s->gptm_talir <<32 ) + s->gptm_tblir; + } + +trace_tm4c123_gptm_build_interval_value (s->gptm_talir, s->gptm_tblir, interval_value); +return interval_value; +} + +static void set_timers (void *opaque) +{ +TM4C123GPTMState *s = opaque; +uint64_t interval_value; +uint16_t timer_width; +if (s->gptm_ctl &GPTM_TACTL_EN ) { + timer_width =get_timer_width (s); +if (timer_width ==TIMER_WIDTH_32 ) { +/* What is the mode of the timer? 16/32 */ +if (s->gptm_cfg ==0x4 ) { +/* 16 bit mode */ + interval_value =extract32 (s->gptm_talir,0 ,16 ); +/* Start the timer? */ +timer_mod (s->a,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) +ticks_to_time_ns (s, interval_value, s->gptm_tapr)); +LOG ("Timer A/16 is running\n" ); + } +else if (s->gptm_cfg ==0x1 ) { +/* 32 bit mode rtc */ + interval_value =build_interval_value (s); +timer_mod (s->a,qemu_clock_get_ns (QEMU_CLOCK_REALTIME ) +ticks_to_time_ns (s, interval_value, s->gptm_tapr)); +LOG ("Timer A/32 RTC is running\n" ); + } +else if (s->gptm_cfg ==0x0 ) { +/* 32 bit mode rtc */ + interval_value =build_interval_value (s); +timer_mod (s->a,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) +ticks_to_time_ns (s, interval_value, s->gptm_tapr)); +LOG ("Timer A/32 is running\n" ); + } + } +else if (timer_width ==TIMER_WIDTH_64 ) { +/* What is the mode of the timer? 32/64 */ +if (s->gptm_cfg ==0 ) { +/* 64 bit mode */ + interval_value =build_interval_value (s); +timer_mod (s->a,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) +ticks_to_time_ns (s, interval_value, s->gptm_tapr)); +LOG ("Timer A/64 is running\n" ); + } +else if (s->gptm_cfg ==0x1 ) { +/* 64 bit mode */ + interval_value =build_interval_value (s); +timer_mod (s->a,qemu_clock_get_ns (QEMU_CLOCK_REALTIME ) +ticks_to_time_ns (s, interval_value, s->gptm_tapr)); +LOG ("Timer A/64 RTC is running\n" ); + } +else if (s->gptm_cfg ==0x4 ) { + interval_value = s->gptm_talir; +timer_mod (s->a,qemu_clock_get_ns (QEMU_CLOCK_REALTIME ) +ticks_to_time_ns (s, interval_value, s->gptm_tapr)); +LOG ("Timer A/32 RTC is running\n" ); + } + } + } +else if (s->gptm_ctl &GPTM_TBCTL_EN ) { + timer_width =get_timer_width (s); +if (timer_width ==TIMER_WIDTH_32 ) { +/* What is the mode of the timer? 16/32 */ +if (s->gptm_cfg ==0x4 ) { +/* 16 bit mode */ + interval_value =extract32 (s->gptm_tblir,0 ,16 ); +/* Start the timer? */ +timer_mod (s->b,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) +ticks_to_time_ns (s, interval_value, s->gptm_tbpr)); +LOG ("Timer B/16 is running\n" ); + } +else if (s->gptm_cfg ==0x01 ) { +/* 32 bit mode rtc */ + interval_value =build_interval_value (s); +timer_mod (s->b,qemu_clock_get_ns (QEMU_CLOCK_REALTIME ) +ticks_to_time_ns (s, interval_value, s->gptm_tbpr)); +LOG ("Timer B/32 RTC is running\n" ); + } +else if (s->gptm_cfg ==0x00 ) { +/* 32 bit mode rtc */ + interval_value =build_interval_value (s); +timer_mod (s->b,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) +ticks_to_time_ns (s, interval_value, s->gptm_tbpr)); +LOG ("Timer B/32 RTC is running\n" ); + } + } +else if (timer_width ==TIMER_WIDTH_64 ) { +/* What is the mode of the timer? 32/64 */ +if (s->gptm_cfg ==0 ) { +/* 64 bit mode */ + interval_value =build_interval_value (s); +timer_mod (s->b,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) +ticks_to_time_ns (s, interval_value, s->gptm_tbpr)); +LOG ("Timer A/64 is running\n" ); + } +else if (s->gptm_cfg ==0x1 ) { +/* 64 bit mode */ + interval_value =build_interval_value (s); +timer_mod (s->b,qemu_clock_get_ns (QEMU_CLOCK_REALTIME ) +ticks_to_time_ns (s, interval_value, s->gptm_tbpr)); +LOG ("Timer A/64 RTC is running\n" ); + } +else if (s->gptm_cfg ==0x4 ) { + interval_value = s->gptm_tblir; +timer_mod (s->b,qemu_clock_get_ns (QEMU_CLOCK_REALTIME ) +ticks_to_time_ns (s, interval_value, s->gptm_tbpr)); +LOG ("Timer A/32 RTC is running\n" ); + } + } + } +} + +static bool gptm_clock_enabled (TM4C123SysCtlState *s,hwaddr addr) +{ +switch (addr) { +case TIMER0_32 : +return test_bit (0 , (const unsigned long *)&s->sysctl_rcgctimer); +break ; +case TIMER1_32 : +return test_bit (1 , (const unsigned long *)&s->sysctl_rcgctimer); +break ; +case TIMER2_32 : +return test_bit (2 , (const unsigned long *)&s->sysctl_rcgctimer); +break ; +case TIMER3_32 : +return test_bit (3 , (const unsigned long *)&s->sysctl_rcgctimer); +break ; +case TIMER4_32 : +return test_bit (4 , (const unsigned long *)&s->sysctl_rcgctimer); +break ; +case TIMER5_32 : +return test_bit (5 , (const unsigned long *)&s->sysctl_rcgctimer); +break ; +case TIMER0_64 : +return test_bit (0 , (const unsigned long *)&s->sysctl_rcgcwtimer); +break ; +case TIMER1_64 : +return test_bit (1 , (const unsigned long *)&s->sysctl_rcgcwtimer); +break ; +case TIMER2_64 : +return test_bit (2 , (const unsigned long *)&s->sysctl_rcgcwtimer); +break ; +case TIMER3_64 : +return test_bit (3 , (const unsigned long *)&s->sysctl_rcgcwtimer); +break ; +case TIMER4_64 : +return test_bit (4 , (const unsigned long *)&s->sysctl_rcgcwtimer); +break ; +case TIMER5_64 : +return test_bit (5 , (const unsigned long *)&s->sysctl_rcgcwtimer); +break ; + } +return false; +} + +static void tm4c123_gptm_reset (DeviceState * dev) +{ +TM4C123GPTMState *s =TM4C123_GPTM (dev); + + s->gptm_cfg =0x00000000 ; + s->gptm_amr =0x00000000 ; + s->gptm_bmr =0x00000000 ; + s->gptm_ctl =0x00000000 ; + s->gptm_sync =0x00000000 ; + s->gptm_imr =0x00000000 ; + s->gptm_ris =0x00000000 ; + s->gptm_mis =0x00000000 ; + s->gptm_icr =0x00000000 ; + s->gptm_talir =0xFFFFFFFF ; + s->gptm_tblir =0x00000000 ; + s->gptm_tamatchr =0xFFFFFFFF ; + s->gptm_tbmatchr =0x00000000 ; + s->gptm_tapr =0x00000000 ; + s->gptm_tbpr =0x00000000 ; + s->gptm_tapmr =0x00000000 ; + s->gptm_tbpmr =0x00000000 ; + s->gptm_tar =0xFFFFFFFF ; + s->gptm_tbr =0x00000000 ; + s->gptm_tav =0xFFFFFFFF ; + s->gptm_tbv =0x00000000 ; + s->gptm_rtcpd =0x00007FFF ; + s->gptm_taps =0x00000000 ; + s->gptm_tbps =0x00000000 ; + s->gptm_tapv =0x00000000 ; + s->gptm_tbpv =0x00000000 ; + s->gptm_pp =0x00000000 ; +} + +static uint64_t tm4c123_gptm_read (void *opaque,hwaddr addr,unsigned int size) +{ +TM4C123GPTMState *s = opaque; + +if (!gptm_clock_enabled (s->sysctl, s->mmio.addr)) { +hw_error ("GPTM module clock is not enabled" ); + } + +trace_tm4c123_gptm_read (addr); + +switch (addr) { +case GPTM_CFG : +return s->gptm_cfg; +case GPTM_AMR : +return s->gptm_amr; +case GPTM_BMR : +return s->gptm_bmr; +case GPTM_CTL : +return s->gptm_ctl; +case GPTM_SYNC : +return s->gptm_sync; +case GPTM_IMR : +return s->gptm_imr; +case GPTM_RIS : +return s->gptm_ris; +case GPTM_MIS : +return s->gptm_mis; +case GPTM_ICR : +return s->gptm_icr; +case GPTM_TALIR : +return s->gptm_talir; +case GPTM_TBLIR : +return s->gptm_tblir; +case GPTM_TAMATCHR : +return s->gptm_tamatchr; +case GPTM_TBMATCHR : +return s->gptm_tbmatchr; +case GPTM_TAPR : +return s->gptm_tapr; +case GPTM_TBPR : +return s->gptm_tbpr; +case GPTM_TAPMR : +return s->gptm_tapmr; +case GPTM_TBPMR : +return s->gptm_tbpmr; +case GPTM_TAR : +return s->gptm_tar; +case GPTM_TBR : +return s->gptm_tbr; +case GPTM_TAV : +if (get_timer_width (s) ==TIMER_WIDTH_64 && s->gptm_cfg ==0 ) { +return extract64 ( +ns_to_ticks (s, s->a->expire_time -qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ), s->gptm_tapr), +0 ,31 ); + } +else { +return ns_to_ticks (s, s->a->expire_time -qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ), s->gptm_tapr); + } +case GPTM_TBV : +if (get_timer_width (s) ==TIMER_WIDTH_64 && s->gptm_cfg ==0 ) { +return extract64 ( +ns_to_ticks (s, s->a->expire_time -qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ), s->gptm_tapr), +32 ,64 ); + } +else { +return ns_to_ticks (s, s->b->expire_time -qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ), s->gptm_tabr); + } +case GPTM_RTCPD : +return s->gptm_rtcpd; +case GPTM_TAPS : +return s->gptm_taps; +case GPTM_TBPS : +return s->gptm_tbps; +case GPTM_TAPV : +return s->gptm_tapv; +case GPTM_TBPV : +return s->gptm_tbpv; +case GPTM_PP : +return s->gptm_pp; +default : +LOG ("Bad address 0x%" HWADDR_PRIx"\n" , addr); + } + +return 0 ; +} + +static void tm4c123_gptm_write (void *opaque,hwaddr addr,uint64_t val64,unsigned int size) +{ +TM4C123GPTMState *s = opaque; +uint32_t val32 = val64; + +if (!gptm_clock_enabled (s->sysctl, s->mmio.addr)) { +hw_error ("GPTM module clock is not enabled" ); + } + +trace_tm4c123_gptm_write (addr, val32); + +switch (addr) { +case GPTM_CFG : + s->gptm_cfg = val32; +break ; +case GPTM_AMR : + s->gptm_amr = val32; +break ; +case GPTM_BMR : + s->gptm_bmr = val32; +break ; +case GPTM_CTL : + s->gptm_ctl = val32; +set_timers (s); +break ; +case GPTM_SYNC : + s->gptm_sync = val32; +break ; +case GPTM_IMR : + s->gptm_imr = val32; +break ; +case GPTM_RIS : +READONLY ; +break ; +case GPTM_MIS : + s->gptm_mis = val32; +break ; +case GPTM_ICR : + s->gptm_ris &= ~val32; + s->gptm_mis &= ~val32; +break ; +case GPTM_TALIR : + s->gptm_talir = val32; +break ; +case GPTM_TBLIR : + s->gptm_tblir = val32; +break ; +case GPTM_TAMATCHR : + s->gptm_tamatchr = val32; +break ; +case GPTM_TBMATCHR : + s->gptm_tbmatchr = val32; +break ; +case GPTM_TAPR : + s->gptm_tapr = val32; +break ; +case GPTM_TBPR : + s->gptm_tbpr = val32; +break ; +case GPTM_TAPMR : + s->gptm_tapmr = val32; +break ; +case GPTM_TBPMR : + s->gptm_tbpmr = val32; +break ; +case GPTM_TAR : +READONLY ; +break ; +case GPTM_TBR : +READONLY ; +break ; +case GPTM_TAV : + s->gptm_tav = val32; +break ; +case GPTM_TBV : + s->gptm_tbv = val32; +break ; +case GPTM_RTCPD : +READONLY ; +break ; +case GPTM_TAPS : +READONLY ; +break ; +case GPTM_TBPS : +READONLY ; +break ; +case GPTM_TAPV : +READONLY ; +break ; +case GPTM_TBPV : +READONLY ; +break ; +case GPTM_PP : +READONLY ; +break ; +default : +LOG ("Bad address 0x%" HWADDR_PRIx"\n" , addr); + } +} + +static const MemoryRegionOps tm4c123_gptm_ops = { + .read = tm4c123_gptm_read, + .write = tm4c123_gptm_write, + .endianness =DEVICE_NATIVE_ENDIAN , +}; + +static void timer_a_callback (void *opaque) +{ +TM4C123GPTMState *s = opaque; + +log_message ("timer A\n" ); + +if (test_bit (0 , (unsigned long *)&s->gptm_imr)) { +qemu_irq_pulse (s->irq_a); +set_bit (0 , (unsigned long *)&s->gptm_mis); + } +set_bit (0 , (unsigned long *)&s->gptm_ris); +if ((s->gptm_amr &0x0000000F ) ==0x2 ) { +set_timers (s); + } +} + +static void timer_b_callback (void *opaque) +{ +TM4C123GPTMState *s = opaque; +log_message ("timer B\n" ); + +if (test_bit (8 , (unsigned long *)&s->gptm_imr)) { +qemu_irq_pulse (s->irq_b); +set_bit (8 , (unsigned long *)&s->gptm_mis); + } +set_bit (8 , (unsigned long *)&s->gptm_ris); +if ((s->gptm_bmr &0x0000000F ) ==0x2 ) { +set_timers (s); + } +} + +static void tm4c123_gptm_init (Object *obj) +{ +TM4C123GPTMState *s =TM4C123_GPTM (obj); + s->clk =qdev_init_clock_in (DEVICE (s),"gptm_clock" ,NULL ,NULL ,0 ); + s->a =timer_new_ns (QEMU_CLOCK_VIRTUAL , timer_a_callback, s); + s->b =timer_new_ns (QEMU_CLOCK_VIRTUAL , timer_b_callback, s); +timer_init_ns (s->a,QEMU_CLOCK_VIRTUAL , timer_a_callback, s); +timer_init_ns (s->b,QEMU_CLOCK_VIRTUAL , timer_b_callback, s); + +sysbus_init_irq (SYS_BUS_DEVICE (obj), &s->irq_a); +sysbus_init_irq (SYS_BUS_DEVICE (obj), &s->irq_b); +memory_region_init_io (&s->mmio, obj, &tm4c123_gptm_ops, s,TYPE_TM4C123_GPTM ,0xFFF ); +sysbus_init_mmio (SYS_BUS_DEVICE (obj), &s->mmio); +} + +static void tm4c123_gptm_realize (DeviceState *dev,Error **errp) +{ +TM4C123GPTMState *s =TM4C123_GPTM (dev); +qdev_connect_clock_in (dev,"gptm_clock" ,qdev_get_clock_out (DEVICE (s->sysctl),"outclk" )); + +} + +static void tm4c123_gptm_class_init (ObjectClass *kclass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (kclass); + dc->reset = tm4c123_gptm_reset; + dc->realize = tm4c123_gptm_realize; +} + +static const TypeInfo tm4c123_gptm_info = { + .name =TYPE_TM4C123_GPTM , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (TM4C123GPTMState), + .instance_init = tm4c123_gptm_init, + .class_init = tm4c123_gptm_class_init, +}; + +static void tm4c123_gptm_register_types (void ) +{ +type_register_static (&tm4c123_gptm_info); +} + +type_init (tm4c123_gptm_register_types)
include/hw/timer/tm4c123_gptm.h new file +131 -0
131 lines not on this page · raw message
Signature · 1 line
2.34.1
[PULL 4/8] tivac system control implementation
In reply to Mohamed ElSayed--- hw/misc/tm4c123_sysctl.c | 989 +++++++++++++++++++++++++++++++ include/hw/misc/tm4c123_sysctl.h | 307 ++++++++++ 2 files changed, 1296 insertions(+) create mode 100644 hw/misc/tm4c123_sysctl.c create mode 100644 include/hw/misc/tm4c123_sysctl.h
hw/misc/tm4c123_sysctl.c new file +989 -0
@@ -0,0 +1,989 @@ +/* +* TM4C123 SYSCTL +* +* Copyright (c) 2023 Mohamed ElSayed <[email protected]> +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +#include "qemu/osdep.h" +#include "hw/misc/tm4c123_sysctl.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "trace.h" + +#define LOG(fmt, args...) qemu_log("%s: " fmt, __func__, ## args) +#define READONLY LOG("0x%"HWADDR_PRIx" is a readonly field\n.", addr) + +static void tm4c123_sysctl_update_system_clock (void *opaque) +{ +TM4C123SysCtlState *s = opaque; + +uint32_t RCC_Val = s->sysctl_rcc; +uint32_t RCC2_Val = s->sysctl_rcc2; + +uint32_t __CORE_CLK_PRE; +uint32_t __CORE_CLK; + +if (RCC2_Val & (1UL <<31 )) {/* is rcc2 used? */ +if (RCC2_Val & (1UL <<11 )) {/* check BYPASS */ +if (((RCC2_Val >>4 ) &0x07 ) ==0x0 ) { +if (((RCC_Val >>6 ) &0x1F ) ==0x0 ) { + __CORE_CLK_PRE =1000000UL ; + }else if (((RCC_Val >>6 ) &0x1F ) ==0x1 ) { + __CORE_CLK_PRE =1843200UL ; + }else if (((RCC_Val >>6 ) &0x1F ) ==0x2 ) { + __CORE_CLK_PRE =2000000UL ; + }else if (((RCC_Val >>6 ) &0x1F ) ==0x3 ) { + __CORE_CLK_PRE =2457600UL ; + }else if (((RCC_Val >>6 ) &0x1F ) ==0x4 ) { + __CORE_CLK_PRE =3579545UL ; + }else if (((RCC_Val >>6 ) &0x1F ) ==0x5 ) { + __CORE_CLK_PRE =3686400UL ; + }else if (((RCC_Val >>6 ) &0x1F ) ==0x6 ) { + __CORE_CLK_PRE =4000000UL ; + }else if (((RCC_Val >>6 ) &0x1F ) ==0x7 ) { + __CORE_CLK_PRE =4096000UL ; + }else if (((RCC_Val >>6 ) &0x1F ) ==0x8 ) { + __CORE_CLK_PRE =4915200UL ; + }else if (((RCC_Val >>6 ) &0x1F ) ==0x9 ) { + __CORE_CLK_PRE =5000000UL ; + }else if (((RCC_Val >>6 ) &0x1F ) ==0xA ) { + __CORE_CLK_PRE =5120000UL ; + }else if (((RCC_Val >>6 ) &0x1F ) ==0xB ) { + __CORE_CLK_PRE =6000000UL ; + }else if (((RCC_Val >>6 ) &0x1F ) ==0xC ) { + __CORE_CLK_PRE =6144000UL ; + }else if (((RCC_Val >>6 ) &0x1F ) ==0xD ) { + __CORE_CLK_PRE =7372800UL ; + }else if (((RCC_Val >>6 ) &0x1F ) ==0xE ) { + __CORE_CLK_PRE =8000000UL ; + }else if (((RCC_Val >>6 ) &0x1F ) ==0xF ) { + __CORE_CLK_PRE =8192000UL ; + }else if (((RCC_Val >>6 ) &0x1F ) ==0x10 ) { + __CORE_CLK_PRE =10000000UL ; + }else if (((RCC_Val >>6 ) &0x1F ) ==0x11 ) { + __CORE_CLK_PRE =12000000UL ; + }else if (((RCC_Val >>6 ) &0x1F ) ==0x12 ) { + __CORE_CLK_PRE =12288000UL ; + }else if (((RCC_Val >>6 ) &0x1F ) ==0x13 ) { + __CORE_CLK_PRE =13560000UL ; + }else if (((RCC_Val >>6 ) &0x1F ) ==0x14 ) { + __CORE_CLK_PRE =14318180UL ; + }else if (((RCC_Val >>6 ) &0x1F ) ==0x15 ) { + __CORE_CLK_PRE =16000000UL ; + }else if (((RCC_Val >>6 ) &0x1F ) ==0x16 ) { + __CORE_CLK_PRE =16384000UL ; + }else if (((RCC_Val >>6 ) &0x1F ) ==0x17 ) { + __CORE_CLK_PRE =18000000UL ; + }else if (((RCC_Val >>6 ) &0x1F ) ==0x18 ) { + __CORE_CLK_PRE =20000000UL ; + }else if (((RCC_Val >>6 ) &0x1F ) ==0x19 ) { + __CORE_CLK_PRE =24000000UL ; + }else if (((RCC_Val >>6 ) &0x1F ) ==0x1A ) { + __CORE_CLK_PRE =25000000UL ; + }else { + __CORE_CLK_PRE =0UL ; + } + __CORE_CLK = __CORE_CLK_PRE /2UL ;/* divide by 2 since BYPASS is set */ + }else {/* PLL is used */ +uint32_t __PLL_MULT = ((RCC2_Val >>4 ) &0x1F ) +2 ; +uint32_t __PLL_DIV = ((RCC2_Val >>0 ) &0x3F ) +1 ; +uint32_t __PLL_SOURCE = ((RCC2_Val >>13 ) &0x01 ); +if (__PLL_SOURCE ==0 ) {/* source is XTAL */ + __CORE_CLK_PRE = (XTALI * __PLL_MULT) / __PLL_DIV; + }else {/* source is internal oscillator */ + __CORE_CLK_PRE = (16000000UL * __PLL_MULT) / __PLL_DIV;/* internal oscillator frequency is 16MHz */ + } + __CORE_CLK = __CORE_CLK_PRE /2UL ;/* divide by 2 since BYPASS is set */ + } + }else {/* BYPASS is not set */ +uint32_t __SYS_DIV = ((RCC2_Val >>22 ) &0x7F ) +1 ; +uint32_t __PLL_MULT = ((RCC2_Val >>4 ) &0x1F ) +2 ; +uint32_t __PLL_DIV = ((RCC2_Val >>0 ) &0x3F ) +1 ; +uint32_t __PLL_SOURCE = ((RCC2_Val >>13 ) &0x01 ); +if (__PLL_SOURCE ==0 ) {/* source is XTAL */ + __CORE_CLK_PRE = (XTALI * __PLL_MULT) / __PLL_DIV; + }else {/* source is internal oscillator */ + __CORE_CLK_PRE = (16000000UL * __PLL_MULT) / __PLL_DIV;/* internal oscillator frequency is 16MHz */ + } + __CORE_CLK = __CORE_CLK_PRE / __SYS_DIV; + } + }else {/* rcc2 is not used */ +if (((RCC_Val >>16 ) &0x01 ) ==0x01 ) {/* check USESYSCLK */ +if (((RCC_Val >>23 ) &0x01 ) ==0x01 ) {/* check BYPASS */ + __CORE_CLK_PRE =XTALI ; + }else {/* PLL is used */ +uint32_t __PLL_MULT = ((RCC_Val >>18 ) &0x1F ) +2 ; +uint32_t __PLL_DIV = ((RCC_Val >>12 ) &0x3F ) +1 ; +uint32_t __PLL_SOURCE = ((RCC_Val >>16 ) &0x01 ); +if (__PLL_SOURCE ==0 ) {/* source is XTAL */ + __CORE_CLK_PRE = (XTALI * __PLL_MULT) / __PLL_DIV; + }else {/* source is internal oscillator */ + __CORE_CLK_PRE = (16000000UL * __PLL_MULT) / __PLL_DIV;/* internal oscillator frequency is 16MHz */ + } + } + }else {/* USESYSCLK bit is not set */ + __CORE_CLK_PRE =16000000UL ;/* default to internal oscillator frequency */ + } + __CORE_CLK = __CORE_CLK_PRE /1UL ;/* no division needed since BYPASS is not set */ + } +trace_tm4c123_sysctl_update_system_clock (__CORE_CLK); +clock_update_hz (s->mainclk, __CORE_CLK); +} + +static void tm4c123_sysctl_reset (DeviceState *dev) +{ +TM4C123SysCtlState *s =TM4C123_SYSCTL (dev); + + s->sysctl_did0 =0x00000000 ; + s->sysctl_did1 =0x10A1606E ; + s->sysctl_pborctl =0x00000000 ; + s->sysctl_ris =0x00000000 ; + s->sysctl_imc =0x00000000 ; + s->sysctl_misc =0x00000000 ; + s->sysctl_resc =0x00000000 ; + s->sysctl_rcc =0x078E3AD1 ; + s->sysctl_gpiohbctl =0x00007E00 ; + s->sysctl_rcc2 =0x07C06810 ; + s->sysctl_moscctl =0x00000000 ; + s->sysctl_dslpclkcfg =0x07800000 ; + s->sysctl_sysprop =0x00001D31 ; + s->sysctl_piosccal =0x00000000 ; + s->sysctl_pioscstat =0x00000040 ; + s->sysctl_pllfreq0 =0x00000032 ; + s->sysctl_pllfreq1 =0x00000001 ; + s->sysctl_pllstat =0x00000000 ; + s->sysctl_slppwrcfg =0x00000000 ; + s->sysctl_dslppwrcfg =0x00000000 ; + s->sysctl_ldospctl =0x00000018 ; + s->sysctl_ldospcal =0x00001818 ; + s->sysctl_ldodpctl =0x00000012 ; + s->sysctl_ldodpcal =0x00001212 ; + s->sysctl_sdpmst =0x00000000 ; + s->sysctl_ppwd =0x00000003 ; + s->sysctl_pptimer =0x0000003F ; + s->sysctl_ppgpio =0x0000003F ; + s->sysctl_ppdma =0x00000001 ; + s->sysctl_pphib =0x00000001 ; + s->sysctl_ppuart =0x000000FF ; + s->sysctl_ppsi =0x0000000F ; + s->sysctl_ppi2c =0x0000000F ; + s->sysctl_ppusb =0x00000001 ; + s->sysctl_ppcan =0x00000003 ; + s->sysctl_ppadc =0x00000003 ; + s->sysctl_ppacmp =0x00000001 ; + s->sysctl_pppwm =0x00000003 ; + s->sysctl_ppqei =0x00000003 ; + s->sysctl_ppeeprom =0x00000001 ; + s->sysctl_ppwtimer =0x0000003F ; + s->sysctl_srwd =0x00000000 ; + s->sysctl_srtimer =0x00000000 ; + s->sysctl_srgpio =0x00000000 ; + s->sysctl_srdma =0x00000000 ; + s->sysctl_srhib =0x00000000 ; + s->sysctl_sruart =0x00000000 ; + s->sysctl_srssi =0x00000000 ; + s->sysctl_sri2c =0x00000000 ; + s->sysctl_srusb =0x00000000 ; + s->sysctl_srcan =0x00000000 ; + s->sysctl_sradc =0x00000000 ; + s->sysctl_sracmp =0x00000000 ; + s->sysctl_srpwm =0x00000000 ; + s->sysctl_srqei =0x00000000 ; + s->sysctl_sreeprom =0x00000000 ; + s->sysctl_srwtimer =0x00000000 ; + s->sysctl_rcgcwd =0x00000000 ; + s->sysctl_rcgctimer =0x00000000 ; + s->sysctl_rcgcgpio =0x00000000 ; + s->sysctl_rcgcdma =0x00000000 ; + s->sysctl_rcgchib =0x00000001 ; + s->sysctl_rcgcuart =0x00000000 ; + s->sysctl_rcgcssi =0x00000000 ; + s->sysctl_rcgci2c =0x00000000 ; + s->sysctl_rcgcusb =0x00000000 ; + s->sysctl_rcgccan =0x00000000 ; + s->sysctl_rcgcadc =0x00000000 ; + s->sysctl_rcgcacmp =0x00000000 ; + s->sysctl_rcgcpwm =0x00000000 ; + s->sysctl_rcgcqei =0x00000000 ; + s->sysctl_rcgceeprom =0x00000000 ; + s->sysctl_rcgcwtimer =0x00000000 ; + s->sysctl_scgcwd =0x00000000 ; + s->sysctl_scgctimer =0x00000000 ; + s->sysctl_scgcgpio =0x00000000 ; + s->sysctl_scgcdma =0x00000000 ; + s->sysctl_scgchib =0x00000001 ; + s->sysctl_scgcuart =0x00000000 ; + s->sysctl_scgcssi =0x00000000 ; + s->sysctl_scgci2c =0x00000000 ; + s->sysctl_scgcusb =0x00000000 ; + s->sysctl_scgccan =0x00000000 ; + s->sysctl_scgcadc =0x00000000 ; + s->sysctl_scgcacmp =0x00000000 ; + s->sysctl_scgcpwm =0x00000000 ; + s->sysctl_scgcqei =0x00000000 ; + s->sysctl_scgceeprom =0x00000000 ; + s->sysctl_scgcwtimer =0x00000000 ; + s->sysctl_dcgcwd =0x00000000 ; + s->sysctl_dcgctimer =0x00000000 ; + s->sysctl_dcgcgpio =0x00000000 ; + s->sysctl_dcgcdma =0x00000000 ; + s->sysctl_dcgchib =0x00000001 ; + s->sysctl_dcgcuart =0x00000000 ; + s->sysctl_dcgcssi =0x00000000 ; + s->sysctl_dcgci2c =0x00000000 ; + s->sysctl_dcgcusb =0x00000000 ; + s->sysctl_dcgccan =0x00000000 ; + s->sysctl_dcgcadc =0x00000000 ; + s->sysctl_dcgcacmp =0x00000000 ; + s->sysctl_dcgcpwm =0x00000000 ; + s->sysctl_dcgcqei =0x00000000 ; + s->sysctl_dcgceeprom =0x00000000 ; + s->sysctl_dcgcwtime =0x00000000 ; + s->sysctl_prwd =0x00000000 ; + s->sysctl_prtimer =0x00000000 ; + s->sysctl_prgpio =0x00000000 ; + s->sysctl_prdma =0x00000000 ; + s->sysctl_prhib =0x00000001 ; + s->sysctl_pruart =0x00000000 ; + s->sysctl_prssi =0x00000000 ; + s->sysctl_pri2c =0x00000000 ; + s->sysctl_prusb =0x00000000 ; + s->sysctl_prcan =0x00000000 ; + s->sysctl_pradc =0x00000000 ; + s->sysctl_pracmp =0x00000000 ; + s->sysctl_prpwm =0x00000000 ; + s->sysctl_prqei =0x00000000 ; + s->sysctl_preeprom =0x00000000 ; + s->sysctl_prwtimer =0x00000000 ; +} + +static void tm4c123_sysctl_write (void *opaque,hwaddr addr,uint64_t val64,unsigned int size) +{ +TM4C123SysCtlState *s = opaque; +uint32_t val32 = val64; + +trace_tm4c123_sysctl_write (addr, val32); + +switch (addr) { +case SYSCTL_DID0 : +READONLY ; +break ; +case SYSCTL_DID1 : +READONLY ; +break ; +case SYSCTL_PBORCTL : + s->sysctl_pborctl = val32; +break ; +case SYSCTL_RIS : +READONLY ; +break ; +case SYSCTL_IMC : + s->sysctl_imc = val32; +/* +* setting the MISC +*/ + s->sysctl_misc = val32; +break ; +case SYSCTL_MISC : + s->sysctl_misc = val32; +break ; +case SYSCTL_RESC : + s->sysctl_resc = val32; +break ; +case SYSCTL_RCC : + s->sysctl_rcc = val32; +/* +* Setting the SYSCTL_RIS manually for now. +*/ +if (s->sysctl_rcc &SYSCTL_RCC_PWRDN && !(s->sysctl_rcc2 &SYSCTL_RCC2_USERCC2 )) { + s->sysctl_ris |=SYSCTL_RIS_PLLRIS ; + } +tm4c123_sysctl_update_system_clock (s); +break ; +case SYSCTL_GPIOHBCTL : + s->sysctl_gpiohbctl = val32; +break ; +case SYSCTL_RCC2 : + s->sysctl_rcc2 = val32; +/* +* Setting the SYSCTL_RIS manually for now. +*/ +if (s->sysctl_rcc2 &SYSCTL_RCC2_USERCC2 && !(s->sysctl_rcc2 &SYSCTL_RCC2_PWRDN2 )) { + s->sysctl_ris |=SYSCTL_RIS_PLLRIS ; + } +tm4c123_sysctl_update_system_clock (s); +break ; +case SYSCTL_MOSCCTL : + s->sysctl_moscctl = val32; +break ; +case SYSCTL_DSLPCLKCFG : + s->sysctl_dslpclkcfg = val32; +break ; +case SYSCTL_SYSPROP : +READONLY ; +break ; +case SYSCTL_PIOSCCAL : + s->sysctl_piosccal = val32; +break ; +case SYSCTL_PIOSCSTAT : +READONLY ; +break ; +case SYSCTL_PLLFREQ0 : +READONLY ; +break ; +case SYSCTL_PLLFREQ1 : +READONLY ; +break ; +case SYSCTL_PLLSTAT : +READONLY ; +break ; +case SYSCTL_SLPPWRCFG : + s->sysctl_slppwrcfg = val32; +break ; +case SYSCTL_DSLPPWRCFG : + s->sysctl_dslppwrcfg = val32; +break ; +case SYSCTL_LDOSPCTL : + s->sysctl_ldospctl = val32; +break ; +case SYSCTL_LDOSPCAL : +READONLY ; +break ; +case SYSCTL_LDODPCTL : + s->sysctl_ldodpctl = val32; +break ; +case SYSCTL_LDODPCAL : +READONLY ; +break ; +case SYSCTL_SDPMST : + s->sysctl_sdpmst = val32; +break ; +case SYSCTL_PPWD : +READONLY ; +break ; +case SYSCTL_PPTIMER : +READONLY ; +break ; +case SYSCTL_PPGPIO : +READONLY ; +break ; +case SYSCTL_PPDMA : +READONLY ; +break ; +case SYSCTL_PPHIB : +READONLY ; +break ; +case SYSCTL_PPUART : +READONLY ; +break ; +case SYSCTL_PPSI : +READONLY ; +break ; +case SYSCTL_PPI2C : +READONLY ; +break ; +case SYSCTL_PPUSB : +READONLY ; +break ; +case SYSCTL_PPCAN : +READONLY ; +break ; +case SYSCTL_PPADC : +READONLY ; +break ; +case SYSCTL_PPACMP : +READONLY ; +break ; +case SYSCTL_PPPWM : +READONLY ; +break ; +case SYSCTL_PPQEI : +READONLY ; +break ; +case SYSCTL_PPEEPROM : +READONLY ; +break ; +case SYSCTL_PPWTIMER : +READONLY ; +break ; +case SYSCTL_SRWD : + s->sysctl_srwd = val32; +break ; +case SYSCTL_SRTIMER : + s->sysctl_srtimer = val32; +break ; +case SYSCTL_SRGPIO : + s->sysctl_srgpio = val32; +break ; +case SYSCTL_SRDMA : + s->sysctl_srdma = val32; +break ; +case SYSCTL_SRHIB : + s->sysctl_srhib = val32; +break ; +case SYSCTL_SRUART : + s->sysctl_sruart = val32; +break ; +case SYSCTL_SRSSI : + s->sysctl_srssi = val32; +break ; +case SYSCTL_SRI2C : + s->sysctl_sri2c = val32; +break ; +case SYSCTL_SRUSB : + s->sysctl_srusb = val32; +break ; +case SYSCTL_SRCAN : + s->sysctl_srcan = val32; +break ; +case SYSCTL_SRADC : + s->sysctl_sradc = val32; +break ; +case SYSCTL_SRACMP : + s->sysctl_sracmp = val32; +break ; +case SYSCTL_SRPWM : + s->sysctl_srpwm = val32; +break ; +case SYSCTL_SRQEI : + s->sysctl_srqei = val32; +break ; +case SYSCTL_SREEPROM : + s->sysctl_sreeprom = val32; +break ; +case SYSCTL_SRWTIMER : + s->sysctl_srwtimer = val32; +break ; +case SYSCTL_RCGCWD : + s->sysctl_rcgcwd = val32; +break ; +case SYSCTL_RCGCTIMER : + s->sysctl_rcgctimer = val32; +break ; +case SYSCTL_RCGCGPIO : + s->sysctl_rcgcgpio = val32; + s->sysctl_prgpio = val32; +break ; +case SYSCTL_RCGCDMA : + s->sysctl_rcgcdma = val32; + s->sysctl_prdma = val32; +break ; +case SYSCTL_RCGCHIB : + s->sysctl_rcgchib = val32; + s->sysctl_prhib = val32; +break ; +case SYSCTL_RCGCUART : + s->sysctl_rcgcuart = val32; + s->sysctl_pruart = val32; +break ; +case SYSCTL_RCGCSSI : + s->sysctl_rcgcssi = val32; + s->sysctl_prssi = val32; +break ; +case SYSCTL_RCGCI2C : + s->sysctl_rcgci2c = val32; + s->sysctl_pri2c = val32; +break ; +case SYSCTL_RCGCUSB : + s->sysctl_rcgcusb = val32; + s->sysctl_prusb = val32; +break ; +case SYSCTL_RCGCCAN : + s->sysctl_rcgccan = val32; + s->sysctl_prcan = val32; +break ; +case SYSCTL_RCGCADC : + s->sysctl_rcgcadc = val32; + s->sysctl_pradc = val32; +break ; +case SYSCTL_RCGCACMP : + s->sysctl_rcgcacmp = val32; + s->sysctl_pracmp = val32; +break ; +case SYSCTL_RCGCPWM : + s->sysctl_rcgcpwm = val32; + s->sysctl_prpwm = val32; +break ; +case SYSCTL_RCGCQEI : + s->sysctl_rcgcqei = val32; + s->sysctl_prqei = val32; +break ; +case SYSCTL_RCGCEEPROM : + s->sysctl_rcgceeprom = val32; + s->sysctl_preeprom = val32; +break ; +case SYSCTL_RCGCWTIMER : + s->sysctl_rcgcwtimer = val32; + s->sysctl_prwtimer = val32; +break ; +case SYSCTL_SCGCWD : + s->sysctl_scgcwd = val32; +break ; +case SYSCTL_SCGCTIMER : + s->sysctl_scgctimer = val32; +break ; +case SYSCTL_SCGCGPIO : + s->sysctl_scgcgpio = val32; +break ; +case SYSCTL_SCGCDMA : + s->sysctl_scgcdma = val32; +break ; +case SYSCTL_SCGCHIB : + s->sysctl_scgchib = val32; +break ; +case SYSCTL_SCGCUART : + s->sysctl_scgcuart = val32; +break ; +case SYSCTL_SCGCSSI : + s->sysctl_scgcssi = val32; +break ; +case SYSCTL_SCGCI2C : + s->sysctl_scgci2c = val32; +break ; +case SYSCTL_SCGCUSB : + s->sysctl_scgcusb = val32; +break ; +case SYSCTL_SCGCCAN : + s->sysctl_scgccan = val32; +break ; +case SYSCTL_SCGCADC : + s->sysctl_scgcadc = val32; +break ; +case SYSCTL_SCGCACMP : + s->sysctl_scgcacmp = val32; +break ; +case SYSCTL_SCGCPWM : + s->sysctl_scgcpwm = val32; +break ; +case SYSCTL_SCGCQEI : + s->sysctl_scgcqei = val32; +break ; +case SYSCTL_SCGCEEPROM : + s->sysctl_scgceeprom = val32; +break ; +case SYSCTL_SCGCWTIMER : + s->sysctl_scgcwtimer = val32; +break ; +case SYSCTL_DCGCWD : + s->sysctl_dcgcwd = val32; +break ; +case SYSCTL_DCGCTIMER : + s->sysctl_dcgctimer = val32; +break ; +case SYSCTL_DCGCGPIO : + s->sysctl_dcgcgpio = val32; +break ; +case SYSCTL_DCGCDMA : + s->sysctl_dcgcdma = val32; +break ; +case SYSCTL_DCGCHIB : + s->sysctl_dcgchib = val32; +break ; +case SYSCTL_DCGCUART : + s->sysctl_dcgcuart = val32; +break ; +case SYSCTL_DCGCSSI : + s->sysctl_dcgcssi = val32; +break ; +case SYSCTL_DCGCI2C : + s->sysctl_dcgci2c = val32; +break ; +case SYSCTL_DCGCUSB : + s->sysctl_dcgcusb = val32; +break ; +case SYSCTL_DCGCCAN : + s->sysctl_dcgccan = val32; +break ; +case SYSCTL_DCGCADC : + s->sysctl_dcgcadc = val32; +break ; +case SYSCTL_DCGCACMP : + s->sysctl_dcgcacmp = val32; +break ; +case SYSCTL_DCGCPWM : + s->sysctl_dcgcpwm = val32; +break ; +case SYSCTL_DCGCQEI : + s->sysctl_dcgcqei = val32; +break ; +case SYSCTL_DCGCEEPROM : + s->sysctl_dcgceeprom = val32; +break ; +case SYSCTL_DCGCWTIME : + s->sysctl_dcgcwtime = val32; +break ; +case SYSCTL_PRWD : +READONLY ; +break ; +case SYSCTL_PRTIMER : +READONLY ; +break ; +case SYSCTL_PRGPIO : +READONLY ; +break ; +case SYSCTL_PRDMA : +READONLY ; +break ; +case SYSCTL_PRHIB : +READONLY ; +break ; +case SYSCTL_PRUART : +READONLY ; +break ; +case SYSCTL_PRSSI : +READONLY ; +break ; +case SYSCTL_PRI2C : +READONLY ; +break ; +case SYSCTL_PRUSB : +READONLY ; +break ; +case SYSCTL_PRCAN : +READONLY ; +break ; +case SYSCTL_PRADC : +READONLY ; +break ; +case SYSCTL_PRACMP : +READONLY ; +break ; +case SYSCTL_PRPWM : +READONLY ; +break ; +case SYSCTL_PRQEI : +READONLY ; +break ; +case SYSCTL_PREEPROM : +READONLY ; +break ; +case SYSCTL_PRWTIMER : +READONLY ; +break ; +default : +LOG ("Bad address 0x%" HWADDR_PRIx"\n" , addr); +break ; + } +} + +static uint64_t tm4c123_sysctl_read (void *opaque,hwaddr addr,unsigned int size) +{ +TM4C123SysCtlState *s = opaque; + +trace_tm4c123_sysctl_read (addr); + +switch (addr) { +case SYSCTL_DID0 : +return s->sysctl_did0; +case SYSCTL_DID1 : +return s->sysctl_did1; +case SYSCTL_PBORCTL : +return s->sysctl_pborctl; +case SYSCTL_RIS : +return s->sysctl_ris; +case SYSCTL_IMC : +return s->sysctl_imc; +case SYSCTL_MISC : +return s->sysctl_misc; +case SYSCTL_RESC : +return s->sysctl_resc; +case SYSCTL_RCC : +return s->sysctl_rcc; +case SYSCTL_GPIOHBCTL : +return s->sysctl_gpiohbctl; +case SYSCTL_RCC2 : +return s->sysctl_rcc2; +case SYSCTL_MOSCCTL : +return s->sysctl_moscctl; +case SYSCTL_DSLPCLKCFG : +return s->sysctl_dslpclkcfg; +case SYSCTL_SYSPROP : +return s->sysctl_sysprop; +case SYSCTL_PIOSCCAL : +return s->sysctl_piosccal; +case SYSCTL_PIOSCSTAT : +return s->sysctl_pioscstat; +case SYSCTL_PLLFREQ0 : +return s->sysctl_pllfreq0; +case SYSCTL_PLLFREQ1 : +return s->sysctl_pllfreq1; +case SYSCTL_PLLSTAT : +return s->sysctl_pllstat; +case SYSCTL_SLPPWRCFG : +return s->sysctl_slppwrcfg; +case SYSCTL_DSLPPWRCFG : +return s->sysctl_dslppwrcfg; +case SYSCTL_LDOSPCTL : +return s->sysctl_ldospctl; +case SYSCTL_LDOSPCAL : +return s->sysctl_ldospcal; +case SYSCTL_LDODPCTL : +return s->sysctl_ldodpctl; +case SYSCTL_LDODPCAL : +return s->sysctl_ldodpcal; +case SYSCTL_SDPMST : +return s->sysctl_sdpmst; +case SYSCTL_PPWD : +return s->sysctl_ppwd; +case SYSCTL_PPTIMER : +return s->sysctl_pptimer; +case SYSCTL_PPGPIO : +return s->sysctl_ppgpio; +case SYSCTL_PPDMA : +return s->sysctl_ppdma; +case SYSCTL_PPHIB : +return s->sysctl_pphib; +case SYSCTL_PPUART : +return s->sysctl_ppuart; +case SYSCTL_PPSI : +return s->sysctl_ppsi; +case SYSCTL_PPI2C : +return s->sysctl_ppi2c; +case SYSCTL_PPUSB : +return s->sysctl_ppusb; +case SYSCTL_PPCAN : +return s->sysctl_ppcan; +case SYSCTL_PPADC : +return s->sysctl_ppadc; +case SYSCTL_PPACMP : +return s->sysctl_ppacmp; +case SYSCTL_PPPWM : +return s->sysctl_pppwm; +case SYSCTL_PPQEI : +return s->sysctl_ppqei; +case SYSCTL_PPEEPROM : +return s->sysctl_ppeeprom; +case SYSCTL_PPWTIMER : +return s->sysctl_ppwtimer; +case SYSCTL_SRWD : +return s->sysctl_srwd; +case SYSCTL_SRTIMER : +return s->sysctl_srtimer; +case SYSCTL_SRGPIO : +return s->sysctl_srgpio; +case SYSCTL_SRDMA : +return s->sysctl_srdma; +case SYSCTL_SRHIB : +return s->sysctl_srhib; +case SYSCTL_SRUART : +return s->sysctl_sruart; +case SYSCTL_SRSSI : +return s->sysctl_srssi; +case SYSCTL_SRI2C : +return s->sysctl_sri2c; +case SYSCTL_SRUSB : +return s->sysctl_srusb; +case SYSCTL_SRCAN : +return s->sysctl_srcan; +case SYSCTL_SRADC : +return s->sysctl_sradc; +case SYSCTL_SRACMP : +return s->sysctl_sracmp; +case SYSCTL_SRPWM : +return s->sysctl_srpwm; +case SYSCTL_SRQEI : +return s->sysctl_srqei; +case SYSCTL_SREEPROM : +return s->sysctl_sreeprom; +case SYSCTL_SRWTIMER : +return s->sysctl_srwtimer; +case SYSCTL_RCGCWD : +return s->sysctl_rcgcwd; +case SYSCTL_RCGCTIMER : +return s->sysctl_rcgctimer; +case SYSCTL_RCGCGPIO : +return s->sysctl_rcgcgpio; +case SYSCTL_RCGCDMA : +return s->sysctl_rcgcdma; +case SYSCTL_RCGCHIB : +return s->sysctl_rcgchib; +case SYSCTL_RCGCUART : +return s->sysctl_rcgcuart; +case SYSCTL_RCGCSSI : +return s->sysctl_rcgcssi; +case SYSCTL_RCGCI2C : +return s->sysctl_rcgci2c; +case SYSCTL_RCGCUSB : +return s->sysctl_rcgcusb; +case SYSCTL_RCGCCAN : +return s->sysctl_rcgccan; +case SYSCTL_RCGCADC : +return s->sysctl_rcgcadc; +case SYSCTL_RCGCACMP : +return s->sysctl_rcgcacmp; +case SYSCTL_RCGCPWM : +return s->sysctl_rcgcpwm; +case SYSCTL_RCGCQEI : +return s->sysctl_rcgcqei; +case SYSCTL_RCGCEEPROM : +return s->sysctl_rcgceeprom; +case SYSCTL_RCGCWTIMER : +return s->sysctl_rcgcwtimer; +case SYSCTL_SCGCWD : +return s->sysctl_scgcwd; +case SYSCTL_SCGCTIMER : +return s->sysctl_scgctimer; +case SYSCTL_SCGCGPIO : +return s->sysctl_scgcgpio; +case SYSCTL_SCGCDMA : +return s->sysctl_scgcdma; +case SYSCTL_SCGCHIB : +return s->sysctl_scgchib; +case SYSCTL_SCGCUART : +return s->sysctl_scgcuart; +case SYSCTL_SCGCSSI : +return s->sysctl_scgcssi; +case SYSCTL_SCGCI2C : +return s->sysctl_scgci2c; +case SYSCTL_SCGCUSB : +return s->sysctl_scgcusb; +case SYSCTL_SCGCCAN : +return s->sysctl_scgccan; +case SYSCTL_SCGCADC : +return s->sysctl_scgcadc; +case SYSCTL_SCGCACMP : +return s->sysctl_scgcacmp; +case SYSCTL_SCGCPWM : +return s->sysctl_scgcpwm; +case SYSCTL_SCGCQEI : +return s->sysctl_scgcqei; +case SYSCTL_SCGCEEPROM : +return s->sysctl_scgceeprom; +case SYSCTL_SCGCWTIMER : +return s->sysctl_scgcwtimer; +case SYSCTL_DCGCWD : +return s->sysctl_dcgcwd; +case SYSCTL_DCGCTIMER : +return s->sysctl_dcgctimer; +case SYSCTL_DCGCGPIO : +return s->sysctl_dcgcgpio; +case SYSCTL_DCGCDMA : +return s->sysctl_dcgcdma; +case SYSCTL_DCGCHIB : +return s->sysctl_dcgchib; +case SYSCTL_DCGCUART : +return s->sysctl_dcgcuart; +case SYSCTL_DCGCSSI : +return s->sysctl_dcgcssi; +case SYSCTL_DCGCI2C : +return s->sysctl_dcgci2c; +case SYSCTL_DCGCUSB : +return s->sysctl_dcgcusb; +case SYSCTL_DCGCCAN : +return s->sysctl_dcgccan; +case SYSCTL_DCGCADC : +return s->sysctl_dcgcadc; +case SYSCTL_DCGCACMP : +return s->sysctl_dcgcacmp; +case SYSCTL_DCGCPWM : +return s->sysctl_dcgcpwm; +case SYSCTL_DCGCQEI : +return s->sysctl_dcgcqei; +case SYSCTL_DCGCEEPROM : +return s->sysctl_dcgceeprom; +case SYSCTL_DCGCWTIME : +return s->sysctl_dcgcwtime; +case SYSCTL_PRWD : +return s->sysctl_prwd; +case SYSCTL_PRTIMER : +return s->sysctl_prtimer; +case SYSCTL_PRGPIO : +return s->sysctl_prgpio; +case SYSCTL_PRDMA : +return s->sysctl_prdma; +case SYSCTL_PRHIB : +return s->sysctl_prhib; +case SYSCTL_PRUART : +return s->sysctl_pruart; +case SYSCTL_PRSSI : +return s->sysctl_prssi; +case SYSCTL_PRI2C : +return s->sysctl_pri2c; +case SYSCTL_PRUSB : +return s->sysctl_prusb; +case SYSCTL_PRCAN : +return s->sysctl_prcan; +case SYSCTL_PRADC : +return s->sysctl_pradc; +case SYSCTL_PRACMP : +return s->sysctl_pracmp; +case SYSCTL_PRPWM : +return s->sysctl_prpwm; +case SYSCTL_PRQEI : +return s->sysctl_prqei; +case SYSCTL_PREEPROM : +return s->sysctl_preeprom; +case SYSCTL_PRWTIMER : +return s->sysctl_prwtimer; +default : +LOG ("Bad address 0x%" HWADDR_PRIx"\n" , addr); +break ; + } +return 0 ; +} + +static const MemoryRegionOps tm4c123_sysctl_ops = { + .read = tm4c123_sysctl_read, + .write = tm4c123_sysctl_write, + .endianness =DEVICE_NATIVE_ENDIAN , +}; + +static void tm4c123_sysctl_init (Object *obj) +{ +TM4C123SysCtlState *s =TM4C123_SYSCTL (obj); + + s->mainclk =clock_new (OBJECT (s),"main-clk" ); +clock_set_hz (s->mainclk,1000 *1000 ); + s->outclk =qdev_init_clock_out (DEVICE (s),"outclk" ); +clock_set_source (s->outclk, s->mainclk); + +memory_region_init_io (&s->mmio, obj, &tm4c123_sysctl_ops, s,TYPE_TM4C123_SYSCTL ,0xFFF ); +sysbus_init_mmio (SYS_BUS_DEVICE (obj), &s->mmio); +} + +static void tm4c123_sysctl_realize (DeviceState *dev,Error **errp) +{ +TM4C123SysCtlState *s =TM4C123_SYSCTL (dev); +tm4c123_sysctl_update_system_clock (s); + +} + +static void tm4c123_sysctl_class_init (ObjectClass *kclass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (kclass); + dc->reset = tm4c123_sysctl_reset; + dc->realize = tm4c123_sysctl_realize; +} + +static const TypeInfo tm4c123_sysctl_info = { + .name =TYPE_TM4C123_SYSCTL , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (TM4C123SysCtlState), + .instance_init = tm4c123_sysctl_init, + .class_init = tm4c123_sysctl_class_init, +}; + +static void tm4c123_sysctl_register_types (void ) +{ +type_register_static (&tm4c123_sysctl_info); +} + +type_init (tm4c123_sysctl_register_types)
include/hw/misc/tm4c123_sysctl.h new file +307 -0
307 lines not on this page · raw message
Signature · 1 line
2.34.1
[PULL 3/8] tivac gpio module implementation
In reply to Mohamed ElSayed--- hw/gpio/tm4c123_gpio.c | 372 +++++++++++++++++++++++++++++++++ include/hw/gpio/tm4c123_gpio.h | 127 +++++++++++ 2 files changed, 499 insertions(+) create mode 100644 hw/gpio/tm4c123_gpio.c create mode 100644 include/hw/gpio/tm4c123_gpio.h
hw/gpio/tm4c123_gpio.c new file +372 -0
@@ -0,0 +1,372 @@ +/* +* TM4C123 GPIO +* +* Copyright (c) 2023 Mohamed ElSayed <[email protected]> +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +#include "qemu/osdep.h" +#include "hw/gpio/tm4c123_gpio.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "hw/misc/tm4c123_sysctl.h" +#include "qemu/bitops.h" +#include "trace.h" + +#define LOG(fmt, args...) qemu_log("%s: " fmt, __func__, ## args) +#define READONLY LOG("0x%"HWADDR_PRIx" is a readonly field\n.", addr) + +static bool gpio_clock_enabled (TM4C123SysCtlState *s,hwaddr addr) +{ +switch (addr) { +case GPIO_A : +return test_bit (0 , (const unsigned long *)&s->sysctl_rcgcgpio); +break ; +case GPIO_B : +return test_bit (1 , (const unsigned long *)&s->sysctl_rcgcgpio); +break ; +case GPIO_C : +return test_bit (2 , (const unsigned long *)&s->sysctl_rcgcgpio); +break ; +case GPIO_D : +return test_bit (3 , (const unsigned long *)&s->sysctl_rcgcgpio); +break ; +case GPIO_E : +return test_bit (4 , (const unsigned long *)&s->sysctl_rcgcgpio); +break ; +case GPIO_F : +return test_bit (5 , (const unsigned long *)&s->sysctl_rcgcgpio); +break ; + } +return false; +} + +static void tm4c123_gpio_reset (DeviceState *dev) +{ +TM4C123GPIOState *s =TM4C123_GPIO (dev); + + s->gpio_data =0x00000000 ; + s->gpio_dir =0x00000000 ; + s->gpio_is =0x00000000 ; + s->gpio_ibe =0x00000000 ; + s->gpio_iev =0x00000000 ; + s->gpio_im =0x00000000 ; + s->gpio_ris =0x00000000 ; + s->gpio_mis =0x00000000 ; + s->gpio_icr =0x00000000 ; + s->gpio_afsel =0x00000000 ; + s->gpio_dr2r =0x000000FF ; + s->gpio_dr4r =0x00000000 ; + s->gpio_dr8r =0x00000000 ; + s->gpio_odr =0x00000000 ; + s->gpio_pur =0x00000000 ; + s->gpio_pdr =0x00000000 ; + s->gpio_slr =0x00000000 ; + s->gpio_den =0x00000000 ; + s->gpio_lock =0x00000001 ; + s->gpio_ocr =0x00000000 ; + s->gpio_amsel =0x00000000 ; + s->gpio_pctl =0x00000000 ; + s->gpio_adcctl =0x00000000 ; + s->gpio_dmactl =0x00000000 ; + s->gpio_per_id4 =0x00000000 ; + s->gpio_per_id5 =0x00000000 ; + s->gpio_per_id6 =0x00000000 ; + s->gpio_per_id7 =0x00000000 ; + s->gpio_per_id0 =0x00000061 ; + s->gpio_per_id1 =0x00000000 ; + s->gpio_per_id2 =0x00000018 ; + s->gpio_per_id3 =0x00000001 ; + s->gpio_pcell_id0 =0x0000000D ; + s->gpio_pcell_id1 =0x000000F0 ; + s->gpio_pcell_id2 =0x00000005 ; + s->gpio_pcell_id3 =0x000000B1 ; +} + +static void tm4c123_gpio_write (void *opaque,hwaddr addr,uint64_t val64,unsigned int size) +{ +TM4C123GPIOState *s = opaque; +uint32_t val32 = val64; + +if (!gpio_clock_enabled (s->sysctl, s->mmio.addr)) { +hw_error ("GPIO module clock is not enabled" ); + } +trace_tm4c123_gpio_write (addr, val32); + +switch (addr) { +case GPIO_DATA : + { +uint32_t rising_edge = (val32 ^ s->gpio_data) & val32; +//level detection + s->gpio_mis = s->gpio_is & s->gpio_iev & val32; + s->gpio_mis |= s->gpio_is & ~(s->gpio_iev | val32); + s->gpio_mis &= s->gpio_im; + +//edge detection +//both edges + s->gpio_mis |= (s->gpio_is | s->gpio_ibe) & (~s->gpio_is); +//rising edge + s->gpio_mis |= (~(s->gpio_is | s->gpio_ibe | s->gpio_iev)) & rising_edge; +//falling edge + s->gpio_mis |= ~(s->gpio_is | s->gpio_ibe | s->gpio_iev | rising_edge); + s->gpio_mis &= s->gpio_im; + s->gpio_ris |= s->gpio_mis & val32; + + s->gpio_data = val32; +if (s->gpio_im !=0 ) +qemu_irq_pulse (s->irq); + } +break ; +case GPIO_DIR : + s->gpio_dir = val32; +break ; +case GPIO_IS : + s->gpio_is = val32; +break ; +case GPIO_IBE : + s->gpio_ibe = val32; +break ; +case GPIO_IEV : + s->gpio_iev = val32; +break ; +case GPIO_IM : + s->gpio_im = val32; +break ; +case GPIO_RIS : + s->gpio_ris = val32; +break ; +case GPIO_MIS : +READONLY ; +break ; +case GPIO_ICR : + s->gpio_mis ^= val32; + s->gpio_ris ^= val32; + s->gpio_icr = val32; +break ; +case GPIO_AFSEL : + s->gpio_afsel = val32; +break ; +case GPIO_DR2R : + s->gpio_dr2r = val32; +break ; +case GPIO_DR4R : + s->gpio_dr4r = val32; +break ; +case GPIO_DR8R : + s->gpio_dr8r = val32; +break ; +case GPIO_ODR : + s->gpio_odr = val32; +break ; +case GPIO_PUR : + s->gpio_pur = val32; +break ; +case GPIO_PDR : + s->gpio_pdr = val32; +break ; +case GPIO_SLR : + s->gpio_slr = val32; +break ; +case GPIO_DEN : + s->gpio_den = val32; +break ; +case GPIO_LOCK : + s->gpio_lock = val32; +break ; +case GPIO_OCR : + s->gpio_ocr = val32; +break ; +case GPIO_AMSEL : + s->gpio_amsel = val32; +break ; +case GPIO_PCTL : + s->gpio_pctl = val32; +break ; +case GPIO_ADCCTL : + s->gpio_adcctl = val32; +break ; +case GPIO_DMACTL : + s->gpio_dmactl = val32; +break ; +case GPIO_PER_ID4 : +READONLY ; +break ; +case GPIO_PER_ID5 : +READONLY ; +break ; +case GPIO_PER_ID6 : +READONLY ; +break ; +case GPIO_PER_ID7 : +READONLY ; +break ; +case GPIO_PER_ID0 : +READONLY ; +break ; +case GPIO_PER_ID1 : +READONLY ; +break ; +case GPIO_PER_ID2 : +READONLY ; +break ; +case GPIO_PER_ID3 : +READONLY ; +break ; +case GPIO_PCELL_ID0 : +READONLY ; +break ; +case GPIO_PCELL_ID1 : +READONLY ; +break ; +case GPIO_PCELL_ID2 : +READONLY ; +break ; +case GPIO_PCELL_ID3 : +READONLY ; +break ; +default : +LOG ("Bad address 0x%" HWADDR_PRIx"\n" , addr); + } +} + +static uint64_t tm4c123_gpio_read (void *opaque,hwaddr addr,unsigned int size) +{ +TM4C123GPIOState *s = opaque; + +trace_tm4c123_gpio_read (addr); + +if (!gpio_clock_enabled (s->sysctl, s->mmio.addr)) { +hw_error ("GPIO module clock is not enabled" ); + } + +switch (addr) { +case GPIO_DATA : +return s->gpio_data; +case GPIO_DIR : +return s->gpio_dir; +case GPIO_IS : +return s->gpio_is; +case GPIO_IBE : +return s->gpio_ibe; +case GPIO_IEV : +return s->gpio_iev; +case GPIO_IM : +return s->gpio_im; +case GPIO_RIS : +return s->gpio_ris; +case GPIO_MIS : +return s->gpio_mis; +case GPIO_ICR : +return s->gpio_icr; +case GPIO_AFSEL : +return s->gpio_afsel; +case GPIO_DR2R : +return s->gpio_dr2r; +case GPIO_DR4R : +return s->gpio_dr4r; +case GPIO_DR8R : +return s->gpio_dr8r; +case GPIO_ODR : +return s->gpio_odr; +case GPIO_PUR : +return s->gpio_pur; +case GPIO_PDR : +return s->gpio_pdr; +case GPIO_SLR : +return s->gpio_slr; +case GPIO_DEN : +return s->gpio_den; +case GPIO_LOCK : +return s->gpio_lock; +case GPIO_OCR : +return s->gpio_ocr; +case GPIO_AMSEL : +return s->gpio_amsel; +case GPIO_PCTL : +return s->gpio_pctl; +case GPIO_ADCCTL : +return s->gpio_adcctl; +case GPIO_DMACTL : +return s->gpio_dmactl; +case GPIO_PER_ID4 : +return s->gpio_per_id4; +case GPIO_PER_ID5 : +return s->gpio_per_id5; +case GPIO_PER_ID6 : +return s->gpio_per_id6; +case GPIO_PER_ID7 : +return s->gpio_per_id7; +case GPIO_PER_ID0 : +return s->gpio_per_id0; +case GPIO_PER_ID1 : +return s->gpio_per_id1; +case GPIO_PER_ID2 : +return s->gpio_per_id2; +case GPIO_PER_ID3 : +return s->gpio_per_id3; +case GPIO_PCELL_ID0 : +return s->gpio_pcell_id0; +case GPIO_PCELL_ID1 : +return s->gpio_pcell_id1; +case GPIO_PCELL_ID2 : +return s->gpio_pcell_id2; +case GPIO_PCELL_ID3 : +return s->gpio_pcell_id3; +default : +LOG ("Bad address 0x%" HWADDR_PRIx"\n" , addr); + } +return 0 ; +} + +static const MemoryRegionOps tm4c123_gpio_ops = { + .read = tm4c123_gpio_read, + .write = tm4c123_gpio_write, + .endianness =DEVICE_NATIVE_ENDIAN , +}; + +static void tm4c123_gpio_init (Object *obj) +{ +TM4C123GPIOState *s =TM4C123_GPIO (obj); + +sysbus_init_irq (SYS_BUS_DEVICE (obj), &s->irq); +memory_region_init_io (&s->mmio, obj, &tm4c123_gpio_ops, s,TYPE_TM4C123_GPIO ,0xFFF ); +sysbus_init_mmio (SYS_BUS_DEVICE (obj), &s->mmio); +} + +static void tm4c123_gpio_class_init (ObjectClass *kclass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (kclass); + dc->reset = tm4c123_gpio_reset; +} + +static const TypeInfo tm4c123_gpio_info = { + .name =TYPE_TM4C123_GPIO , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (TM4C123GPIOState), + .instance_init = tm4c123_gpio_init, + .class_init = tm4c123_gpio_class_init, +}; + +static void tm4c123_gpio_register_types (void ) +{ +type_register_static (&tm4c123_gpio_info); +} + +type_init (tm4c123_gpio_register_types)
include/hw/gpio/tm4c123_gpio.h new file +127 -0
127 lines not on this page · raw message
Signature · 1 line
2.34.1
[PULL 6/8] tivac watchdog timers implementation
In reply to Mohamed ElSayed--- hw/watchdog/tm4c123_watchdog.c | 298 +++++++++++++++++++++++++ include/hw/watchdog/tm4c123_watchdog.h | 97 ++++++++ 2 files changed, 395 insertions(+) create mode 100644 hw/watchdog/tm4c123_watchdog.c create mode 100644 include/hw/watchdog/tm4c123_watchdog.h
hw/watchdog/tm4c123_watchdog.c new file +298 -0
@@ -0,0 +1,298 @@ +/* +* TM4C123 Watchdog Timers +* +* Copyright (c) 2023 Mohamed ElSayed <[email protected]> +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +#include "qemu/osdep.h" +#include "hw/watchdog/tm4c123_watchdog.h" +#include "hw/irq.h" +#include "hw/qdev-properties.h" +#include "hw/qdev-clock.h" +#include "sysemu/runstate.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "hw/nmi.h" +#include "trace.h" + +#define READONLY LOG("0x%"HWADDR_PRIx" is a readonly field\n.", addr) +#define LOG(fmt, args...) qemu_log("%s: " fmt, __func__, ## args) + +static bool locked = false; + +static void tm4c123_wdt_expired (void *opaque) +{ +TM4C123WatchdogState *s = opaque; +/*if this is the first timeout/the ris is not cleared */ +if (!test_bit (0 , (const unsigned long *)&s->wdt_mis)) { +set_bit (0 , (unsigned long *)&s->wdt_mis); +nmi_monitor_handle (0 ,NULL ); +qemu_irq_pulse (s->irq); + } +else { +if (test_bit (1 , (const unsigned long *)&s->wdt_ctl)) +qemu_system_reset_request (SHUTDOWN_CAUSE_GUEST_RESET ); +else { +nmi_monitor_handle (0 ,NULL ); +qemu_irq_pulse (s->irq); + } + } +} + +static bool wdt_clock_enabled (TM4C123SysCtlState *s,hwaddr addr) +{ +switch (addr) { +case WDT_0 : +return (s->sysctl_rcgcwd & (1 <<0 )); +break ; +case WDT_1 : +return (s->sysctl_rcgcwd & (1 <<1 )); +break ; + } +return false; +} + +static void tm4c123_wdt_reset (DeviceState *dev) +{ +TM4C123WatchdogState *s =TM4C123_WATCHDOG (dev); + + s->wdt_load =0xFFFFFFFF ; + s->wdt_value =0xFFFFFFFF ; + s->wdt_ctl = (s->mmio.addr ==WDT_0 ?0x00000000 :0x80000000 ); + s->wdt_icr =0x00000000 ; + s->wdt_ris =0x00000000 ; + s->wdt_mis =0x00000000 ; + s->wdt_test =0x00000000 ; + s->wdt_lock =0x00000000 ; + s->wdt_per_id4 =0x00000000 ; + s->wdt_per_id5 =0x00000000 ; + s->wdt_per_id6 =0x00000000 ; + s->wdt_per_id7 =0x00000000 ; + s->wdt_per_id0 =0x00000005 ; + s->wdt_per_id1 =0x00000018 ; + s->wdt_per_id2 =0x00000018 ; + s->wdt_per_id3 =0x00000001 ; + s->wdt_pcell_id0 =0x0000000D ; + s->wdt_pcell_id1 =0x000000F0 ; + s->wdt_pcell_id2 =0x00000006 ; + s->wdt_pcell_id3 =0x000000B1 ; +} + +static uint64_t tm4c123_wdt_read (void *opaque,hwaddr addr,unsigned int size) +{ +TM4C123WatchdogState *s = opaque; + +if (!wdt_clock_enabled (s->sysctl, s->mmio.addr)) { +hw_error ("Watchdog timer module clock is not enabled" ); + } + +switch (addr) { +case WDT_LOAD : +return s->wdt_load; +case WDT_VALUE : +return ptimer_get_count (s->timer); +case WDT_CTL : +return s->wdt_ctl; +case WDT_ICR : +return s->wdt_icr; +case WDT_RIS : +return s->wdt_ris; +case WDT_MIS : +return s->wdt_mis; +case WDT_TEST : +return s->wdt_test; +case WDT_LOCK : +return s->wdt_lock; +case WDT_PER_ID4 : +return s->wdt_per_id4; +case WDT_PER_ID5 : +return s->wdt_per_id5; +case WDT_PER_ID6 : +return s->wdt_per_id6; +case WDT_PER_ID7 : +return s->wdt_per_id7; +case WDT_PER_ID0 : +return s->wdt_per_id0; +case WDT_PER_ID1 : +return s->wdt_per_id1; +case WDT_PER_ID2 : +return s->wdt_per_id2; +case WDT_PER_ID3 : +return s->wdt_per_id3; +case WDT_PCELL_ID0 : +return s->wdt_pcell_id0; +case WDT_PCELL_ID1 : +return s->wdt_pcell_id1; +case WDT_PCELL_ID2 : +return s->wdt_pcell_id2; +case WDT_PCELL_ID3 : +return s->wdt_pcell_id3; +default : +LOG ("Bad address 0x%" HWADDR_PRIx"\n" , addr); + } +return 0 ; +} + +static void tm4c123_wdt_write (void *opaque,hwaddr addr,uint64_t val64,unsigned int size) +{ +TM4C123WatchdogState *s = opaque; +uint32_t val32 = val64; + +trace_tm4c123_wdt_write (addr, val64); +if (!wdt_clock_enabled (s->sysctl, s->mmio.addr)) { +hw_error ("Watchdog module clock is not enabled" ); + } + +switch (addr) { +case WDT_LOAD : + s->wdt_load = val32; + locked = true; + s->wdt_ctl |=WDT_CTL_INTEN ; +ptimer_transaction_begin (s->timer); +ptimer_set_count (s->timer, s->wdt_load); +ptimer_set_limit (s->timer, s->wdt_load,1 ); +ptimer_run (s->timer,0 ); +ptimer_transaction_commit (s->timer); +break ; +case WDT_VALUE : +READONLY ; +break ; +case WDT_CTL : + s->wdt_ctl = val32; +break ; +case WDT_ICR : +ptimer_transaction_begin (s->timer); +ptimer_set_limit (s->timer, s->wdt_load,1 ); +ptimer_transaction_commit (s->timer); +clear_bit (0 , (unsigned long *)&s->wdt_ris); +clear_bit (0 , (unsigned long *)&s->wdt_mis); + s->wdt_icr = val32; +break ; +case WDT_RIS : +READONLY ; +break ; +case WDT_MIS : +READONLY ; +break ; +case WDT_TEST : + s->wdt_test = val32; +break ; +case WDT_LOCK : +/* The actual hardware never locks the module */ +if (val32 ==UNLOCK_VALUE ) { + locked = false; + s->wdt_lock =0 ; + } +break ; +case WDT_PER_ID4 : +READONLY ; +break ; +case WDT_PER_ID5 : +READONLY ; +break ; +case WDT_PER_ID6 : +READONLY ; +break ; +case WDT_PER_ID7 : +READONLY ; +break ; +case WDT_PER_ID0 : +READONLY ; +break ; +case WDT_PER_ID1 : +READONLY ; +break ; +case WDT_PER_ID2 : +READONLY ; +break ; +case WDT_PER_ID3 : +READONLY ; +break ; +case WDT_PCELL_ID0 : +READONLY ; +break ; +case WDT_PCELL_ID1 : +READONLY ; +break ; +case WDT_PCELL_ID2 : +READONLY ; +break ; +case WDT_PCELL_ID3 : +READONLY ; +break ; +default : +LOG ("Bad address 0x%" HWADDR_PRIx"\n" , addr); + } +} + +const struct MemoryRegionOps tm4c123_wdt_ops = { + .read = tm4c123_wdt_read, + .write = tm4c123_wdt_write, + .endianness =DEVICE_NATIVE_ENDIAN , +}; + +static void tm4c123_wdt_init (Object *obj) +{ +TM4C123WatchdogState *s =TM4C123_WATCHDOG (obj); + + s->wdt_clock =qdev_init_clock_in (DEVICE (s),"wdt_clock" ,NULL ,NULL ,0 ); + +sysbus_init_irq (SYS_BUS_DEVICE (obj), &s->irq); +memory_region_init_io (&s->mmio, obj, &tm4c123_wdt_ops, s,TYPE_TM4C123_WATCHDOG ,0xFFF ); +sysbus_init_mmio (SYS_BUS_DEVICE (obj), &s->mmio); +} + +static void tm4c123_wdt_realize (DeviceState *dev,Error **errp) +{ +TM4C123WatchdogState *s =TM4C123_WATCHDOG (dev); +qdev_connect_clock_in (dev,"wdt_clock" ,qdev_get_clock_out (DEVICE (s->sysctl),"outclk" )); + + s->timer =ptimer_init (tm4c123_wdt_expired, s, +PTIMER_POLICY_NO_IMMEDIATE_RELOAD | +PTIMER_POLICY_NO_COUNTER_ROUND_DOWN ); + +ptimer_transaction_begin (s->timer); +ptimer_set_period_from_clock (s->timer, s->wdt_clock,1 ); +ptimer_set_limit (s->timer,0xFFFFFFFF ,0 ); +ptimer_transaction_commit (s->timer); +} + +static void tm4c123_wdt_class_init (ObjectClass *kclass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (kclass); + dc->realize = tm4c123_wdt_realize; + dc->reset = tm4c123_wdt_reset; +} + +static const TypeInfo tm4c123_wdt_info = { + .name =TYPE_TM4C123_WATCHDOG , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (TM4C123WatchdogState), + .instance_init = tm4c123_wdt_init, + .class_init = tm4c123_wdt_class_init, +}; + +static void tm4c123_wdt_register_types (void ) +{ +type_register_static (&tm4c123_wdt_info); +} + +type_init (tm4c123_wdt_register_types)
include/hw/watchdog/tm4c123_watchdog.h new file +97 -0
97 lines not on this page · raw message
Signature · 1 line
2.34.1
[PULL 2/8] tivac usart module implementation
In reply to Mohamed ElSayed--- hw/char/tm4c123_usart.c | 387 ++++++++++++++++++++++++++++++++ include/hw/char/tm4c123_usart.h | 124 ++++++++++ 2 files changed, 511 insertions(+) create mode 100644 hw/char/tm4c123_usart.c create mode 100644 include/hw/char/tm4c123_usart.h
hw/char/tm4c123_usart.c new file +387 -0
@@ -0,0 +1,387 @@ +/* +* TM4C123 USART +* +* Copyright (c) 2023 Mohamed ElSayed <[email protected]> +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +#include "qemu/osdep.h" +#include "hw/char/tm4c123_usart.h" +#include "hw/irq.h" +#include "hw/qdev-properties.h" +#include "hw/qdev-properties-system.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "trace.h" + +#define LOG(fmt, args...) qemu_log("%s: " fmt, __func__, ## args) +#define READONLY LOG("0x%"HWADDR_PRIx" is a readonly field\n.", addr) + +static bool usart_clock_enabled (TM4C123SysCtlState *s,hwaddr addr) +{ +switch (addr) { +case USART_0 : +return (s->sysctl_rcgcuart & (1 <<0 )); +break ; +case USART_1 : +return (s->sysctl_rcgcuart & (1 <<1 )); +break ; +case USART_2 : +return (s->sysctl_rcgcuart & (1 <<2 )); +break ; +case USART_3 : +return (s->sysctl_rcgcuart & (1 <<3 )); +break ; +case USART_4 : +return (s->sysctl_rcgcuart & (1 <<4 )); +break ; +case USART_5 : +return (s->sysctl_rcgcuart & (1 <<5 )); +break ; +case USART_6 : +return (s->sysctl_rcgcuart & (1 <<6 )); +break ; +case USART_7 : +return (s->sysctl_rcgcuart & (1 <<7 )); +break ; + } +return false; +} + + +static int tm4c123_usart_can_receive (void * opaque) +{ +TM4C123USARTState *s = opaque; + +if (!(s->usart_fr &USART_FR_RXFF )) { +//the module can receive data. +return 1 ; + } +return 0 ; +} + +static void tm4c123_usart_receive (void *opaque,const uint8_t *buf,int size) +{ +TM4C123USARTState *s = opaque; + +if (!(s->usart_ctl &USART_CR_EN && s->usart_ctl &USART_CR_RXE )) { +//the module is not enabled +LOG ("The module is not enbled\n" ); +return ; + } + + s->usart_dr = *buf; + s->usart_ctl &= ~USART_FR_RXFE ; + +if (s->usart_im &USART_IM_RXIM ) { +qemu_set_irq (s->irq,1 ); + } + +LOG ("Receiving: %c\n" , s->usart_dr); +} + +static void tm4c123_usart_reset (DeviceState *dev) +{ +TM4C123USARTState *s =TM4C123_USART (dev); + + s->usart_dr =0x00000000 ; + s->usart_rsr =0x00000000 ; + s->usart_fr =0x00000090 ; + s->usart_ilpr =0x00000000 ; + s->usart_ibrd =0x00000000 ; + s->usart_fbrd =0x00000000 ; + s->usart_lcrh =0x00000000 ; + s->usart_ctl =0x00000300 ; + s->usart_ifls =0x00000012 ; + s->usart_im =0x00000000 ; + s->usart_ris =0x00000000 ; + s->usart_mis =0x00000000 ; + s->usart_icr =0x00000000 ; + s->usart_dma_ctl =0x00000000 ; + s->usart_9bit_addr =0x00000000 ; + s->usart_9bit_mask =0x000000FF ; + s->usart_pp =0x00000003 ; + s->usart_cc =0x00000000 ; + s->usart_per_id4 =0x00000000 ; + s->usart_per_id5 =0x00000000 ; + s->usart_per_id6 =0x00000000 ; + s->usart_per_id7 =0x00000000 ; + s->usart_per_id0 =0x00000060 ; + s->usart_per_id1 =0x00000000 ; + s->usart_per_id2 =0x00000018 ; + s->usart_per_id3 =0x00000001 ; + s->usart_pcell_id0 =0x0000000D ; + s->usart_pcell_id1 =0x000000F0 ; + s->usart_pcell_id2 =0x00000005 ; + s->usart_pcell_id3 =0x000000B1 ; + +qemu_set_irq (s->irq,0 ); +} + +static uint64_t tm4c123_usart_read (void *opaque,hwaddr addr,unsigned int size) +{ +TM4C123USARTState *s = opaque; + +if (!usart_clock_enabled (s->sysctl, s->mmio.addr)) { +hw_error ("USART module clock is not enabled" ); + } + +trace_tm4c123_usart_read (addr); + +switch (addr) { +case USART_DR : +return s->usart_dr; +case USART_RSR : +return s->usart_rsr; +case USART_FR : +return s->usart_fr; +case USART_ILPR : +return s->usart_ilpr; +case USART_IBRD : +return s->usart_ibrd; +case USART_FBRD : +return s->usart_fbrd; +case USART_LCRH : +return s->usart_lcrh; +case USART_CTL : +return s->usart_ctl; +case USART_IFLS : +return s->usart_ifls; +case USART_IM : +return s->usart_im; +case USART_RIS : +return s->usart_ris; +case USART_MIS : +return s->usart_mis; +case USART_ICR : +return s->usart_icr; +case USART_DMA_CTL : +return s->usart_dma_ctl; +case USART_9BIT_ADDR : +return s->usart_9bit_addr; +case USART_9BIT_MASK : +return s->usart_9bit_mask; +case USART_PP : +return s->usart_pp; +case USART_CC : +return s->usart_cc; +case USART_PER_ID4 : +return s->usart_per_id4; +case USART_PER_ID5 : +return s->usart_per_id5; +case USART_PER_ID6 : +return s->usart_per_id6; +case USART_PER_ID7 : +return s->usart_per_id7; +case USART_PER_ID0 : +return s->usart_per_id0; +case USART_PER_ID1 : +return s->usart_per_id1; +case USART_PER_ID2 : +return s->usart_per_id2; +case USART_PER_ID3 : +return s->usart_per_id3; +case USART_PCELL_ID0 : +return s->usart_pcell_id0; +case USART_PCELL_ID1 : +return s->usart_pcell_id1; +case USART_PCELL_ID2 : +return s->usart_pcell_id2; +case USART_PCELL_ID3 : +return s->usart_pcell_id3; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: Bad offset 0x%" HWADDR_PRIx"\n" , __func__, addr); +return 0 ; + } + +return 0 ; +} + +static void tm4c123_usart_write (void *opaque,hwaddr addr,uint64_t val64,unsigned int size) +{ +TM4C123USARTState *s = opaque; +uint32_t val32 = val64; +unsigned char ch; + +if (!usart_clock_enabled (s->sysctl, s->mmio.addr)) { +hw_error ("USART module clock is not enabled" ); + } + +trace_tm4c123_usart_write (addr, val32); + +switch (addr) { +case USART_DR : + s->usart_dr = val32; +if (val32 <0xF000 ) { + ch = val32; +qemu_chr_fe_write_all (&s->chr, &ch,1 ); + } +break ; +case USART_RSR : + s->usart_rsr = val32; +break ; +case USART_FR : +READONLY ; +break ; +case USART_ILPR : + s->usart_ilpr = val32; +break ; +case USART_IBRD : + s->usart_ibrd = val32; +break ; +case USART_FBRD : + s->usart_fbrd = val32; +break ; +case USART_LCRH : + s->usart_lcrh = val32; +break ; +case USART_CTL : + s->usart_ctl = val32; +break ; +case USART_IFLS : + s->usart_ifls = val32; +break ; +case USART_IM : + s->usart_im = val32; +break ; +case USART_RIS : +READONLY ; +break ; +case USART_MIS : +READONLY ; +break ; +case USART_ICR : + s->usart_icr = val32; +break ; +case USART_DMA_CTL : + s->usart_dma_ctl = val32; +break ; +case USART_9BIT_ADDR : + s->usart_9bit_addr = val32; +break ; +case USART_9BIT_MASK : + s->usart_9bit_mask = val32; +break ; +case USART_PP : +READONLY ; +break ; +case USART_CC : + s->usart_cc = val32; +break ; +case USART_PER_ID4 : +READONLY ; +break ; +case USART_PER_ID5 : +READONLY ; +break ; +case USART_PER_ID6 : +READONLY ; +break ; +case USART_PER_ID7 : +READONLY ; +break ; +case USART_PER_ID0 : +READONLY ; +break ; +case USART_PER_ID1 : +READONLY ; +break ; +case USART_PER_ID2 : +READONLY ; +break ; +case USART_PER_ID3 : +READONLY ; +break ; +case USART_PCELL_ID0 : +READONLY ; +break ; +case USART_PCELL_ID1 : +READONLY ; +break ; +case USART_PCELL_ID2 : +READONLY ; +break ; +case USART_PCELL_ID3 : +READONLY ; +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: Bad offset 0x%" HWADDR_PRIx"\n" , __func__, addr); +return ; + } + +return ; +} + +static const MemoryRegionOps tm4c123_usart_ops = { + .read = tm4c123_usart_read, + .write = tm4c123_usart_write, + .endianness =DEVICE_NATIVE_ENDIAN , +}; + +static Property tm4c123_usart_properties[] = { +DEFINE_PROP_CHR ("chardev" , TM4C123USARTState, chr), +DEFINE_PROP_END_OF_LIST (), +}; + +static void tm4c123_usart_init (Object *obj) +{ +TM4C123USARTState *s =TM4C123_USART (obj); + +sysbus_init_irq (SYS_BUS_DEVICE (obj), &s->irq); + +memory_region_init_io (&s->mmio, obj, &tm4c123_usart_ops, s, +TYPE_TM4C123_USART ,0xFFF ); +sysbus_init_mmio (SYS_BUS_DEVICE (obj), &s->mmio); +} + +static void tm4c123_usart_realize (DeviceState *dev,Error **errp) +{ +TM4C123USARTState *s =TM4C123_USART (dev); + +qemu_chr_fe_set_handlers (&s->chr, tm4c123_usart_can_receive, + tm4c123_usart_receive,NULL ,NULL , + s,NULL , true); +} + +static void tm4c123_usart_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->reset = tm4c123_usart_reset; +device_class_set_props (dc, tm4c123_usart_properties); + dc->realize = tm4c123_usart_realize; +} + +static const TypeInfo tm4c123_usart_info = { + .name =TYPE_TM4C123_USART , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (TM4C123USARTState), + .instance_init = tm4c123_usart_init, + .class_init = tm4c123_usart_class_init, +}; + +static void tm4c123_usart_register_types (void ) +{ +type_register_static (&tm4c123_usart_info); +} + +type_init (tm4c123_usart_register_types)
include/hw/char/tm4c123_usart.h new file +124 -0
124 lines not on this page · raw message
Signature · 1 line
2.34.1
[PULL 7/8] editing the meson and KConfig files to add tivac to qemu build system
In reply to Mohamed ElSayed--- .gitignore | 1 + README.rst | 150 ++---------------------- configs/devices/arm-softmmu/default.mak | 1 + hw/arm/Kconfig | 13 ++ hw/arm/meson.build | 3 + hw/char/Kconfig | 3 + hw/char/meson.build | 1 + hw/char/trace-events | 4 + hw/gpio/Kconfig | 3 + hw/gpio/meson.build | 1 + hw/gpio/trace-events | 4 + hw/misc/Kconfig | 3 + hw/misc/meson.build | 1 + hw/misc/trace-events | 5 + hw/timer/Kconfig | 3 + hw/timer/meson.build | 1 + hw/timer/trace-events | 5 + hw/watchdog/Kconfig | 3 + hw/watchdog/meson.build | 1 + hw/watchdog/trace-events | 3 + 20 files changed, 72 insertions(+), 137 deletions(-)
.gitignore +1 -0
@@ -10,6 +10,7 @@ .gdb_history cscope.* tags +compile_commands.json TAGS GPATH GRTAGS
README.rst +13 -137
176 lines not on this page · raw message
configs/devices/arm-softmmu/default.mak +1 -0
@@ -43,3 +43,4 @@ CONFIG_FSL_IMX6UL=y CONFIG_SEMIHOSTING=y CONFIG_ARM_COMPATIBLE_SEMIHOSTING=y CONFIG_ALLWINNER_H3=y +CONFIG_TIVAC=y
hw/arm/Kconfig +13 -0
@@ -581,3 +581,16 @@ config ARMSSE select UNIMP select SSE_COUNTER select SSE_TIMER + +config TM4C123GH6PM_SOC + bool + select ARM_V7M + select TM4C123_USART + select TM4C123_SYSCTL + select TM4C123_GPIO + select TM4C123_WDT + select TM4C123_GPTM + +config TIVAC + bool + select TM4C123GH6PM_SOC
hw/arm/meson.build +3 -0
@@ -62,10 +62,13 @@ arm_ss.add(when: 'CONFIG_FSL_IMX7', if_true: files('fsl-imx7.c', 'mcimx7d-sabre. arm_ss.add(when: 'CONFIG_ARM_SMMUV3', if_true: files('smmuv3.c')) arm_ss.add(when: 'CONFIG_FSL_IMX6UL', if_true: files('fsl-imx6ul.c', 'mcimx6ul-evk.c')) arm_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_soc.c')) +arm_ss.add(when: 'CONFIG_TM4C123GH6PM_SOC', if_true: files('tm4c123gh6pm_soc.c')) +arm_ss.add(when: 'CONFIG_TIVAC', if_true: files('tivac.c')) softmmu_ss.add(when: 'CONFIG_ARM_SMMUV3', if_true: files('smmu-common.c')) softmmu_ss.add(when: 'CONFIG_EXYNOS4', if_true: files('exynos4_boards.c')) softmmu_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2835_peripherals.c')) softmmu_ss.add(when: 'CONFIG_TOSA', if_true: files('tosa.c')) + hw_arch += {'arm': arm_ss}
hw/char/Kconfig +3 -0
@@ -71,3 +71,6 @@ config GOLDFISH_TTY config SHAKTI_UART bool + +config TM4C123_USART + bool
hw/char/meson.build +1 -0
@@ -33,6 +33,7 @@ softmmu_ss.add(when: 'CONFIG_SH_SCI', if_true: files('sh_serial.c')) softmmu_ss.add(when: 'CONFIG_STM32F2XX_USART', if_true: files('stm32f2xx_usart.c')) softmmu_ss.add(when: 'CONFIG_MCHP_PFSOC_MMUART', if_true: files('mchp_pfsoc_mmuart.c')) softmmu_ss.add(when: 'CONFIG_HTIF', if_true: files('riscv_htif.c')) +softmmu_ss.add(when: 'CONFIG_TM4C123_USART', if_true: files('tm4c123_usart.c')) softmmu_ss.add(when: 'CONFIG_GOLDFISH_TTY', if_true: files('goldfish_tty.c')) specific_ss.add(when: 'CONFIG_TERMINAL3270', if_true: files('terminal3270.c'))
hw/char/trace-events +4 -0
@@ -1,5 +1,9 @@ # See docs/devel/tracing.rst for syntax documentation. +# tm4c123_usart.c +tm4c123_usart_read(uint64_t offset) " offset: 0x%" PRIu64 +tm4c123_usart_write(uint64_t offset, uint64_t value) " offset: 0x%" PRIu64 " - value: 0x%" PRIu64 + # parallel.c parallel_ioport_read(const char *desc, uint16_t addr, uint8_t value) "read [%s] addr 0x%02x val 0x%02x" parallel_ioport_write(const char *desc, uint16_t addr, uint8_t value) "write [%s] addr 0x%02x val 0x%02x"
hw/gpio/Kconfig +3 -0
@@ -16,3 +16,6 @@ config GPIO_PWR config SIFIVE_GPIO bool + +config TM4C123_GPIO + bool
hw/gpio/meson.build +1 -0
@@ -12,3 +12,4 @@ softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_gpio.c')) softmmu_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2835_gpio.c')) softmmu_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_gpio.c')) softmmu_ss.add(when: 'CONFIG_SIFIVE_GPIO', if_true: files('sifive_gpio.c')) +softmmu_ss.add(when: 'CONFIG_TM4C123_GPIO', if_true: files('tm4c123_gpio.c'))
hw/gpio/trace-events +4 -0
@@ -1,5 +1,9 @@ # See docs/devel/tracing.rst for syntax documentation. +# tm4c123_gpio.c +tm4c123_gpio_read(uint64_t offset) " offset: 0x%" PRIx64 +tm4c123_gpio_write(uint64_t offset, uint64_t value) " offset: 0x%" PRIx64 " - value: 0x%" PRIx64 + # npcm7xx_gpio.c npcm7xx_gpio_read(const char *id, uint64_t offset, uint64_t value) " %s offset: 0x%04" PRIx64 " value 0x%08" PRIx64 npcm7xx_gpio_write(const char *id, uint64_t offset, uint64_t value) "%s offset: 0x%04" PRIx64 " value 0x%08" PRIx64
hw/misc/Kconfig +3 -0
@@ -180,4 +180,7 @@ config AXP209_PMU bool depends on I2C +config TM4C123_SYSCTL + bool + source macio/Kconfig
hw/misc/meson.build +1 -0
@@ -141,3 +141,4 @@ softmmu_ss.add(when: 'CONFIG_SBSA_REF', if_true: files('sbsa_ec.c')) # HPPA devices softmmu_ss.add(when: 'CONFIG_LASI', if_true: files('lasi.c')) +softmmu_ss.add(when: 'CONFIG_TM4C123_SYSCTL', if_true: files('tm4c123_sysctl.c'))
hw/misc/trace-events +5 -0
@@ -1,5 +1,10 @@ # See docs/devel/tracing.rst for syntax documentation. +# tm4c123_sysctl.c +tm4c123_sysctl_read(uint64_t offset) " offset: 0x%" PRIu64 +tm4c123_sysctl_write(uint64_t offset, uint64_t value) " offset: 0x%" PRIu64 " - value: 0x%"PRIu64 +tm4c123_sysctl_update_system_clock(uint32_t value) "New clock value = %"PRIu32" Hz" + # allwinner-cpucfg.c allwinner_cpucfg_cpu_reset(uint8_t cpu_id, uint32_t reset_addr) "id %u, reset_addr 0x%" PRIx32 allwinner_cpucfg_read(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
hw/timer/Kconfig +3 -0
@@ -60,3 +60,6 @@ config STELLARIS_GPTM config AVR_TIMER16 bool + +config TM4C123_GPTM + bool
hw/timer/meson.build +1 -0
@@ -36,5 +36,6 @@ softmmu_ss.add(when: 'CONFIG_STM32F2XX_TIMER', if_true: files('stm32f2xx_timer.c softmmu_ss.add(when: 'CONFIG_XILINX', if_true: files('xilinx_timer.c')) specific_ss.add(when: 'CONFIG_IBEX', if_true: files('ibex_timer.c')) softmmu_ss.add(when: 'CONFIG_SIFIVE_PWM', if_true: files('sifive_pwm.c')) +softmmu_ss.add(when: 'CONFIG_TM4C123_GPTM', if_true: files('tm4c123_gptm.c')) specific_ss.add(when: 'CONFIG_AVR_TIMER16', if_true: files('avr_timer16.c'))
hw/timer/trace-events +5 -0
@@ -1,5 +1,10 @@ # See docs/devel/tracing.rst for syntax documentation. +# tm4c123_gptm.c +tm4c123_gptm_read(uint32_t offset) "offset: 0x%"PRIx32 +tm4c123_gptm_write(uint32_t offset, uint32_t value) "offset: 0x%"PRIx32" - value: 0x%"PRIx32 +tm4c123_gptm_build_interval_value(uint32_t talir, uint32_t tblir, uint64_t result) "TALIR: 0x%"PRIx32" - TBLIR: 0x%"PRIx32" - value: 0x%"PRIx64 + # slavio_timer.c slavio_timer_get_out(uint64_t limit, uint32_t counthigh, uint32_t count) "limit 0x%"PRIx64" count 0x%x0x%08x" slavio_timer_irq(uint32_t counthigh, uint32_t count) "callback: count 0x%x0x%08x"
hw/watchdog/Kconfig +3 -0
@@ -24,3 +24,6 @@ config WDT_SBSA config ALLWINNER_WDT bool select PTIMER + +config TM4C123_WDT + bool
hw/watchdog/meson.build +1 -0
@@ -7,4 +7,5 @@ softmmu_ss.add(when: 'CONFIG_WDT_DIAG288', if_true: files('wdt_diag288.c')) softmmu_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('wdt_aspeed.c')) softmmu_ss.add(when: 'CONFIG_WDT_IMX2', if_true: files('wdt_imx2.c')) softmmu_ss.add(when: 'CONFIG_WDT_SBSA', if_true: files('sbsa_gwdt.c')) +softmmu_ss.add(when: 'CONFIG_TM4C123_WDT', if_true: files('tm4c123_watchdog.c')) specific_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr_watchdog.c'))
hw/watchdog/trace-events +3 -0
@@ -1,5 +1,8 @@ # See docs/devel/tracing.rst for syntax documentation. +# tm4c123_wdt.c +tm4c123_wdt_write(uint64_t offset, uint64_t data) "TM4C123-WDT Write: [ Offset 0x%" PRIx64 " - Data 0x%" PRIx64 "]" + # allwinner-wdt.c allwinner_wdt_read(uint64_t offset, uint64_t data, unsigned size) "Allwinner watchdog read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" allwinner_wdt_write(uint64_t offset, uint64_t data, unsigned size) "Allwinner watchdog write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u"
Signature · 1 line
2.34.1
[PULL 8/8] code style fixes
In reply to Mohamed ElSayed--- hw/arm/tm4c123gh6pm_soc.c | 14 ++-- hw/char/tm4c123_usart.c | 28 +++---- hw/misc/tm4c123_sysctl.c | 6 +- hw/timer/tm4c123_gptm.c | 134 ++++++++++++--------------------- hw/watchdog/tm4c123_watchdog.c | 25 +++--- 5 files changed, 85 insertions(+), 122 deletions(-)
hw/arm/tm4c123gh6pm_soc.c +8 -6
@@ -89,7 +89,8 @@ static void tm4c123gh6pm_soc_initfn(Object *obj)object_initialize_child (obj,"sysctl" , &s->sysctl,TYPE_TM4C123_SYSCTL );for (i =0 ; i <USART_COUNT ; i++) { -object_initialize_child (obj,"usart[*]" , &s->usart[i],TYPE_TM4C123_USART ); +object_initialize_child (obj,"usart[*]" , + &s->usart[i],TYPE_TM4C123_USART ); }for (i =0 ; i <GPIO_COUNT ; i++) {
@@ -97,7 +98,8 @@ static void tm4c123gh6pm_soc_initfn(Object *obj) }for (i =0 ; i <WDT_COUNT ; i++) { -object_initialize_child (obj,"watchdog-timer[*]" , &s->wdt[i],TYPE_TM4C123_WATCHDOG ); +object_initialize_child (obj,"watchdog-timer[*]" , + &s->wdt[i],TYPE_TM4C123_WATCHDOG ); }for (i =0 ; i <GPTM_COUNT ; i++) {
@@ -115,14 +117,14 @@ static void tm4c123gh6pm_soc_realize(DeviceState *dev_soc, Error **errp)MemoryRegion *system_memory =get_system_memory (); -//init flash memory +/* init flash memory */ memory_region_init_rom ( &s->flash,OBJECT (dev_soc),"TM4C123GH6PM.flash" ,FLASH_SIZE , &error_fatal );memory_region_add_subregion (system_memory,FLASH_BASE_ADDRESS , &s->flash); -//init sram and the sram alias region +/* init sram and the sram alias region */ memory_region_init_ram ( &s->sram,OBJECT (dev_soc),"TM4C123GH6PM.sram" ,SRAM_SIZE , &error_fatal);
@@ -181,7 +183,7 @@ static void tm4c123gh6pm_soc_realize(DeviceState *dev_soc, Error **errp)/* General purpose timers */ int j =0 ; -for (i =0 , j =0 ; i <GPTM_COUNT ; i++, j+=2 ) { +for (i =0 , j =0 ; i <GPTM_COUNT ; i++, j +=2 ) { dev =DEVICE (&(s->gptm[i])); s->gptm[i].sysctl = &s->sysctl;if (!sysbus_realize (SYS_BUS_DEVICE (&s->gptm[i]), errp)) {
@@ -190,7 +192,7 @@ static void tm4c123gh6pm_soc_realize(DeviceState *dev_soc, Error **errp) busdev =SYS_BUS_DEVICE (dev);sysbus_mmio_map (busdev,0 , gptm_addrs[i]);sysbus_connect_irq (busdev,0 ,qdev_get_gpio_in (armv7m, gptm_irqs[j])); -sysbus_connect_irq (busdev,1 ,qdev_get_gpio_in (armv7m, gptm_irqs[j+1 ])); +sysbus_connect_irq (busdev,1 ,qdev_get_gpio_in (armv7m, gptm_irqs[j +1 ])); }/* SYSCTL */
hw/char/tm4c123_usart.c +12 -16
@@ -36,42 +36,41 @@static bool usart_clock_enabled (TM4C123SysCtlState *s,hwaddr addr) { -switch (addr) { +switch (addr) {case USART_0 : -return (s->sysctl_rcgcuart & (1 <<0 )); +return s->sysctl_rcgcuart & (1 <<0 );break ;case USART_1 : -return (s->sysctl_rcgcuart & (1 <<1 )); +return s->sysctl_rcgcuart & (1 <<1 );break ;case USART_2 : -return (s->sysctl_rcgcuart & (1 <<2 )); +return s->sysctl_rcgcuart & (1 <<2 );break ;case USART_3 : -return (s->sysctl_rcgcuart & (1 <<3 )); +return s->sysctl_rcgcuart & (1 <<3 );break ;case USART_4 : -return (s->sysctl_rcgcuart & (1 <<4 )); +return s->sysctl_rcgcuart & (1 <<4 );break ;case USART_5 : -return (s->sysctl_rcgcuart & (1 <<5 )); +return s->sysctl_rcgcuart & (1 <<5 );break ;case USART_6 : -return (s->sysctl_rcgcuart & (1 <<6 )); +return s->sysctl_rcgcuart & (1 <<6 );break ;case USART_7 : -return (s->sysctl_rcgcuart & (1 <<7 )); +return s->sysctl_rcgcuart & (1 <<7 );break ; }return false; } -static int tm4c123_usart_can_receive (void * opaque) +static int tm4c123_usart_can_receive (void *opaque) {TM4C123USARTState *s = opaque;if (!(s->usart_fr &USART_FR_RXFF )) { -//the module can receive data. return 1 ; }return 0 ;
@@ -82,7 +81,6 @@ static void tm4c123_usart_receive(void *opaque, const uint8_t *buf, int size)TM4C123USARTState *s = opaque;if (!(s->usart_ctl &USART_CR_EN && s->usart_ctl &USART_CR_RXE )) { -//the module is not enabled LOG ("The module is not enbled\n" );return ; }
@@ -93,8 +91,6 @@ static void tm4c123_usart_receive(void *opaque, const uint8_t *buf, int size)if (s->usart_im &USART_IM_RXIM ) {qemu_set_irq (s->irq,1 ); } - -LOG ("Receiving: %c\n" , s->usart_dr); }static void tm4c123_usart_reset (DeviceState *dev)
@@ -145,7 +141,7 @@ static uint64_t tm4c123_usart_read(void *opaque, hwaddr addr, unsigned int size)trace_tm4c123_usart_read (addr); -switch (addr) { +switch (addr) {case USART_DR :return s->usart_dr;case USART_RSR :
@@ -227,7 +223,7 @@ static void tm4c123_usart_write(void *opaque, hwaddr addr, uint64_t val64, unsigtrace_tm4c123_usart_write (addr, val32); -switch (addr) { +switch (addr) {case USART_DR : s->usart_dr = val32;if (val32 <0xF000 ) {
hw/misc/tm4c123_sysctl.c +3 -3
@@ -282,7 +282,7 @@ static void tm4c123_sysctl_write(void *opaque, hwaddr addr, uint64_t val64, unsitrace_tm4c123_sysctl_write (addr, val32); -switch (addr) { +switch (addr) {case SYSCTL_DID0 :READONLY ;break ;
@@ -690,7 +690,7 @@ static uint64_t tm4c123_sysctl_read(void *opaque, hwaddr addr, unsigned int sizetrace_tm4c123_sysctl_read (addr); -switch (addr) { +switch (addr) {case SYSCTL_DID0 :return s->sysctl_did0;case SYSCTL_DID1 :
@@ -951,7 +951,7 @@ static void tm4c123_sysctl_init(Object *obj)TM4C123SysCtlState *s =TM4C123_SYSCTL (obj); s->mainclk =clock_new (OBJECT (s),"main-clk" ); -clock_set_hz (s->mainclk,1000 *1000 ); +clock_set_hz (s->mainclk,1000 *1000 ); s->outclk =qdev_init_clock_out (DEVICE (s),"outclk" );clock_set_source (s->outclk, s->mainclk);
hw/timer/tm4c123_gptm.c +50 -84
275 lines not on this page · raw message
hw/watchdog/tm4c123_watchdog.c +12 -13
@@ -36,19 +36,18 @@#define READONLY LOG("0x%"HWADDR_PRIx" is a readonly field\n.", addr) #define LOG(fmt, args...) qemu_log("%s: " fmt, __func__, ## args) -static bool locked = false; +static bool locked;static void tm4c123_wdt_expired (void *opaque) {TM4C123WatchdogState *s = opaque;/*if this is the first timeout/the ris is not cleared */ -if (!test_bit (0 , (const unsigned long *)&s->wdt_mis)) { -set_bit (0 , (unsigned long *)&s->wdt_mis); +if (!test_bit (0 , (const unsigned long *)&s->wdt_mis)) { +set_bit (0 , (unsigned long *)&s->wdt_mis);nmi_monitor_handle (0 ,NULL );qemu_irq_pulse (s->irq); - } -else { -if (test_bit (1 , (const unsigned long *)&s->wdt_ctl)) + }else { +if (test_bit (1 , (const unsigned long *)&s->wdt_ctl))qemu_system_reset_request (SHUTDOWN_CAUSE_GUEST_RESET );else {nmi_monitor_handle (0 ,NULL );
@@ -59,12 +58,12 @@ static void tm4c123_wdt_expired(void *opaque)static bool wdt_clock_enabled (TM4C123SysCtlState *s,hwaddr addr) { -switch (addr) { +switch (addr) {case WDT_0 : -return (s->sysctl_rcgcwd & (1 <<0 )); +return s->sysctl_rcgcwd & (1 <<0 );break ;case WDT_1 : -return (s->sysctl_rcgcwd & (1 <<1 )); +return s->sysctl_rcgcwd & (1 <<1 );break ; }return false;
@@ -104,7 +103,7 @@ static uint64_t tm4c123_wdt_read(void *opaque, hwaddr addr, unsigned int size)hw_error ("Watchdog timer module clock is not enabled" ); } -switch (addr) { +switch (addr) {case WDT_LOAD :return s->wdt_load;case WDT_VALUE :
@@ -161,7 +160,7 @@ static void tm4c123_wdt_write(void *opaque, hwaddr addr, uint64_t val64, unsignehw_error ("Watchdog module clock is not enabled" ); } -switch (addr) { +switch (addr) {case WDT_LOAD : s->wdt_load = val32; locked = true;
@@ -182,8 +181,8 @@ static void tm4c123_wdt_write(void *opaque, hwaddr addr, uint64_t val64, unsigneptimer_transaction_begin (s->timer);ptimer_set_limit (s->timer, s->wdt_load,1 );ptimer_transaction_commit (s->timer); -clear_bit (0 , (unsigned long *)&s->wdt_ris); -clear_bit (0 , (unsigned long *)&s->wdt_mis); +clear_bit (0 , (unsigned long *)&s->wdt_ris); +clear_bit (0 , (unsigned long *)&s->wdt_mis); s->wdt_icr = val32;break ;case WDT_RIS :
Signature · 1 line
2.34.1
Quoted 6 lines · Mohamed ElSayed
***
This is an implementation for the TivaC board.
For now it models the system control block, the general purpose I/O, the general purpose timers, the watchdog timers and the usart module.The code is available at https://github.com/moesay/qemu_TivaC.git
***
Hi Mohamed,
I'm afraid this pull request won't get processed. Pull requests are sent by maintainers who are listed in the MAINTAINERS file with signed PRs. If you want to get support for the TivacC board up-streamed you should post a series of patches and participate in code review. We have some general guidance for the process here:
https://qemu.readthedocs.io/en/latest/devel/submitting-a-patch.html
A couple of general points to get you started:
- patch 7
This is obviously wrong as it updates the project README with your personal fork information.
- patch 8
code format fixes to your own code should be folded into the relevant commit
- use of qemu_log
direct use of qemu_log is discouraged. Generally for devices you would be using qemu_log_mask with LOG_UNIMP or LOG_GUEST_ERROR as appropriate. Think about if the log point would be better handled at a tracepoint (or removed completely if it was a debugging aid during development).
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro