00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00020 #include "sceptre.h"
00021 #include "device.h"
00022 #include "ds18b20.h"
00023
00024
00025 #ifdef THERMO_DEBUG
00026 #include <stdio.h>
00027 #endif
00028
00029
00030 int thermo_open(struct _reent *p_reent, const char *p_name, int flags, int mode);
00031 _ssize_t thermo_read(struct _reent *p_reent, int file, void *p_dst, size_t dst_size);
00032 _ssize_t thermo_write(struct _reent *p_reent, int file, const void *p_src, size_t src_size);
00033
00034
00038 device_table_entry_t thermo_device =
00039 {
00040 "thermo",
00041 SCEPTRE_THERMOMETER,
00042 thermo_open,
00043 NULL,
00044 thermo_read,
00045 thermo_write,
00046 NULL,
00047 NULL
00048 };
00049
00050
00071 int thermo_open(struct _reent *p_reent, const char *p_name, int flags, int mode)
00072 {
00073 #ifdef THERMO_DEBUG
00074 printf("thermo_open(%s,%d,%d)\n",p_name,flags,mode);
00075 #endif
00076
00077 if (ds18b20_init()==true)
00078 {
00079
00080 return DEVICE(SCEPTRE_THERMOMETER);
00081 }
00082 #ifdef THERMO_DEBUG
00083 printf("thermo_open failed\n");
00084 #endif
00085 p_reent->_errno = ENODEV;
00086 return -1;
00087 }
00088
00089
00105 _ssize_t thermo_read(struct _reent *p_reent, int file, void *p_dst, size_t dst_size)
00106 {
00107 int size = ds18b20_read(p_dst,dst_size);
00108 #ifdef THERMO_DEBUG
00109
00110 #endif
00111 if (size<0) p_reent->_errno = ENODEV;
00112 return size;
00113 }
00114
00115
00131 _ssize_t thermo_write(struct _reent *p_reent, int file, const void *p_src, size_t src_size)
00132 {
00133 int size = ds18b20_write(p_src,src_size);
00134 if (size<0) p_reent->_errno = ENODEV;
00135 return size;
00136 }