Announcement

Collapse
No announcement yet.

Problem when reading data from another bank

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem when reading data from another bank

    Hello Sir,

    I found the problem when reading data from another bank. I assign the product0Window[PR2_PURCHASE_PRICE_LSB] := 32000 from bank3, then that value is read from bank0 and assign to product0Window[PR2_PURCHASE_PRICE_LSB_T] and show the results on the screen. I get output is 393216, not 32000(output expected). How to solve this problem? Thank You.

    shared.inc
    Code:
    //////////////////// ENUM ////////////////////
    #CONST
        PR_PRODUCT_NAME
        PR_PURCHASE_PRICE
        PR_SELLING_PRICE
    #END
    
    #CONST
         _loadSettingsInit
    #END
    
    #CONST
        _12,
        _13,
        _14,
        _15,
        _16,
        _17,
        _18,
        _19,
        _1A,
        _1B,
        _1C,
        _1D,
        _1E,
        _1F,
        _20,
        _21,
        _paramsLimit
    #END
    
    //////////////////// CONSTANT ////////////////////
    #CONST
        NULL                     '\0'
    
        PRODUCT_STRUCT_LENGTH    39
    #END
    
    //////////////////// STRUCT ////////////////////
    #CONST
        PR0_PRODUCT_ID           0  // 2 bytes  (1 word)
    
        PR1_LENGTH               1  // 2 bytes  (1 word)
        PR1_XPOS                 2  // 2 bytes  (1 word)
        PR1_YPOS                 3  // 2 bytes  (1 word)
        PR1_PRODUCT_NAME         4  // 20 bytes (10 word)
        PR1_PRODUCT_NAME_T       14 // 20 bytes (10 word)
    
        PR2_LENGTH               24 // 2 bytes (1 word)
        PR2_XPOS                 25 // 2 bytes (1 word)
        PR2_YPOS                 26 // 2 bytes (1 word)
        PR2_PURCHASE_PRICE_MSB   27 // 2 bytes (1 word)  // 0xFFFFFFFF
        PR2_PURCHASE_PRICE_LSB   28 // 2 bytes (1 word)
        PR2_PURCHASE_PRICE_MSB_T 29 // 2 bytes (1 word)  // 0xFFFFFFFF
        PR2_PURCHASE_PRICE_LSB_T 30 // 2 bytes (1 word)
    
        PR3_LENGTH               31 // 2 bytes (1 word)
        PR3_XPOS                 32 // 2 bytes (1 word)
        PR3_YPOS                 33 // 2 bytes (1 word)
        PR3_SELLING_PRICE_MSB    34 // 2 bytes (1 word)  // 0xFFFFFFFF
        PR3_SELLING_PRICE_LSB    35 // 2 bytes (1 word)
        PR3_SELLING_PRICE_MSB_T  36 // 2 bytes (1 word)  // 0xFFFFFFFF
        PR3_SELLING_PRICE_LSB_T  37 // 2 bytes (1 word)  => 0-37 = 38+1 = 39 word
    #END
    slave.4dg
    Code:
    #platform "uLCD-43DT"
    #STACK 512
    #MODE FLASHBANK_3
    #inherit  "shared.inc"
    
    /////// INITIALIZE ROUTINES ///////
    
    func main(var *params, var funcId)
        var product0Window[PRODUCT_STRUCT_LENGTH];
    
        switch(funcId)
            case _loadSettingsInit:                                              
                product0Window[PR0_PRODUCT_ID]           := 0;
                product0Window[PR1_LENGTH]               := 17; // product name length
                product0Window[PR1_XPOS]                 := 102;
                product0Window[PR1_YPOS]                 := 107;
                str_Copy(str_Ptr(&product0Window[PR1_PRODUCT_NAME]), "Product 0");
                str_Copy(str_Ptr(&product0Window[PR1_PRODUCT_NAME_T]), NULL);
                product0Window[PR2_LENGTH]               := 6;  // purchase price length
                product0Window[PR2_XPOS]                 := 262;
                product0Window[PR2_YPOS]                 := 107;
                product0Window[PR2_PURCHASE_PRICE_MSB]   := 0;
                product0Window[PR2_PURCHASE_PRICE_LSB]   := 32000;
                product0Window[PR2_PURCHASE_PRICE_MSB_T] := 0;
                product0Window[PR2_PURCHASE_PRICE_LSB_T] := 0;
                product0Window[PR3_LENGTH]               := 6; // selling price length
                product0Window[PR3_XPOS]                 := 362;
                product0Window[PR3_YPOS]                 := 107;
                product0Window[PR3_SELLING_PRICE_MSB]    := 0;
                product0Window[PR3_SELLING_PRICE_LSB]    := 32000;
                product0Window[PR3_SELLING_PRICE_MSB_T]  := 0;
                product0Window[PR3_SELLING_PRICE_LSB_T]  := 0;
                params[_12] := product0Window;      // output
                break;
        endswitch
    endfunc
    master.4dg
    Code:
    #platform "uLCD-43DT"
    #STACK 4096
    #MODE RUNFLASH
    #inherit  "shared.inc"
    
    var product0Window[PRODUCT_STRUCT_LENGTH];  // 39
    
    var params3[_paramsLimit], args3[3] ;
    func callBank3(var funcId)
        args3[0] :=  2;
        args3[1] := params3;
        args3[2] := funcId;
        flash_Exec(FLASHBANK_3, args3);
    endfunc
    
    func loadSettingsInit()
        var *pSrc, *pDest;
        var i, j;
        callBank3(_loadSettingsInit);
        //for(i:=0; i<=15; i++)
            i:=0;
            pSrc := str_Ptr(params3[_12] + (i * PRODUCT_STRUCT_LENGTH));
            pDest := str_Ptr(product0Window + (i * PRODUCT_STRUCT_LENGTH));
            for(j:=0; j<PRODUCT_STRUCT_LENGTH; j++)
                str_PutWord(pDest, str_GetWord(pSrc));
                pSrc += 2;
                pDest += 2;
            next
        //next
    endfunc
    
    func main()
        var *p;
    
        gfx_ScreenMode(LANDSCAPE) ; // change manually if orientation change
    
        // read settings from bank3
        loadSettingsInit();
    
        // copy value from lsb to lsb temporary
        product0Window[PR2_PURCHASE_PRICE_LSB_T] := product0Window[PR2_PURCHASE_PRICE_LSB];  // print this value
    
        // print lsb(original), result expected = 32000
        gfx_MoveTo(0,0);
        p := str_Ptr(&product0Window[PR2_PURCHASE_PRICE_LSB]); str_Printf(&p, "original : %lu");
    
        // print lsb (temporary), result expected = 32000, error in here... I get 393216, not 3200?
        gfx_MoveTo(0,20);
        p := str_Ptr(&product0Window[PR2_PURCHASE_PRICE_LSB_T]); str_Printf(&p, "temporary: %lu");
    
    
        repeat                      // maybe replace
        forever                     // this as well
    
    endfunc
    Attached Files
    Last edited by rwin; 17th July 2015, 08:27 PM.

  • #2
    In the bank you just put those values in a local variable, then you put the address of the local variable into params[_12]. When the program returns the contents of the local variable will be 'undefined'.

    The way you have written your code, this would be more appropriate
    params[PR0_PRODUCT_ID] := 0;
    params[PR1_LENGTH] := 17; // product name length
    etc.
    Mark

    Comment


    • #3
      Hello Mark,

      I tried your instructions, appearing error 8 in screen, what does it mean? What is the maximum character length of parameters in the slave, is limited?

      Comment


      • #4
        Hmm, that could typically only happen if there wasn't enough memory to call the flash bank, which you would think was unlikely.

        Can you post the code that has this error?
        Mark

        Comment


        • #5
          Hello Mark,

          I send a file to your email because the program is too large for the pasted here. Thank you.

          Comment

          Working...
          X