Revision: 1441 Author: jsuijs Date: Sat Oct 31 15:34:12 2009 Log: sqrt update, test added & profiler added http://code.google.com/p/jallib/source/detail?r=1441
Added: /trunk/include/jal/profiler.jal /trunk/test/jal/test_sqrt.jal Modified: /trunk/CHANGELOG /trunk/TORELEASE /trunk/include/jal/sqrt.jal ======================================= --- /dev/null +++ /trunk/include/jal/profiler.jal Sat Oct 31 15:34:12 2009 @@ -0,0 +1,95 @@ +-- ----------------------------------------------------------------------------- +-- Title: profiler.jal +-- 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 ZLIB license (http://www.opensource.org/licenses/zlib-license.html) +-- +-- Sources: +-- +-- Description: +-- This library provides procedures to profile code parts. +-- Intended for software development, uses timer1. +-- +-- ----------------------------------------------------------------------------- + + + +procedure profiler_setup(byte in resolution) is + + case resolution of + 0 : block + t1con = 0x00 ; TMR1 off, prescaler 1 (1 tick = 0.2 us @ 20 MHz, 32k = 6,5 ms ) + end block + 1 : block + t1con = 0x10 ; TMR1 off, prescaler 2 (1 tick = 0.4 us @ 20 MHz, 32k = 13 ms ) + end block + 2 : block + t1con = 0x20 ; TMR1 off, prescaler 4 (1 tick = 0.8 us @ 20 MHz, 32k = 26 ms ) + end block + otherwise block + t1con = 0x30 ; TMR1 off, prescaler 8 (1 tick = 1.6 us @ 20 MHz, 32k = 52 ms ) + end block + + end case +end procedure + + +const byte m1[] = "Profiler " +const byte m2[] = " us" + +procedure profiler_report(volatile byte out device) is +-- note: device does not work, probably due to compiler bug... +-- left it in to be fixed in time. + + ; calculate tick time in 1ns steps + var dword tick = target_clock + tick = 4000_000_000 / tick + case ((t1con & 0x30) / 0x10) of + 1 : block + tick = tick * 2 + end block + + 2 : block + tick = tick * 4 + end block + + 3 : block + tick = tick * 8 + end block + + end case + + tick = tick * TMR1 + tick = tick / 100 ; scale from ns to .1 us + + print_string(serial_hw_data, m1) + print_word_dec(serial_hw_data, tick / 10) + serial_hw_data = "." + print_word_dec(serial_hw_data, tick % 10) + print_string(serial_hw_data, m2) + print_crlf(serial_hw_data) + +end procedure + +procedure profiler_start is + pragma inline + + TMR1 = 0 + T1CON_TMR1ON = true +end procedure + +procedure profiler_stop is + pragma inline + + T1CON_TMR1ON = false +end procedure + +procedure profiler_stop_and_report (volatile byte in out device) is + pragma inline + + profiler_stop + profiler_report(device) +end procedure ======================================= --- /dev/null +++ /trunk/test/jal/test_sqrt.jal Sat Oct 31 15:34:12 2009 @@ -0,0 +1,61 @@ +-- ------------------------------------------------------ +-- Title: Test program for sqrt.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 + +include delay +include print + +-- set all IO as digital +enable_digital_io() + +-- setup serial (see echo.jal for more details) +;@jallib use serial +include serial_hardware +serial_hw_init() +include profiler + +include sqrt + +led_direction = output + +var word r + +forever loop + delay_100ms( 5 ) + LED = high + delay_100ms( 5 ) + LED = low + + -- serial_hw_data is a pseudo-var of the desired output-device. + serial_hw_data = "A" -- output an A to the serial port. + + profiler_setup(0) + + profiler_start() + r = sqrt32(65535*65533) + profiler_stop_and_report(serial_hw_data) + + print_word_dec(serial_hw_data, r) + +end loop + ======================================= --- /trunk/CHANGELOG Sat Oct 24 12:01:57 2009 +++ /trunk/CHANGELOG Sat Oct 31 15:34:12 2009 @@ -29,6 +29,8 @@ jal extension: - added delay_1s to delay library - provisional fix to make rtc_int_tmr0 library independent of ocsillator frequency + - profiler library to measure execution time of a procedure + - sqrt library samples: - seven_segment samples ======================================= --- /trunk/TORELEASE Sat Oct 24 12:01:57 2009 +++ /trunk/TORELEASE Sat Oct 31 15:34:12 2009 @@ -223,12 +223,14 @@ include/jal/format.jal include/jal/jascii.jal include/jal/print.jal +include/jal/profiler.jal include/jal/queue01.jal include/jal/queue02.jal include/jal/queue03.jal include/jal/queue04.jal include/jal/random.jal include/jal/rtc_isr_tmr0.jal +include/jal/sqrt.jal include/jal/unittest.jal # Peripherals ======================================= --- /trunk/include/jal/sqrt.jal Sun Oct 25 00:22:03 2009 +++ /trunk/include/jal/sqrt.jal Sat Oct 31 15:34:12 2009 @@ -1,18 +1,14 @@ --- Title: sqrt - dword sqrt --- Author: Joep Suijs, Copyright (c) 2009, all rights reserved. --- Adapted-by: +-- Title: sqrt.jal +-- Author: Kyle York, Copyright (c) 2009, all rights reserved. +-- Adapted-by: Joep Suijs -- 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 sqrt. --- The param is a dword, the result a word. Rounding of the result can be wrong +-- Description: this library provides sqrt for 16 and 32 bit vars, result is 8 or 16 bits. -- -- Sources: --- http://www.azillionmonkeys.com/qed/sqroot.html --- xest = (xest + y/xest) / 2 --- with the rigth preset of xest, the result is calculated in 4 itterations (+/- 1) -- @@ -39,3 +35,41 @@ return word(xest) end function + +function sqrt16(word in x) return byte is + var word m, y + + m = 0x4000 + y = 0 + while (m != 0) loop + var word b + + b = y | m + y = y >> 1 + if (x >= b) then + x = x - b + y = y | m + end if + m = m >> 2 + end loop + return byte(y) +end function + +function sqrt32(dword in x) return word is + var dword m, y + + m = 0x40000000 + y = 0 + while (m != 0) loop + var dword b + + b = y | m + y = y >> 1 + if (x >= b) then + x = x - b + y = y | m + end if + m = m >> 2 + end loop + return word(y) +end function --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
