Menu

DMA usage on HSerReceive command

ikonsgr74
2024-11-11
2024-11-11
  • ikonsgr74

    ikonsgr74 - 2024-11-11

    From asm files, i saw that the "core" of the hserReceive command execution is an rcall to a HSERRECEIVE322 routine (PIC used is 18F47Q10):

    ;Source: usart.h (1946)
    FN_HSERRECEIVE2
    ;Comport = 2
        movlw   2
        movwf   COMPORT,ACCESS
    ;HSerReceive( SerData )
        rcall   HSERRECEIVE322
    ;HSerReceive2 = SerData
        movff   SERDATA,HSERRECEIVE2
        return
    
    ;Overloaded signature: BYTE:, Source: usart.h (1960)
    HSERRECEIVE322
    HSERRECEIVE1HANDLER
    ;Wait Until USART2HasData
    SysWaitLoop4
        banksel PIR3
        btfss   PIR3,RC2IF,BANKED
        bra SysWaitLoop4
    ;if  RC2STA_OERR = 1 Then
        btfss   RC2STA,OERR,BANKED
        bra ENDIF327
    ;EUSART5 error - restart
    ;RC2STA_CREN = 0
        bcf RC2STA,CREN,BANKED
    ;RC2STA_CREN = 1
        bsf RC2STA,CREN,BANKED
    ;End IF
    ENDIF327
    ;Get a byte from register, if interrupt flag is valid
    ;If USART2HasData Then
        btfsc   PIR3,RC2IF,BANKED
    ;SerData = RC2REG
        movff   RC2REG,SERDATA
    ;End if
    ;Get a byte from register, if interrupt flag is valid
    ;If USART2HasData Then
        btfsc   PIR3,RC2IF,BANKED
    ;SerData = RCREG2
        movff   RCREG2,SERDATA
    ;End if
    ;Clear error to ensure next in byte can happen
    ;If OERR2 Then
        btfss   RC2STA,OERR,BANKED
        bra ENDIF330
    ;Set CREN2 Off
        bcf RC2STA,CREN,BANKED
    ;Set CREN2 On
        bsf RC2STA,CREN,BANKED
    ;End If
    ENDIF330
        banksel 0
        return
    

    So, i was wondering, since now we have quite a few PIC 18F chips with DMA support, would it be possible to implement DMA usage (using for example a 18F47Q43 instead of Q10) on cow basic's HSerReceive command?
    And does the usage of DMA would have a big impact in execution time of the command?

     

    Last edit: ikonsgr74 2024-11-11
  • Anobium

    Anobium - 2024-11-11

    There are DMA demos that show how this works. The performance is stunning.

    Also, do a search of this forum for the DMA posts relating to the DMA work I dis.

    Let me know if you have issues finding anything.

     
  • ikonsgr74

    ikonsgr74 - 2024-11-11

    I'm aware of these demos, we have already discussed the DMA subject in more general, a couple of years ago, but what i was hoping for, is for an update of the HSERRECEIVE cowbasic command itself, without needing to alter the existing code of our cowbasic programs.
    I was thinking something like an "alternative" code path for the HSERRECEIVE command: Whenever a PIC MCU with DMA support is used in cowbasic #CHIP directive, every time an HSERRECEIVE command is shown in source code, the compiler would choose an alternative code that will use DMA ;-)

     
  • Anobium

    Anobium - 2024-11-11

    You can write a DMA receive routine but I am not sure how you would manage. The serial interrupt buffer ring is my go to method to handle incoming serial.

    I guess The DMA serial in routine could put the coming data into a buffer ring ( an array ) and then use the DMA counters to process the buffer ring.

    NOTE: the DMA would ONLY WORK on a specific message size. You would need to ensure the message size is always the same size.

     
  • ikonsgr74

    ikonsgr74 - 2024-11-11

    Exactly, i'm using the same method too, an input buffer ring and an interrupt:
    On Interrupt UsartRX2Ready Call readUSART
    The readusart routine deals with the input buffer ring:

        Sub readUSART
           buffer(next_in) = HSerReceive2
           next_in = ( next_in + 1 )
           IF (NEXT_IN>BUFFER_SIZE) Then
           NEXT_IN=1
           END IF
        End Sub
    

    But, the "core" of this routine, is the assignment in the input buffer, of the byte received from HwSerial port, using cow basic's HSerReceive command! So, what i proposed was to "encapsulate" any DMA usage inside the HSerReceive command code itself! Do you think this is feasible, and will it help to speed up things?
    btw, i suppose the message size in this case will always be 1, as we only receive one byte at a time...

     

    Last edit: ikonsgr74 2024-11-11
  • Anobium

    Anobium - 2024-11-11

    OK. That approach of the buffer makes sense.

    Any solution would be specific to each implementation. Incrementing the buffer pointer and managing the state may take more code than the call to HSerRecieve.

    But, it should be possible. Give it a try.

     
  • ikonsgr74

    ikonsgr74 - 2024-11-11

    So if i get it right, you say that even if HserReceive command supports DMA (and is faster than the existed non DMA command code), practically you wil not get any great speed advantage, because the code for incrementing the buffer pointer and managing the state ,takes more time?

     
  • Anobium

    Anobium - 2024-11-11

    I think a reference AppNote would help us understand. Have a search to see if you can find some reference.

    I am not clear on how a DMA read operation would work. Fixed packet size, error handling, pointer management. A reference implementation from Microchip would really help.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.