views:

672

answers:

6

Hi All. I would like to create/start a simulator for the following microcontroller board: http://www.sparkfun.com/commerce/product_info.php?products_id=707#

The firmware is written in assembly so I'm looking for some pointers on how one would go about simulating the inputs that the hardware would receive and then the simulator would respond to the outputs from the firmware. (which would also require running the firmware in the simulated environment).

Any pointers on how to start?

Thanks Chris

+2  A: 

You'll have to write a PIC simulator and then emulate the IO functionality of the ports.

To be honest, it looks like its designed as a dev kit - I wouldn't worry about your code destroying the device if you take care. Unless this a runner-up for an enterprise package, I would seriously question the ROI on writing a sim.

Paul Nathan
+1  A: 

Writing a whole emulator is going to be a real challenge. I've attempted to write an ARM emulator before, and let me tell you, it's not a small project. You're going to either have to emulate the entire CPU core, or find one that's already written.

You'll also need to figure out how all the IO works. There may be docs from sparkfun about that board, but you'll need to write a memory manager if it uses MMIO, etc.

The concept of an emulator isn't that far away from an interpreter, really. You need to interpret the firmware code, and basically follow along with the instructions.

I would recommend a good interactive debugger instead of tackling an emulator. The chances of destroying the hardware is low, but really, would you rather buy a new board or spend 9 months writing something that won't implement the entire system?

It's likely that the PIC 18F2520 already has an emulator core written for it, but you'll need to delve into all the hardware specs to see how all the IO is mapped still. If you're feeling up to it, it would be a good project, but I would consider just using a remote debugger instead.

Alex Fort
re: destroying hardware1) the board is like 300$ 2) if the plane crashes, that's more. Thanks. I'm going to put up another question about an interpreter
cbrulak
Aehm? Why do you think an arm-emulator is hard to write? It takes like - a day (ARMv5). The instruction encoding is highly orthogonal and there are not that many instructions to simulate. Piece of cake if you ask me.
Nils Pipenbrinck
"if the plane crashes, that's more" -- um, we didn't hear that. High-reliability applications like avionics have their own kinds of design/test practices.
Jason S
+1  A: 

It's extremely unlikely that a bug in your code could damage the physical circuitry. If that's possible, then it is either a bug in the board design or it should be very clearly documented.

If I may offer you a suggestion from many years of experience working with these devices: don't program them in assembly. You will go insane. Use C or BASIC or some higher-level language. Microchip produces a C compiler for most of their chips (dunno about this one), and other companies produce them as well.

If you insist on using an emulator, I'm pretty sure Microchip makes an emulator for nearly every one of their microcontrollers (at least one from each product line, which would probably be good enough). These emulators are not always cheap, and I'm unsure of their ability to accept complex external input.

If you still want to try writing your own, I think you'll find that emulating the PIC itself will be fairly straightforward -- the format of all the opcodes is well documented, as is the memory architecture, etc. It's going to be emulating the other devices on the board and the interconnections between them that will kill you. You might want to look into coding the interconnections between the components using a VHDL tool that will allow you to create custom simulations for the different components.

rmeador
+2  A: 

Is there a particular reason to make an emulator/simulator, vs. just using the real thing?

The board is inexpensive; Microchip now has the RealICE debugger which is quite a bit more responsive than the old ICD2 "hockey puck".

Microchip's MPLAB already has a built-in simulator. It won't simulate the whole board for you, but it will handle the 18F2520. You can sort of use input test vectors & log output files, I've done this before with a different Microchip IC and it was doable but kinda cumbersome. I would suggest you take the unit-testing approach and modularize the way you do things; figure out your test inputs and expected outputs for a manageable piece of the system.

Jason S
can you point me in the direction of creating test vectors?
cbrulak
They're called "stimulus" functions -- http://ww1.microchip.com/downloads/en/devicedoc/51025e.pdf and see section 2.9
Jason S
+1  A: 

Isn't this a hardware-in-the-loop simulator problem? (e.g. http://www.embedded.com/15201692 )

Matt Rogish
+1  A: 

It's likely that the PIC 18F2520 already has an emulator core written for it,

An open source, cross-platform simulator for microchip/PICs is available under the name of "gpsim".

none