Author: jsuijs
Date: Sat Mar  7 10:48:13 2009
New Revision: 836

Added:
    trunk/sample/test/peripheral/usart/serial_testconsole.jal
Modified:
    trunk/sample/test/board/board_16f877a_dwarf.jal
    trunk/sample/test/external/lcd/test_display_hd44780_4_line.jal
    trunk/sample/test/external/lcd/test_lcd_hd44780_4.jal

Log:
serial_testconsole.jal gives easy access to up to 26 unit tests.

Modified: trunk/sample/test/board/board_16f877a_dwarf.jal
==============================================================================
--- trunk/sample/test/board/board_16f877a_dwarf.jal     (original)
+++ trunk/sample/test/board/board_16f877a_dwarf.jal     Sat Mar  7 10:48:13 2009
@@ -36,8 +36,8 @@

  ;@jallib section led
  -- LED IO definition
-var bit led             is pin_a0
-var bit led_direction   is pin_a0_direction
+var bit led             is pin_b6
+var bit led_direction   is pin_b6_direction
  var bit led2            is pin_a1
  var bit led2_direction  is pin_a1_direction


Modified: trunk/sample/test/external/lcd/test_display_hd44780_4_line.jal
==============================================================================
--- trunk/sample/test/external/lcd/test_display_hd44780_4_line.jal       
(original)
+++ trunk/sample/test/external/lcd/test_display_hd44780_4_line.jal      Sat Mar 
  
7 10:48:13 2009
@@ -30,34 +30,15 @@
  ;@jallib use lcd_hd44780_4
  ;@jallib use led

-enable_digital_io()
-
-led_direction = output
-
+-- setup libs, io etc
  lcd_rs_direction        = output
  lcd_en_direction        = output
  lcd_dataport_direction  = output

  include print
  include lcd_hd44780_4
-;include js_replace
  include delay
-
-lcd_init()                  ; init the lcd
-
-for 4 loop                              -- blink LED 4 times to indicate  
startup
-   LED = on
-   delay_100ms(2)
-   LED = off
-   delay_100ms(2)
-end loop
-
-
-
---------------------------------------------------------------------------
-------------- MAIN program -----------------------------------------------
---------------------------------------------------------------------------
-
+lcd_init()                              -- initialize LCD



@@ -85,13 +66,16 @@
     lcd = "e"
     lcd = "s"
     lcd = "t"
-   delay_100ms (10)
-
+;   delay_100ms (10)

-   forever loop

-      lcd_cursor_position (2, 1)
-
+-- Define all unit tests required
+-- (testname string constants are optional)
+
+const byte testname_a[] = "shift test"
+procedure unit_test_a() is
+
+      lcd_cursor_position (2, 1)
        print_string(lcd, teststring)

        delay_100ms (10)
@@ -99,6 +83,17 @@
        delay_100ms (10)
        lcd_shift_left (4)
        delay_100ms (10)
+
+end procedure
+
+const byte testname_b[] = "blink on test"
+procedure unit_test_b() is
+
+      lcd_cursor_position (2, 1)
+
+
+      lcd_cursor_position (2, 1)
+      print_string(lcd, teststring)
        lcd_cursor_blink_display (on,on,on)
        delay_100ms (10)
        lcd_cursor_shift_left (4)
@@ -110,6 +105,12 @@
        lcd_home()
        delay_100ms (10)
        lcd_clear_screen()
+
+end procedure
+
+
+const byte testname_c[] = "blink off test"
+procedure unit_test_c() is

        lcd_cursor_blink_display (off,off,on)
        lcd_clear_line  (2)
@@ -123,6 +124,10 @@
  ;      lcd_bvalue_dp_line_pos_left_sign ( value, 0, 1, 5, true, false)
        delay_100ms (20)
        lcd_clear_screen()
+end procedure
+
+const byte testname_d[] = "blink off test"
+procedure unit_test_d() is

  ;      lcd_bvalue_dp_line_pos_left_sign ( 200, 0, 1, 1, true, false)
  ;      delay_100ms (10)
@@ -172,6 +177,10 @@
  ;      lcd_cursor_position (1, 5)
  ;      lcd_date ( day, month, yearw, "/", false )
  ;      delay_100ms (30)
+end procedure
+
+const byte testname_e[] = "hex run test"
+procedure unit_test_e() is

        lcd_clear_screen()

@@ -205,6 +214,16 @@

        lcd_clear_screen()

- end loop
+end procedure
+
+
+--  
-----------------------------------------------------------------------------
+--  
-----------------------------------------------------------------------------
+-- include testconsole after definition of unit tests
+--  
-----------------------------------------------------------------------------
+--  
-----------------------------------------------------------------------------
+include serial_testconsole
+testconsole_init()
+testconsole()  -- contains forever loop



Modified: trunk/sample/test/external/lcd/test_lcd_hd44780_4.jal
==============================================================================
--- trunk/sample/test/external/lcd/test_lcd_hd44780_4.jal       (original)
+++ trunk/sample/test/external/lcd/test_lcd_hd44780_4.jal       Sat Mar  7  
10:48:13 2009
@@ -36,8 +36,7 @@
  lcd_en_direction        = output
  lcd_dataport_direction  = output

-;include lcd_hd44780_4                   -- LCD library with 4 data lines
-include lcd_hd44780_4
+include lcd_hd44780_4                   -- LCD library with 4 data lines
  include print                           -- formatted output library

  for 4 loop                              -- blink LED 4 times to indicate  
startup

Added: trunk/sample/test/peripheral/usart/serial_testconsole.jal
==============================================================================
--- (empty file)
+++ trunk/sample/test/peripheral/usart/serial_testconsole.jal   Sat Mar  7  
10:48:13 2009
@@ -0,0 +1,170 @@
+-- ------------------------------------------------------
+-- Title: Serial test console
+--
+-- Author: Joep Suijs, Copyright (c) 2009..2009, 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: support lib for testing
+-- --
+-- This file provides a framework to select (unit) tests via the
+-- serial port.
+--
+-- Sources:
+--
+-- Notes:
+-- setup: a terminal program connected to the serial port
+--
+-- ------------------------------------------------------
+
+include serial_hardware
+include delay
+include print                       -- output library
+
+procedure testconsole_init() is
+   serial_hw_init()
+
+   led_direction = output
+   for 2 loop
+      LED = on
+      delay_100ms(1)
+      LED = off
+      delay_100ms(1)
+   end loop
+
+end procedure
+
+--  
-----------------------------------------------------------------------------
+-- run_test -
+--  
-----------------------------------------------------------------------------
+-- conditional compile enables automatic adjustment to up to 26 tests.
+--  
-----------------------------------------------------------------------------
+procedure _run_test(byte in nr) is
+   if (defined(unit_test_a) == true) then  if (nr == "A") then  
unit_test_a() end if end if
+   if (defined(unit_test_b) == true) then  if (nr == "B") then  
unit_test_b() end if end if
+   if (defined(unit_test_c) == true) then  if (nr == "C") then  
unit_test_c() end if end if
+   if (defined(unit_test_d) == true) then  if (nr == "D") then  
unit_test_d() end if end if
+   if (defined(unit_test_e) == true) then  if (nr == "E") then  
unit_test_e() end if end if
+   if (defined(unit_test_f) == true) then  if (nr == "F") then  
unit_test_f() end if end if
+   if (defined(unit_test_g) == true) then  if (nr == "G") then  
unit_test_g() end if end if
+   if (defined(unit_test_h) == true) then  if (nr == "H") then  
unit_test_h() end if end if
+   if (defined(unit_test_i) == true) then  if (nr == "I") then  
unit_test_i() end if end if
+   if (defined(unit_test_j) == true) then  if (nr == "J") then  
unit_test_j() end if end if
+   if (defined(unit_test_k) == true) then  if (nr == "K") then  
unit_test_k() end if end if
+   if (defined(unit_test_l) == true) then  if (nr == "L") then  
unit_test_l() end if end if
+   if (defined(unit_test_m) == true) then  if (nr == "M") then  
unit_test_m() end if end if
+   if (defined(unit_test_n) == true) then  if (nr == "N") then  
unit_test_n() end if end if
+   if (defined(unit_test_o) == true) then  if (nr == "O") then  
unit_test_o() end if end if
+   if (defined(unit_test_p) == true) then  if (nr == "P") then  
unit_test_p() end if end if
+   if (defined(unit_test_q) == true) then  if (nr == "Q") then  
unit_test_q() end if end if
+   if (defined(unit_test_r) == true) then  if (nr == "R") then  
unit_test_r() end if end if
+   if (defined(unit_test_s) == true) then  if (nr == "S") then  
unit_test_s() end if end if
+   if (defined(unit_test_t) == true) then  if (nr == "T") then  
unit_test_t() end if end if
+   if (defined(unit_test_u) == true) then  if (nr == "U") then  
unit_test_u() end if end if
+   if (defined(unit_test_v) == true) then  if (nr == "V") then  
unit_test_v() end if end if
+   if (defined(unit_test_w) == true) then  if (nr == "W") then  
unit_test_w() end if end if
+   if (defined(unit_test_x) == true) then  if (nr == "X") then  
unit_test_x() end if end if
+   if (defined(unit_test_y) == true) then  if (nr == "Y") then  
unit_test_y() end if end if
+   if (defined(unit_test_z) == true) then  if (nr == "Z") then  
unit_test_z() end if end if
+end procedure
+
+--  
-----------------------------------------------------------------------------
+-- _print_default_testmsg
+--  
-----------------------------------------------------------------------------
+--  
-----------------------------------------------------------------------------
+const byte default_tst_msg1[] = "unit test '"
+const byte default_tst_msg2[] = "' - "
+procedure _print_default_testmsg(byte in nr) is
+  print_string(serial_hw_data, default_tst_msg1)
+  serial_hw_data = nr
+  print_string(serial_hw_data, default_tst_msg2)
+end procedure
+
+--  
-----------------------------------------------------------------------------
+-- print_testname - print message (custom or standard) for existing tests
+--  
-----------------------------------------------------------------------------
+-- conditional compile enables automatic adjustment to up to 26 tests.
+--  
-----------------------------------------------------------------------------
+function _print_testname(byte in nr) return bit is
+
+   _print_default_testmsg(nr)
+
+   if (defined(unit_test_a) == true) then if (nr == "A") then if  
(defined(testname_a) == true) then print_string(serial_hw_data, testname_a)  
end if return true end if end if
+   if (defined(unit_test_b) == true) then if (nr == "B") then if  
(defined(testname_b) == true) then print_string(serial_hw_data, testname_b)  
end if return true end if end if
+   if (defined(unit_test_c) == true) then if (nr == "C") then if  
(defined(testname_c) == true) then print_string(serial_hw_data, testname_c)  
end if return true end if end if
+   if (defined(unit_test_d) == true) then if (nr == "D") then if  
(defined(testname_d) == true) then print_string(serial_hw_data, testname_d)  
end if return true end if end if
+   if (defined(unit_test_e) == true) then if (nr == "E") then if  
(defined(testname_e) == true) then print_string(serial_hw_data, testname_e)  
end if return true end if end if
+   if (defined(unit_test_f) == true) then if (nr == "F") then if  
(defined(testname_f) == true) then print_string(serial_hw_data, testname_f)  
end if return true end if end if
+   if (defined(unit_test_g) == true) then if (nr == "G") then if  
(defined(testname_g) == true) then print_string(serial_hw_data, testname_g)  
end if return true end if end if
+   if (defined(unit_test_h) == true) then if (nr == "H") then if  
(defined(testname_h) == true) then print_string(serial_hw_data, testname_h)  
end if return true end if end if
+   if (defined(unit_test_i) == true) then if (nr == "I") then if  
(defined(testname_i) == true) then print_string(serial_hw_data, testname_i)  
end if return true end if end if
+   if (defined(unit_test_j) == true) then if (nr == "J") then if  
(defined(testname_j) == true) then print_string(serial_hw_data, testname_j)  
end if return true end if end if
+   if (defined(unit_test_k) == true) then if (nr == "K") then if  
(defined(testname_k) == true) then print_string(serial_hw_data, testname_k)  
end if return true end if end if
+   if (defined(unit_test_l) == true) then if (nr == "L") then if  
(defined(testname_l) == true) then print_string(serial_hw_data, testname_l)  
end if return true end if end if
+   if (defined(unit_test_m) == true) then if (nr == "M") then if  
(defined(testname_m) == true) then print_string(serial_hw_data, testname_m)  
end if return true end if end if
+   if (defined(unit_test_n) == true) then if (nr == "N") then if  
(defined(testname_n) == true) then print_string(serial_hw_data, testname_n)  
end if return true end if end if
+   if (defined(unit_test_o) == true) then if (nr == "O") then if  
(defined(testname_o) == true) then print_string(serial_hw_data, testname_o)  
end if return true end if end if
+   if (defined(unit_test_p) == true) then if (nr == "P") then if  
(defined(testname_p) == true) then print_string(serial_hw_data, testname_p)  
end if return true end if end if
+   if (defined(unit_test_q) == true) then if (nr == "Q") then if  
(defined(testname_q) == true) then print_string(serial_hw_data, testname_q)  
end if return true end if end if
+   if (defined(unit_test_r) == true) then if (nr == "R") then if  
(defined(testname_r) == true) then print_string(serial_hw_data, testname_r)  
end if return true end if end if
+   if (defined(unit_test_s) == true) then if (nr == "S") then if  
(defined(testname_s) == true) then print_string(serial_hw_data, testname_s)  
end if return true end if end if
+   if (defined(unit_test_t) == true) then if (nr == "T") then if  
(defined(testname_t) == true) then print_string(serial_hw_data, testname_t)  
end if return true end if end if
+   if (defined(unit_test_u) == true) then if (nr == "U") then if  
(defined(testname_u) == true) then print_string(serial_hw_data, testname_u)  
end if return true end if end if
+   if (defined(unit_test_v) == true) then if (nr == "V") then if  
(defined(testname_v) == true) then print_string(serial_hw_data, testname_v)  
end if return true end if end if
+   if (defined(unit_test_w) == true) then if (nr == "W") then if  
(defined(testname_w) == true) then print_string(serial_hw_data, testname_w)  
end if return true end if end if
+   if (defined(unit_test_x) == true) then if (nr == "X") then if  
(defined(testname_x) == true) then print_string(serial_hw_data, testname_x)  
end if return true end if end if
+   if (defined(unit_test_y) == true) then if (nr == "Y") then if  
(defined(testname_y) == true) then print_string(serial_hw_data, testname_y)  
end if return true end if end if
+   if (defined(unit_test_z) == true) then if (nr == "Z") then if  
(defined(testname_z) == true) then print_string(serial_hw_data, testname_z)  
end if return true end if end if
+
+   return false;
+end function
+
+--  
-----------------------------------------------------------------------------
+-- testconsole - this is the main test loop
+--  
-----------------------------------------------------------------------------
+--  
-----------------------------------------------------------------------------
+procedure testconsole() is
+   var byte char
+   var byte testnr
+   const byte test_ready_msg[] = "Testconsole ready.\r\n"
+
+   forever loop
+
+      print_string(serial_hw_data, test_ready_msg)
+      testnr = 0
+
+      -- wait for char
+      LED = on
+       while (serial_hw_read(char) == false) loop end loop
+      LED = off
+
+          toupper(char)  -- convert testcmd to upper case
+      if ((char >= "A") & (char <= "Z")) then
+         -- valid test range
+         testnr   = char               -- A...Z
+       end if          
+
+      -- print test name
+      if (testnr != 0) then
+         if(_print_testname(testnr) == false) then
+            -- test does not exist
+            const byte unkown_tst_msg[] = "unknown unit test."
+            print_string(serial_hw_data, unkown_tst_msg)
+           testnr = 0
+         end if
+         print_crlf(serial_hw_data)
+      end if
+       
+      -- execute test
+      if (testnr > 0) then
+         _run_test(testnr)
+      end if
+
+   end loop
+
+end procedure

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