Author: jsuijs
Date: Sat Jan 24 10:10:47 2009
New Revision: 747

Added:
    trunk/include/jal/queue01.jal
Modified:
    trunk/include/peripheral/i2c/i2c_hw_slave_msg.jal
    trunk/sample/test/peripheral/i2c/test_i2c_hw_slave_msg.jal

Log:
generic queue added (can be multiplied on source-level when proper  
operation is verified)

Added: trunk/include/jal/queue01.jal
==============================================================================
--- (empty file)
+++ trunk/include/jal/queue01.jal       Sat Jan 24 10:10:47 2009
@@ -0,0 +1,145 @@
+-- Title: queuexx - fifo queue
+-- Author: Joep Suijs, Copyright (c) 2009, all rights reserved.
+-- Adapted-by:
+-- Compiler: >=2.4i
+--
+-- This file is part of jallib (http://jallib.googlecode.com)
+-- Released under the ZLIB license  
(http://www.opensource.org/licenses/zlib-license.html)
+--
+-- Description: this library provides a (one) byte fifo queue.
+-- This queue is interrupt-safe in the sense that you can write to the  
queue from the interrupt and
+-- read from the main program or vice versa without special precautions.
+-- Reading (or writing) from both interrupt and main program might not  
work properly.
+-- --
+-- The basic interface is pseudo var:
+-- queue01 = x -- put x into queue; block if queue is full
+-- x = queue01 -- read x from queue; block if queue is empty
+-- --
+-- non-blocking access to the same queue is provided by
+-- queue01_nb_put()
+-- and
+-- queue01_nb_get()
+-- --
+-- other methods:
+-- queue01_clear() -- clear queue (makes queue empty)
+-- queue01_empty() -- returns true if queue is emtpy
+--
+-- Sources:
+--
+
+if (defined(queue01_size) == false) then
+   -- queue size default
+   const byte  queue01_size = 10
+end if
+
+-- queue vars
+var volatile byte queue01_data[queue01_size + 1]
+var volatile byte queue01_in_pointer  = 0 ; wijst naar vrije locatie
+var volatile byte queue01_out_pointer = 0 ; wijst naar databyte
+
+procedure queue01_clear() is
+
+   queue01_in_pointer  = 0
+   queue01_out_pointer = 0
+
+end procedure
+
+function queue01_empty() return bit is
+
+   return (queue01_in_pointer == queue01_out_pointer)
+
+end function
+
+
+-- -----------------------------------------------------------------------
+-- queue01_nb_get - get one byte from queue (non-blocking)
+-- -----------------------------------------------------------------------
+-- The byte read is put into v (calling param)
+--
+-- returns: true  when we read a byte from the queue
+--          false when the queue is empty (byte is not read from queue)
+-- -----------------------------------------------------------------------
+function queue01_nb_get(byte out v) return bit is
+
+   if (queue01_in_pointer == queue01_out_pointer) then
+      -- queue is empty
+      return false;
+   end if
+
+   ; data in queue
+   v = queue01_data[queue01_out_pointer]
+   queue01_out_pointer = queue01_out_pointer + 1
+   if (queue01_out_pointer > queue01_size) then
+      queue01_out_pointer = 0
+   end if
+   return true;
+
+end function
+
+
+-- -----------------------------------------------------------------------
+-- queue01_nb_put - put one byte into queue (non-blocking)
+-- -----------------------------------------------------------------------
+-- return:  true  when the byte is put into the queue
+--          false when the queue is full (byte is not put in queue)
+-- -----------------------------------------------------------------------
+function queue01_nb_put(byte in v) return bit is
+
+   var byte pntr = queue01_in_pointer + 1
+   if (pntr > queue01_size) then
+      pntr = 0
+   end if
+
+   if (pntr == queue01_out_pointer) then
+      -- queue full
+      return false;
+   end if
+
+   queue01_data[queue01_in_pointer] = v
+   queue01_in_pointer = pntr
+
+   return true;
+
+end function
+
+-- -----------------------------------------------------------------------
+-- queue01'put - put one byte into queue
+-- -----------------------------------------------------------------------
+-- When the queue is full, it waits until a byte is removed from the queue.
+-- -----------------------------------------------------------------------
+procedure queue01'put(byte in v) is
+
+   var byte pntr = queue01_in_pointer + 1
+   if (pntr > queue01_size) then
+      pntr = 0
+   end if
+
+   -- wait until there is a free space in the queue
+   while (pntr == queue01_out_pointer) loop end loop
+
+   queue01_data[queue01_in_pointer] = v
+   queue01_in_pointer = pntr
+
+end procedure
+
+-- -----------------------------------------------------------------------
+-- queue01'get - get one byte from queue
+-- -----------------------------------------------------------------------
+-- returns byte from queue.
+-- When the queue is empty, it waits until a byte is put into the queue.
+-- -----------------------------------------------------------------------
+function queue01'get() return byte is
+   var byte v
+
+   -- wait if there are no bytes in the queue
+   while (queue01_in_pointer == queue01_out_pointer) loop end loop
+
+   ; data in queue01_
+   v = queue01_data[queue01_out_pointer]
+   queue01_out_pointer = queue01_out_pointer + 1
+   if (queue01_out_pointer > queue01_size) then
+      queue01_out_pointer = 0
+   end if
+
+   return v
+end function
\ No newline at end of file

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   Sat Jan 24 10:10:47  
2009
@@ -22,14 +22,15 @@
  var volatile bit   SSPCON1_CKP          at SSPCON1 : 4
  var volatile bit*4 SSPCON1_SSPM         at SSPCON1 : 0

+-- prototype
+procedure i2c_process_message(byte in byte_count)
+
  include i2c_hw_slave

  -- vars
  var byte i2c_index         -- i2c index (pointer)
  var byte i2c_datapresent   -- datapresent flag
-var byte i2c_status        -- status (of last user command)
  var byte i2c_buffer[I2C_BUFFER_SIZE]
-

  procedure i2c_call_process_message() is
     pragma inline

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  Sat Jan 24  
10:10:47 2009
@@ -19,7 +19,7 @@
  led_direction = output


-procedure i2c_process_message(byte in byte_count);
+

  const byte I2C_BUFFER_SIZE = 40
  include i2c_hw_slave_msg
@@ -46,31 +46,36 @@

        if (byte_count == 1) then

-         -- cmd 0x80 - request version and status
+         -- cmd 0x80 - request version
           i2c_buffer[0]   = 0x3C         -- application code
           i2c_buffer[1]   = 0x01         -- version
-         i2c_buffer[2]   = i2c_status   -- status

-         i2c_status = 0          -- succes
-      else
-         i2c_status = 1          -- invalid write length
        end if

     elsif (i2c_buffer[0] == 0x90) then
        if (byte_count == 2) then
           -- cmd 00x90 - set servo & request sensor data
---//            I2cBeep  = i2c_buffer[1]
+--            I2cBeep  = i2c_buffer[1]
        elsif (byte_count == 1) then
---//         i2c_buffer[0] = I2cOdoCounter1
---//         i2c_buffer[1] = I2cOdoCounter2
-      else
-         i2c_status = 1          -- invalid write length
+--         i2c_buffer[0] = I2cOdoCounter1
+--         i2c_buffer[1] = I2cOdoCounter2
        end if

-   else
-      i2c_status = 2             -- unknown command
     end if

  end procedure


+
+
+-- blink a little to tell the world we're up
+for 4 loop
+   led = on
+   _usec_delay(100000)
+   led = off
+   _usec_delay(100000)
+end loop
+
+-- just loop until interrupt is raised
+forever loop
+end loop

--~--~---------~--~----~------------~-------~--~----~
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