source: rtems/c/src/libchip/i2c/i2c-ds1621.c @ 40a24661

4.115
Last change on this file since 40a24661 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

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