Author: jsuijs
Date: Thu Jan  1 12:32:23 2009
New Revision: 695

Removed:
    trunk/unvalidated/compiler/jav2-manual_fixed.html
Modified:
    trunk/unvalidated/compiler/JalV2-manual.html
    trunk/unvalidated/include/peripheral/i2c/i2c_software.jal

Log:


Modified: trunk/unvalidated/compiler/JalV2-manual.html
==============================================================================
--- trunk/unvalidated/compiler/JalV2-manual.html        (original)
+++ trunk/unvalidated/compiler/JalV2-manual.html        Thu Jan  1 12:32:23 2009
@@ -1,3 +1,4 @@
+<a name="top">
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  <HTML>
  <HEAD>
@@ -91,7 +92,7 @@
  </DIV>
  <P><BR><BR>
  </P>
-<H1 CLASS="western">1. Introduction</H1>
+<a name="0.1. Introduction|outline"><H1 CLASS="western">1.  
Introduction</H1>
  <P STYLE="margin-bottom: 0in">This text is not meant to be a
  programming tutorial &ndash; the reader is expected to have some
  programming background and understand concepts like procedure,
@@ -131,7 +132,7 @@
  or a semi-colon (&quot;<FONT FACE="Courier, monospace"><FONT  
SIZE=2>;</FONT></FONT>&quot;).
  Once a comment mark has been found, the comment continues until the
  end of the current line.</P>
-<H1 CLASS="western">2. Conventions Used in This Text</H1>
+<a name="0.2. Conventions Used in This Text|outline"><H1  
CLASS="western">2. Conventions Used in This Text</H1>
  <P><FONT FACE="Courier, monospace"><FONT SIZE=2>Fixed Font</FONT></FONT>
  : JALv2 program</P>
  <P><FONT FACE="Courier, monospace"><FONT SIZE=2>UPPER CASE</FONT></FONT>
@@ -148,7 +149,7 @@
  : a single JALv2 statement (assignment, flow control, etc.)</P>
  <P><FONT FACE="Courier, monospace"><FONT SIZE=2>statement  
block</FONT></FONT>
  : one or more JALv2 statements; implies a block</P>
-<H1 CLASS="western">3. Program Structure</H1>
+<a name="0.3. Program Structure|outline"><H1 CLASS="western">3. Program  
Structure</H1>
  <P>A program is a series of statements. Like BASIC, the statements
  simply begin. Procedures and Functions are skipped unless explicitly
  called. Identifier scoping looks like:</P>
@@ -206,7 +207,7 @@
  identifiers defined in proc1, or proc2 (so it cannot see proc2a or
  proc2b). Proc2 can see proc2a and proc2b. Proc2a and proc2b can see
  A2, B2, C2, proc1, A, B, and C</P>
-<H1 CLASS="western">4. Identifiers</H1>
+<a name="0.4. Identifiers|outline"><H1 CLASS="western">4. Identifiers</H1>
  <P>An identifier may begin with an underscore (&ldquo;_&rdquo;) or a
  letter, and may be followed by any number of letters, numbers, or
  underscores. By convention, all identifiers beginning with &ldquo;_&rdquo;
@@ -237,14 +238,14 @@
  is defined in a different block. This is generally a bad idea since
  when reading the program one might be confused about what <FONT  
FACE="Courier, monospace"><FONT SIZE=2>x</FONT></FONT>
  is.</P>
-<H1 CLASS="western">5. Types</H1>
+<a name="0.5. Types|outline"><H1 CLASS="western">5. Types</H1>
  <P>There are three of variables in JALv2 &ndash; <FONT FACE="Courier,  
monospace"><FONT SIZE=2>BIT</FONT></FONT>,
  <FONT FACE="Courier, monospace"><FONT SIZE=2>BYTE</FONT></FONT>, and
  <FONT FACE="Courier, monospace"><FONT SIZE=2>SBYTE</FONT></FONT>.</P>
-<H2 CLASS="western">5.1 BIT</H2>
+<a name="0.0.5.1 BIT|outline""><H2 CLASS="western">5.1 BIT</H2>
  <P>A single bit variable useful for addressing individual pins in a
  port for example.</P>
-<H2 CLASS="western">5.2 BYTE[*cexpr]</H2>
+<a name="0.0.5.2 BYTE[*cexpr]|outline""><H2 CLASS="western">5.2  
BYTE[*cexpr]</H2>
  <P>A single or multi-byte unsigned variable. <FONT FACE="Courier,  
monospace"><FONT SIZE=2>cexpr</FONT></FONT>,
  if present, sets the width (in BYTEs). JALv2 has two useful aliases,
  <FONT FACE="Courier, monospace"><FONT SIZE=2>WORD</FONT></FONT> which
@@ -254,14 +255,14 @@
  These are not the only allowed sizes. It is useful to have <FONT  
FACE="Courier, monospace"><FONT SIZE=2>BYTE*3</FONT></FONT>
  for some fixed-point operations, or even <FONT FACE="Courier,  
monospace"><FONT SIZE=2>BYTE*8</FONT></FONT>
  to prevent overflow in operations.</P>
-<H2 CLASS="western">5.3 SBYTE[*cexpr]</H2>
+<a name="0.0.5.3 SBYTE[*cexpr]|outline""><H2 CLASS="western">5.3  
SBYTE[*cexpr]</H2>
  <P>A single or multi-byte signed variable. <FONT FACE="Courier,  
monospace"><FONT SIZE=2>cexpr</FONT></FONT>,
  if present, sets the width (in BYTEs). Again JALv2 has two useful
  aliases, <FONT FACE="Courier, monospace"><FONT SIZE=2>SWORD</FONT></FONT>
  which is <FONT FACE="Courier, monospace"><FONT  
SIZE=2>SBYTE*2</FONT></FONT>,
  and <FONT FACE="Courier, monospace"><FONT SIZE=2>SDWORD</FONT></FONT>
  which is <FONT FACE="Courier, monospace"><FONT  
SIZE=2>SBYTE*4</FONT></FONT>.</P>
-<H2 CLASS="western">5.4 Universal</H2>
+<a name="0.0.5.4 Universal|outline""><H2 CLASS="western">5.4 Universal</H2>
  <P>The <FONT FACE="Courier, monospace"><FONT SIZE=2>UNIVERSAL</FONT></FONT>
  type is the type assumed for unnamed constants and literals.
  Internally, it is 32 bits wide, either signed or unsigned. When used
@@ -269,8 +270,8 @@
  operand. In the event that the <FONT FACE="Courier, monospace"><FONT  
SIZE=2>UNIVERSAL</FONT></FONT>
  constant will not fit within the other operand and warning will be
  generated.</P>
-<H1 CLASS="western">6. Constants</H1>
-<H2 CLASS="western">6.1 Literal</H2>
+<a name="0.6. Constants|outline"><H1 CLASS="western">6. Constants</H1>
+<a name="0.0.6.1 Literal|outline""><H2 CLASS="western">6.1 Literal</H2>
  <P>A literal constant is simply a number. It has the <FONT FACE="Courier,  
monospace"><FONT SIZE=2>UNIVERSAL</FONT></FONT>
  type. By default, literal constants are assumed to be decimal, but
  this can be overridden with the following prefixes:</P>
@@ -293,7 +294,7 @@
  <P><FONT FACE="Courier New, monospace"><FONT SIZE=2>{ cexpr1, cexpr2,
  ... }<FONT FACE="Times New Roman, serif"><FONT SIZE=3> ; defines a
  universal array.</FONT></FONT></FONT></FONT></P>
-<H2 CLASS="western">6.2 Named</H2>
+<a name="0.0.6.2 Named|outline""><H2 CLASS="western">6.2 Named</H2>
  <P>Syntax:</P>
  <P STYLE="margin-left: 0.49in"><FONT FACE="Courier, monospace"><FONT  
SIZE=2>CONST
  [type] identifier1 &ldquo;=&rdquo; cexpr1[, identifier2 &ldquo;=&rdquo;
@@ -316,7 +317,7 @@
  Array elements are numbered 0 through <FONT FACE="Courier,  
monospace"><FONT SIZE=2>cexpr
  - 1</FONT></FONT>. A constant array is limited by available program
  space in the destination device.</P>
-<H1 CLASS="western">7. Variables</H1>
+<a name="0.7. Variables|outline"><H1 CLASS="western">7. Variables</H1>
  <P>Syntax:</P>
  <P STYLE="margin-left: 0.5in"><FONT FACE="Courier, monospace"><FONT  
SIZE=2>VAR
  [VOLATILE] <I>type</I> identifier[ [&quot;[&quot; cexpr &quot;]&quot;]
@@ -372,7 +373,7 @@
  alias, the syntax is:</P>
  <P STYLE="margin-left: 0.5in"><FONT FACE="Courier, monospace"><FONT  
SIZE=2>VAR
  [VOLATILE] type identifier1 IS identifier2</FONT></FONT></P>
-<H1 CLASS="western">8. Expressions</H1>
+<a name="0.8. Expressions|outline"><H1 CLASS="western">8. Expressions</H1>
  <P>Now that we have variables and constants, it's time to create
  expressions. An expression is simply value (variables or constants)
  and operators. The operators of JALv2 are:</P>
@@ -662,8 +663,8 @@
  result is unsigned.</P>
  <P>If one operand is wider than the other, the other operand will be
  promoted to the wider type.</P>
-<H1 CLASS="western">9. Flow Control</H1>
-<H2 CLASS="western">9.1 BLOCK</H2>
+<a name="0.9. Flow Control|outline"><H1 CLASS="western">9. Flow  
Control</H1>
+<a name="0.0.9.1 BLOCK|outline""><H2 CLASS="western">9.1 BLOCK</H2>
  <P STYLE="margin-bottom: 0in">Syntax:</P>
  <P STYLE="margin-left: 0.5in; margin-bottom: 0in"><FONT FACE="Courier,  
monospace"><FONT SIZE=2>BLOCK</FONT></FONT></P>
  <P STYLE="margin-left: 0.7in; margin-bottom: 0in"><FONT FACE="Courier,  
monospace"><FONT SIZE=2>statement
@@ -676,7 +677,7 @@
  variables defined in this block go out of scope at the block. Mainly
  useful with the <FONT FACE="Courier, monospace"><FONT  
SIZE=2>CASE</FONT></FONT>
  statement (below).</P>
-<H2 CLASS="western">9.2 CASE</H2>
+<a name="0.0.9.2 CASE|outline""><H2 CLASS="western">9.2 CASE</H2>
  <P STYLE="margin-bottom: 0in">Syntax:</P>
  <P STYLE="margin-left: 0.51in; margin-bottom: 0in"><FONT FACE="Courier,  
monospace"><FONT SIZE=2>CASE
  expr OF</FONT></FONT></P>
@@ -705,7 +706,7 @@
  the <FONT FACE="Courier, monospace"><FONT SIZE=2>END  
CASE.</FONT></FONT></P>
  <P STYLE="margin-bottom: 0in">Each <FONT FACE="Courier, monospace"><FONT  
SIZE=2>cexpr</FONT></FONT>
  must evaluate to a unique value.</P>
-<H2 CLASS="western">9.3 FOR</H2>
+<a name="0.0.9.3 FOR|outline""><H2 CLASS="western">9.3 FOR</H2>
  <P>Syntax:</P>
  <P STYLE="margin-left: 0.5in"><FONT FACE="Courier, monospace"><FONT  
SIZE=2>FOR
  expr [USING var] LOOP</FONT></FONT></P>
@@ -724,7 +725,7 @@
  not large enough to hold <FONT FACE="Courier, monospace"><FONT  
SIZE=2>expr</FONT></FONT>,
  a warning is generated. If <FONT FACE="Courier New, monospace"><FONT  
SIZE=2>[exit
  loop]</FONT></FONT> is used, the loop is immediately exited.</P>
-<H2 CLASS="western">9.4 FOREVER</H2>
+<a name="0.0.9.4 FOREVER|outline""><H2 CLASS="western">9.4 FOREVER</H2>
  <P>Syntax:</P>
  <P STYLE="margin-left: 0.51in"><FONT FACE="Courier, monospace"><FONT  
SIZE=2>FOREVER
  LOOP</FONT></FONT></P>
@@ -739,7 +740,7 @@
  loop]</FONT></FONT> is encountered, in which case the loop is
  immediately terminated.. This is commonly used for the main loop in a
  program because an embedded program like this never ends.</P>
-<H2 CLASS="western">9.5 IF</H2>
+<a name="0.0.9.5 IF|outline""><H2 CLASS="western">9.5 IF</H2>
  <P>Syntax:</P>
  <P STYLE="margin-left: 0.51in"><FONT FACE="Courier, monospace"><FONT  
SIZE=2>IF
  expr THEN</FONT></FONT></P>
@@ -775,7 +776,7 @@
  is a dummy block that won't even be parsed!</FONT></FONT></P>
  <P STYLE="margin-left: 0.52in; margin-bottom: 0in"><FONT FACE="Courier,  
monospace"><FONT SIZE=2>END
  IF</FONT></FONT></P>
-<H2 CLASS="western">9.6 REPEAT</H2>
+<a name="0.0.9.6 REPEAT|outline""><H2 CLASS="western">9.6 REPEAT</H2>
  <P STYLE="margin-bottom: 0in">Syntax:</P>
  <P STYLE="margin-left: 0.51in; margin-bottom: 0in"><FONT FACE="Courier,  
monospace"><FONT SIZE=2>REPEAT</FONT></FONT></P>
  <P STYLE="margin-left: 0.7in; margin-bottom: 0in"><FONT FACE="Courier,  
monospace"><FONT SIZE=2>statement
@@ -786,7 +787,7 @@
  block</FONT></FONT> will be executed until <FONT FACE="Courier,  
monospace"><FONT SIZE=2>expr</FONT></FONT>
  evaluates to a non-zero value, or until <FONT FACE="Courier,  
monospace"><FONT SIZE=2>[exit
  loop] </FONT></FONT>is encountered.</P>
-<H2 CLASS="western">9.7 WHILE</H2>
+<a name="0.0.9.7 WHILE|outline""><H2 CLASS="western">9.7 WHILE</H2>
  <P STYLE="margin-bottom: 0in">Syntax:</P>
  <P STYLE="margin-left: 0.51in; margin-bottom: 0in"><FONT FACE="Courier,  
monospace"><FONT SIZE=2>WHILE
  expr LOOP</FONT></FONT></P>
@@ -806,7 +807,7 @@
  loop may never execute.</P>
  <P STYLE="margin-bottom: 0in"><BR>
  </P>
-<H1 CLASS="western">10. Sub-programs : Procedures and Functions</H1>
+<a name="0.10. Sub-programs : Procedures and Functions|outline""><H1  
CLASS="western">10. Sub-programs : Procedures and Functions</H1>
  <P>Syntax:</P>
  <P STYLE="margin-left: 0.51in"><FONT FACE="Courier, monospace"><FONT  
SIZE=2>PROCEDURE
  identifier [ &ldquo;(&ldquo; [VOLATILE] type { IN | OUT | IN OUT }
@@ -889,7 +890,7 @@
  </P>
  <P STYLE="margin-bottom: 0in">Recursion is fully supported but due to
  the overhead it is discouraged.</P>
-<H1 CLASS="western">11. Pseudo-variables</H1>
+<a name="0.11. Pseudo-variables|outline""><H1 CLASS="western">11.  
Pseudo-variables</H1>
  <P>Syntax:</P>
  <P STYLE="margin-left: 0.5in"><FONT FACE="Courier, monospace"><FONT  
SIZE=2>PROCEDURE
  identifier &ldquo;'&rdquo; PUT &ldquo;(&ldquo; type IN identifier2
@@ -911,7 +912,7 @@
  associated value is used is an implicit call to the function.</P>
  <P>If both a 'GET and 'PUT sub-program are defined, the parameter
  type of the 'PUT must match the return type of the 'GET.</P>
-<H1 CLASS="western">12. Interrupts</H1>
+<a name="0.12. Interrupts|outline""><H1 CLASS="western">12. Interrupts</H1>
  <P>Syntax:</P>
  <P STYLE="margin-left: 0.51in"><FONT FACE="Courier, monospace"><FONT  
SIZE=2>PROCEDURE
  identifier IS</FONT></FONT></P>
@@ -950,7 +951,7 @@
  should be used. Any JAL statements might invalidate the internal
  state of the compiler. If any interrupt handler is marked <FONT  
FACE="Courier, monospace"><FONT SIZE=2>FAST</FONT></FONT>
  then only one interrupt handler is allowed.</P>
-<H1 CLASS="western">13. Tasks</H1>
+<a name="0.13. Tasks|outline""><H1 CLASS="western">13. Tasks</H1>
  <P>Syntax:</P>
  <P STYLE="margin-left: 0.5in"><FONT FACE="Courier, monospace"><FONT  
SIZE=2>TASK
  identifier [ &ldquo;(&ldquo; parameter list &ldquo;)&rdquo; ]  
IS</FONT></FONT></P>
@@ -991,7 +992,7 @@
  LOOP</FONT></FONT></P>
  <P><BR><BR>
  </P>
-<H1 CLASS="western">14. Assembly</H1>
+<a name="0.14. Assembly|outline""><H1 CLASS="western">14. Assembly</H1>
  <P STYLE="margin-bottom: 0in">Finally, when all else fails, one can
  resort to in-line assembly. This can be in the form of a single
  statement:</P>

Modified: trunk/unvalidated/include/peripheral/i2c/i2c_software.jal
==============================================================================
--- trunk/unvalidated/include/peripheral/i2c/i2c_software.jal   (original)
+++ trunk/unvalidated/include/peripheral/i2c/i2c_software.jal   Thu Jan  1  
12:32:23 2009
@@ -16,7 +16,9 @@
  -- prototypes
  procedure  _i2c_wait()
  procedure _i2c_bit_in(bit out x)
-procedure _i2c_bit_out(bit in x)
+procedure _i2c_bit_out(bit in x)
+procedure i2c_start()
+procedure i2c_stop()

  -- ------------------------------------------------------------------------
  -- i2c_initialize - initialize the software i2c bus
@@ -27,9 +29,22 @@
  -- ------------------------------------------------------------------------
  procedure i2c_initialize() is
     i2c_scl              = low
-   i2c_scl_direction    = output
     i2c_sda              = low
-   i2c_sda_direction    = output
+   i2c_scl_direction    = high
+   i2c_sda_direction    = high
+
+   -- Clear the bus, regardless the state it is in.
+   --
+   -- This code is based on atmel AT24C32C datasheet, page 6
+   -- http://www.atmel.com/dyn/resources/prod_documents/doc5298.pdf
+   --
+   i2c_start()
+   for 9 loop
+      _i2c_bit_out(1);
+   end loop
+   i2c_start()
+   i2c_stop()
+
  end procedure

  -- ------------------------------------------------------------------------
@@ -67,9 +82,9 @@
     _i2c_wait()
     i2c_sda_direction   = low        -- data low
     _i2c_wait()
-   i2c_scl_direction  = low        -- clock low
+   i2c_scl_direction   = low        -- clock low
     _i2c_wait()
-   i2c_scl_direction  = high       -- clock high
+   i2c_scl_direction   = high       -- clock high
     _i2c_wait()
     i2c_sda_direction   = high       -- data high
     _i2c_wait()
@@ -93,18 +108,16 @@
     _i2c_wait()
     i2c_sda_direction    = high       -- data open
     _i2c_wait()
-   i2c_scl_direction   = high       -- clock high
+   i2c_scl_direction    = high       -- clock high
     _i2c_wait()
     while i2c_scl == low loop
     end loop                     -- wait for slow slave
-   -- a check for the slave's acknowledge
-   -- (data should be low)
-   -- could be added here
+
+   -- check for the slave's acknowledge
     r = ! i2c_sda
     _i2c_wait()
-   i2c_scl_direction   = low        -- clock low
+   i2c_scl_direction    = low        -- clock low
     _i2c_wait()
-   ;end procedure

     return r -- true = okay, false = no ack received
  end function
@@ -175,16 +188,17 @@
  -- ------------------------------------------------------------------------
  -- ------------------------------------------------------------------------
  procedure _i2c_bit_out(bit in x) is
-;    _i2c_wait()
-   i2c_sda_direction   = x           -- high data bit
+
+   i2c_sda_direction   = x          -- high data bit
     _i2c_wait()
     i2c_scl_direction  = high        -- clock high
     _i2c_wait()
     while i2c_scl == low loop
-   end loop                     -- wait for slow slave
+   end loop                         -- wait for slow slave
     _i2c_wait()
     i2c_scl_direction  = low         -- clock low
     _i2c_wait()
+
  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