16 #include <sys/neutrino.h> 17 #include <sys/iofunc.h> 18 #include <sys/dispatch.h> 22 #define min(a, b) ((a) < (b) ? (a) : (b)) 24 int io_read(resmgr_context_t * ctp, io_read_t * msg, RESMGR_OCB_T * ocb);
25 static char *
buffer = (
char *)
"Hello world\n";
29 #include "QNX101/jr3pci3.idm" 31 #define VENDORID 0x1762 34 #define DEVICEID 0x3112 37 #define Jr3ResetAddr 0x18000 38 #define Jr3NoAddrMask 0x40000 39 #define Jr3DmAddrMask 0x6000 43 #define ToJr3PciAddrH(addr) (((int)(addr) << 2) + Jr3BaseAddressH) 44 #define ToJr3PciAddrL(addr) (((int)(addr) << 2) + Jr3BaseAddressL) 47 #define ReadJr3Pm(addr) (*(uint16_t volatile *)(ToJr3PciAddrH((addr))) << 8 |\ 48 *(uint8_t volatile *)(ToJr3PciAddrL((addr)))) 50 #define WriteJr3Pm2(addr,data,data2) (*(int volatile *)ToJr3PciAddrH((addr)) = (int)(data));(*(int volatile *)ToJr3PciAddrL((addr)) = (int)(data2)) 52 #define WriteJr3Pm(addr,data) WriteJr3Pm2((addr),(data) >> 8, (data)) 55 #define ReadJr3Dm(addr) (*(uint16_t volatile *)(ToJr3PciAddrH((addr)))) 56 #define WriteJr3Dm(addr,data) *(int volatile *)(ToJr3PciAddrH((addr))) = (int)(data) 59 #define ReadJr3(addr) (ReadJr3Dm((addr) | Jr3DmAddrMask)) 60 #define WriteJr3(addr,data) WriteJr3Dm((addr) | Jr3DmAddrMask,data) 132 uint8_t changedV1 :1;
133 uint8_t changedV2 :1;
138 uint8_t fx_near_set :1;
139 uint8_t fy_near_set :1;
140 uint8_t fz_near_set :1;
141 uint8_t mx_near_set :1;
142 uint8_t my_near_set :1;
143 uint8_t mz_near_set :1;
156 uint8_t researved :2;
158 uint8_t memry_error :1;
159 uint8_t sensor_charge :1;
160 uint8_t system_busy :1;
161 uint8_t cal_crc_bad :1;
162 uint8_t watch_dog2 :1;
163 uint8_t watch_dog :1;
168 { (
char *)
"pound, inch*pound, inch*1000",
170 (
char *)
"Newton, Newton*meter*10, mm*10",
171 (
char *)
"kilogram-force*10, kilogram-Force*cm, mm*10",
172 (
char *)
"kilopound, kiloinch*pound, inch*1000" };
224 char copyright[0x18 * 4];
225 int16_t reserved1[0x08 * 2];
227 int16_t reserved2[2];
329 int download(
unsigned int base0,
unsigned int base1) {
330 printf(
"Download %x %x\n", base0, base1);
337 Jr3BaseAddressH = base0;
338 Jr3BaseAddressL = base1;
341 count = dsp[index++];
344 while (count != 0xffff) {
361 printf(
"data addr: %4.4x out: %4.4x in: %4.4x\n", addr,
370 data2 = dsp[index++];
375 if (((data << 8) | (data2 & 0xff))
382 count = dsp[index++];
390 struct tm t1, *soft_day, *cal_day;
393 t1.tm_sec = t1.tm_min = t1.tm_hour = 0;
399 soft_day = localtime(&t2);
400 t1.tm_sec = t1.tm_min = t1.tm_hour = 0;
406 cal_day = localtime(&t2);
407 snprintf(msg, 128,
"rom # %d, soft # %d, %d/%d/%d\n" 408 "serial # %d, model # %d, cal day %d/%d/%d\n" 409 "%s, %d bits, %d ch\n" 410 "(C) %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n\n",
412 soft_day->tm_mon + 1, soft_day->tm_year + 1900, data->
serial_no,
413 data->
model_no, cal_day->tm_mday, cal_day->tm_mon + 1,
449 num = type - _IO_MAX;
453 float tmp[12] = { -1.0 * (float) data_0->
filter0.
fx 454 / (
float) data_0->full_scale.fx, -1.0
455 * (float) data_0->filter0.fy / (
float) data_0->full_scale.fy,
456 -1.0 * (float) data_0->filter0.fz
457 / (
float) data_0->full_scale.fz, -1.0
458 * (float) data_0->filter0.mx
459 / (
float) data_0->full_scale.mx * 0.1,
460 -1.0 * (float) data_0->filter0.my
461 / (
float) data_0->full_scale.my * 0.1, -1.0
462 * (float) data_0->filter0.mz
463 / (
float) data_0->full_scale.mz * 0.1, -1.0
464 * (float) data_1->filter0.fx
465 / (
float) data_1->full_scale.fx, -1.0
466 * (float) data_1->filter0.fy
467 / (
float) data_1->full_scale.fy, -1.0
468 * (float) data_1->filter0.fz
469 / (
float) data_1->full_scale.fz, -1.0
470 * (float) data_1->filter0.mx
471 / (
float) data_1->full_scale.mx * 0.1, -1.0
472 * (float) data_1->filter0.my
473 / (
float) data_1->full_scale.my * 0.1, -1.0
474 * (float) data_1->filter0.mz
475 / (
float) data_1->full_scale.mz * 0.1 };
476 memcpy(msg_reply, tmp,
sizeof(
float) * 12);
480 data_0->offsets.fx += data_0->filter0.fx;
481 data_0->offsets.fy += data_0->filter0.fy;
482 data_0->offsets.fz += data_0->filter0.fz;
483 data_0->offsets.mx += data_0->filter0.mx;
484 data_0->offsets.my += data_0->filter0.my;
485 data_0->offsets.mz += data_0->filter0.mz;
486 data_1->offsets.fx += data_1->filter0.fx;
487 data_1->offsets.fy += data_1->filter0.fy;
488 data_1->offsets.fz += data_1->filter0.fz;
489 data_1->offsets.mx += data_1->filter0.mx;
490 data_1->offsets.my += data_1->filter0.my;
491 data_1->offsets.mz += data_1->filter0.mz;
502 MsgReply(ctp->rcvid, EOK, msg_reply, 256);
506 int main(
int argc,
char **argv) {
507 resmgr_attr_t resmgr_attr;
508 message_attr_t message_attr;
510 dispatch_context_t *ctp, *ctp_ret;
511 int resmgr_id, message_id;
514 dpp = dispatch_create();
516 fprintf(
stderr,
"dispatch_create() failed: %s\n", strerror(errno));
520 memset(&resmgr_attr, 0,
sizeof(resmgr_attr));
521 resmgr_attr.nparts_max = 1;
522 resmgr_attr.msg_max_size = 2048;
525 iofunc_func_init(_RESMGR_CONNECT_NFUNCS, &
ConnectFuncs, _RESMGR_IO_NFUNCS,
531 iofunc_attr_init(&
IoFuncAttr, S_IFNAM | 0666, 0, 0);
534 resmgr_id = resmgr_attach(dpp, &resmgr_attr,
"/dev/jr3q", _FTYPE_ANY, 0,
536 if (resmgr_id == -1) {
537 fprintf(
stderr,
"resmgr_attach() failed: %s\n", strerror(errno));
542 unsigned int flags = 0;
543 unsigned bus,
function,
index = 0;
544 unsigned devid, venid;
546 unsigned lastbus,
version, hardware;
547 unsigned int address0;
552 result = pci_present(&lastbus, &version, &hardware);
554 printf(
"PCI BIOS not present!\n");
558 result = pci_find_device(devid, venid, index, &bus, &
function);
559 printf(
"result PCI %d\n", result);
560 printf(
"bus %d\n", bus);
561 printf(
"function %d\n",
function);
562 pci_read_config_bus(bus,
function, 0x10, 1,
sizeof(
unsigned int), bufptr);
564 address0 = *(
unsigned int *) bufptr;
566 printf(
"Board addr 0x%x\n", *(
unsigned int *)
buffer);
569 PROT_READ | PROT_WRITE | PROT_NOCACHE, 0, address0);
571 PROT_READ | PROT_WRITE | PROT_NOCACHE, 0, address0 +
Jr3NoAddrMask);
572 Jr3BaseAddressH = (
volatile uint32_t) mmap_device_memory(NULL, 0x100000,
573 PROT_READ | PROT_WRITE | PROT_NOCACHE, 0, address0);
580 PROT_READ | PROT_WRITE | PROT_NOCACHE, 0, address0 + 0x80000);
582 PROT_READ | PROT_WRITE | PROT_NOCACHE, 0, address0 + 0x80000 +
605 memset(&message_attr, 0,
sizeof(message_attr));
606 message_attr.nparts_max = 1;
607 message_attr.msg_max_size = 4096;
610 message_id = message_attach(dpp, &message_attr, _IO_MAX + 1, _IO_MAX + 10,
612 if (message_id == -1) {
613 fprintf(
stderr,
"message_attach() failed: %s\n", strerror(errno));
618 ctp = dispatch_context_alloc(dpp);
620 fprintf(
stderr,
"dispatch_context_alloc() failed: %s\n",
627 ctp_ret = dispatch_block(ctp);
629 dispatch_handler(ctp);
631 fprintf(
stderr,
"dispatch_block() failed: %s\n", strerror(errno));
639 int io_read(resmgr_context_t * ctp, io_read_t * msg, RESMGR_OCB_T * ocb) {
645 if ((status = iofunc_read_verify(ctp, msg, ocb, NULL)) != EOK)
648 if ((msg->i.xtype & _IO_XTYPE_MASK) != _IO_XTYPE_NONE)
658 nleft = ocb->attr->nbytes - ocb->offset;
659 nbytes =
min(msg->i.nbytes, nleft);
663 SETIOV(ctp->iov,
buffer + ocb->offset, nbytes);
666 _IO_SET_READ_NBYTES(ctp, nbytes);
673 ocb->offset += nbytes;
680 _IO_SET_READ_NBYTES(ctp, 0);
686 if (msg->i.nbytes > 0)
687 ocb->attr->flags |= IOFUNC_ATTR_ATIME;
689 return (_RESMGR_NPARTS(nparts));
694 struct timeval tv, tv1;
699 gettimeofday(&tv, NULL);
700 }
while (tv.tv_sec - tv1.tv_sec < 3);
six_axis_array default_FS
volatile uint32_t Jr3BaseAddressH
int16_t number_of_ge_thresholds
static resmgr_connect_funcs_t ConnectFuncs
static iofunc_attr_t IoFuncAttr
#define WriteJr3Dm(addr, data)
volatile uint32_t Jr3BaseAddress1L
six_axis_array max_full_scale
int16_t number_of_le_thresholds
static resmgr_io_funcs_t IoFuncs
int gettimeofday(struct timeval *tv, struct timezone *tz)
int message_callback(message_context_t *ctp, int type, unsigned flags, void *handle)
int main(int argc, char **argv)
volatile uint32_t Jr3BaseAddress0L
volatile uint32_t Jr3BaseAddressL
int16_t load_envelope_num
volatile uint32_t Jr3BaseAddress0H
int io_read(resmgr_context_t *ctp, io_read_t *msg, RESMGR_OCB_T *ocb)
#define WriteJr3Pm2(addr, data, data2)
void get_force_sensor_info(force_sensor_data *data, char *msg)
int download(unsigned int base0, unsigned int base1)
six_axis_array min_full_scale
unsigned long MappedAddress
volatile uint32_t Jr3BaseAddress1H