Today 10:22
Forum: The Lounge
Starter: fanie
Views: 3727
Replies: 41
Today 08:50
Forum: Proton Plus Compiler v3
Starter: SELCUK
Views: 0
Replies: 0
Yesterday 16:35
Forum: The Lounge
Starter: dolci
Views: 2653
Replies: 15
+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Prolific Poster RGV250's Avatar
    Join Date
    Aug 2005
    Posts
    2,307
    Thumbs Up
    Received: 29
    Given: 7
    Total Downloaded
    331.30 MB

    0 Not allowed!

    Default Is it possible to get a return parameter from PreProcessor

    I probably don't have a clue what I am talking about so bear with me.
    In subroutines it is possible to get a returned variable (Receipt Variable) and this was also made possible in Library manager.
    I believe I had to create an array with a length of 1 to get it but it worked, I cannot figure out if it is possible in the PreProcessor so if there are any examples out there I would appreciate it. Basically I only require a bit variable.
    This is what I have but cannot figure out what to do about the return variable which is CAN_TX_OK or if what I have done will work?.

    Bob

    Code:
    '-------------------------------------------------------------
    'CAN Send Message
    '-------------------------------------------------------------
    Dim CAN_TX_DATA_LENGTH As Byte
    Dim CAN_TX_FLAGS As Byte
    Dim TX_PRIORITY_TEMP As Byte    
    Dim CANCON_TEMP As Byte          
    Dim TX_LOOP_COUNTER As Byte 
    Dim CAN_TX_OK As Byte 
    
    '!!!!!!!!!!!!!!  Need to look at code for return value
    
    $define CANSendMessage(pParam1, pParam2, pParam3, RETURNVALUE)'
        CAN_TX_DATA = pParam1'
        CAN_TX_DATA_LENGTH = pParam2'
        CAN_TX_FLAGS = pParam3'
        CAN_TX_OK = RETURNVALUE'
        GoSub _CAN_SEND_DATA_CODE
    
    _CAN_SEND_DATA_CODE:
    'Determine which TX buffer is available to use, always use the first available one.
    If TXB0CON.3 = 0 Then GoTo TX_BUFFER_0
    If TXB1CON.3 = 0 Then GoTo TX_BUFFER_1
    If TXB2CON.3 = 0 Then GoTo TX_BUFFER_2
    CAN_TX_OK = 0 'Return value of 0 if ALL TX buffers are full
    Return        'Return if all the TX buffers are full
    TX_BUFFER_0:
    FSR1H = $0F           '!!!Make sure this location does not change
    FSR1L = $46           ' in future versions of the CAN module
            
    For TX_LOOP_COUNTER = 0 To CAN_TX_DATA_LENGTH -1               
    POSTINC1 = POSTINC0   'Move Data into transmit buffer 0 
    
    Next TX_LOOP_COUNTER                       
    
    'Set data length and RTR bit if required       
    TXB0DLC = CAN_TX_DATA_LENGTH
    Btfsc CAN_TX_FLAGS.6
    Bsf TXB0DLC.6
    
    'Set TX priority bits        
    TX_PRIORITY_TEMP = CAN_TX_FLAGS & CAN_TX_PRIORITY_BITS
    TXB0CON = TX_PRIORITY_TEMP        
    
    'Set TX buffer to use
    CANCON_TEMP = CANCON    'Store CANCON mode
    CANCON = CANCON | %000001000  'Use transmit buffer 0
    
    TXERRCNT = 0            'Clear TX error counter
    TXB0CON = TXB0CON | %00001000  'Start transmission.
    
    CANCON = CANCON_TEMP    'Set CANCON back To previous state.
    CAN_TX_OK = 1 'Return value for TX successful
    Return
    
    TX_BUFFER_1:
    FSR1H = $0F           '!!!Make sure this location does not change
    FSR1L = $36           ' in future versions of the CAN module
            
    For TX_LOOP_COUNTER = 0 To CAN_TX_DATA_LENGTH -1               
    POSTINC1 = POSTINC0   'Move Data into transmit buffer 1 
    
    Next TX_LOOP_COUNTER                       
    
    'Set data length and RTR bit if required      
    TXB1DLC = CAN_TX_DATA_LENGTH
    Btfsc CAN_TX_FLAGS.6
    Bsf TXB1DLC.6 
    
    'Set TX priority bits        
    TX_PRIORITY_TEMP = CAN_TX_FLAGS & CAN_TX_PRIORITY_BITS
    TXB1CON = TX_PRIORITY_TEMP                 
    
    'Set TX buffer to use
    CANCON_TEMP = CANCON    'Store CANCON mode
    CANCON = CANCON | %000000110  'Use transmit buffer 1
    
    TXERRCNT = 0            'Clear TX error counter.
    TXB1CON = TXB1CON | %00001000  'Start transmission.
    CANCON = CANCON_TEMP    'Set CANCON back To previous state.
    CAN_TX_OK = 1 'Return value for TX successful        
    Return
    
    TX_BUFFER_2:
    FSR1H = $0F           '!!!Make sure this location does not change
    FSR1L = $26           ' in future versions of the CAN module
    
            
    For TX_LOOP_COUNTER = 0 To CAN_TX_DATA_LENGTH -1               
    POSTINC1 = POSTINC0   'Move data into transmit buffer 2 
    
    Next TX_LOOP_COUNTER                       
    
    'Set data length and RTR bit if required        
    TXB2DLC = CAN_TX_DATA_LENGTH
    Btfsc CAN_TX_FLAGS.6
    Bsf TXB2DLC.6 
    
    'Set TX priority bits        
    TX_PRIORITY_TEMP = CAN_TX_FLAGS & CAN_TX_PRIORITY_BITS
    TXB2CON = TX_PRIORITY_TEMP                 
    
    'Set TX buffer to use
    CANCON_TEMP = CANCON    'Store CANCON mode
    CANCON = CANCON | %000000100  'Use transmit buffer 2
    
    TXERRCNT = 0            'Clear TX error counter
    TXB2CON = TXB2CON | %00001000  'Start transmission.         
    CANCON = CANCON_TEMP    'Set CANCON back to previous state.
    CAN_TX_OK = 1 'Return value for TX successful        
    Return
    '-------------------------------------------------------------
    'End of CAN Send Message
    '-------------------------------------------------------------

  2. #2
    Senior Member SimonJA's Avatar
    Join Date
    Mar 2006
    Posts
    783
    Thumbs Up
    Received: 19
    Given: 14
    Total Downloaded
    463.32 MB

    0 Not allowed!

    Default Re: Is it possible to get a return parameter from PreProcessor

    I'm very possibly missing something here but can't you simply set your CAN_TX_OK to 0 before entering the subroutine and then check it after the subroutine? If it's 1 then it was successful.

    .... Or Proton24 does have return variables.

  3. #3
    Senior Member AlbertoFS's Avatar
    Join Date
    Apr 2005
    Posts
    603
    Thumbs Up
    Received: 87
    Given: 2
    Total Downloaded
    2.48 GB

    1 Not allowed!

    Default Re: Is it possible to get a return parameter from PreProcessor

    Hi Bob,
    I have lost a bit of practice in Macros. I suppose that the routines are going to be used several times, You would have to make a mix of Preprocessor and Macro asm.
    There are several solutions but the simplest one is to pass the return variable through WREG. I have not checked the solution, but the compiled asm code seems correct. It is a solution that I used sometimes. This way of using the Macro allows not to write the subroutine in the ROM when this macro is not used.
    Code:
        $define CANSendMessage(pParam1, pParam2, pParam3, pReturn) '
        CAN_TX_DATA = pParam1                                      '
        CAN_TX_DATA_LENGTH = pParam2                               '
        CAN_TX_FLAGS = pParam3                                     '
        _mCANSendMessage                                           '
        pReturn = WREG
    
    _mCANSendMessage Macro-
        GoSub _CAN_SEND_DATA_CODE_Sub 
    Endm
    
    #ifMacro- _mCANSendMessage
    _CAN_SEND_DATA_CODE_Sub:
        'Determine which TX buffer is available to use, always use the first available one.
        If TXB0CON.3 = 0 Then GoTo TX_BUFFER_0
        If TXB1CON.3 = 0 Then GoTo TX_BUFFER_1
        If TXB2CON.3 = 0 Then GoTo TX_BUFFER_2
        CAN_TX_OK = 0 'Return value of 0 if ALL TX buffers are full
        Return        'Return if all the TX buffers are full
        TX_BUFFER_0:
        FSR1H = $0F           '!!!Make sure this location does not change
        FSR1L = $46           ' in future versions of the CAN module
                
        For TX_LOOP_COUNTER = 0 To CAN_TX_DATA_LENGTH -1               
        POSTINC1 = POSTINC0   'Move Data into transmit buffer 0 
        
        Next TX_LOOP_COUNTER                       
        
        'Set data length and RTR bit if required       
        TXB0DLC = CAN_TX_DATA_LENGTH
        Btfsc CAN_TX_FLAGS.6
        Bsf TXB0DLC.6
        
        'Set TX priority bits        
        TX_PRIORITY_TEMP = CAN_TX_FLAGS & CAN_TX_PRIORITY_BITS
        TXB0CON = TX_PRIORITY_TEMP        
        
        'Set TX buffer to use
        CANCON_TEMP = CANCON    'Store CANCON mode
        CANCON = CANCON | 0001000  'Use transmit buffer 0
        
        TXERRCNT = 0            'Clear TX error counter
        TXB0CON = TXB0CON | 001000  'Start transmission.
        
        CANCON = CANCON_TEMP    'Set CANCON back To previous state.
        WREG = 1 'Return value for TX successful
        Return
    #endIfMacro-
    In other way. (no asm macro)
    Code:
        $define CANSendMessage(pParam1, pParam2, pParam3, pReturn) '
        CAN_TX_DATA = pParam1                                      '
        CAN_TX_DATA_LENGTH = pParam2                               '
        CAN_TX_FLAGS = pParam3                                     '
        GoSub _CAN_SEND_DATA_CODE_Sub                            '
        pReturn = WREG
    
    _CAN_SEND_DATA_CODE_Sub:
        'Determine which TX buffer is available to use, always use the first available one.
        If TXB0CON.3 = 0 Then GoTo TX_BUFFER_0
        If TXB1CON.3 = 0 Then GoTo TX_BUFFER_1
        If TXB2CON.3 = 0 Then GoTo TX_BUFFER_2
        CAN_TX_OK = 0 'Return value of 0 if ALL TX buffers are full
        Return        'Return if all the TX buffers are full
        TX_BUFFER_0:
        FSR1H = $0F           '!!!Make sure this location does not change
        FSR1L = $46           ' in future versions of the CAN module
                
        For TX_LOOP_COUNTER = 0 To CAN_TX_DATA_LENGTH -1               
        POSTINC1 = POSTINC0   'Move Data into transmit buffer 0 
        
        Next TX_LOOP_COUNTER                       
        
        'Set data length and RTR bit if required       
        TXB0DLC = CAN_TX_DATA_LENGTH
        Btfsc CAN_TX_FLAGS.6
        Bsf TXB0DLC.6
        
        'Set TX priority bits        
        TX_PRIORITY_TEMP = CAN_TX_FLAGS & CAN_TX_PRIORITY_BITS
        TXB0CON = TX_PRIORITY_TEMP        
        
        'Set TX buffer to use
        CANCON_TEMP = CANCON    'Store CANCON mode
        CANCON = CANCON | 0001000  'Use transmit buffer 0
        
        TXERRCNT = 0            'Clear TX error counter
        TXB0CON = TXB0CON | 001000  'Start transmission.
        
        CANCON = CANCON_TEMP    'Set CANCON back To previous state.
        WREG = 1 'Return value for TX successful
        Return
    How to use:
    CANSendMessage(3, 4, 5, CAN_TX_OK)

    Using WREG is always a good trick to pass a variable because it does not use any new variable and is fast.
    Last edited by AlbertoFS; 17th January 2018 at 08:59.
    [U]73's de Alberto ea3agv[/U]

  4. #4
    Prolific Poster RGV250's Avatar
    Join Date
    Aug 2005
    Posts
    2,307
    Thumbs Up
    Received: 29
    Given: 7
    Total Downloaded
    331.30 MB

    0 Not allowed!

    Default Re: Is it possible to get a return parameter from PreProcessor

    Hi Simon,
    I thought of that but the routine is used repeatedly and the calling routine may have a different variable. I keep looking at Proton24 but the CAN side is difficult/impossible, I do not think there are any working examples from the extensive searches I have made. It would be nice as I think there are devices with 2 CAN modules which could be useful.

    Hi Alberto,
    I think that is exactly what I need, I will have to read up on Wreg. I noticed I had made an error with "CAN_TX_OK = RETURNVALUE" and it should have been the other way round as it is the return var.

    Regards using Macro's I am not sure if I really need them, I am trying to re-write my CAN library so it does not require the Library manager as the newer versions of the compiler do not support it. Pretty much all of the routines will be used so probably no benefit.

    Regards,
    Bob

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Never to Return
    By crankshaft in forum Proton Plus Compiler v3
    Replies: 6
    Last Post: 19th December 2011, 04:29
  2. Macro problem parameter
    By auban in forum Proton Plus Compiler v3
    Replies: 10
    Last Post: 6th October 2008, 21:40
  3. [SOLVED !] HPWM bug - duty cycle parameter?
    By rocknrollal in forum Mecanique - IDE
    Replies: 9
    Last Post: 26th August 2006, 22:13
  4. GOSUB with return parameter only.
    By Mohammed Tayem in forum Proton Plus Compiler v3
    Replies: 0
    Last Post: 4th December 2004, 19:27

Members who have read this thread since 20th May 2018, 04:29 : 0

Actions :  (Set Date)  (Clear Date)

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts