Compare commits
5 Commits
1e9ad4c8bb
...
e4157b37dd
| Author | SHA1 | Date | |
|---|---|---|---|
| e4157b37dd | |||
| 60fa41ba14 | |||
| 97c2088828 | |||
| 48cddf247a | |||
| e0641beacc |
1
src/drivers/i2c/aht10/.gitignore
vendored
Normal file
1
src/drivers/i2c/aht10/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
aarch64/o-le/aht10
|
||||
@ -1,4 +1,4 @@
|
||||
LIST=OS
|
||||
LIST=CPU
|
||||
|
||||
ifndef QRECURSE
|
||||
QRECURSE=recurse.mk
|
||||
|
||||
1
src/drivers/i2c/aht10/aarch64/o-le/Makefile
Normal file
1
src/drivers/i2c/aht10/aarch64/o-le/Makefile
Normal file
@ -0,0 +1 @@
|
||||
include ../../common.mk
|
||||
@ -1,3 +1,124 @@
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <sys/iofunc.h>
|
||||
#include <sys/dispatch.h>
|
||||
|
||||
int io_read (resmgr_context_t *ctp, io_read_t *msg, RESMGR_OCB_T *ocb);
|
||||
|
||||
static char *buffer = "Hello world\n";
|
||||
|
||||
static resmgr_connect_funcs_t connect_funcs;
|
||||
static resmgr_io_funcs_t io_funcs;
|
||||
static iofunc_attr_t attr;
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
/* declare variables we'll be using */
|
||||
resmgr_attr_t resmgr_attr;
|
||||
dispatch_t *dpp;
|
||||
dispatch_context_t *ctp;
|
||||
int id;
|
||||
|
||||
/* initialize dispatch interface */
|
||||
if((dpp = dispatch_create()) == NULL) {
|
||||
fprintf(stderr, "%s: Unable to allocate dispatch handle.\n", argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* initialize resource manager attributes */
|
||||
memset(&resmgr_attr, 0, sizeof resmgr_attr);
|
||||
resmgr_attr.nparts_max = 1;
|
||||
resmgr_attr.msg_max_size = 2048;
|
||||
|
||||
/* initialize functions for handling messages, including our read handlers */
|
||||
iofunc_func_init(_RESMGR_CONNECT_NFUNCS, &connect_funcs,
|
||||
_RESMGR_IO_NFUNCS, &io_funcs);
|
||||
io_funcs.read = io_read;
|
||||
io_funcs.read64 = io_read;
|
||||
|
||||
/* initialize attribute structure used by the device */
|
||||
iofunc_attr_init(&attr, S_IFNAM | 0666, 0, 0);
|
||||
attr.nbytes = strlen(buffer)+1;
|
||||
|
||||
/* attach our device name */
|
||||
if((id = resmgr_attach(dpp, &resmgr_attr, "/dev/sample", _FTYPE_ANY, 0,
|
||||
&connect_funcs, &io_funcs, &attr)) == -1) {
|
||||
fprintf(stderr, "%s: Unable to attach name.\n", argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* allocate a context structure */
|
||||
ctp = dispatch_context_alloc(dpp);
|
||||
|
||||
/* start the resource manager message loop */
|
||||
while(1) {
|
||||
if((ctp = dispatch_block(ctp)) == NULL) {
|
||||
fprintf(stderr, "block error\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
dispatch_handler(ctp);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int io_read (resmgr_context_t *ctp, io_read_t *msg, RESMGR_OCB_T *ocb)
|
||||
{
|
||||
size_t nleft;
|
||||
size_t nbytes;
|
||||
int nparts;
|
||||
int status;
|
||||
|
||||
if ((status = iofunc_read_verify (ctp, msg, ocb, NULL)) != EOK)
|
||||
return (status);
|
||||
|
||||
if ((msg->i.xtype & _IO_XTYPE_MASK) != _IO_XTYPE_NONE)
|
||||
return (ENOSYS);
|
||||
|
||||
/*
|
||||
* On all reads (first and subsequent), calculate how many bytes we can
|
||||
* return to the client, based upon the number of bytes available (nleft)
|
||||
* and the client's buffer size
|
||||
*/
|
||||
nleft = ocb->attr->nbytes - ocb->offset;
|
||||
nbytes = min (_IO_READ_GET_NBYTES(msg), nleft);
|
||||
|
||||
if (nbytes > 0) {
|
||||
/* set up the return data IOV */
|
||||
SETIOV (ctp->iov, buffer + ocb->offset, nbytes);
|
||||
|
||||
/* set up the number of bytes (returned by client's read()) */
|
||||
_IO_SET_READ_NBYTES (ctp, nbytes);
|
||||
|
||||
/*
|
||||
* advance the offset by the number of bytes returned to the client
|
||||
*/
|
||||
ocb->offset += nbytes;
|
||||
|
||||
nparts = 1;
|
||||
} else {
|
||||
/*
|
||||
* they've asked for zero bytes or they've already previously
|
||||
* read everything
|
||||
*/
|
||||
_IO_SET_READ_NBYTES (ctp, 0);
|
||||
|
||||
nparts = 0;
|
||||
}
|
||||
|
||||
/* mark the access time as invalid (we just accessed it) */
|
||||
if (msg->i.nbytes > 0)
|
||||
ocb->attr->flags |= IOFUNC_ATTR_ATIME;
|
||||
|
||||
return (_RESMGR_NPARTS (nparts));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <hw/i2c.h>
|
||||
@ -43,3 +164,4 @@ int main() {
|
||||
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
@ -13,9 +13,9 @@ static int fd_i2c;
|
||||
static int _i2c_read(uint8_t address, uint8_t *data, size_t length, uint8_t stop)
|
||||
{
|
||||
int ret = 0;
|
||||
char *data_recv = NULL;
|
||||
i2c_recv_t *data_msg = NULL;
|
||||
char *data_recv = NULL, *data_buf = NULL;
|
||||
unsigned int recv_lent = sizeof(i2c_recv_t) + length;
|
||||
i2c_recv_t *data_msg = NULL, *data_buf = NULL;
|
||||
|
||||
data_recv = malloc(recv_lent);
|
||||
if (data_recv == NULL) {
|
||||
@ -88,7 +88,7 @@ static int aht1x_getStatus(uint8_t address)
|
||||
|
||||
ret = _i2c_read(address, recv_data, 1, 1);
|
||||
if (ret < 0) {
|
||||
printf("[%s|%4u] ErrNo(%d) %s, failed to read date from I2C Address[%#X]\n", __FILE_NAME__, __LINE__, ret, address);
|
||||
printf("[%s|%4u] ErrNo(%d), failed to read date from I2C Address[%#X]\n", __FILE_NAME__, __LINE__, ret, address);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -167,7 +167,7 @@ int aht1x_getEvent(int i2c_dev, uint8_t i2c_address, float *_humidity, float *_t
|
||||
// read the data and store it!
|
||||
ret = _i2c_write(i2c_address, cmd, sizeof(cmd), 1);
|
||||
if (ret < 0) {
|
||||
printf("[%s|%4u] ErrNo(%d) %s, failed to write TRIGGER command\n", __FILE_NAME__, __LINE__, ret);
|
||||
printf("[%s|%4u] ErrNo(%d), failed to write TRIGGER command\n", __FILE_NAME__, __LINE__, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -176,7 +176,7 @@ int aht1x_getEvent(int i2c_dev, uint8_t i2c_address, float *_humidity, float *_t
|
||||
|
||||
ret = _i2c_read(i2c_address, data, sizeof(data), 1);
|
||||
if (ret < 0) {
|
||||
printf("[%s|%4u] ErrNo(%d) %s, failed to read date from I2C Address[%#X]\n", __FILE_NAME__, __LINE__, ret, i2c_address);
|
||||
printf("[%s|%4u] ErrNo(%d), failed to read date from I2C Address[%#X]\n", __FILE_NAME__, __LINE__, ret, i2c_address);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@ -1,10 +0,0 @@
|
||||
LIST=CPU
|
||||
|
||||
ifndef QRECURSE
|
||||
QRECURSE=recurse.mk
|
||||
ifdef QCONFIG
|
||||
QRDIR=$(dir $(QCONFIG))
|
||||
endif
|
||||
endif
|
||||
include $(QRDIR)$(QRECURSE)
|
||||
|
||||
@ -1 +0,0 @@
|
||||
include ../../../common.mk
|
||||
Reference in New Issue
Block a user