afonteles
Posts: 6
Joined: Sun Jan 10, 2021 4:35 am

Not able to set the virtual offset repeatedly (double buffer)

Tue Jan 12, 2021 3:53 am

Hello, everyone.

I'm trying to implement double buffer by changing the virtual Y offset of a frame buffer, but I'm having some problems. Everything seems to be working correctly, however, I can only change the offset once. Any other message I send to the VC through messagebox's channel 8 proves ineffective. I'm using the RPI4 for what it's worth.

Could that be related with caching? I'm a bit lost to be frank. Here is the relevant part o my code.

Code: Select all

/* frame buffer struct */
.align 16
offsetStruct:
  .int offsetStructEnd - offsetStruct @ Message buffer size 
  .int 0x00000000                     @ Buffer request/response code
  /* Sequence of tags */
  /* Tag: Set virtual offset */
  .int 0x00048009                     @ Tag ID: Set virtual offset
offsetBufferSize:      
  .int 0x00000008                     @ Tag buffer size in bytes
offsetReqResp:
  .int 0x00000008                     @ Tag Request/response code
offsetX:      
  .int 0                              @ X offset
offSetY:      
  .int 0                              @ Y offset
  /* End of tags */     
  .int 0x0                            @ End of tag (0x0)
offsetStructEnd:

Code: Select all

.globl frameBuffer_swapPage
frameBuffer_swapPage:
    PUSH {lr}

    page .req r0
    value .req r1
    addr .req r3
    
    /* Adjust offset according to page */
    TEQ page, #1                        /* Check if page == 1 or something else */
    LDREQ value, =HEIGHT               /* If page == 1, set HEIGHT as offset */
    MOVNE value, #0                    /* Else, remove any offset */

    /* Set the offset in the message */
    LDR addr, =offSetY
    STR value, [addr]

    /* Reset buffer size */
    LDR addr, =offsetBufferSize
    MOV value, #8
    STR value, [addr]

    /* Reset Request/Response */
    LDR addr, =offsetReqResp
    MOV value, #8
    STR value, [addr]

    .unreq page
    .unreq value
    .unreq addr

    /* Write to the mail box */
    LDR r0, =offsetStruct               /* Move the address of the framebuffer to r0 */
    ORR r0, #0xC0000000                 /* Convert ARM address to VC address */
    MOV r1, #8                          /* Channel 8 is the VC's */
    BL mailbox_write                    /* Write to the mailbox */

    /* Read from the mail box */
    MOV r0, #8                          /* Read from channel 8 */
    BL mailbox_read                     /* Read the response (ACK) from the VideoCore */

    POP {pc}
Any help is greatly appreciated.

Return to “Bare metal, Assembly language”