Author: jsuijs
Date: Fri May 29 07:15:09 2009
New Revision: 1016
Added:
trunk/include/jal/queue02.jal
trunk/include/jal/queue03.jal
trunk/include/jal/queue04.jal
trunk/test/jal/test_queue_isr.jal
Modified:
trunk/include/jal/queue01.jal
trunk/test/jal/test_queue.jal
Log:
extended queue interface and created 4 queue's (3 copies)
Modified: trunk/include/jal/queue01.jal
==============================================================================
--- trunk/include/jal/queue01.jal (original)
+++ trunk/include/jal/queue01.jal Fri May 29 07:15:09 2009
@@ -1,4 +1,4 @@
--- Title: queuexx - fifo queue
+-- Title: queue01 - fifo queue (number 01 is the template)
-- Author: Joep Suijs, Copyright (c) 2009, all rights reserved.
-- Adapted-by:
-- Compiler: >=2.4i
@@ -21,8 +21,12 @@
-- queue01_nb_get()
-- --
-- other methods:
--- queue01_clear() -- clear queue (makes queue empty)
--- queue01_empty() -- returns true if queue is emtpy
+-- queue01_clear() -- clear queue (makes queue empty)
+-- queue01_empty() -- returns true if queue is emtpy (depricated, use
queue1_is_empty())
+-- queue01_is_empty() -- returns true if queue is emtpy
+-- queue01_is_full() -- returns true if queue is full
+-- queue01_nr_free() -- returns nr of free places in queue
+-- queue01_nr_used() -- returns nr of used places in queue
--
-- Sources:
--
@@ -37,6 +41,7 @@
var volatile byte queue01_in_pointer = 0 ; wijst naar vrije locatie
var volatile byte queue01_out_pointer = 0 ; wijst naar databyte
+-- deprecated
procedure queue01_clear() is
queue01_in_pointer = 0
@@ -44,12 +49,52 @@
end procedure
+-- -----------------------------------------------------------------------
+-- -----------------------------------------------------------------------
+-- -----------------------------------------------------------------------
function queue01_empty() return bit is
return (queue01_in_pointer == queue01_out_pointer)
end function
+-- -----------------------------------------------------------------------
+-- -----------------------------------------------------------------------
+-- -----------------------------------------------------------------------
+function queue01_nr_used() return byte is
+
+ var byte ret = queue01_in_pointer - queue01_out_pointer
+ if (queue01_in_pointer < queue01_out_pointer) then
+ ret = ret + queue01_size
+ end if
+
+ return ret
+
+end function
+
+-- -----------------------------------------------------------------------
+-- -----------------------------------------------------------------------
+-- -----------------------------------------------------------------------
+function queue01_nr_free() return byte is
+
+ return queue01_size - 1 - queue01_nr_used()
+
+end function
+
+-- -----------------------------------------------------------------------
+-- -----------------------------------------------------------------------
+-- -----------------------------------------------------------------------
+function queue01_is_empty() return bit is
+
+ return (queue01_in_pointer == queue01_out_pointer)
+
+end function
+
+function queue01_is_full() return bit is
+
+ return (queue01_size - 1) == queue01_nr_used()
+
+end function
-- -----------------------------------------------------------------------
-- queue01_nb_get - get one byte from queue (non-blocking)
Added: trunk/include/jal/queue02.jal
==============================================================================
--- (empty file)
+++ trunk/include/jal/queue02.jal Fri May 29 07:15:09 2009
@@ -0,0 +1,237 @@
+-- Title: queue02 - fifo queue (number 02 is the template)
+-- 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:
+-- queue02 = x -- put x into queue; block if queue is full
+-- x = queue02 -- read x from queue; block if queue is empty
+-- --
+-- non-blocking access to the same queue is provided by
+-- queue02_nb_put()
+-- and
+-- queue02_nb_get()
+-- --
+-- other methods:
+-- queue02_clear() -- clear queue (makes queue empty)
+-- queue02_empty() -- returns true if queue is emtpy (depricated, use
queue2_is_empty())
+-- queue02_is_empty() -- returns true if queue is emtpy
+-- queue02_is_full() -- returns true if queue is full
+-- queue02_nr_free() -- returns nr of free places in queue
+-- queue02_nr_used() -- returns nr of used places in queue
+--
+-- Sources:
+--
+
+if (defined(queue02_size) == false) then
+ -- queue size default
+ const byte queue02_size = 20
+end if
+
+-- queue vars
+var volatile byte queue02_data[queue02_size + 2]
+var volatile byte queue02_in_pointer = 0 ; wijst naar vrije locatie
+var volatile byte queue02_out_pointer = 0 ; wijst naar databyte
+
+-- deprecated
+procedure queue02_clear() is
+
+ queue02_in_pointer = 0
+ queue02_out_pointer = 0
+
+end procedure
+
+-- -----------------------------------------------------------------------
+-- -----------------------------------------------------------------------
+-- -----------------------------------------------------------------------
+function queue02_empty() return bit is
+
+ return (queue02_in_pointer == queue02_out_pointer)
+
+end function
+
+-- -----------------------------------------------------------------------
+-- -----------------------------------------------------------------------
+-- -----------------------------------------------------------------------
+function queue02_nr_used() return byte is
+
+ var byte ret = queue02_in_pointer - queue02_out_pointer
+ if (queue02_in_pointer < queue02_out_pointer) then
+ ret = ret + queue02_size
+ end if
+
+ return ret
+
+end function
+
+-- -----------------------------------------------------------------------
+-- -----------------------------------------------------------------------
+-- -----------------------------------------------------------------------
+function queue02_nr_free() return byte is
+
+ return queue02_size - 2 - queue02_nr_used()
+
+end function
+
+-- -----------------------------------------------------------------------
+-- -----------------------------------------------------------------------
+-- -----------------------------------------------------------------------
+function queue02_is_empty() return bit is
+
+ return (queue02_in_pointer == queue02_out_pointer)
+
+end function
+
+function queue02_is_full() return bit is
+
+ return (queue02_size - 2) == queue02_nr_used()
+
+end function
+
+-- -----------------------------------------------------------------------
+-- queue02_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 queue02_nb_get(byte out v) return bit is
+
+ if (queue02_in_pointer == queue02_out_pointer) then
+ -- queue is empty
+ return false;
+ end if
+
+ ; data in queue
+ v = queue02_data[queue02_out_pointer]
+ queue02_out_pointer = queue02_out_pointer + 2
+ if (queue02_out_pointer > queue02_size) then
+ queue02_out_pointer = 0
+ end if
+ return true;
+
+end function
+
+
+-- -----------------------------------------------------------------------
+-- queue02_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 queue02_nb_put(byte in v) return bit is
+
+ var byte pntr = queue02_in_pointer + 2
+ if (pntr > queue02_size) then
+ pntr = 0
+ end if
+
+ if (pntr == queue02_out_pointer) then
+ -- queue full
+ return false;
+ end if
+
+ queue02_data[queue02_in_pointer] = v
+ queue02_in_pointer = pntr
+
+ return true;
+
+end function
+
+
+-- -----------------------------------------------------------------------
+-- queue02_nb'get - get one byte from queue (non-blocking)
+-- -----------------------------------------------------------------------
+-- returns byte from queue, 0 if queue empty
+-- -----------------------------------------------------------------------
+function queue02_nb'get() return byte is
+ var byte v
+
+ if (queue02_in_pointer == queue02_out_pointer) then
+ -- queue is empty
+ return 0;
+ end if
+
+ ; data in queue
+ v = queue02_data[queue02_out_pointer]
+ queue02_out_pointer = queue02_out_pointer + 2
+ if (queue02_out_pointer > queue02_size) then
+ queue02_out_pointer = 0
+ end if
+
+ return v
+
+end function
+
+
+-- -----------------------------------------------------------------------
+-- queue02_nb'put - put one byte into queue (non-blocking)
+-- -----------------------------------------------------------------------
+-- -----------------------------------------------------------------------
+procedure queue02_nb'put(byte in v) is
+
+ var byte pntr = queue02_in_pointer + 2
+ if (pntr > queue02_size) then
+ pntr = 0
+ end if
+
+ if (pntr == queue02_out_pointer) then
+ -- queue full
+ return;
+ end if
+
+ queue02_data[queue02_in_pointer] = v
+ queue02_in_pointer = pntr
+
+end procedure
+
+-- -----------------------------------------------------------------------
+-- queue02'put - put one byte into queue
+-- -----------------------------------------------------------------------
+-- When the queue is full, it waits until a byte is removed from the queue.
+-- -----------------------------------------------------------------------
+procedure queue02'put(byte in v) is
+
+ var byte pntr = queue02_in_pointer + 2
+ if (pntr > queue02_size) then
+ pntr = 0
+ end if
+
+ -- wait until there is a free space in the queue
+ while (pntr == queue02_out_pointer) loop end loop
+
+ queue02_data[queue02_in_pointer] = v
+ queue02_in_pointer = pntr
+
+end procedure
+
+-- -----------------------------------------------------------------------
+-- queue02'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 queue02'get() return byte is
+ var byte v
+
+ -- wait if there are no bytes in the queue
+ while (queue02_in_pointer == queue02_out_pointer) loop end loop
+
+ ; data in queue02_
+ v = queue02_data[queue02_out_pointer]
+ queue02_out_pointer = queue02_out_pointer + 2
+ if (queue02_out_pointer > queue02_size) then
+ queue02_out_pointer = 0
+ end if
+
+ return v
+end function
\ No newline at end of file
Added: trunk/include/jal/queue03.jal
==============================================================================
--- (empty file)
+++ trunk/include/jal/queue03.jal Fri May 29 07:15:09 2009
@@ -0,0 +1,237 @@
+-- Title: queue03 - fifo queue (number 03 is the template)
+-- 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:
+-- queue03 = x -- put x into queue; block if queue is full
+-- x = queue03 -- read x from queue; block if queue is empty
+-- --
+-- non-blocking access to the same queue is provided by
+-- queue03_nb_put()
+-- and
+-- queue03_nb_get()
+-- --
+-- other methods:
+-- queue03_clear() -- clear queue (makes queue empty)
+-- queue03_empty() -- returns true if queue is emtpy (depricated, use
queue3_is_empty())
+-- queue03_is_empty() -- returns true if queue is emtpy
+-- queue03_is_full() -- returns true if queue is full
+-- queue03_nr_free() -- returns nr of free places in queue
+-- queue03_nr_used() -- returns nr of used places in queue
+--
+-- Sources:
+--
+
+if (defined(queue03_size) == false) then
+ -- queue size default
+ const byte queue03_size = 30
+end if
+
+-- queue vars
+var volatile byte queue03_data[queue03_size + 3]
+var volatile byte queue03_in_pointer = 0 ; wijst naar vrije locatie
+var volatile byte queue03_out_pointer = 0 ; wijst naar databyte
+
+-- deprecated
+procedure queue03_clear() is
+
+ queue03_in_pointer = 0
+ queue03_out_pointer = 0
+
+end procedure
+
+-- -----------------------------------------------------------------------
+-- -----------------------------------------------------------------------
+-- -----------------------------------------------------------------------
+function queue03_empty() return bit is
+
+ return (queue03_in_pointer == queue03_out_pointer)
+
+end function
+
+-- -----------------------------------------------------------------------
+-- -----------------------------------------------------------------------
+-- -----------------------------------------------------------------------
+function queue03_nr_used() return byte is
+
+ var byte ret = queue03_in_pointer - queue03_out_pointer
+ if (queue03_in_pointer < queue03_out_pointer) then
+ ret = ret + queue03_size
+ end if
+
+ return ret
+
+end function
+
+-- -----------------------------------------------------------------------
+-- -----------------------------------------------------------------------
+-- -----------------------------------------------------------------------
+function queue03_nr_free() return byte is
+
+ return queue03_size - 3 - queue03_nr_used()
+
+end function
+
+-- -----------------------------------------------------------------------
+-- -----------------------------------------------------------------------
+-- -----------------------------------------------------------------------
+function queue03_is_empty() return bit is
+
+ return (queue03_in_pointer == queue03_out_pointer)
+
+end function
+
+function queue03_is_full() return bit is
+
+ return (queue03_size - 3) == queue03_nr_used()
+
+end function
+
+-- -----------------------------------------------------------------------
+-- queue03_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 queue03_nb_get(byte out v) return bit is
+
+ if (queue03_in_pointer == queue03_out_pointer) then
+ -- queue is empty
+ return false;
+ end if
+
+ ; data in queue
+ v = queue03_data[queue03_out_pointer]
+ queue03_out_pointer = queue03_out_pointer + 3
+ if (queue03_out_pointer > queue03_size) then
+ queue03_out_pointer = 0
+ end if
+ return true;
+
+end function
+
+
+-- -----------------------------------------------------------------------
+-- queue03_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 queue03_nb_put(byte in v) return bit is
+
+ var byte pntr = queue03_in_pointer + 3
+ if (pntr > queue03_size) then
+ pntr = 0
+ end if
+
+ if (pntr == queue03_out_pointer) then
+ -- queue full
+ return false;
+ end if
+
+ queue03_data[queue03_in_pointer] = v
+ queue03_in_pointer = pntr
+
+ return true;
+
+end function
+
+
+-- -----------------------------------------------------------------------
+-- queue03_nb'get - get one byte from queue (non-blocking)
+-- -----------------------------------------------------------------------
+-- returns byte from queue, 0 if queue empty
+-- -----------------------------------------------------------------------
+function queue03_nb'get() return byte is
+ var byte v
+
+ if (queue03_in_pointer == queue03_out_pointer) then
+ -- queue is empty
+ return 0;
+ end if
+
+ ; data in queue
+ v = queue03_data[queue03_out_pointer]
+ queue03_out_pointer = queue03_out_pointer + 3
+ if (queue03_out_pointer > queue03_size) then
+ queue03_out_pointer = 0
+ end if
+
+ return v
+
+end function
+
+
+-- -----------------------------------------------------------------------
+-- queue03_nb'put - put one byte into queue (non-blocking)
+-- -----------------------------------------------------------------------
+-- -----------------------------------------------------------------------
+procedure queue03_nb'put(byte in v) is
+
+ var byte pntr = queue03_in_pointer + 3
+ if (pntr > queue03_size) then
+ pntr = 0
+ end if
+
+ if (pntr == queue03_out_pointer) then
+ -- queue full
+ return;
+ end if
+
+ queue03_data[queue03_in_pointer] = v
+ queue03_in_pointer = pntr
+
+end procedure
+
+-- -----------------------------------------------------------------------
+-- queue03'put - put one byte into queue
+-- -----------------------------------------------------------------------
+-- When the queue is full, it waits until a byte is removed from the queue.
+-- -----------------------------------------------------------------------
+procedure queue03'put(byte in v) is
+
+ var byte pntr = queue03_in_pointer + 3
+ if (pntr > queue03_size) then
+ pntr = 0
+ end if
+
+ -- wait until there is a free space in the queue
+ while (pntr == queue03_out_pointer) loop end loop
+
+ queue03_data[queue03_in_pointer] = v
+ queue03_in_pointer = pntr
+
+end procedure
+
+-- -----------------------------------------------------------------------
+-- queue03'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 queue03'get() return byte is
+ var byte v
+
+ -- wait if there are no bytes in the queue
+ while (queue03_in_pointer == queue03_out_pointer) loop end loop
+
+ ; data in queue03_
+ v = queue03_data[queue03_out_pointer]
+ queue03_out_pointer = queue03_out_pointer + 3
+ if (queue03_out_pointer > queue03_size) then
+ queue03_out_pointer = 0
+ end if
+
+ return v
+end function
\ No newline at end of file
Added: trunk/include/jal/queue04.jal
==============================================================================
--- (empty file)
+++ trunk/include/jal/queue04.jal Fri May 29 07:15:09 2009
@@ -0,0 +1,237 @@
+-- Title: queue04 - fifo queue (number 04 is the template)
+-- 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:
+-- queue04 = x -- put x into queue; block if queue is full
+-- x = queue04 -- read x from queue; block if queue is empty
+-- --
+-- non-blocking access to the same queue is provided by
+-- queue04_nb_put()
+-- and
+-- queue04_nb_get()
+-- --
+-- other methods:
+-- queue04_clear() -- clear queue (makes queue empty)
+-- queue04_empty() -- returns true if queue is emtpy (depricated, use
queue4_is_empty())
+-- queue04_is_empty() -- returns true if queue is emtpy
+-- queue04_is_full() -- returns true if queue is full
+-- queue04_nr_free() -- returns nr of free places in queue
+-- queue04_nr_used() -- returns nr of used places in queue
+--
+-- Sources:
+--
+
+if (defined(queue04_size) == false) then
+ -- queue size default
+ const byte queue04_size = 40
+end if
+
+-- queue vars
+var volatile byte queue04_data[queue04_size + 4]
+var volatile byte queue04_in_pointer = 0 ; wijst naar vrije locatie
+var volatile byte queue04_out_pointer = 0 ; wijst naar databyte
+
+-- deprecated
+procedure queue04_clear() is
+
+ queue04_in_pointer = 0
+ queue04_out_pointer = 0
+
+end procedure
+
+-- -----------------------------------------------------------------------
+-- -----------------------------------------------------------------------
+-- -----------------------------------------------------------------------
+function queue04_empty() return bit is
+
+ return (queue04_in_pointer == queue04_out_pointer)
+
+end function
+
+-- -----------------------------------------------------------------------
+-- -----------------------------------------------------------------------
+-- -----------------------------------------------------------------------
+function queue04_nr_used() return byte is
+
+ var byte ret = queue04_in_pointer - queue04_out_pointer
+ if (queue04_in_pointer < queue04_out_pointer) then
+ ret = ret + queue04_size
+ end if
+
+ return ret
+
+end function
+
+-- -----------------------------------------------------------------------
+-- -----------------------------------------------------------------------
+-- -----------------------------------------------------------------------
+function queue04_nr_free() return byte is
+
+ return queue04_size - 4 - queue04_nr_used()
+
+end function
+
+-- -----------------------------------------------------------------------
+-- -----------------------------------------------------------------------
+-- -----------------------------------------------------------------------
+function queue04_is_empty() return bit is
+
+ return (queue04_in_pointer == queue04_out_pointer)
+
+end function
+
+function queue04_is_full() return bit is
+
+ return (queue04_size - 4) == queue04_nr_used()
+
+end function
+
+-- -----------------------------------------------------------------------
+-- queue04_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 queue04_nb_get(byte out v) return bit is
+
+ if (queue04_in_pointer == queue04_out_pointer) then
+ -- queue is empty
+ return false;
+ end if
+
+ ; data in queue
+ v = queue04_data[queue04_out_pointer]
+ queue04_out_pointer = queue04_out_pointer + 4
+ if (queue04_out_pointer > queue04_size) then
+ queue04_out_pointer = 0
+ end if
+ return true;
+
+end function
+
+
+-- -----------------------------------------------------------------------
+-- queue04_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 queue04_nb_put(byte in v) return bit is
+
+ var byte pntr = queue04_in_pointer + 4
+ if (pntr > queue04_size) then
+ pntr = 0
+ end if
+
+ if (pntr == queue04_out_pointer) then
+ -- queue full
+ return false;
+ end if
+
+ queue04_data[queue04_in_pointer] = v
+ queue04_in_pointer = pntr
+
+ return true;
+
+end function
+
+
+-- -----------------------------------------------------------------------
+-- queue04_nb'get - get one byte from queue (non-blocking)
+-- -----------------------------------------------------------------------
+-- returns byte from queue, 0 if queue empty
+-- -----------------------------------------------------------------------
+function queue04_nb'get() return byte is
+ var byte v
+
+ if (queue04_in_pointer == queue04_out_pointer) then
+ -- queue is empty
+ return 0;
+ end if
+
+ ; data in queue
+ v = queue04_data[queue04_out_pointer]
+ queue04_out_pointer = queue04_out_pointer + 4
+ if (queue04_out_pointer > queue04_size) then
+ queue04_out_pointer = 0
+ end if
+
+ return v
+
+end function
+
+
+-- -----------------------------------------------------------------------
+-- queue04_nb'put - put one byte into queue (non-blocking)
+-- -----------------------------------------------------------------------
+-- -----------------------------------------------------------------------
+procedure queue04_nb'put(byte in v) is
+
+ var byte pntr = queue04_in_pointer + 4
+ if (pntr > queue04_size) then
+ pntr = 0
+ end if
+
+ if (pntr == queue04_out_pointer) then
+ -- queue full
+ return;
+ end if
+
+ queue04_data[queue04_in_pointer] = v
+ queue04_in_pointer = pntr
+
+end procedure
+
+-- -----------------------------------------------------------------------
+-- queue04'put - put one byte into queue
+-- -----------------------------------------------------------------------
+-- When the queue is full, it waits until a byte is removed from the queue.
+-- -----------------------------------------------------------------------
+procedure queue04'put(byte in v) is
+
+ var byte pntr = queue04_in_pointer + 4
+ if (pntr > queue04_size) then
+ pntr = 0
+ end if
+
+ -- wait until there is a free space in the queue
+ while (pntr == queue04_out_pointer) loop end loop
+
+ queue04_data[queue04_in_pointer] = v
+ queue04_in_pointer = pntr
+
+end procedure
+
+-- -----------------------------------------------------------------------
+-- queue04'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 queue04'get() return byte is
+ var byte v
+
+ -- wait if there are no bytes in the queue
+ while (queue04_in_pointer == queue04_out_pointer) loop end loop
+
+ ; data in queue04_
+ v = queue04_data[queue04_out_pointer]
+ queue04_out_pointer = queue04_out_pointer + 4
+ if (queue04_out_pointer > queue04_size) then
+ queue04_out_pointer = 0
+ end if
+
+ return v
+end function
\ No newline at end of file
Modified: trunk/test/jal/test_queue.jal
==============================================================================
--- trunk/test/jal/test_queue.jal (original)
+++ trunk/test/jal/test_queue.jal Fri May 29 07:15:09 2009
@@ -27,71 +27,27 @@
led_direction= output
-const byte queue01_size = 4
+const byte queue01_size = 8
include queue01
queue01_clear()
var byte isr_put_counter = 0
var volatile byte test_mode
--- -----------------------------------------------------------------------
--- serial_receive_wedge - handle each received char at ISR level
--- -----------------------------------------------------------------------
--- receive wedge - a user defined procedure, which is called by
--- serial_hw_int_cts from the receive ISR for each received char.
---
--- CAUTION: the wedge is part of the ISR and should be designed
--- to behave accordingly. If you are not sure you need this, you
--- probably don't!
--- -----------------------------------------------------------------------
-procedure serial_receive_wedge(byte in char) is
- pragma inline
-
- var byte dummy
- var bit ret
-
-
- if (char == "*") then
- -- when a space is received in the ISR
- LED = ! LED ; high
-
- if ((test_mode == 1) | (test_mode == 2)) then
- -- non-block-get
-
- ret = queue01_nb_get(dummy)
- return
- end if
-
- if ((test_mode == 3) | (test_mode == 4)) then
- -- non-block-put
- ret = queue01_nb_put(isr_put_counter)
- isr_put_counter = isr_put_counter + 1
- return
- end if
-
- end if
-
-end procedure
-
+
include delay
-var bit serial_ctsinv is pin_B4 -- incoming data flow control
-var bit serial_overflow_discard -- With transmit buffer overflow
-include serial_hw_int_cts
-;include serial_hardware
+include serial_hardware
serial_hw_init()
-
include print
-
-
const byte str1[] = " - Test queue\r\n" -- define a string
print_string(serial_hw_data, str1) -- output string
var byte char, i
-
+
forever loop
delay_100ms( 2 )
; LED = ! LED ; high
@@ -110,7 +66,7 @@
"1" : block
test_mode = char - "0"
- const byte str11[] = "\r\n1 - put 5 chars in queue (blocking),
use * to remove them\r\n"
+ const byte str11[] = "\r\n1 - put 5 chars in queue
(blocking)\r\n"
print_string(serial_hw_data, str11)
for 5 using i loop
queue01 = i
@@ -118,26 +74,24 @@
end loop
end block
+ "2" : block
+ test_mode = char - "0"
+ const byte str11[] = "\r\n2 - try to put 5 chars in queue
(non-blocking)r\n"
+ print_string(serial_hw_data, str11)
-;; note: due to compiler bug, we can't use non-blocking interface at both
main and isr level
-;; "2" : block
-;; test_mode = char - "0"
-;; const byte str11[] = "\r\n2 - try to put 5 chars in queue
(non-blocking), use * to remove them\r\n"
-;; print_string(serial_hw_data, str11)
-;;
-;; for 5 using i loop
-;; serial_hw_data = "0" | i
-;; if (queue01_nb_put(i) == true) then
-;; serial_hw_data = "s" -- succes
-;; else
-;; serial_hw_data = "f" -- fail
-;; end if
-;; end loop
-;; end block
+ for 5 using i loop
+ serial_hw_data = "0" | i
+ if (queue01_nb_put(i) == true) then
+ serial_hw_data = "s" -- succes
+ else
+ serial_hw_data = "f" -- fail
+ end if
+ end loop
+ end block
"3" : block
test_mode = char - "0"
- const byte str11[] = "\r\n1 - get 5 chars from queue
(blocking), use * to add them\r\n"
+ const byte str11[] = "\r\n1 - get 5 chars from queue
(blocking)\r\n"
print_string(serial_hw_data, str11)
for 5 loop
i = queue01
@@ -145,53 +99,64 @@
end loop
end block
-;; note: due to compiler bug, we can't use non-blocking interface at both
main and isr level
-;; "4" : block
-;; test_mode = char - "0"
-;; const byte str11[] = "\r\n1 - get 5 chars from queue
(non-blocking), use * to add them\r\n"
-;; print_string(serial_hw_data, str11)
-;;
-;; for 5 loop
-;; if (queue01_nb_get(i) == true) then -- get byte
-;; serial_hw_data = "s" -- succes
-;; else
-;; serial_hw_data = "f" -- fail
-;; end if
-;; serial_hw_data = "0" | i -- print byte
-;; end loop
-;; end block
-
-;; note: due to compiler bug, we can't use non-blocking interface at both
main and isr level
-;; "8" : block
-;; test_mode = char - "0"
-;; const byte str11[] = "put "
-;; print_string(serial_hw_data, str11)
-;;
-;; var bit ret = queue01_nb_put(99)
-;; print_bit_truefalse(serial_hw_data, ret)
-;;
-;; serial_hw_data = "+"
-;; print_byte_dec(serial_hw_data, queue01_in_pointer)
-;; serial_hw_data = " "
-;; print_byte_dec(serial_hw_data, queue01_out_pointer)
-;; print_crlf(serial_hw_data)
-;;
-;; end block
-;;
-;; note: due to compiler bug, we can't use non-blocking interface at both
main and isr level
-;; "9" : block
-;; test_mode = char - "0"
-;; const byte str11[] = "get "
-;; print_string(serial_hw_data, str11)
-;; var bit ret = queue01_nb_get(i)
-;; print_bit_truefalse(serial_hw_data, ret)
-;; serial_hw_data = "+"
-;; print_byte_dec(serial_hw_data, queue01_in_pointer)
-;; serial_hw_data = " "
-;; print_byte_dec(serial_hw_data, queue01_out_pointer)
-;; print_crlf(serial_hw_data)
-;;
-;; end block
+ "4" : block
+ test_mode = char - "0"
+ const byte str11[] = "\r\n1 - get 5 chars from queue
(non-blocking)\r\n"
+ print_string(serial_hw_data, str11)
+
+ for 5 loop
+ if (queue01_nb_get(i) == true) then -- get byte
+ serial_hw_data = "s" -- succes
+ else
+ serial_hw_data = "f" -- fail
+ end if
+ serial_hw_data = "0" | i -- print byte
+ end loop
+ end block
+
+ "8" : block
+ test_mode = char - "0"
+ const byte str11[] = "put "
+ print_string(serial_hw_data, str11)
+
+ var bit ret = queue01_nb_put(99)
+ print_bit_truefalse(serial_hw_data, ret)
+
+ serial_hw_data = "+"
+ print_byte_dec(serial_hw_data, queue01_in_pointer)
+ serial_hw_data = " "
+ print_byte_dec(serial_hw_data, queue01_out_pointer)
+ print_crlf(serial_hw_data)
+
+ end block
+
+ "9" : block
+ test_mode = char - "0"
+ const byte str11[] = "get "
+ print_string(serial_hw_data, str11)
+ var bit ret = queue01_nb_get(i)
+ print_bit_truefalse(serial_hw_data, ret)
+ serial_hw_data = "+"
+ print_byte_dec(serial_hw_data, queue01_in_pointer)
+ serial_hw_data = " "
+ print_byte_dec(serial_hw_data, queue01_out_pointer)
+ print_crlf(serial_hw_data)
+
+ end block
+
+
+ " " : block
+ test_mode = char - "0"
+ const byte str11[] = "free/used: "
+ print_string(serial_hw_data, str11)
+ var byte ret = queue01_nr_free()
+ print_byte_dec(serial_hw_data, ret)
+ serial_hw_data = "/"
+ ret = queue01_nr_used()
+ print_byte_dec(serial_hw_data, ret)
+ print_crlf(serial_hw_data)
+
+ end block
end case
end loop
Added: trunk/test/jal/test_queue_isr.jal
==============================================================================
--- (empty file)
+++ trunk/test/jal/test_queue_isr.jal Fri May 29 07:15:09 2009
@@ -0,0 +1,198 @@
+-- ------------------------------------------------------
+-- Title: Test program for queue01.jal
+--
+-- Author: Joep Suijs, Copyright (c) 2008..2008, all rights reserved.
+--
+-- Adapted-by:
+--
+-- Compiler: >=2.4g
+--
+-- This file is part of jallib (http://jallib.googlecode.com)
+-- Released under the BSD license
(http://www.opensource.org/licenses/bsd-license.php)
+--
+-- Description: Test program
+--
+-- Sources:
+--
+-- Notes: as output, this sample produces characters on a serial link.
First
+-- run serial tests to make sure serial comms works okay.
+--
+-- ------------------------------------------------------
+
+;@jallib use chipdef
+;@jallib use led
+
+-- set all IO as digital
+enable_digital_io()
+
+led_direction= output
+
+const byte queue01_size = 4
+include queue01
+queue01_clear()
+
+var byte isr_put_counter = 0
+var volatile byte test_mode
+-- -----------------------------------------------------------------------
+-- serial_receive_wedge - handle each received char at ISR level
+-- -----------------------------------------------------------------------
+-- receive wedge - a user defined procedure, which is called by
+-- serial_hw_int_cts from the receive ISR for each received char.
+--
+-- CAUTION: the wedge is part of the ISR and should be designed
+-- to behave accordingly. If you are not sure you need this, you
+-- probably don't!
+-- -----------------------------------------------------------------------
+procedure serial_receive_wedge(byte in char) is
+ pragma inline
+
+ var byte dummy
+ var bit ret
+
+
+ if (char == "*") then
+ -- when a space is received in the ISR
+ LED = ! LED ; high
+
+ if ((test_mode == 1) | (test_mode == 2)) then
+ -- non-block-get
+
+ ret = queue01_nb_get(dummy)
+ return
+ end if
+
+ if ((test_mode == 3) | (test_mode == 4)) then
+ -- non-block-put
+ ret = queue01_nb_put(isr_put_counter)
+ isr_put_counter = isr_put_counter + 1
+ return
+ end if
+
+ end if
+
+end procedure
+
+include delay
+
+var bit serial_ctsinv is pin_B4 -- incoming data flow control
+var bit serial_overflow_discard -- With transmit buffer overflow
+include serial_hw_int_cts
+;include serial_hardware
+serial_hw_init()
+
+
+include print
+
+
+
+const byte str1[] = " - Test queue\r\n" -- define a string
+print_string(serial_hw_data, str1) -- output string
+
+
+
+var byte char, i
+
+ forever loop
+ delay_100ms( 2 )
+; LED = ! LED ; high
+; delay_100ms( 2 )
+; LED = low
+
+ serial_hw_data = "."
+
+ while (serial_hw_read(char)) loop
+ case char of
+
+ "0" : block
+ test_mode = char - "0"
+
+ end block
+
+ "1" : block
+ test_mode = char - "0"
+ const byte str11[] = "\r\n1 - put 5 chars in queue (blocking),
use * to remove them\r\n"
+ print_string(serial_hw_data, str11)
+ for 5 using i loop
+ queue01 = i
+ serial_hw_data = "0" | i
+ end loop
+ end block
+
+
+;; note: due to compiler bug, we can't use non-blocking interface at both
main and isr level
+;; "2" : block
+;; test_mode = char - "0"
+;; const byte str11[] = "\r\n2 - try to put 5 chars in queue
(non-blocking), use * to remove them\r\n"
+;; print_string(serial_hw_data, str11)
+;;
+;; for 5 using i loop
+;; serial_hw_data = "0" | i
+;; if (queue01_nb_put(i) == true) then
+;; serial_hw_data = "s" -- succes
+;; else
+;; serial_hw_data = "f" -- fail
+;; end if
+;; end loop
+;; end block
+
+ "3" : block
+ test_mode = char - "0"
+ const byte str11[] = "\r\n1 - get 5 chars from queue
(blocking), use * to add them\r\n"
+ print_string(serial_hw_data, str11)
+ for 5 loop
+ i = queue01
+ serial_hw_data = "0" | i
+ end loop
+ end block
+
+;; note: due to compiler bug, we can't use non-blocking interface at both
main and isr level
+;; "4" : block
+;; test_mode = char - "0"
+;; const byte str11[] = "\r\n1 - get 5 chars from queue
(non-blocking), use * to add them\r\n"
+;; print_string(serial_hw_data, str11)
+;;
+;; for 5 loop
+;; if (queue01_nb_get(i) == true) then -- get byte
+;; serial_hw_data = "s" -- succes
+;; else
+;; serial_hw_data = "f" -- fail
+;; end if
+;; serial_hw_data = "0" | i -- print byte
+;; end loop
+;; end block
+
+;; note: due to compiler bug, we can't use non-blocking interface at both
main and isr level
+;; "8" : block
+;; test_mode = char - "0"
+;; const byte str11[] = "put "
+;; print_string(serial_hw_data, str11)
+;;
+;; var bit ret = queue01_nb_put(99)
+;; print_bit_truefalse(serial_hw_data, ret)
+;;
+;; serial_hw_data = "+"
+;; print_byte_dec(serial_hw_data, queue01_in_pointer)
+;; serial_hw_data = " "
+;; print_byte_dec(serial_hw_data, queue01_out_pointer)
+;; print_crlf(serial_hw_data)
+;;
+;; end block
+;;
+;; note: due to compiler bug, we can't use non-blocking interface at both
main and isr level
+;; "9" : block
+;; test_mode = char - "0"
+;; const byte str11[] = "get "
+;; print_string(serial_hw_data, str11)
+;; var bit ret = queue01_nb_get(i)
+;; print_bit_truefalse(serial_hw_data, ret)
+;; serial_hw_data = "+"
+;; print_byte_dec(serial_hw_data, queue01_in_pointer)
+;; serial_hw_data = " "
+;; print_byte_dec(serial_hw_data, queue01_out_pointer)
+;; print_crlf(serial_hw_data)
+;;
+;; end block
+
+ end case
+ end loop
+end loop
\ No newline at end of file
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---