Developer World
Spresense SDK Library v3.2.0-ebc0364
transport_mode.h
1/****************************************************************************
2 * modules/include/sensing/logical_sensor/transport_mode.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 ****************************************************************************/
35
36#ifndef __INCLUDE_SENSING_LOGICAL_SENSOR_TRANSPORT_MODE_H
37#define __INCLUDE_SENSING_LOGICAL_SENSOR_TRANSPORT_MODE_H
38
44/****************************************************************************
45 * Included Files
46 ****************************************************************************/
47
48#include <asmp/mpmq.h>
49#include <asmp/mptask.h>
50
51#include "sensing/sensor_api.h"
52#include "sensing/sensor_id.h"
53#include "sensing/sensor_ecode.h"
55#include "memutils/s_stl/queue.h"
57
58/****************************************************************************
59 * Pre-processor Definitions
60 ****************************************************************************/
61
62#define TRAM_NUMBER_OF_MODES 13
64#define ACCEL_SAMPLING_FREQUENCY_MS 16
65#define ACCEL_SAMPLING_FREQUENCY_CMD 64
66#define ACCEL_SAMPLING_FREQUENCY_TMI 64
67#define ACCEL_WATERMARK_NUM 320
68#define ACCEL_FIFO_NUM (ACCEL_WATERMARK_NUM * 2)
69#define ACCEL_TRIGGER_RISE_THRESS 50
70#define ACCEL_TRIGGER_RISE_COUNT0 2
71#define ACCEL_TRIGGER_RISE_COUNT1 20
72#define ACCEL_TRIGGER_RISE_DELAY 0
73#define ACCEL_TRIGGER_FALL_THRESS 49
74#define ACCEL_TRIGGER_FALL_COUNT0 2
75#define ACCEL_TRIGGER_FALL_COUNT1 4
76#define ACCEL_TRIGGER_FALL_DELAY 0
78#define GET_SCU_ACCEL_SAMPLING_FREQUENCY(_x_) (512 / (1 << (_x_)))
80#define MAG_SAMPLING_FREQUENCY 8
81#define MAG_WATERMARK_NUM 40
83/****************************************************************************
84 * Public Types
85 ****************************************************************************/
86
91typedef enum
92{
97 TRAM_STATE_NUM
99
106};
107
114};
115
121 uint16_t fifosize;
122 uint8_t samplingrate;
123 uint8_t elements;
124 FAR struct scuev_notify_s *ev;
125 FAR struct math_filter_s *mf;
126 FAR struct scufifo_wm_s *wm;
127};
128
129/*--------------------------------------------------------------------
130 * TRAM Class
131 *--------------------------------------------------------------------
132 */
133
135{
136public:
137
138 /* public methods */
139 int open(FAR float *likelihood);
140 int close(void);
141 int start(void);
142 int stop(void);
143 int write(FAR sensor_command_data_mh_t*);
144 void send_detection_result(uint32_t pred);
145 void send_notification(TramNotification notification);
146 void set_power(uint32_t subscriptions);
147 void clear_power(uint32_t subscriptions);
148 void receive_sync_msg(void);
149 void receive_async_msg(uint32_t param);
150 int receive(void);
151 int handle_event(TramEvent event);
152
153 int set_state(tram_state_e state);
154 tram_state_e get_state(void);
155
156 TramClass(MemMgrLite::PoolId cmd_pool_id)
157 : m_cmd_pool_id(cmd_pool_id),
159 {
160 };
161
162 ~TramClass(){};
163
164private:
165 #define MAX_EXEC_COUNT 8
166
167 struct exe_mh_s {
170 };
171
172 s_std::Queue<struct exe_mh_s, MAX_EXEC_COUNT> m_exe_que;
173
174 /* private members */
175
176 MemMgrLite::PoolId m_cmd_pool_id;
177
178 mptask_t m_mptask;
179 mpmq_t m_mq;
180
181 pthread_t m_thread_id;
182
183 tram_state_e m_state;
184
185 /* private methods */
186
187 int sendInit(FAR float *likelihood);
188};
189
190/****************************************************************************
191 * Public Function Prototypes
192 ****************************************************************************/
193
201
209int TramOpen(FAR TramClass *ins, FAR float *likelihood = NULL);
210
216int TramClose(FAR TramClass *ins);
217
223int TramStart(FAR TramClass *ins);
224
230int TramStop(FAR TramClass *ins);
231
238int TramWrite(FAR TramClass *ins, FAR sensor_command_data_mh_t *command);
239
247
254
259#endif /* __INCLUDE_SENSING_LOGICAL_SENSOR_TRANSPORT_MODE_H */
Memory Handler API.
Memory Handler Class for "Memory Manager Lite". This is only wrapper class for convert project-specif...
Definition: MemManager.h:107
Definition: transport_mode.h:135
TramEvent
Definition: transport_mode.h:104
int TramStop(FAR TramClass *ins)
Stop TRAM with Dsp analysing.
int TramHandleEvent(FAR TramClass *ins, TramEvent event)
Send event to TRAM to handle event.
TramNotification
Definition: transport_mode.h:112
int TramOpen(FAR TramClass *ins, FAR float *likelihood=NULL)
Load TRAM library and boot up as worker task. After booted up, send initialize and wait complete.
tram_state_e
Definition: transport_mode.h:92
TramClass * TramCreate(MemMgrLite::PoolId cmd_pool_id)
Create TramClass instance.
int TramWrite(FAR TramClass *ins, FAR sensor_command_data_mh_t *command)
Send data to TRAM worker task.
int TramClose(FAR TramClass *ins)
Destory TRAM worker task.
struct ScuSettings * TramGetAccelScuSettings(FAR TramClass *ins)
Get settings information of accelerator.
int TramStart(FAR TramClass *ins)
Start TRAM with Dsp analysing.
@ MathFuncEvent
Definition: transport_mode.h:105
@ ChangeScuSettings
Definition: transport_mode.h:113
@ TRAM_STATE_UNINITIALIZED
Definition: transport_mode.h:93
@ TRAM_STATE_CMD
Definition: transport_mode.h:95
@ TRAM_STATE_MS
Definition: transport_mode.h:94
@ TRAM_STATE_TMI
Definition: transport_mode.h:96
Definition: MemMgrTypes.h:88
Definition: transport_mode.h:120
FAR struct math_filter_s * mf
Definition: transport_mode.h:125
uint16_t fifosize
Definition: transport_mode.h:121
FAR struct scuev_notify_s * ev
Definition: transport_mode.h:124
FAR struct scufifo_wm_s * wm
Definition: transport_mode.h:126
uint8_t elements
Definition: transport_mode.h:123
uint8_t samplingrate
Definition: transport_mode.h:122
Definition: scu.h:321
Definition: mpmq.h:77
Definition: mptask.h:248
Definition: scu.h:364
Definition: scu.h:404
The command of send some sensor data with MemHandle to the sensor manager. This function only can cal...
Definition: sensor_api.h:134