From: Aurelien Jarno <aurelien@aurel32.net>
To: Serge Vakulenko <serge.vakulenko@gmail.com>
Cc: Leon Alrae <leon.alrae@imgtec.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH pic32 v3 05/16] pic32: add file pic32_peripherals.h
Date: Mon, 6 Jul 2015 11:01:40 +0200 [thread overview]
Message-ID: <20150706090140.GX931@aurel32.net> (raw)
In-Reply-To: <1436163304-6167-6-git-send-email-serge.vakulenko@gmail.com>
On 2015-07-05 23:14, Serge Vakulenko wrote:
> Data definitions and function declarations for simulation
> of pic32 microcontrollers.
>
> Signed-off-by: Serge Vakulenko <serge.vakulenko@gmail.com>
> ---
> hw/mips/pic32_peripherals.h | 210 ++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 210 insertions(+)
> create mode 100644 hw/mips/pic32_peripherals.h
>
> diff --git a/hw/mips/pic32_peripherals.h b/hw/mips/pic32_peripherals.h
> new file mode 100644
> index 0000000..4435991
> --- /dev/null
> +++ b/hw/mips/pic32_peripherals.h
> @@ -0,0 +1,210 @@
> +/*
> + * Define memory map for PIC32 microcontroller.
> + *
> + * Copyright (C) 2015 Serge Vakulenko
> + *
> + * Permission to use, copy, modify, and distribute this software
> + * and its documentation for any purpose and without fee is hereby
> + * granted, provided that the above copyright notice appear in all
> + * copies and that both that the copyright notice and this
> + * permission notice and warranty disclaimer appear in supporting
> + * documentation, and that the name of the author not be used in
> + * advertising or publicity pertaining to distribution of the
> + * software without specific, written prior permission.
> + *
> + * The author disclaim all warranties with regard to this
> + * software, including all implied warranties of merchantability
> + * and fitness. In no event shall the author be liable for any
> + * special, indirect or consequential damages or any damages
> + * whatsoever resulting from loss of use, data or profits, whether
> + * in an action of contract, negligence or other tortious action,
> + * arising out of or in connection with the use or performance of
> + * this software.
> + */
> +#include "hw/sysbus.h" /* SysBusDevice */
> +#include "net/net.h"
> +
> +#define IO_MEM_SIZE (1024*1024) /* 1 Mbyte */
> +
> +typedef struct _uart_t uart_t;
> +typedef struct _spi_t spi_t;
> +typedef struct _sdcard_t sdcard_t;
> +typedef struct _pic32_t pic32_t;
> +typedef struct _eth_t eth_t;
> +
> +/*
> + * UART private data.
> + */
> +struct _uart_t {
> + pic32_t *mcu; /* back pointer to pic32 object */
> + unsigned irq; /* interrupt number */
> + int oactive; /* output active */
> + unsigned sta; /* UxSTA address */
> + unsigned mode; /* UxMODE address */
> + unsigned rxbyte; /* received byte */
> + CharDriverState *chr; /* pointer to serial_hds[i] */
> + QEMUTimer *transmit_timer; /* needed to delay TX interrupt */
> +};
> +
> +/*
> + * SPI private data.
> + */
> +struct _spi_t {
> + unsigned buf[4]; /* transmit and receive buffer */
> + unsigned rfifo; /* read fifo counter */
> + unsigned wfifo; /* write fifo counter */
> + unsigned irq; /* interrupt numbers */
> + unsigned con; /* SPIxCON address */
> + unsigned stat; /* SPIxSTAT address */
> +};
> +
> +/*
> + * SD card private data.
> + */
> +struct _sdcard_t {
> + const char *name; /* Device name */
> + unsigned gpio_port; /* GPIO port number of CS0 signal */
> + unsigned gpio_cs; /* GPIO pin mask of CS0 signal */
> + unsigned kbytes; /* Disk size */
> + int unit; /* Index (sd0 or sd1) */
> + int fd; /* Image file */
> + int select; /* Selected */
> + int read_multiple; /* Read-multiple mode */
> + unsigned blen; /* Block length */
> + unsigned wbecnt; /* Write block erase count */
> + unsigned offset; /* Read/write offset */
> + unsigned count; /* Byte count */
> + unsigned limit; /* Reply length */
> + unsigned char buf[1024 + 16];
> +};
> +
> +/*
> + * PIC32 data structure.
> + */
> +struct _pic32_t {
> + SysBusDevice parent_obj;
> + MIPSCPU *cpu; /* back pointer to cpu object */
> + uint32_t *iomem; /* backing storage for I/O area */
> +
> + int board_type; /* board variant */
> + int stop_on_reset; /* halt simulation on soft reset */
> + unsigned syskey_unlock; /* syskey state */
> +
> +#define NUM_UART 6 /* number of UART ports */
> + uart_t uart[NUM_UART]; /* UART data */
> +
> +#define NUM_SPI 6 /* max number of SPI ports */
> + spi_t spi[NUM_SPI]; /* SPI data */
> +
> + unsigned sdcard_spi_port; /* SPI port number of SD card */
> + sdcard_t sdcard[2]; /* SD card data */
> +
> + DeviceState *eth_dev; /* Ethernet device */
> + eth_t *eth; /* Ethernet driver data */
> +
> + void (*irq_raise)(pic32_t *s, int irq); /* set interrupt request */
> + void (*irq_clear)(pic32_t *s, int irq); /* clear interrupt request */
> +};
I don't think this is the correct way of modeling the PIC32 peripherals.
Instead of modeling one "big PIC32 peripheral", you should model single
UART, Ethernet device, SPI port, etc. separately. They have their own
address space and IRQ, so each one will have their own ioread/iowrite
function.
Then you can instanciate the peripherals depending on the
micro-controller you emulate (for example 2 UART for the PIC32MX4 or 6
UART for the PIC32MX7) instead of relying on #ifdef at compilation time.
Aurelien
--
Aurelien Jarno GPG: 4096R/1DDD8C9B
aurelien@aurel32.net http://www.aurel32.net
next prev parent reply other threads:[~2015-07-06 9:01 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-06 6:14 [Qemu-devel] [PATCH pic32 v3 00/16] add support for pic32 microcontrollers Serge Vakulenko
2015-07-06 6:14 ` [Qemu-devel] [PATCH pic32 v3 01/16] pic32: make the CPU clock frequency configurable per platform Serge Vakulenko
2015-07-06 8:42 ` Aurelien Jarno
2015-07-06 6:14 ` [Qemu-devel] [PATCH pic32 v3 02/16] pic32: use LCG algorithm for generated random index of TLBWR instruction Serge Vakulenko
2015-07-06 8:43 ` Aurelien Jarno
2015-09-15 9:46 ` Leon Alrae
2015-07-06 6:14 ` [Qemu-devel] [PATCH pic32 v3 03/16] pic32: add support for external interrupt controller mode (EIC) Serge Vakulenko
2015-07-06 9:34 ` Aurelien Jarno
2015-07-06 6:14 ` [Qemu-devel] [PATCH pic32 v3 04/16] pic32: add two MIPS processor variants: M4K and microAptivUP Serge Vakulenko
2015-07-06 9:35 ` Aurelien Jarno
2015-10-02 10:37 ` Leon Alrae
2015-07-06 6:14 ` [Qemu-devel] [PATCH pic32 v3 05/16] pic32: add file pic32_peripherals.h Serge Vakulenko
2015-07-06 8:02 ` Peter Crosthwaite
2015-07-06 9:01 ` Aurelien Jarno [this message]
2015-07-06 17:04 ` Peter Crosthwaite
2015-07-06 6:14 ` [Qemu-devel] [PATCH pic32 v3 06/16] pic32: add file pic32mx.h Serge Vakulenko
2015-07-06 6:14 ` [Qemu-devel] [PATCH pic32 v3 07/16] pic32: add file pic32mz.h Serge Vakulenko
2015-07-06 6:14 ` [Qemu-devel] [PATCH pic32 v3 08/16] pic32: add file mips_pic32mx7.c Serge Vakulenko
2015-07-06 11:18 ` Antony Pavlov
2015-07-06 6:14 ` [Qemu-devel] [PATCH pic32 v3 09/16] pic32: add file mips_pic32mz.c Serge Vakulenko
2015-07-06 6:14 ` [Qemu-devel] [PATCH pic32 v3 10/16] pic32: add file pic32_load_hex.c Serge Vakulenko
2015-07-06 6:14 ` [Qemu-devel] [PATCH pic32 v3 11/16] pic32: add file pic32_uart.c Serge Vakulenko
2015-07-06 8:08 ` Peter Crosthwaite
2015-07-06 6:15 ` [Qemu-devel] [PATCH pic32 v3 12/16] pic32: add file pic32_gpio.c Serge Vakulenko
2015-07-06 6:15 ` [Qemu-devel] [PATCH pic32 v3 13/16] pic32: add file pic32_spi.c Serge Vakulenko
2015-07-06 7:58 ` Peter Crosthwaite
2015-07-06 6:15 ` [Qemu-devel] [PATCH pic32 v3 14/16] pic32: add file pic32_sdcard.c Serge Vakulenko
2015-07-06 8:05 ` Peter Crosthwaite
2015-07-06 6:15 ` [Qemu-devel] [PATCH pic32 v3 15/16] pic32: add file pic32_ethernet.c Serge Vakulenko
2015-07-06 6:15 ` [Qemu-devel] [PATCH pic32 v3 16/16] pic32: update makefiles to cover pic32 support Serge Vakulenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150706090140.GX931@aurel32.net \
--to=aurelien@aurel32.net \
--cc=leon.alrae@imgtec.com \
--cc=qemu-devel@nongnu.org \
--cc=serge.vakulenko@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.