sumikchakka / jallib

Automatically exported from code.google.com/p/jallib
0 stars 0 forks source link

Libraries for second serial port do not work for all PICs with 2 USARTs #181

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The libraries serial_hardware2 and serial_hw2_int_cts assume that 
interrupts are handle by PIE3 and PIR3, while some PICs (e.g. 16F1947) do it 
with PIE4 and PIR4.
The library usart2_common assumes that device files have SPBGR2 declared (as 
word), which is not always the case (e.g. 16f1947).

Original issue reported on code.google.com by robhamerling on 14 Mar 2012 at 4:27

GoogleCodeExporter commented 9 years ago

With respect to the SPBRG registers:

As usual with MC the mplab .dev files have a lot of variations in the naming of 
SPBRG registers. The current normalisation of these names in Jallib device 
files should be extended. Regardless if the USART provides an 8-bits or a 
16-bits baudrate divisor the device files should declare SPBRGL (byte) for the 
first or only USART and SPBRGL2 (byte) for the second USART.  
Note: With a 16-bits divisor the device files already have SPBRGH (and 
SPBRGH2).   

After this additional normalization the serial hardware libraries can safely 
use the 
byte values SPBRGL and SPBRGL2 in all cases (and SPBRGH and SPBRGH2 with 
16-bits divisor).  

Original comment by robhamerling on 15 Mar 2012 at 9:08

GoogleCodeExporter commented 9 years ago
With respect to the different registers for TX and RX interrupt bits of the 2nd 
USART:

Library serial_hardware2 only disables these interrupts, so on only one place a 
simple 'if defined(...)' will be sufficient to select one or the other set of 
interrupt registers.  

Library serial_hw2_int_cts manipulates the interrupt bits on several places, so 
in that case set of aliases seems more appropriate (readability, 
maintainability), like: 

if (defined(PIR3_RCIF2) == TRUE) then               
   alias serial2_RCIE2 is PIE3_RCIE2
   alias serial2_RCIF2 is PIR3_RCIF2
   alias serial2_TXIE2 is PIE3_TXIE2
   alias serial2_TXIF2 is PIR3_TXIF2
elsif (defined(PIR4_TXIF2) == TRUE) then              
   alias serial2_RCIE2 is PIE4_RCIE2
   alias serial2_RCIF2 is PIR4_RCIF2
   alias serial2_TXIE2 is PIE4_TXIE2
   alias serial2_TXIF2 is PIR4_TXIF2
else
   -error "...."
end if

Using the aliases in the procedures/functions will automatically select the 
proper registers.

Original comment by robhamerling on 15 Mar 2012 at 2:20

GoogleCodeExporter commented 9 years ago
The proposed changes have been implemented (with minor differences)in the 
device files and the following libraries:
 - serial_hardware 
 - serial_hardware2
 - serial_hw_int_cts
 - serial_hw2_int_cts
Tests were successful, so issue closed.  

Note: Libraries for the 3rd or 4th USART may require additional changes.

Original comment by robhamerling on 19 Mar 2012 at 8:10