Developer World
Spresense SDK Library v2.0.1-3834d32
scu.h
Go to the documentation of this file.
1 /****************************************************************************
2  * arch/arm/include/cxd56xx/scu.h
3  *
4  * Copyright 2018 Sony Semiconductor Solutions Corporation
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the
15  * distribution.
16  * 3. Neither the name of Sony Semiconductor Solutions Corporation nor
17  * the names of its contributors may be used to endorse or promote
18  * products derived from this software without specific prior written
19  * permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  ****************************************************************************/
39 #ifndef __ARCH_ARM_INCLUDE_CXD56XX_SCU_H
40 #define __ARCH_ARM_INCLUDE_CXD56XX_SCU_H
41 
47 /****************************************************************************
48  * include files
49  ****************************************************************************/
50 
51 #include <stdint.h>
52 #include <stdbool.h>
53 #include <nuttx/fs/ioctl.h>
54 
55 /***************************************************************************
56  * Pre-processor Definitions
57  ****************************************************************************/
58 
59 #define _SCUIOCBASE (0xa000)
60 
61 #define _SCUIOCVALID(c) (_IOC_TYPE(c)==_SCUIOCBASE)
62 #define _SCUIOC(nr) _IOC(_SCUIOCBASE,nr)
63 
76 #define SCUIOC_SETFIFO _SCUIOC(0x0001)
77 
85 #define SCUIOC_FREEFIFO _SCUIOC(0x0002)
86 
94 #define SCUIOC_SETSAMPLE _SCUIOC(0x0003)
95 
103 #define SCUIOC_SETSIGNCONV _SCUIOC(0x0004)
104 
112 #define SCUIOC_SETOGADJUST _SCUIOC(0x0005)
113 
121 #define SCUIOC_CLROGADJUST _SCUIOC(0x0006)
122 
130 #define SCUIOC_SETFILTER _SCUIOC(0x0007)
131 
142 #define SCUIOC_SETNOTIFY _SCUIOC(0x0008)
143 
156 #define SCUIOC_SETELEMENTS _SCUIOC(0x0009)
157 
165 #define SCUIOC_SETDECIMATION _SCUIOC(0x000a)
166 
174 #define SCUIOC_SETWATERMARK _SCUIOC(0x000b)
175 
183 #define SCUIOC_START _SCUIOC(0x0010)
184 
192 #define SCUIOC_STOP _SCUIOC(0x0011)
193 
201 #define SCUIOC_SETFIFOMODE _SCUIOC(0x0012)
202 
210 #define SCUIOC_DELFIFODATA _SCUIOC(0x0013)
211 
219 #define SCU_BUS_SPI 1
220 #define SCU_BUS_I2C0 2
221 #define SCU_BUS_I2C1 3
222 #define SCU_BUS_LPADC0 0x10
223 #define SCU_BUS_LPADC1 0x11
224 #define SCU_BUS_LPADC2 0x12
225 #define SCU_BUS_LPADC3 0x13
226 #define SCU_BUS_HPADC0 0x14
227 #define SCU_BUS_HPADC1 0x15
231 #define SCU_INST_SEND(val) ((val) & 0xff)
232 
235 #define SCU_INST_RECV(n) ((1 << 8) | (((n) - 1) & 0x7) << 12)
236 
237 #define SCU_INST_TERM (1 << 11)
238 #define SCU_INST_RESTART (1 << 10)
239 #define SCU_INST_STOP (1 << 9)
240 
243 #define SCU_INST_LAST (SCU_INST_TERM|SCU_INST_STOP)
244 
245 /* Sequencer types */
246 
247 #define SEQ_TYPE_NORMAL 0
248 #define SEQ_TYPE_DECI 1
250 /* Event control */
251 
252 #define SCU_EV_RISE_EN (1 << 31)
253 #define SCU_EV_FALL_EN (1 << 30)
254 #define SCU_EV_OUT8BITS (1 << 29)
256 #define SCU_EV_OUTSHIFT 16
257 #define SCU_EV_OUTMASK (3 << SCU_EV_OUTSHIFT)
258 #define SCU_EV_OUTALWAYS (0 << SCU_EV_OUTSHIFT)
259 #define SCU_EV_OUTSTART (1 << SCU_EV_OUTSHIFT)
260 #define SCU_EV_OUTSTOP (2 << SCU_EV_OUTSHIFT)
261 #define SCU_EV_NOTOUT (3 << SCU_EV_OUTSHIFT)
263 #define SCU_EV_WRITESAMPLEMASK 0xfff
264 
267 #define SCU_EV_WRITESAMPLES(sample) ((sample) & SCU_EV_WRITESAMPLEMASK)
268 
269 /* Event type flags */
270 
271 #define SCU_EV_RISE (1)
272 #define SCU_EV_FALL (2)
274 /* Level adjustment (decimator only) */
275 
276 #define SCU_LEVELADJ_X1 (0)
277 #define SCU_LEVELADJ_X2 (1)
278 #define SCU_LEVELADJ_X4 (2)
279 #define SCU_LEVELADJ_X8 (3)
283 /****************************************************************************
284  * Public Types
285  ****************************************************************************/
286 
298 {
306 };
307 
311 {
312  uint32_t sec;
313  uint16_t tick;
314 };
315 
319 {
320  uint32_t h;
321  uint8_t l;
322 };
323 
327 {
328  uint8_t ishift;
329  uint8_t oshift;
330  struct iir_coeff_s coeff[5];
331 };
332 
336 {
337  enum filter_pos_e pos;
338  struct iir_filter_s filter[2];
339 };
340 
361 {
362  uint16_t threshold;
363  uint16_t count0;
364  uint16_t count1;
365  uint16_t delaysamples;
366 };
367 
371 {
372  struct scutimestamp_s ts;
373  uint32_t type;
374 };
375 
379 {
380  int signo;
382  struct sensor_event_s rise;
383  struct sensor_event_s fall;
385  uint32_t ctrl;
387  FAR struct scuev_arg_s *arg;
388 };
389 
392 struct adjust_s {
393  uint16_t offset;
394  uint16_t gain;
395 };
396 
399 struct adjust_xyz_s {
400  struct adjust_s x;
401  struct adjust_s y;
402  struct adjust_s z;
403 };
404 
408 {
409  uint8_t ratio;
410  uint8_t leveladj;
411  uint8_t forcethrough;
412 };
413 
417 {
418  int signo;
422  FAR struct scutimestamp_s *ts;
423 
430  uint16_t watermark;
431 };
432 
433 struct seq_s; /* The sequencer object */
434 
456 FAR struct seq_s *seq_open(int type, int bustype);
457 
464 void seq_close(FAR struct seq_s *seq);
465 
477 int seq_read(FAR struct seq_s *seq, int fifoid, char *buffer, int length);
478 
494 int seq_ioctl(FAR struct seq_s *seq, int fifoid, int cmd, unsigned long arg);
495 
506 int seq_setinstruction(FAR struct seq_s *seq, const uint16_t *inst,
507  uint16_t nr_insts);
508 
521 void seq_setsample(FAR struct seq_s *seq, uint8_t sample, uint8_t offset,
522  uint8_t elemsize, bool swapbyte);
523 
531 void seq_setaddress(FAR struct seq_s *seq, uint32_t slave_addr);
532 
549 int scu_spitransfer(int slavesel, uint16_t *inst, uint32_t nr_insts,
550  uint8_t *buffer, int len);
551 
569 int scu_i2ctransfer(int port, int slave, uint16_t *inst, uint32_t nr_insts,
570  uint8_t *buffer, int len);
571 
578 void scu_initialize(void);
579 
586 void scu_uninitialize(void);
587 
592 #endif /* __ARCH_ARM_INCLUDE_CXD56XX_SCU_H */
uint16_t watermark
Definition: scu.h:430
uint16_t delaysamples
Definition: scu.h:365
uint32_t ctrl
Definition: scu.h:385
Definition: scu.h:399
FAR struct seq_s * seq_open(int type, int bustype)
uint16_t count1
Definition: scu.h:364
int signo
Definition: scu.h:380
Definition: scu.h:302
Definition: scu.h:299
FAR struct scutimestamp_s * ts
Definition: scu.h:422
void scu_initialize(void)
Definition: scu.h:305
uint16_t gain
Definition: scu.h:394
uint16_t count0
Definition: scu.h:363
Definition: scu.h:360
Definition: scu.h:326
FAR struct scuev_arg_s * arg
Definition: scu.h:387
int seq_ioctl(FAR struct seq_s *seq, int fifoid, int cmd, unsigned long arg)
uint8_t l
Definition: scu.h:321
Definition: scu.h:304
Definition: scu.h:318
Definition: scu.h:407
Definition: scu.h:335
Definition: scu.h:301
uint16_t offset
Definition: scu.h:393
Definition: scu.h:392
uint8_t leveladj
Definition: scu.h:410
void seq_setsample(FAR struct seq_s *seq, uint8_t sample, uint8_t offset, uint8_t elemsize, bool swapbyte)
int scu_spitransfer(int slavesel, uint16_t *inst, uint32_t nr_insts, uint8_t *buffer, int len)
Definition: scu.h:416
uint16_t threshold
Definition: scu.h:362
uint8_t forcethrough
Definition: scu.h:411
uint8_t oshift
Definition: scu.h:329
int signo
Definition: scu.h:418
uint16_t tick
Definition: scu.h:313
Definition: scu.h:378
uint32_t sec
Definition: scu.h:312
uint32_t type
Definition: scu.h:373
uint8_t ratio
Definition: scu.h:409
uint8_t ishift
Definition: scu.h:328
Definition: scu.h:370
void seq_setaddress(FAR struct seq_s *seq, uint32_t slave_addr)
Definition: scu.h:300
Definition: scu.h:303
filter_pos_e
Definition: scu.h:297
int seq_read(FAR struct seq_s *seq, int fifoid, char *buffer, int length)
void scu_uninitialize(void)
Definition: scu.h:310
void seq_close(FAR struct seq_s *seq)
int seq_setinstruction(FAR struct seq_s *seq, const uint16_t *inst, uint16_t nr_insts)
int scu_i2ctransfer(int port, int slave, uint16_t *inst, uint32_t nr_insts, uint8_t *buffer, int len)