Author: jsuijs
Date: Wed Jan 28 00:26:18 2009
New Revision: 756

Modified:
    trunk/include/peripheral/i2c/i2c_hw_slave.jal
    trunk/include/peripheral/i2c/i2c_hw_slave_isr.jal
    trunk/include/peripheral/i2c/i2c_hw_slave_msg.jal
    trunk/sample/test/peripheral/i2c/test_i2c_hw_slave_msg.jal

Log:
i2c hw slave message interface works now (using start & stop interrupts)

Modified: trunk/include/peripheral/i2c/i2c_hw_slave.jal
==============================================================================
--- trunk/include/peripheral/i2c/i2c_hw_slave.jal       (original)
+++ trunk/include/peripheral/i2c/i2c_hw_slave.jal       Wed Jan 28 00:26:18 2009
@@ -29,7 +29,7 @@
        end if

     -- if this procedure exists, enable start/stop interrupts.
-   if(defined(i2c_hw_slave_on_stop) == true) then
+   if(defined(i2c_enable_start_stop_interrupts) == true) then
                SSPCON1 = SSPCON1 | 0b_0000_1000        -- enable start/stop 
interrupts
     end if


Modified: trunk/include/peripheral/i2c/i2c_hw_slave_isr.jal
==============================================================================
--- trunk/include/peripheral/i2c/i2c_hw_slave_isr.jal   (original)
+++ trunk/include/peripheral/i2c/i2c_hw_slave_isr.jal   Wed Jan 28 00:26:18  
2009
@@ -60,13 +60,21 @@
     end if

     PIR1_SSPIF = false
-    var byte tmpstat
+   var byte tmpstat
     tmpstat = SSPSTAT
+
+;   queue01 = "*"
+;   print_byte_hex(queue01, tmpstat)

-   -- if this procedure exists, call it on stop interrupt.
-   if(defined(i2c_hw_slave_on_stop) == true) then
-      if (tmpstat & 0b_0001_0000) == true then
-         i2c_hw_slave_on_stop();
+   -- if this constant is defined, call start & stop handlers.
+   if(defined(i2c_enable_start_stop_interrupts) == true) then
+      if (tmpstat & 0b_0000_1111) == 0b_0000_1000 then
+         i2c_hw_slave_on_start();
+         return
+      end if
+      if (tmpstat & 0b_0011_0000) == 0b_0011_0000 then
+         i2c_hw_slave_on_stop();
+         return
        end if
     end if


Modified: trunk/include/peripheral/i2c/i2c_hw_slave_msg.jal
==============================================================================
--- trunk/include/peripheral/i2c/i2c_hw_slave_msg.jal   (original)
+++ trunk/include/peripheral/i2c/i2c_hw_slave_msg.jal   Wed Jan 28 00:26:18  
2009
@@ -16,9 +16,6 @@
  -- it wants to have them.
  -- See corresponding sample for more details.
  -- --
--- Limitation: The master needs to read at least one byte after writing a  
sequence to
--- the slave to trigger proper message processing. See the LED on/off  
examples for
--- more details.
  --
  -- Sources:
  --   - AN734:  
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en011798
@@ -38,6 +35,7 @@
  -- prototype
  procedure i2c_process_message(byte in byte_count)

+const i2c_enable_start_stop_interrupts = 1
  include i2c_hw_slave

  -- vars
@@ -64,15 +62,37 @@
  procedure i2c_hw_slave_on_error() is
     pragma inline
     -- Just tell user user something's got wrong
-   forever loop
-         led = on
-         _usec_delay(200000)
-         led = off
-         _usec_delay(200000)
-   end loop
+;   forever loop
+;        led = on
+;        _usec_delay(200000)
+;        led = off
+;        _usec_delay(200000)
+;   end loop
+
+   queue01 = "#"
+   queue01 = "E"
+
  end procedure

+procedure i2c_hw_slave_on_start() is
+   pragma inline
+
+   queue01 = "#"
+   queue01 = "S"
+
+end procedure

+procedure i2c_hw_slave_on_stop() is
+   pragma inline
+
+   -- let user process buffer
+   i2c_call_process_message()
+
+   queue01 = "#"
+   queue01 = "P"
+
+end procedure
+
  -- this callback is used when master wants to talk to us
  -- and our i2c address has been recognized
  procedure i2c_hw_slave_on_state_1(byte in _trash) is
@@ -81,6 +101,9 @@
     -- let user process buffer (there should not be one if the proper  
procedure is executed)
     i2c_call_process_message()

+   queue01 = "#"
+   queue01 = "1"
+
  end procedure


@@ -96,6 +119,9 @@
        i2c_index = i2c_index + 1   -- point to next position
     end if

+   queue01 = "#"
+   queue01 = "2"
+
  end procedure


@@ -111,6 +137,9 @@
     i2c_index = 0                          -- set pointer to buffer start
     i2c_hw_slave_write_i2c(i2c_buffer[0])   -- send data
     i2c_index = 1                          -- point to next position
+
+   queue01 = "#"
+   queue01 = "3"

  end procedure

@@ -127,6 +156,9 @@
     i2c_hw_slave_write_i2c(i2c_buffer[i2c_index])    -- send data
     i2c_index = i2c_index + 1                    -- point to next position

+   queue01 = "#"
+   queue01 = "4"
+
  end procedure

  -- this callback is used when master does not want to talk
@@ -134,7 +166,11 @@
  -- data for instance
  procedure i2c_hw_slave_on_state_5() is
     pragma inline
-   -- data = 0
+   -- data = 0
+
+   queue01 = "#"
+   queue01 = "5"
+
  end procedure

  -- callbacks are defined, now include ISR

Modified: trunk/sample/test/peripheral/i2c/test_i2c_hw_slave_msg.jal
==============================================================================
--- trunk/sample/test/peripheral/i2c/test_i2c_hw_slave_msg.jal  (original)
+++ trunk/sample/test/peripheral/i2c/test_i2c_hw_slave_msg.jal  Wed Jan 28  
00:26:18 2009
@@ -11,10 +11,6 @@
  -- a full message to arrive and then calls a user routine to process the  
message and
  -- (optional) prepare a response.
  -- --
--- Limitation: The master needs to read at least one byte after writing a  
sequence to
--- the slave to trigger proper message processing. See the LED on/off  
examples for
--- more details.
--- --
  -- Conventions:
  -- S = create (re)start state
  -- P = create stop state
@@ -23,8 +19,8 @@
  -- N   = master reads and NACKs
  -- --
  -- s5Cw80ws5Dwrnp - reads application code and version (0x31 0x01)
--- s5Cw90w00ws5Dwnp    - LED off
--- s5Cw90wFFws5Dwnp    - LED on
+-- s5Cw90w00wp    - LED off
+-- s5Cw90wFFwp    - LED on
  -- --


@@ -42,7 +38,9 @@

  const byte str1[] = "Test i2c hardware slave - msg interface.\r\n"   --  
define a string
  print_string(serial_hw_data, str1)                 -- output string
-
+
+-- setup queue for debugging
+const byte  queue01_size = 20
  include queue01
  queue01_clear()


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jallib" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/jallib?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to