![]() |
|
|||
File indexing completed on 2025-05-11 08:24:04
0001 /* Trivial i2c driver for the maxim DS1621 temperature sensor; 0002 * just implements reading constant conversions with 8-bit 0003 * resolution. 0004 * Demonstrates the implementation of a i2c high-level driver. 0005 */ 0006 0007 /* 0008 * Authorship 0009 * ---------- 0010 * This software was created by 0011 * Till Straumann <strauman@slac.stanford.edu>, 2005, 0012 * Stanford Linear Accelerator Center, Stanford University. 0013 * 0014 * Acknowledgement of sponsorship 0015 * ------------------------------ 0016 * This software was produced by 0017 * the Stanford Linear Accelerator Center, Stanford University, 0018 * under Contract DE-AC03-76SFO0515 with the Department of Energy. 0019 * 0020 * Government disclaimer of liability 0021 * ---------------------------------- 0022 * Neither the United States nor the United States Department of Energy, 0023 * nor any of their employees, makes any warranty, express or implied, or 0024 * assumes any legal liability or responsibility for the accuracy, 0025 * completeness, or usefulness of any data, apparatus, product, or process 0026 * disclosed, or represents that its use would not infringe privately owned 0027 * rights. 0028 * 0029 * Stanford disclaimer of liability 0030 * -------------------------------- 0031 * Stanford University makes no representations or warranties, express or 0032 * implied, nor assumes any liability for the use of this software. 0033 * 0034 * Stanford disclaimer of copyright 0035 * -------------------------------- 0036 * Stanford University, owner of the copyright, hereby disclaims its 0037 * copyright and all other rights in this software. Hence, anyone may 0038 * freely use it for any purpose without restriction. 0039 * 0040 * Maintenance of notices 0041 * ---------------------- 0042 * In the interest of clarity regarding the origin and status of this 0043 * SLAC software, this and all the preceding Stanford University notices 0044 * are to remain affixed to any copy or derivative of this software made 0045 * or distributed by the recipient and are to be affixed to any copy of 0046 * software made or distributed by the recipient that contains a copy or 0047 * derivative of this software. 0048 * 0049 * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03 0050 */ 0051 #include <rtems.h> 0052 #include <rtems/libi2c.h> 0053 0054 #include <libchip/i2c-ds1621.h> 0055 0056 #include <rtems/libio.h> 0057 0058 0059 static rtems_status_code 0060 ds1621_init (rtems_device_major_number major, rtems_device_minor_number minor, 0061 void *arg) 0062 { 0063 int sc; 0064 unsigned char csr[2] = { DS1621_CMD_CSR_ACCESS, 0 }, cmd; 0065 0066 /* First start command acquires a lock for the bus */ 0067 0068 /* Initialize; switch continuous conversion on */ 0069 sc = rtems_libi2c_start_write_bytes (minor, csr, 1); 0070 if (sc < 0) 0071 return -sc; 0072 0073 sc = rtems_libi2c_start_read_bytes (minor, csr + 1, 1); 0074 if (sc < 0) 0075 return -sc; 0076 0077 csr[1] &= ~DS1621_CSR_1SHOT; 0078 0079 sc = rtems_libi2c_start_write_bytes (minor, csr, 2); 0080 if (sc < 0) 0081 return -sc; 0082 0083 /* Start conversion */ 0084 cmd = DS1621_CMD_START_CONV; 0085 0086 sc = rtems_libi2c_start_write_bytes (minor, &cmd, 1); 0087 if (sc < 0) 0088 return -sc; 0089 0090 /* sending 'stop' relinquishes the bus mutex -- don't hold it 0091 * across system calls! 0092 */ 0093 return rtems_libi2c_send_stop (minor); 0094 } 0095 0096 static rtems_status_code 0097 ds1621_read (rtems_device_major_number major, rtems_device_minor_number minor, 0098 void *arg) 0099 { 0100 int sc; 0101 rtems_libio_rw_args_t *rwargs = arg; 0102 unsigned char cmd = DS1621_CMD_READ_TEMP; 0103 0104 sc = rtems_libi2c_start_write_bytes (minor, &cmd, 1); 0105 if (sc < 0) 0106 return -sc; 0107 if (sc < 1) 0108 return RTEMS_IO_ERROR; 0109 sc = rtems_libi2c_start_read_bytes(minor, (unsigned char *)rwargs->buffer, 1); 0110 if (sc < 0) { 0111 rwargs->bytes_moved = 0; 0112 return -sc; 0113 } 0114 rwargs->bytes_moved = 1; 0115 return rtems_libi2c_send_stop (minor); 0116 } 0117 0118 static rtems_driver_address_table myops = { 0119 .initialization_entry = ds1621_init, 0120 .read_entry = ds1621_read, 0121 }; 0122 0123 static rtems_libi2c_drv_t my_drv_tbl = { 0124 .ops = &myops, 0125 .size = sizeof (my_drv_tbl), 0126 }; 0127 0128 rtems_libi2c_drv_t *i2c_ds1621_driver_descriptor = &my_drv_tbl;
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |