source: rtems/c/src/libchip/i2c/i2c-ds1621.c @ 06a36cd1

4.11
Last change on this file since 06a36cd1 was 06a36cd1, checked in by Joel Sherrill <joel.sherrill@…>, on Jul 7, 2011 at 10:15:25 PM

2011-07-07 Joel Sherrill <joel.sherrill@…>

  • libchip/display/disp_hcms29xx.c, libchip/flash/am29lv160.c, libchip/i2c/i2c-2b-eeprom.c, libchip/i2c/i2c-ds1621.c, libchip/i2c/spi-flash-m25p40.c, libchip/i2c/spi-fram-fm25l256.c, libchip/i2c/spi-memdrv.c, libchip/rtc/ds1375.c: Eliminate use of GNU old-style field designator extension as recommended by clang.
  • Property mode set to 100644
File size: 3.9 KB
Line 
1/* $Id$ */
2
3/* Trivial i2c driver for the maxim DS1621 temperature sensor;
4 * just implements reading constant conversions with 8-bit
5 * resolution.
6 * Demonstrates the implementation of a i2c high-level driver.
7 */
8
9/*
10 * Authorship
11 * ----------
12 * This software was created by
13 *     Till Straumann <strauman@slac.stanford.edu>, 2005,
14 *         Stanford Linear Accelerator Center, Stanford University.
15 *
16 * Acknowledgement of sponsorship
17 * ------------------------------
18 * This software was produced by
19 *     the Stanford Linear Accelerator Center, Stanford University,
20 *         under Contract DE-AC03-76SFO0515 with the Department of Energy.
21 *
22 * Government disclaimer of liability
23 * ----------------------------------
24 * Neither the United States nor the United States Department of Energy,
25 * nor any of their employees, makes any warranty, express or implied, or
26 * assumes any legal liability or responsibility for the accuracy,
27 * completeness, or usefulness of any data, apparatus, product, or process
28 * disclosed, or represents that its use would not infringe privately owned
29 * rights.
30 *
31 * Stanford disclaimer of liability
32 * --------------------------------
33 * Stanford University makes no representations or warranties, express or
34 * implied, nor assumes any liability for the use of this software.
35 *
36 * Stanford disclaimer of copyright
37 * --------------------------------
38 * Stanford University, owner of the copyright, hereby disclaims its
39 * copyright and all other rights in this software.  Hence, anyone may
40 * freely use it for any purpose without restriction.
41 *
42 * Maintenance of notices
43 * ----------------------
44 * In the interest of clarity regarding the origin and status of this
45 * SLAC software, this and all the preceding Stanford University notices
46 * are to remain affixed to any copy or derivative of this software made
47 * or distributed by the recipient and are to be affixed to any copy of
48 * software made or distributed by the recipient that contains a copy or
49 * derivative of this software.
50 *
51 * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
52 */
53#include <rtems.h>
54#include <rtems/libi2c.h>
55
56#include <libchip/i2c-ds1621.h>
57
58#include <rtems/libio.h>
59
60
61static rtems_status_code
62ds1621_init (rtems_device_major_number major, rtems_device_minor_number minor,
63             void *arg)
64{
65  int sc;
66  unsigned char csr[2] = { DS1621_CMD_CSR_ACCESS, 0 }, cmd;
67
68  /* First start command acquires a lock for the bus */
69
70  /* Initialize; switch continuous conversion on */
71  sc = rtems_libi2c_start_write_bytes (minor, csr, 1);
72  if (sc < 0)
73    return -sc;
74
75  sc = rtems_libi2c_start_read_bytes (minor, csr + 1, 1);
76  if (sc < 0)
77    return -sc;
78
79  csr[1] &= ~DS1621_CSR_1SHOT;
80
81  sc = rtems_libi2c_start_write_bytes (minor, csr, 2);
82  if (sc < 0)
83    return -sc;
84
85  /* Start conversion */
86  cmd = DS1621_CMD_START_CONV;
87
88  sc = rtems_libi2c_start_write_bytes (minor, &cmd, 1);
89  if (sc < 0)
90    return -sc;
91
92  /* sending 'stop' relinquishes the bus mutex -- don't hold it
93   * across system calls!
94   */
95  return rtems_libi2c_send_stop (minor);
96}
97
98static rtems_status_code
99ds1621_read (rtems_device_major_number major, rtems_device_minor_number minor,
100             void *arg)
101{
102  int sc;
103  rtems_libio_rw_args_t *rwargs = arg;
104  unsigned char cmd = DS1621_CMD_READ_TEMP;
105
106  sc = rtems_libi2c_start_write_bytes (minor, &cmd, 1);
107  if (sc < 0)
108    return -sc;
109  if (sc < 1)
110    return RTEMS_IO_ERROR;
111  sc = rtems_libi2c_start_read_bytes(minor, (unsigned char *)rwargs->buffer, 1);
112  if (sc < 0) {
113    rwargs->bytes_moved = 0;
114    return -sc;
115  }
116  rwargs->bytes_moved = 1;
117  return rtems_libi2c_send_stop (minor);
118}
119
120static rtems_driver_address_table myops = {
121  .initialization_entry = ds1621_init,
122  .read_entry =           ds1621_read,
123};
124
125static rtems_libi2c_drv_t my_drv_tbl = {
126  .ops =                  &myops,
127  .size =                 sizeof (my_drv_tbl),
128};
129
130rtems_libi2c_drv_t *i2c_ds1621_driver_descriptor = &my_drv_tbl;
Note: See TracBrowser for help on using the repository browser.