avr-libc-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-libc-commit] [2138] Submitted by Ruwan Jayanetti:


From: Joerg Wunsch
Subject: [avr-libc-commit] [2138] Submitted by Ruwan Jayanetti:
Date: Tue, 08 Jun 2010 12:54:10 +0000

Revision: 2138
          http://svn.sv.gnu.org/viewvc/?view=rev&root=avr-libc&revision=2138
Author:   joerg_wunsch
Date:     2010-06-08 12:54:10 +0000 (Tue, 08 Jun 2010)
Log Message:
-----------
Submitted by Ruwan Jayanetti:
patch #6194: Twitest updated to handle larger EEPROM devices
* doc/examples/twitest/twitest.c: Implement the
WORD_ADDRESS_16BIT option.
* doc/examples/twitest/twitest.dox: Document the new option.

Ticket Links:
:-----------
    http://savannah.gnu.org/patch/?6194

Modified Paths:
--------------
    trunk/avr-libc/ChangeLog
    trunk/avr-libc/NEWS
    trunk/avr-libc/doc/examples/twitest/twitest.c
    trunk/avr-libc/doc/examples/twitest/twitest.dox

Modified: trunk/avr-libc/ChangeLog
===================================================================
--- trunk/avr-libc/ChangeLog    2010-06-08 12:18:40 UTC (rev 2137)
+++ trunk/avr-libc/ChangeLog    2010-06-08 12:54:10 UTC (rev 2138)
@@ -1,5 +1,13 @@
 2010-06-08  Joerg Wunsch <address@hidden>
 
+       Submitted by Ruwan Jayanetti:
+       patch #6194: Twitest updated to handle larger EEPROM devices
+       * doc/examples/twitest/twitest.c: Implement the
+       WORD_ADDRESS_16BIT option.
+       * doc/examples/twitest/twitest.dox: Document the new option.
+
+2010-06-08  Joerg Wunsch <address@hidden>
+
        Submitted by Gerben van den Broeke:
        patch #6555: malloc improvement
        * libc/stdlib/malloc.c (malloc): Speed up reallocations.

Modified: trunk/avr-libc/NEWS
===================================================================
--- trunk/avr-libc/NEWS 2010-06-08 12:18:40 UTC (rev 2137)
+++ trunk/avr-libc/NEWS 2010-06-08 12:54:10 UTC (rev 2138)
@@ -277,6 +277,7 @@
 
 * Contributed Patches:
 
+  [#6194] Twitest updated to handle larger EEPROM devices
   [#6500] Reentrant code faq
   [#6517] Pgmspace with float support
   [#6555] malloc improvement

Modified: trunk/avr-libc/doc/examples/twitest/twitest.c
===================================================================
--- trunk/avr-libc/doc/examples/twitest/twitest.c       2010-06-08 12:18:40 UTC 
(rev 2137)
+++ trunk/avr-libc/doc/examples/twitest/twitest.c       2010-06-08 12:54:10 UTC 
(rev 2138)
@@ -6,6 +6,12 @@
  * this stuff is worth it, you can buy me a beer in return.        Joerg Wunsch
  * ----------------------------------------------------------------------------
  */
+/*
+ * ----------------------------------------------------------------------------
+ * Updated to handle larger devices having 16-bit addresses
+ *                                                 (2007-09-05) Ruwan Jayanetti
+ * ----------------------------------------------------------------------------
+ */
 
 /* $Id$ */
 
@@ -62,6 +68,14 @@
 #define TWI_SLA_24CXX  0xa0    /* E2 E1 E0 = 0 0 0 */
 
 /*
+ * Note [3a]
+ * Device word address length for 24Cxx EEPROM
+ * Larger EEPROM devices (from 24C32) have 16-bit address
+ * Define or undefine according to the used device
+ */
+//#define WORD_ADDRESS_16BIT
+
+/*
  * Maximal number of iterations to wait for a device to respond for a
  * selection.  Should be large enough to allow for a pending write to
  * complete, but low enough to properly abort an infinite loop in case
@@ -146,8 +160,11 @@
  *
  * This requires two bus cycles: during the first cycle, the device
  * will be selected (master transmitter mode), and the address
- * transfered.  Address bits exceeding 256 are transfered in the
+ * transfered.
+ * Address bits exceeding 256 are transfered in the
  * E2/E1/E0 bits (subaddress bits) of the device selector.
+ * Address is sent in two dedicated 8 bit transfers
+ * for 16 bit address devices (larger EEPROM devices)
  *
  * The second bus cycle will reselect the device (repeated start
  * condition, going into master receiver mode), and transfer the data
@@ -162,8 +179,13 @@
   uint8_t sla, twcr, n = 0;
   int rv = 0;
 
+#ifndef WORD_ADDRESS_16BIT
   /* patch high bits of EEPROM address into SLA */
   sla = TWI_SLA_24CXX | (((eeaddr >> 8) & 0x07) << 1);
+#else
+  /* 16-bit address devices need only TWI Device Address */
+  sla = TWI_SLA_24CXX;
+#endif
 
   /*
    * Note [8]
@@ -211,6 +233,26 @@
       goto error;              /* must send stop condition */
     }
 
+#ifdef WORD_ADDRESS_16BIT
+  TWDR = (eeaddr >> 8);                /* 16-bit word address device, send 
high 8 bits of addr */
+  TWCR = _BV(TWINT) | _BV(TWEN); /* clear interrupt to start transmission */
+  while ((TWCR & _BV(TWINT)) == 0) ; /* wait for transmission */
+  switch ((twst = TW_STATUS))
+    {
+    case TW_MT_DATA_ACK:
+      break;
+
+    case TW_MT_DATA_NACK:
+      goto quit;
+
+    case TW_MT_ARB_LOST:
+      goto begin;
+
+    default:
+      goto error;              /* must send stop condition */
+    }
+#endif
+
   TWDR = eeaddr;               /* low 8 bits of addr */
   TWCR = _BV(TWINT) | _BV(TWEN); /* clear interrupt to start transmission */
   while ((TWCR & _BV(TWINT)) == 0) ; /* wait for transmission */
@@ -332,8 +374,13 @@
     endaddr = (eeaddr | (PAGE_SIZE - 1)) + 1;
   len = endaddr - eeaddr;
 
+#ifndef WORD_ADDRESS_16BIT
   /* patch high bits of EEPROM address into SLA */
   sla = TWI_SLA_24CXX | (((eeaddr >> 8) & 0x07) << 1);
+#else
+  /* 16-bit address devices need only TWI Device Address */
+  sla = TWI_SLA_24CXX;
+#endif
 
   restart:
   if (n++ >= MAX_ITER)
@@ -376,6 +423,26 @@
       goto error;              /* must send stop condition */
     }
 
+#ifdef WORD_ADDRESS_16BIT
+  TWDR = (eeaddr>>8);          /* 16 bit word address device, send high 8 bits 
of addr */
+  TWCR = _BV(TWINT) | _BV(TWEN); /* clear interrupt to start transmission */
+  while ((TWCR & _BV(TWINT)) == 0) ; /* wait for transmission */
+  switch ((twst = TW_STATUS))
+    {
+    case TW_MT_DATA_ACK:
+      break;
+
+    case TW_MT_DATA_NACK:
+      goto quit;
+
+    case TW_MT_ARB_LOST:
+      goto begin;
+
+    default:
+      goto error;              /* must send stop condition */
+    }
+#endif
+
   TWDR = eeaddr;               /* low 8 bits of addr */
   TWCR = _BV(TWINT) | _BV(TWEN); /* clear interrupt to start transmission */
   while ((TWCR & _BV(TWINT)) == 0) ; /* wait for transmission */

Modified: trunk/avr-libc/doc/examples/twitest/twitest.dox
===================================================================
--- trunk/avr-libc/doc/examples/twitest/twitest.dox     2010-06-08 12:18:40 UTC 
(rev 2137)
+++ trunk/avr-libc/doc/examples/twitest/twitest.dox     2010-06-08 12:54:10 UTC 
(rev 2138)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2002, Joerg Wunsch
+/* Copyright (c) 2002, 2010 Joerg Wunsch
    All rights reserved.
 
    Redistribution and use in source and binary forms, with or without
@@ -133,6 +133,14 @@
 simply assumes all subaddress bits are 0 for the smaller devices, so
 the E0, E1, and E2 inputs of the 24Cxx must be grounded.
 
+\par Note [3a]
+
+EEPROMs of type 24C32 and above cannot be addressed anymore even with
+the subaddress bit trick.  Thus, they require the upper address bits
+being sent separately on the bus.  When activating the
+\c WORD_ADDRESS_16BIT define, the algorithm implements that auxiliary
+address byte transmission.
+
 \par Note [4]
 
 For slow clocks, enable the 2 x U[S]ART clock multiplier, to improve




reply via email to

[Prev in Thread] Current Thread [Next in Thread]