Thu Sep 4 18:51:32 CEST 2008

more pk2

Added accessors to the pk2 module namespace that query the current
device's properties:

box> (print-script (ProgMemWrWords))
Erase progmem (09) & EE(0B), int timed 10ms


box> (script (ProgMemWrWords))
Erase progmem (09) & EE(0B), int timed 10ms
(238 6 0 242 0 242 0 238 6 9 232 2 238 6 11 232 2)

This required only minor modification:

;; Also create accessor thunks for properties on top of hash DB.  These
;; will get the property of the current part (makes name-checking
;; static).
(define-syntax-rule (define-reader/provide name (type id . args) ...)
    (define-reader name (type id . args) ...)
    (begin (define (id) (property 'id)) ...)
    (provide id ...)))
(define part (make-parameter 'PIC18F1220))
(define (property tag [dev (part)])
  (let* ((part (hash-ref *part-index* dev))
         (fam  (vector-ref *family* (hash-ref part 'Family))))
    (hash-ref part tag
              (lambda ()
                (hash-ref fam tag)))))

Trying to make a device-read script now, but something is missing: the
code executes scripts on the device, but i didn't see the part where
it gets uploaded.

The lowlevel routine is
\\ PICkitFunctions.cpp
bool CPICkitFunctions::downloadScript(unsigned char scriptBufferLocation, int scriptArrayIndex)

The one that calls this is:
void CPICkitFunctions::downloadPartScripts(int familyIndex)

This is called by
void CPICkitFunctions::PrepPICkit2(void)

Which also sets VDD and Vpp voltages

Scripts start from index 1, not 0 !!

(0 0 0 0)
box> (DOWNLOAD_SCRIPT 1 (script (ProgMemRdScript)))
Reads 64 words of program memory.
(1 0 238 0)

So uploading seems to work.  Execution not though:

;; CPICkitFunctions::ReadDevice
(define (read-program-memory)

                   (VDD_ON))             ;; we power the device

                   (DOWNLOAD_DATA 0 0 0))
  (EXECUTE_SCRIPT  (script (ProgMemAddrSetScript)))

  (DOWNLOAD_SCRIPT 1 (script (ProgMemRdScript)))

                    1 ;; index ???
                    1 ;; repititions?

I'd like to eliminate the use of 'script' too.  For printing scripts,
one should use the 'properties function.  This requires some type
spec, maybe derived from the name?