CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Is source for I2C functions provided?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
allenhuffman



Joined: 17 Jun 2019
Posts: 552
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

Is source for I2C functions provided?
PostPosted: Thu Aug 22, 2019 1:46 pm     Reply with quote

Is the source code for any of the built in library functions, specifically I2C, available?
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
newguy



Joined: 24 Jun 2004
Posts: 1907

View user's profile Send private message

PostPosted: Thu Aug 22, 2019 2:02 pm     Reply with quote

Near the top of each processor's include file, for example "18F452.h" will be a #nolist. Comment that out and recompile. I believe that whatever built-in functions you use will then be visible in the list file (disassembly).

Also note that the compiler can be set to use register names/variable names in the list file. Project->Output Files->List File. Relevant boxes are SFR Names, Symbols, Interpret.
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Aug 22, 2019 2:04 pm     Reply with quote

Yes, all compiled code can be seen in the listing, though you may need to delete the '#nolist' option for some drivers.

also

the listing is NOT in 'program memory' order
allenhuffman



Joined: 17 Jun 2019
Posts: 552
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Thu Aug 22, 2019 2:49 pm     Reply with quote

Thanks ... I'm not sure I am looking in the proper place. I commented out #nolist, then it wanted me to save it with the project. I did that, and then even put a #error line in to make sure it was reference MY copy (it is -- I changed the #include <file> to "file" like normal C, which might not have been necessary).

I don't think I saw the generated asm from this. I do see a bunch (half a dozen or more) blank "....." lines with the _bif prototype of i2c_read() but no related assembly. I searched through the 82,000+ lines of the list file for the "i2c_read" references but didn't find any asm that wasn't for the calls in our code.
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Aug 22, 2019 3:09 pm     Reply with quote

Here's a snippet from my modified DS3231 RTC driver..It's similar to the DS1307 driver and the 1st one that know has I2C functions in it...


from the .lst file...

Code:

.................... rtcsec = bcd2bin(i2c_read() & 0x7f); 
03656:  MOVLW  01
03658:  MOVWF  00
0365A:  CALL   0148
0365E:  MOVF   01,W
03660:  ANDLW  7F
03662:  MOVWF  xBD
03664:  MOVWF  xC2
03666:  CALL   0196
0366A:  MOVFF  01,10


I know the code works...
allenhuffman



Joined: 17 Jun 2019
Posts: 552
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Thu Aug 22, 2019 3:44 pm     Reply with quote

Ah, I see. I'm seeing the code in-lined, rather than finding the i2c_read() function somewhere else?
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
jeremiah



Joined: 20 Jul 2010
Posts: 1346

View user's profile Send private message

PostPosted: Thu Aug 22, 2019 4:53 pm     Reply with quote

In some cases yes. For situations that they use non inlined functions, at least for me in the PCD compiler, it shows the functions under their respective "#use" directive in the disassembly.
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Aug 22, 2019 5:04 pm     Reply with quote

Here's what the code at CALL 0148 looks like.
Obviously no comments, though if you look at the PIC instruction set and SFR list, you can decode what is happening.
Code:

00148:  MOVLW  08
0014A:  MOVWF  xC2
0014C:  MOVFF  00,C3
00150:  BSF    F94.4
00152:  BRA    0154
00154:  NOP   
00156:  BSF    F94.3
00158:  BTFSS  F82.3
0015A:  BRA    0158
0015C:  BTFSC  F82.4
0015E:  BSF    FD8.0
00160:  BTFSS  F82.4
00162:  BCF    FD8.0
00164:  RLCF   01,F
00166:  BRA    0168
00168:  BCF    F94.3
0016A:  BCF    F8B.3
0016C:  DECFSZ xC2,F
0016E:  BRA    0150
00170:  BSF    F94.4
00172:  BRA    0174
00174:  NOP   
00176:  BCF    F8B.4
00178:  MOVF   xC3,W
0017A:  BTFSS  FD8.2
0017C:  BCF    F94.4
0017E:  NOP   
00180:  BSF    F94.3
00182:  BTFSS  F82.3
00184:  BRA    0182
00186:  BRA    0188
00188:  BCF    F8B.3
0018A:  BCF    F94.3
0018C:  BRA    018E
0018E:  NOP   
00190:  BCF    F8B.4
00192:  BCF    F94.4
00194:  RETLW  00


Hopefully I'm not breaking the 'rules'...this code is available for all to see. If I have please let me know.

The other call (196 ?) goes to the BINBCD routines.

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19505

View user's profile Send private message

PostPosted: Fri Aug 23, 2019 1:22 am     Reply with quote

and (of course) if you switch the compiler to 'symbolic' mode, it'll tell
you the register names etc..
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 23, 2019 2:34 am     Reply with quote

allenhuffman wrote:

I don't think I saw the generated asm from this. I do see a bunch (half a
dozen or more) blank "....." lines with the _bif prototype of i2c_read() but
no related assembly.

In the .LST file, the i2c code will be placed underneath the #use i2c()
statement. Example:
Code:
.................... #use i2c(master, i2c1, slow)
000AE:  BCF    SSP1CON1.SSPOV
000B0:  BSF    SSP1CON2.RCEN
000B2:  BTFSC  SSP1CON2.RCEN
000B4:  BRA    00B2
000B6:  BTFSC  00.0
000B8:  BCF    SSP1CON2.ACKDT
000BA:  BTFSS  00.0
000BC:  BSF    SSP1CON2.ACKDT
000BE:  BSF    SSP1CON2.ACKEN
000C0:  BTFSC  SSP1CON2.ACKEN
000C2:  BRA    00C0
000C4:  MOVFF  SSP1BUF,01
000C8:  RETURN 0

The above code is for i2c_read() for the 18F46K22.


allenhuffman wrote:

I searched through the 82,000+ lines of the list file for the "i2c_read"
references but didn't find any asm that wasn't for the calls in our code.

You won't see labels for the CCS Library code in the .LST file or
in the View / Assembly Listing. You will see them in View / Program
Memory. (This is in MPLAB vs. 8.92) Here is the beginning of the code,
to show how the label is displayed:
Code:

Line  Address  Opcode  Label        Disassembly
88    00AE     9CC6    @I2C_READU_  BCF SSP1CON1, 0x06, ACCESS
89    00B0     86C5                 BCF SSP1CON2, 0x03, ACCESS
90    00B2     B6C5                 BTFSC SSP1CON2, 0x3, ACCESS
91    00B4     D7FE                 BRA 0xb2
Ttelmah



Joined: 11 Mar 2010
Posts: 19505

View user's profile Send private message

PostPosted: Fri Aug 23, 2019 3:34 am     Reply with quote

Just a slight 'eppend' to this.
The labels are present in the .sym file. So (for example), on a project of mine:

In the sym:

00110A @I2C_WRITEU_1

and (compiled with SFR names selected), the .lst gives:

Code:

.................... #USE I2C(I2C1, FAST=400000, STREAM=EEPROM) //EEPROM uses ALTI2C1 connections
*
0110A:  MOV     #FFFF,W0
0110C:  BTSS.B  I2C1STAT.S
0110E:  BRA     111A
01110:  BTSC.B  I2C1STAT.TRSTAT
01112:  BRA     1110
01114:  MOV     W1,I2C1TRN
01116:  BTSC.B  I2C1STAT.TRSTAT
01118:  BRA     1116
0111A:  MOV     #0,W0
0111C:  BTSC.B  I2C1STAT.ACKSTAT
0111E:  INC     W0,W0
01120:  RETURN 


So 'where' the routine is is in the .sym file, and the code for this is in
the .lst file.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group