Update d_process examples.

This commit is contained in:
Brian Taylor 2023-10-20 11:38:21 -07:00 committed by Holger Vogt
parent c83d11c9c0
commit 1f5f7ae439
8 changed files with 107 additions and 106 deletions

View File

@ -34,7 +34,11 @@ before ngspice prog-pipes.cir, and in another shell:
needs to be started.
NOTE on debugging. On Linux or Cygwin on Windows, gdb can be attached to
The file checks.cir can be run to test the error handling in d_process.
==============================================================================
NOTE ON DEBUGGING. On Linux or Cygwin on Windows, gdb can be attached to
the running d_process programs, or in --pipe mode with fifos, the graycode
example can be run when invoked from gdb.
@ -42,13 +46,16 @@ From a Windows Powershell, WinDbg can be attached to a running d_process
program.
To enable the debugging hooks in the programs (graycode.c, prog1in4out.c,
prog4in1out.c), edit them to #define ENABLE_DEBUGGING.
prog4in1out.c), edit them to #define ENABLE_DEBUGGING. The debugging
hooks are in the debugging.h include file.
Each program prints (to stderr) its process id when started. This makes
it easier to know the process when attaching a debugger.
All the programs (graycode.c, prog1in4out.c, prog4in1out.c) contain a call
to sleep to give you time to attach a debugger. This is enabled by:
to debug_info() which calls sleep() to give you time to attach a debugger.
Just after the sleep() call, there is a call to known_bp() on which you can
set a breakpoint. The sleep() is enabled by:
export GO_TO_SLEEP=1 (on Linux, Cygwin)
$env:go_to_sleep = '1' (on Windows Powershell)

View File

@ -0,0 +1,44 @@
checks.cir test error handling.
*** analysis type ***
.tran .01us 10us
v1 1 0 DC 1.0
v2 2 0 DC 0.0
.model d_osc1 d_osc (cntl_array=[-1.0 0.0 1.0 2.0]
+ freq_array=[1.0e6 1.0e6 4.0e6 4.0e6]
+ rise_delay=1.0e-6 fall_delay=2.0e-6)
a1 1 clk1 d_osc1
a2 2 clk2 d_osc1
** Too few outputs, 4 required
ap0 null clk1 null [q2 q3 q4] proc0
.model proc0 d_process (process_file="graycode" process_params=["none"])
ap1 [clk2] clk1 null [o1 o2 o3 o4] proc1
.model proc1 d_process (process_file="prog1in4out" process_params=["opt1", "qwerty"])
ap2 [o1 o2 o3 o4] clk1 null [zeros] proc2
** Non existent process_file or missing fifos
** Unsupported fifo on Windows VisualC
.model proc2 d_process (process_file="badprog4in1out|" process_params=["abc", "99"])
ap3 [q1 q2 q3 q4] clk1 null [qzeros] proc3
** Non existent process_file
.model proc3 d_process (process_file="prog4in1outxxx")
an1 [o1 ~o2 o3] reseto dand1
.model dand1 d_and(inertial_delay=true rise_delay=1ns fall_delay=50ns)
ap4 [clk2] clk1 reseto [b1 b2 b3 b4] proc4
** Empty process_file name
.model proc4 d_process (process_file="")
.control
run
edisplay
quit
.endc
.end

View File

@ -0,0 +1,40 @@
#ifndef INCLUDED_DEBUGGING_H
#define INCLUDED_DEBUGGING_H
static int known_bp(int iargc)
{
return iargc;
}
void debug_info(int argc, char **argv)
{
#if defined(_MSC_VER) || defined(__MINGW64__)
fprintf(stderr, "%s pid %d\n", argv[0], _getpid());
#else
fprintf(stderr, "%s pid %d\n", argv[0], getpid());
#endif
#if !defined(_MSC_VER) && !defined(__MINGW64__)
if (getenv("GO_TO_SLEEP")) {
sleep(40);
}
#endif
#if defined(__MINGW64__)
if (getenv("GO_TO_SLEEP")) {
sleep(40);
}
#endif
#if defined(_MSC_VER)
if (getenv("GO_TO_SLEEP")) {
Sleep(60000);
}
#endif
(void)known_bp(argc);
for (int i=0; i<argc; i++) {
fprintf(stderr, "[%d] %s\n", i, argv[i]);
}
}
#endif

View File

@ -22,10 +22,7 @@ static int compute(uint8_t *dataout, int outsz, double time);
//#define ENABLE_DEBUGGING 1
#ifdef ENABLE_DEBUGGING
static int known_bp(int iargc)
{
return iargc;
}
#include "debugging.h"
#endif
int main(int argc, char *argv[]) {
@ -60,33 +57,10 @@ int main(int argc, char *argv[]) {
#endif
#ifdef ENABLE_DEBUGGING
#if defined(_MSC_VER) || defined(__MINGW64__)
fprintf(stderr, "%s pid %d\n", argv[0], _getpid());
#else
fprintf(stderr, "%s pid %d\n", argv[0], getpid());
debug_info(argc, argv);
#endif
#if !defined(_MSC_VER) && !defined(__MINGW64__)
if (getenv("GO_TO_SLEEP")) {
sleep(40);
}
#endif
#if defined(__MINGW64__)
if (getenv("GO_TO_SLEEP")) {
sleep(40);
}
#endif
#if defined(_MSC_VER)
if (getenv("GO_TO_SLEEP")) {
Sleep(60000);
}
#endif
(void)known_bp(argc);
#endif
for (i=0; i<argc; i++) {
//fprintf(stderr, "[%d] %s\n", i, argv[i]);
for (i = 0; i <argc; i++) {
if (strcmp(argv[i],"--pipe")==0) {
#if defined(_MSC_VER) || defined(__MINGW64__)
if ((pipein = _open("graycode_in", O_RDONLY)) < 0 || (pipeout = _open("graycode_out", O_WRONLY)) < 0)

View File

@ -33,8 +33,3 @@ shell gtkwave prog1-4.vcd --script nggtk.tcl &
.endc
.end

View File

@ -37,14 +37,13 @@ eprvcd clk1 clk2 o1 o2 o3 o4 q1 q2 q3 q4 b1 b2 b3 b4 zeros qzeros reseto > prog
if $oscompiled = 1 | $oscompiled = 8 ; MS Windows
shell start gtkwave prog1-4.vcd --script nggtk.tcl
else
shell gtkwave prog1-4.vcd --script nggtk.tcl &
if $oscompiled = 7 ; macOS, manual tweaking required (mark, insert, Zoom Fit)
shell open -a gtkwave prog1-4.vcd
else ; Linux and others
shell gtkwave prog1-4.vcd --script nggtk.tcl &
end
end
quit
.endc
.end

View File

@ -24,10 +24,7 @@ static int compute(
//#define ENABLE_DEBUGGING 1
#ifdef ENABLE_DEBUGGING
static int known_bp(int iargc)
{
return iargc;
}
#include "debugging.h"
#endif
int main(int argc, char *argv[]) {
@ -64,35 +61,9 @@ int main(int argc, char *argv[]) {
#endif
#ifdef ENABLE_DEBUGGING
#if defined(_MSC_VER) || defined(__MINGW64__)
fprintf(stderr, "%s pid %d\n", argv[0], _getpid());
#else
fprintf(stderr, "%s pid %d\n", argv[0], getpid());
debug_info(argc, argv);
#endif
#if !defined(_MSC_VER) && !defined(__MINGW64__)
if (getenv("GO_TO_SLEEP")) {
sleep(40);
}
#endif
#if defined(__MINGW64__)
if (getenv("GO_TO_SLEEP")) {
sleep(40);
}
#endif
#if defined(_MSC_VER)
if (getenv("GO_TO_SLEEP")) {
Sleep(60000);
}
#endif
(void)known_bp(argc);
for (int i=0; i<argc; i++) {
fprintf(stderr, "[%d] %s\n", i, argv[i]);
}
#endif
if (d_process_init(pipein, pipeout, DIGITAL_IN, DIGITAL_OUT) ) {
#if defined(_MSC_VER) || defined(__MINGW64__)
while(_read(pipein, &in, sizeof(in)) == sizeof(in)) {
@ -126,7 +97,7 @@ static int compute(
uint8_t inbit0 = datain[0] & 1;
static uint8_t count = 0;
if (time < 0.0) {
//fprintf(stderr, "Reset prog1in4out at time %g\n", -time);
fprintf(stderr, "Reset prog1in4out at time %g\n", -time);
count = 15;
}
if (count < 15) {

View File

@ -24,10 +24,7 @@ static int compute(
//#define ENABLE_DEBUGGING 1
#ifdef ENABLE_DEBUGGING
static int known_bp(int iargc)
{
return iargc;
}
#include "debugging.h"
#endif
int main(int argc, char *argv[]) {
@ -64,33 +61,7 @@ int main(int argc, char *argv[]) {
#endif
#ifdef ENABLE_DEBUGGING
#if defined(_MSC_VER) || defined(__MINGW64__)
fprintf(stderr, "%s pid %d\n", argv[0], _getpid());
#else
fprintf(stderr, "%s pid %d\n", argv[0], getpid());
#endif
#if !defined(_MSC_VER) && !defined(__MINGW64__)
if (getenv("GO_TO_SLEEP")) {
sleep(40);
}
#endif
#if defined(__MINGW64__)
if (getenv("GO_TO_SLEEP")) {
sleep(40);
}
#endif
#if defined(_MSC_VER)
if (getenv("GO_TO_SLEEP")) {
Sleep(60000);
}
#endif
(void)known_bp(argc);
for (int i=0; i<argc; i++) {
fprintf(stderr, "[%d] %s\n", i, argv[i]);
}
debug_info(argc, argv);
#endif
if (d_process_init(pipein, pipeout, DIGITAL_IN, DIGITAL_OUT) ) {