Documentation for “Zerocat Chipflasher” as of Wed, 24 Jun 2026 07:28:15 +0200
Repository: git://zerocat.org/zerocat/projects/chipflasher.git
Version: v3.0.0-0-b445ef922
Branch: master

status.spin.nointerface.html

{{

______________________________________________________________________________
********************************************************* File starts here ***
Zerocat Chipflasher --- Flash free firmware, kick the Management Engine.

File status.spin --- provide status and error codes.

Copyright (C) 2020, 2021, 2022, 2026  Kai Mertens 

This file is part of Zerocat Chipflasher.

See end of file for terms of use.

******************************************************************************
}}



''
''
''# Object Summary
OBJ     'This directive triggers the compiler to insert a summary.



''
''
''# Loaded Objects
                                                ''
        time                : "time"            ''* time object



''
''
''# Included Files



''
''
''# Constants
CON
        ''
        ''* LED pins
        D1      =   15
        D2      =   14
        D3      =   13

        ''
        ''* ENUM CODE_type
        ''
        ''    - CODE_RQ_SUSPEND        -- internal flag
        ''    - CODE_HELLO_38400       -> all LEDs blink once or twice (according to board version), very very slow
        ''    - CODE_HELLO_57600       -> all LEDs blink once or twice (according to board version), very slow
        ''    - CODE_HELLO             -> all LEDs blink once or twice (according to board version), slow
        ''    - CODE_HELLO_230400      -> all LEDs blink once or twice (according to board version)
        ''    - CODE_RST               -> LED D2 on
        ''    - CODE_CANCEL            -> LED D2 off
        ''    - CODE_SUCCESS           -> LED D2 blinks once
        ''    - CODE_HANDSHAKE         -> LED D2 blinks twice
        ''    - CODE_JOB               -> LED D2 blinks three times
        ''    - CODE_TIMEOUT           -> LED D2 blinks 4 times
        ''    - CODE_TX                -> LED D2 blinks 5 times
        ''    - CODE_INTERNAL          -> LED D2 blinks 6 times
        ''    - CODE_INTERFACE         -> LED D2 blinks 7 times
        ''    - CODE_LOWVOLTAGE        -> LED D2 blinks 8 times
        ''    - CODE_CABLE             -> LED D2 blinks 9 times
        #-3
        CODE_RQ_SUSPEND
        CODE_HELLO_38400       'one or two pulses all LEDs unisono, very slow
        CODE_HELLO_57600       'one or two pulses all LEDs unisono, slow
        CODE_HELLO             'one or two pulses all LEDs unisono, normal
        CODE_HELLO_230400      'one or two pulses all LEDs unisono, fast
        CODE_RST               'D2 on
        CODE_CANCEL            'D2 off
        CODE_SUCCESS           'D2 one pulse
        CODE_HANDSHAKE         'D2 two pulses
        CODE_JOB               'D2 three
        CODE_TIMEOUT           'D2 four
        CODE_TX                'D2 5
        CODE_INTERNAL          'D2 6
        CODE_INTERFACE         'D2 7
        CODE_LOWVOLTAGE        'D2 8
        CODE_CABLE             'D2 9



''
''
''# Functions


PUB     drive_LEDs (code)

        '' Display status codes with D1..D3:
        ''
        ''  Status codes are displayed ...
        ''
        ''  a) at program start
        ''  b) when program is done
        ''
        ''  During start, all LEDs D1..D3 blink in unisono as a `hello world' greeting message.
        ''  If they light up once, a PCB of type board-v1 has been detected.
        ''  If they light up twice, a PCB of type board-v2 has been detected.
        ''
        ''  The light up duration tells you about the baudrate in use by the firmware.
        ''  An intuitively `normal' duration is used for 115200 bps.
        ''  A greater duration is used for 57600 bps.
        ''  An even greater duration is used for 38700 bps.
        ''  However, a very short light up pulse is used for 230400 bps.
        ''
        ''  Right after this `hello world' greeter, LED D2 might get
        ''  switched on for up to 25 seconds in order to tell us that the RST
        ''  reset line is inhibited to allow a follow-up handhake with
        ''  `connect'.
        ''
        ''  At the end of the program, LED D2 provides trains of pulses to report the status code:
        ''
        ''  CODE_SUCCESS      -- one pulse    : no failure, success!
        ''  CODE_HANDSHAKE    -- two pulses   : handshake failure
        ''  CODE_JOB          -- three pulses : job error
        ''  CODE_TIMEOUT      -- 4            : timeout error
        ''  CODE_TX           -- 5            : transmission error
        ''  CODE_INTERNAL     -- 6            : internal code error
        ''  CODE_INTERFACE    -- 7            : no interface
        ''  CODE_LOWVOLTAGE   -- 8            : voltage too low
        ''  CODE_CABLE        -- 9 pulses     : SPI cable absent or twisted
        ''
        ''  While in this status report mode, the firmware is open to receive a reset or a new firmware upload.


        CASE code
            CODE_HELLO, CODE_HELLO_230400, CODE_HELLO_57600, CODE_HELLO_38400:
                time.sleep_msec(100)
                OUTA[D1..D3] := %111
                time.sleep_msec(300 + code * -200)
                OUTA[D1..D3] := %000
                time.sleep_msec(100)

            CODE_RST:
                OUTA[D2]~~
                time.sleep_msec(300)

            CODE_CANCEL:
                OUTA[D2]~

            ' maximal pulse train duration is:
            ' 350ms + pulses * 400ms + 350ms
            ' = 4300ms for 9 pulses
            OTHER:
                OUTA[D2]~
                time.sleep_msec(350)
                REPEAT code - CODE_SUCCESS + 1
                    OUTA[D2]~~
                    time.sleep_msec(50)
                    OUTA[D2]~
                    time.sleep_msec(350)
                time.sleep_msec(350)



{{


******************************************************************************
Terms of Use:

Zerocat Chipflasher is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

Zerocat Chipflasher is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License along
with Zerocat Chipflasher.  If not, see <http://www.gnu.org/licenses/>.

************************************************************** End of File ***
}}