• General
  • [16-bit ClassB V2.40] Bug in class_b_pc_.s
2020/06/11 09:57:35
nice
Code snippets from the file "VDE_MCU16_ClassB_V240b.zip" as downloaded from this page:
 
//classb.h

typedef enum _CLASSBRESULT_
{
  CLASSB_TEST_PASS = 0,
  CLASSB_TEST_FAIL,
} CLASSBRESULT; 

CLASSBRESULT CLASSB_CPUPCTest();


; classb_pc_.s

.global _CLASSB_CPUPCTest
    
.bss                   ;  uninitialized data section
PCErrorFlag: .space 2  ; program counter error flag  
                          ; after POR PCErrorFlag holds a random value
.section function5555, code, address(0x00001554-2)
    return ; guard return instruction
PCTestFunction5555:
    dec [w0], [w0]
    return

.section functionAAAA, code, address(0x00002aaa-2)
    return ; guard return instruction
PCTestFunctionAAAA:
    dec [w0], [w0]
    return

_CLASSB_CPUPCTest:
    mov #PCErrorFlag, w0          ; w0 points to PCErrorFlag
    inc [w0], [w0]                     ; PCError Flag now contains a random value + 1 …
    call PCTestFunction5555
    inc [w0], [w0]    
    call PCTestFunctionAAAA    
    mov [w0], w0
    return
   

Most of the times CLASSB_CPUPCTest will fail, although the calls of both test functions decremented PCErrorFLag. PCErrorFlag must be initialized to zero. In the worst case the random value in PCErrorFLag is 0xFFFE. If both calls fail, the function will return CLASSB_TEST_PASS.

IMO PCErrorFlag isn’t needed at all.
_CLASSB_CPUPCTest:
    mov #1, w0      
    call PCTestFunction5555
    inc w0, w0    
    call PCTestFunctionAAAA
    return

.section functionAAAA, code, address(0x00002aaa-2)
    return ; guard return instruction
PCTestFunction5555:
    dec w0, w0
    return
; …
 


2020/06/11 14:24:59
Jacob the dane
Hi Nice,
Thanks for reporting it. I have made the MCU16 team aware.
2020/06/17 12:36:42
FuSaDude
@Nice, Thanks again for flagging this bug. It was confirmed and an update is forthcoming. Please check the web for a new version of the library in a few days. 
© 2021 APG vNext Commercial Version 4.5

Use My Existing Forum Account