kinetis_k64_sim.h has been added
PATCH v3 4/11 kinetis_k64_sim.h has been added
I made a new arm machine with some peripherals. The machine is mk64fn1m0, a cortex-m4 microcontroller from NXP Kinetis family. The machine can run a simple arm binary file using UART0 in polling mode.
I have prepared a series of patchs to include this machine:
PATCH v3 n/11: It adds the machine and peripherals devices; PATCH v4 n/2: It changes the Make files to compile this machine.
--- include/hw/misc/kinetis_k64_sim.h | 56 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 include/hw/misc/kinetis_k64_sim.h
include/hw/misc/kinetis_k64_sim.h new file +56 -0
@@ -0,0 +1,56 @@ +/* +* Kinetis K64 peripheral microcontroller emulation. +* +* Copyright (c) 2017 Advantech Wireless +* Written by Gabriel Costa <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 or +* (at your option) any later version. +*/ + +/* Kinetis K64 series SIM controller. */ + +#ifndef KINETIS_SIM_H +#define KINETIS_SIM_H + +#include "hw/sysbus.h" +#include "chardev/char-fe.h" +#include "chardev/char-mux.h" +#include "hw/hw.h" + +#define TYPE_KINETIS_K64_SIM "kinetis_k64_sim" +#define KINETIS_K64_SIM (obj) \ + OBJECT_CHECK(kinetis_k64_sim_state, (obj), TYPE_KINETIS_K64_SIM) + +typedef struct { +SysBusDevice parent_obj; + +MemoryRegion iomem; + +uint32_t SOPT1;/**< System Options Register 1, offset: 0x0 */ +uint32_t SOPT1CFG;/**< SOPT1 Configuration Register, offset: 0x4 */ +uint32_t SOPT2;/**< System Options Register 2, offset: 0x1004 */ +uint32_t SOPT4;/**< System Options Register 4, offset: 0x100C */ +uint32_t SOPT5;/**< System Options Register 5, offset: 0x1010 */ +uint32_t SOPT7;/**< System Options Register 7, offset: 0x1018 */ +uint32_t SDID;/**< System Device Id Register, offset: 0x1024 */ +uint32_t SCGC1;/**< System Clock Gating Ctrl Reg 1, offset: 0x1028 */ +uint32_t SCGC2;/**< System Clock Gating Ctrl Reg 2, offset: 0x102C */ +uint32_t SCGC3;/**< System Clock Gating Ctrl Reg 3, offset: 0x1030 */ +uint32_t SCGC4;/**< System Clock Gating Ctrl Reg 4, offset: 0x1034 */ +uint32_t SCGC5;/**< System Clock Gating Ctrl Reg 5, offset: 0x1038 */ +uint32_t SCGC6;/**< System Clock Gating Ctrl Reg 6, offset: 0x103C */ +uint32_t SCGC7;/**< System Clock Gating Ctrl Reg 7, offset: 0x1040 */ +uint32_t CLKDIV1;/**< System Clock Divider Register 1, offset: 0x1044 */ +uint32_t CLKDIV2;/**< System Clock Divider Register 2, offset: 0x1048 */ +uint32_t FCFG1;/**< Flash Configuration Register 1, offset: 0x104C */ +uint32_t FCFG2;/**< Flash Configuration Register 2, offset: 0x1050 */ +uint32_t UIDH;/**< Unique Id Register High, offset: 0x1054 */ +uint32_t UIDMH;/**< Unique Id Register Mid-High, offset: 0x1058 */ +uint32_t UIDML;/**< Unique Id Register Mid Low, offset: 0x105C */ +uint32_t UIDL;/**< Unique Id Register Low, offset: 0x1060 */ + +}kinetis_k64_sim_state ; + +#endif
Signature · 1 line
2.1.4
Hi Gabriel,
include/hw/misc/kinetis_k64_sim.h
Quoted 18 lines · Gabriel Augusto Costa
I made a new arm machine with some peripherals. The machine is mk64fn1m0, a cortex-m4 microcontroller from NXP Kinetis family. The machine can run a simple arm binary file using UART0 in polling mode.
I have prepared a series of patchs to include this machine:
PATCH v3 n/11: It adds the machine and peripherals devices; PATCH v4 n/2: It changes the Make files to compile this machine.Signed-off-by Gabriel Augusto Costa <[email protected]>--- include/hw/misc/kinetis_k64_sim.h | 56 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 include/hw/misc/kinetis_k64_sim.hinclude/hw/misc/kinetis_k64_sim.h new file +0
-0
I'd rather name it kinetis_k64_system.h or kinetis_k64_sysctl.h
Quoted 9 lines
include/hw/misc/kinetis_k64_sim.h new file +8
-0@@ -0,0 +1,56 @@ +/* +* Kinetis K64 peripheral microcontroller emulation. +* +* Copyright (c) 2017 Advantech Wireless +* Written by Gabriel Costa <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 or
include/hw/misc/kinetis_k64_sim.h line 18
Quoted 10 lines
include/hw/misc/kinetis_k64_sim.h new file +10
-0+* (at your option) any later version. +*/ + +/* Kinetis K64 series SIM controller. */ + +#ifndef KINETIS_SIM_H +#define KINETIS_SIM_H + +#include "hw/sysbus.h" +#include "chardev/char-fe.h"
not used
include/hw/misc/kinetis_k64_sim.h line 19
Quoted 1 line
include/hw/misc/kinetis_k64_sim.h new file +1
-0+#include "chardev/char-mux.h"
not used
Quoted 7 lines
include/hw/misc/kinetis_k64_sim.h new file +7
-0+#include "hw/hw.h" + +#define TYPE_KINETIS_K64_SIM "kinetis_k64_sim" +#define KINETIS_K64_SIM (obj) \ + OBJECT_CHECK(kinetis_k64_sim_state, (obj), TYPE_KINETIS_K64_SIM) + +typedef struct {
include/hw/misc/kinetis_k64_sim.h line 36
Quoted 10 lines
include/hw/misc/kinetis_k64_sim.h new file +10
-0+SysBusDevice parent_obj; + +MemoryRegion iomem; + +uint32_t SOPT1 ;/**< System Options Register 1, offset: 0x0 */ +uint32_t SOPT1CFG ;/**< SOPT1 Configuration Register, offset: 0x4 */ +uint32_t SOPT2 ;/**< System Options Register 2, offset: 0x1004 */ +uint32_t SOPT4 ;/**< System Options Register 4, offset: 0x100C */ +uint32_t SOPT5 ;/**< System Options Register 5, offset: 0x1010 */ +uint32_t SOPT7 ;/**< System Options Register 7, offset: 0x1018 */
could be uint32_t SOPT[8] ...
include/hw/misc/kinetis_k64_sim.h line 44
Quoted 8 lines
include/hw/misc/kinetis_k64_sim.h new file +8
-0+uint32_t SDID ;/**< System Device Id Register, offset: 0x1024 */ +uint32_t SCGC1 ;/**< System Clock Gating Ctrl Reg 1, offset: 0x1028 */ +uint32_t SCGC2 ;/**< System Clock Gating Ctrl Reg 2, offset: 0x102C */ +uint32_t SCGC3 ;/**< System Clock Gating Ctrl Reg 3, offset: 0x1030 */ +uint32_t SCGC4 ;/**< System Clock Gating Ctrl Reg 4, offset: 0x1034 */ +uint32_t SCGC5 ;/**< System Clock Gating Ctrl Reg 5, offset: 0x1038 */ +uint32_t SCGC6 ;/**< System Clock Gating Ctrl Reg 6, offset: 0x103C */ +uint32_t SCGC7 ;/**< System Clock Gating Ctrl Reg 7, offset: 0x1040 */
... and uint32_t SCGC[8]
Then in the source I'd do:
case 0x0000:
value = s->SOPT[0];
break;
case 0x0004:
value = s->SOPTCFG[0];
break;
case 0x1004 ... 0x1018:
value = s->SOPT[(value & 0x1f) >> 2];
break;Quoted 13 lines
include/hw/misc/kinetis_k64_sim.h new file +12
-0+uint32_t CLKDIV1 ;/**< System Clock Divider Register 1, offset: 0x1044 */ +uint32_t CLKDIV2 ;/**< System Clock Divider Register 2, offset: 0x1048 */ +uint32_t FCFG1 ;/**< Flash Configuration Register 1, offset: 0x104C */ +uint32_t FCFG2 ;/**< Flash Configuration Register 2, offset: 0x1050 */ +uint32_t UIDH ;/**< Unique Id Register High, offset: 0x1054 */ +uint32_t UIDMH ;/**< Unique Id Register Mid-High, offset: 0x1058 */ +uint32_t UIDML ;/**< Unique Id Register Mid Low, offset: 0x105C */ + uint32_t UIDL; /**< Unique Id Register Low, offset: 0x1060 */ + +} kinetis_k64_sim_state; + +#endif
Hi Philippe,
Thanks for all your comments!
The name SIM came from kinetis datasheet, it is the name of the peripheral. I believe others families of kinetis microcontrollers uses the same name.
Quoted 131 lines · Philippe Mathieu-Daudé
Hi Gabriel,
Quoted 1 line · Gabriel Augusto Costa
I made a new arm machine with some peripherals. The machine is
mk64fn1m0, a
Quoted 9 lines
cortex-m4 microcontroller from NXP Kinetis family. The machine can run a simple arm binary file using UART0 in polling mode.
I have prepared a series of patchs to include this machine:
PATCH v3 n/11: It adds the machine and peripherals devices; PATCH v4 n/2: It changes the Make files to compile this machine.Signed-off-by Gabriel Augusto Costa <[email protected]>--- include/hw/misc/kinetis_k64_sim.h | 56 +++++++++++++++++++++++++++++++++++++++
Review
Quoted 4 lines
1 file changed, 56 insertions(+) create mode 100644 include/hw/misc/kinetis_k64_sim.h(quoted diff) +0
-0
b/include/hw/misc/kinetis_k64_sim.hinclude/hw/misc/kinetis_k64_sim.h
Quoted 4 lines
new file mode 100644
index 0000000..2eb1f5cinclude/hw/misc/kinetis_k64_sim.h new file +0
-0I'd rather name it
kinetis_k64_system.horkinetis_k64_sysctl.hQuoted 9 lines
include/hw/misc/kinetis_k64_sim.h new file +8
-0@@ -0,0 +1,56 @@ +/* +* Kinetis K64 peripheral microcontroller emulation. +* +* Copyright (c) 2017 Advantech Wireless +* Written by Gabriel Costa <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 or include/hw/misc/kinetis_k64_sim.h line 18
Quoted 10 lines
include/hw/misc/kinetis_k64_sim.h new file +10
-0+* (at your option) any later version. +*/ + +/* Kinetis K64 series SIM controller. */ + +#ifndef KINETIS_SIM_H +#define KINETIS_SIM_H + +#include "hw/sysbus.h" +#include "chardev/char-fe.h" not used
include/hw/misc/kinetis_k64_sim.h line 19
Quoted 1 line
include/hw/misc/kinetis_k64_sim.h new file +1
-0+#include "chardev/char-mux.h" not used
include/hw/misc/kinetis_k64_sim.h
Quoted 13 lines
include/hw/misc/kinetis_k64_sim.h new file +13
-0+#include "hw/hw.h" + +#define TYPE_KINETIS_K64_SIM "kinetis_k64_sim" +#define KINETIS_K64_SIM (obj) \ + OBJECT_CHECK(kinetis_k64_sim_state, (obj), TYPE_KINETIS_K64_SIM) + +typedef struct { + SysBusDevice parent_obj; + + MemoryRegion iomem; + + uint32_t SOPT1; /**< System Options Register 1, offset: 0x0 */ + uint32_t SOPT1CFG; /**< SOPT1 Configuration Register, offset: 0x4*/
include/hw/misc/kinetis_k64_sim.h line 33
Quoted 1 line
include/hw/misc/kinetis_k64_sim.h new file +1
-0+uint32_t SOPT2 ;/**< System Options Register 2, offset: 0x1004 */
include/hw/misc/kinetis_k64_sim.h line 34
Quoted 1 line
include/hw/misc/kinetis_k64_sim.h new file +1
-0+uint32_t SOPT4 ;/**< System Options Register 4, offset: 0x100C */
include/hw/misc/kinetis_k64_sim.h line 35
Quoted 1 line
include/hw/misc/kinetis_k64_sim.h new file +1
-0+uint32_t SOPT5 ;/**< System Options Register 5, offset: 0x1010 */
include/hw/misc/kinetis_k64_sim.h line 36
Quoted 1 line
include/hw/misc/kinetis_k64_sim.h new file +1
-0+uint32_t SOPT7 ;/**< System Options Register 7, offset: 0x1018 */
could be
uint32_tSOPT[8] ...include/hw/misc/kinetis_k64_sim.h line 37
Quoted 1 line
include/hw/misc/kinetis_k64_sim.h new file +1
-0+uint32_t SDID ;/**< System Device Id Register, offset: 0x1024 */
include/hw/misc/kinetis_k64_sim.h line 38
Quoted 1 line
include/hw/misc/kinetis_k64_sim.h new file +1
-0+uint32_t SCGC1 ;/**< System Clock Gating Ctrl Reg 1, offset:
0x1028*/include/hw/misc/kinetis_k64_sim.h line 39
Quoted 1 line
include/hw/misc/kinetis_k64_sim.h new file +1
-0+uint32_t SCGC2 ;/**< System Clock Gating Ctrl Reg 2, offset:
0x102C*/include/hw/misc/kinetis_k64_sim.h line 40
Quoted 1 line
include/hw/misc/kinetis_k64_sim.h new file +1
-0+uint32_t SCGC3 ;/**< System Clock Gating Ctrl Reg 3, offset:
0x1030*/include/hw/misc/kinetis_k64_sim.h line 41
Quoted 1 line
include/hw/misc/kinetis_k64_sim.h new file +1
-0+uint32_t SCGC4 ;/**< System Clock Gating Ctrl Reg 4, offset:
0x1034*/include/hw/misc/kinetis_k64_sim.h line 42
Quoted 1 line
include/hw/misc/kinetis_k64_sim.h new file +1
-0+uint32_t SCGC5 ;/**< System Clock Gating Ctrl Reg 5, offset:
0x1038*/include/hw/misc/kinetis_k64_sim.h line 43
Quoted 1 line
include/hw/misc/kinetis_k64_sim.h new file +1
-0+uint32_t SCGC6 ;/**< System Clock Gating Ctrl Reg 6, offset:
0x103C*/include/hw/misc/kinetis_k64_sim.h line 44
Quoted 1 line
include/hw/misc/kinetis_k64_sim.h new file +1
-0+uint32_t SCGC7 ;/**< System Clock Gating Ctrl Reg 7, offset:
0x1040*/... and
uint32_tSCGC[8]Then in the source I'd do:
case 0x0000: value = s->SOPT[0]; break; case 0x0004: value = s->SOPTCFG[0]; break; case 0x1004 ... 0x1018: value = s->SOPT[(value & 0x1f) >> 2]; break;include/hw/misc/kinetis_k64_sim.h line 45
Quoted 1 line
include/hw/misc/kinetis_k64_sim.h new file +1
-0+uint32_t CLKDIV1 ;/**< System Clock Divider Register 1, offset:
0x1044*/include/hw/misc/kinetis_k64_sim.h line 46
Quoted 1 line
include/hw/misc/kinetis_k64_sim.h new file +1
-0+uint32_t CLKDIV2 ;/**< System Clock Divider Register 2, offset:
0x1048*/include/hw/misc/kinetis_k64_sim.h line 47
Quoted 1 line
include/hw/misc/kinetis_k64_sim.h new file +1
-0+uint32_t FCFG1 ;/**< Flash Configuration Register 1, offset:
0x104C*/include/hw/misc/kinetis_k64_sim.h line 48
Quoted 1 line
include/hw/misc/kinetis_k64_sim.h new file +1
-0+uint32_t FCFG2 ;/**< Flash Configuration Register 2, offset:
0x1050*/include/hw/misc/kinetis_k64_sim.h line 50
Quoted 2 lines
include/hw/misc/kinetis_k64_sim.h new file +2
-0+uint32_t UIDH ;/**< Unique Id Register High, offset: 0x1054 */ +uint32_t UIDMH ;/**< Unique Id Register Mid-High, offset:
0x1058*/include/hw/misc/kinetis_k64_sim.h line 51
Quoted 1 line
include/hw/misc/kinetis_k64_sim.h new file +1
-0+uint32_t UIDML ;/**< Unique Id Register Mid Low, offset: 0x105C */
Quoted 6 lines
include/hw/misc/kinetis_k64_sim.h new file +5
-0+ uint32_t UIDL; /**< Unique Id Register Low, offset: 0x1060 */ + +} kinetis_k64_sim_state; + +#endif
Quoted 2 lines · Gabriel Costa
The name SIM came from kinetis datasheet, it is the name of the peripheral. I believe others families of kinetis microcontrollers uses the same name.
SIM stands for "System Integration Module"; naming it "kinetis_k64_sim.c" does not sound very helpful.
This is why I suggested "kinetis_k64_system.c" which better matches the system controller of the other SoCs.
Quoted 3 lines
Quoted 1 line · Philippe Mathieu-Daudé
I'd rather name it
kinetis_k64_system.horkinetis_k64_sysctl.h