From 6f873b0d45ce00c1ba0d0e3a7d30bf8647fa5928 Mon Sep 17 00:00:00 2001 From: ian Date: Wed, 16 Nov 2005 23:18:55 +0000 Subject: [PATCH] i2clib compiles --- detpic/i2clib.asm | 54 +++++++++++++++++++------------------- detpic/i2clib.inc | 36 ++++++++++++------------- detpic/morse-auto.messages | 4 +-- detpic/panic.fin | 1 + detpic/panic.inc | 6 +++++ 5 files changed, 54 insertions(+), 47 deletions(-) create mode 100644 detpic/panic.fin diff --git a/detpic/i2clib.asm b/detpic/i2clib.asm index 00196b9..49e8b37 100644 --- a/detpic/i2clib.asm +++ b/detpic/i2clib.asm @@ -6,6 +6,7 @@ include /usr/share/gputils/header/p18f458.inc radix dec include ../iwjpictest/insn-aliases.inc + include panic.inc ;====================================================================== ; NOTATION @@ -78,7 +79,7 @@ slave2addr ; computes slave address in form suitable for use in i2c controller ; actual i2c slave address is (slave number) + 0b0001000 ; W slave number i2c address * 2 - add_lw 0b0001000 + add_lw b'0001000' rlc_w return @@ -139,7 +140,7 @@ i2cm_interrupt bra m_event_done_reading m_event_bad - panic morse_SM ; master, interrupt, controller in bad state + panic morse_SM ;======================================== ; MASTER - STARTING, ADDRESSING, STOPPING @@ -156,14 +157,13 @@ m_start and_lw 31 bra_nz m_improper_slave bs_f i2c_st, st_starting - bs_f i2c_st, st_working bs_f SSPCON2, SEN return ;---------- m_event_done_starting mov_fw i2c_slave - bsr slave2addr + rcall slave2addr bt_f_if1 i2c_st, st_reading bs_w 0 ; address bottom bit means read @@ -219,7 +219,7 @@ i2cm_write_start bra m_improper_write_start bs_f i2c_st, st_writing - bra m_do_start + bra m_start ;---------- m_event_done_writing @@ -267,7 +267,7 @@ i2cm_read_start bra m_improper_read_start bs_f i2c_st, st_reading - bra m_do_start + bra m_start ;---------- m_event_done_addressing_read @@ -344,7 +344,7 @@ m_improper_read_done ;---------- i2cs_init ; W slave number undefined - rcall slave2addr2 + rcall slave2addr mov_wf SSPADD clr_f i2c_st mov_lw 0x16 ; !SSPEN, CKP(release), I2C 7-bit slave no-SP-int @@ -353,7 +353,7 @@ i2cs_init mov_wf SSPCON2 mov_lw 0x8 ; SMP(noslew), !CKE(!smbus) mov_wf SSPSTAT -ms_init_enable +init_enable ; Actually engages the I2C controller, which must already have ; been set up (all but SSPEN): ; SSPADD,SSPCON1,SSPCON2 configured correctly unchanged @@ -388,19 +388,18 @@ ms_init_enable chkvals_start_sspstat macro mov_fw i2c_sspstat -chkval_lastvalue equ 0 endm -chkval macro value, label - xor_lw value ^ chkval_lastvalue - chkval_lastvalue equ value +chkval macro lastval, value, label + xor_lw value ^ lastval bra_z label endm -chkvals_addrrecv macro - chkval 0x8c, s_event_idle_addrrecvread ; A,!P, S,R,!BF - chkval 0x89, s_event_idle_addrrecvwrite ; A,!P, S,W,BF - endm +chkvals_addrrecv macro lastval + chkval lastval, 0x8c, s_event_idle_addrrecvread ; A,!P, S,R,!BF + chkval 0x8c, 0x89, s_event_idle_addrrecvwrite ; A,!P, S,W,BF + endm +chkvals_addrrecv_lastval equ 0x89 ;---------- i2cs_interrupt @@ -419,8 +418,6 @@ i2cs_interrupt mov_ff SSPSTAT, i2c_sspstat mov_ff SSPCON1, i2c_sspcon1 -; Check that nothing obvious is wrong: - bsr check_wcolsspov bt_f_if0 i2c_st, st_reading bra s_event_reading @@ -429,8 +426,8 @@ i2cs_interrupt bra s_event_writing s_event_idle - chkvals_start - chkvals_addrrecv + chkvals_start_sspstat + chkvals_addrrecv 0 s_event_bad panic morse_SS ; slave, interrupt, controller in bad state @@ -441,20 +438,21 @@ s_event_bad s_event_idle_addrrecvread bs_f i2c_st, st_reading call i2csu_read_begin - bra s_events_read_datasend + bra s_events_reading_datasend ;---------- s_event_reading chkvals_start_sspstat - chkval 0xac, s_event_reading_datasent ; D,!P, S,R,!BF + chkval 0, 0xac, s_event_reading_datasent ; D,!P, S,R,!BF ; Whatever is happening, we're done reading now ! clr_f i2c_st call i2csu_read_done - chkval 0xa8, s_event_reading_datanack ; D,!P, S,!R,!BF + chkvals_start_sspstat + chkval 0, 0xa8, s_event_reading_datanack ; D,!P, S,!R,!BF ; Or, maybe it was nack and then we were reselected: - chkvals_addrrecv + chkvals_addrrecv 0xa8 bra s_event_bad @@ -472,7 +470,7 @@ s_event_reading_datanack ;---------- s_event_idle_addrrecvwrite - bs_f SSPCON, 3 ; we'll need the Stop interrupt + bs_f SSPCON1, 3 ; we'll need the Stop interrupt bs_f i2c_st, st_writing ; well, this is all fine so far, so do carry on: @@ -486,7 +484,7 @@ s_write_slurpbyte ;---------- s_event_writing chkvals_start_sspstat - chkval 0xa9, s_event_writing_datarecv ; D,!P, S,W,BF + chkval 0, 0xa9, s_event_writing_datarecv ; D,!P, S,W,BF ; Well, we're done writing now in any case clr_f i2c_st @@ -500,7 +498,7 @@ s_event_writing ; First, the nice cases: chkvals_start_sspstat - chkvals_addrrecv + chkvals_addrrecv 0 ; Then random junk: mov_fw i2c_sspstat @@ -525,5 +523,7 @@ s_event_writing_datarecv ;====================================================================== + include panic.fin include i2clib.inc + end diff --git a/detpic/i2clib.inc b/detpic/i2clib.inc index 9d24229..9e4b5e4 100644 --- a/detpic/i2clib.inc +++ b/detpic/i2clib.inc @@ -58,7 +58,7 @@ ; COMMON ADMINISTRATIVE ROUTINES ;-------------------- -extern i2cm_init + extern i2cm_init ; ; Initialises the i2c system for use by a master PIC. Must be called ; exactly once, which must be before any other i2c?_... function. @@ -69,7 +69,7 @@ extern i2cm_init ; State Not-in-use Idle (as master) ;-------------------- -extern i2cs_init + extern i2cs_init ; ; Initialises the i2c system for use by a slave PIC. Must be called ; exactly once, which must be before any other i2c?_... function. @@ -82,8 +82,8 @@ extern i2cs_init ; W slave number any ;-------------------- -extern i2cm_interrupt -extern i2cs_interrupt + extern i2cm_interrupt + extern i2cs_interrupt ; ; Must be called by the main program's low priority interrupt handler. ; The main program's interrupt handler is responsible for saving W and @@ -132,7 +132,7 @@ extern i2cs_interrupt ; `----------------------------------' ;-------------------- -extern i2cmu_done + extern i2cmu_done ; Called to notify that the previous conversation with the slave has ; been finished as requested. The i2c system is now available and @@ -150,7 +150,7 @@ extern i2cmu_done ; MASTER - WRITES (ie, transmission of data to the slave) ;-------------------- -extern i2cm_write_start + extern i2cm_write_start ; ; Requests that a slave be contacted for writing. When communication ; has been established, i2cmu_write_next_byte will be called. @@ -159,7 +159,7 @@ extern i2cm_write_start ; State Idle Writing-Setup ; W slave number any -extern i2cmu_write_next_byte + extern i2cmu_write_next_byte ; ; Called to notify the main program that we are now ready to transmit ; a byte to the slave that we're currently talking to. This may be @@ -196,7 +196,7 @@ extern i2cmu_write_next_byte ; MASTER - READS (ie, reception of data from the slave) ;-------------------- -extern i2cm_read_start + extern i2cm_read_start ; ; Requests that a slave be contacted for reading. When communication ; has been established and the first byte received, @@ -206,7 +206,7 @@ extern i2cm_read_start ; State Idle Reading-Busy ; W slave number any -extern i2cmu_read_got_byte + extern i2cmu_read_got_byte ; ; Called to notify the main program that a byte has been recieved from ; the slave PIC. The byte value is supplied. Communication with the @@ -218,7 +218,7 @@ extern i2cmu_read_got_byte ; State Reading Reading-Wait ; W data from slave -extern i2cm_read_another + extern i2cm_read_another ; ; Requests that the communication with the slave continue and another ; byte be read. When this is complete, i2cmu_read_got_byte will be @@ -227,7 +227,7 @@ extern i2cm_read_another ; At call On return ; State Reading-Wait Reading-Busy -extern i2cm_read_done + extern i2cm_read_done ; ; Requests that reading from the slave be terminated. When the ; conversation is finished and the bus and i2c controller are free @@ -255,13 +255,13 @@ extern i2cm_read_done ; write_another | | read_another | ; | read_done| | ; write_done| \ | - `--------------+->----------------' +; `--------------+->----------------' ;======================================== ; SLAVE - WRITES (ie, reception of data from the master) ;-------------------- -extern i2csu_write_begin + extern i2csu_write_begin ; ; Called to notify the main program that the master PIC has selected this ; slave to talk to, for writing. Provides the first byte of data @@ -272,7 +272,7 @@ extern i2csu_write_begin ; W data from master any ;-------------------- -extern i2csu_write_another + extern i2csu_write_another ; ; Called to notify the main program that the master PIC has continued ; by transmitting another byte of data. Provides the byte we received. @@ -282,7 +282,7 @@ extern i2csu_write_another ; W data from master any ;-------------------- -extern i2csu_write_done + extern i2csu_write_done ; ; Called to notify the main program that the master PIC has stopped ; transmitting data (ie, finished the i2c conversation). @@ -294,7 +294,7 @@ extern i2csu_write_done ; SLAVE - READS (ie, transmission of data to the master) ;-------------------- -extern i2csu_read_begin + extern i2csu_read_begin ; ; Called to notify the main program that the master PIC has selected ; this slave to talk to, for reading, and to obtain the first byte of @@ -305,7 +305,7 @@ extern i2csu_read_begin ; W any data for master ;-------------------- -extern i2csu_read_another + extern i2csu_read_another ; ; Called to notify the main program that the master PIC has continued ; by asking for another byte of data. Must provide the byte. @@ -315,7 +315,7 @@ extern i2csu_read_another ; W any data for master ;-------------------- -extern i2csu_read_done + extern i2csu_read_done ; ; Called to notify the main program that the master PIC has stopped ; asking for data (ie, finished receiving). diff --git a/detpic/morse-auto.messages b/detpic/morse-auto.messages index 0705bea..7b8acc8 100644 --- a/detpic/morse-auto.messages +++ b/detpic/morse-auto.messages @@ -32,8 +32,8 @@ TI4 ; for iwj TI5 ; for iwj # Messages for i2clib, S* -SM i2c_st, sspstat, sspcon1, sspcon2 -SS i2c_st, sspstat, sspcon1 +SM i2c_st,i2c_sspstat,i2c_sspcon1,i2c_sspcon2 ; m.,i., ctrlr bad state +SS i2c_st,i2c_sspstat,i2c_sspcon1 ; slave, intr, controller bad state SK slave ; m. couldn't address slave (no ack) SN slave ; improper slave number SW i2c_st ; improper i2cm_write_start diff --git a/detpic/panic.fin b/detpic/panic.fin new file mode 100644 index 0000000..d3d298f --- /dev/null +++ b/detpic/panic.fin @@ -0,0 +1 @@ + extern panic_routine diff --git a/detpic/panic.inc b/detpic/panic.inc index 27fb6d4..1cff68a 100644 --- a/detpic/panic.inc +++ b/detpic/panic.inc @@ -7,3 +7,9 @@ panic macro message goto panic_routine endm +;-------------------- +; Area filled in by morse-auto.asm (see morse-auto.asm-gen for details) +morse_messages_start equ 0x4000 +morse_messages_end equ 0x4400 + + include morse-auto.inc -- 2.30.2