-#include <stdio.h>
+/*********************/
+/*** Include Files ***/
+/*********************/
#include <stdlib.h>
+#include <stdint.h>
#include <string.h>
-#include <stdarg.h>
#include "cwm_lib.h"
+#include "config.h"
+#include "simulate_signal.h"
-int CWM_OS_dbgOutput(const char * format) {
- printf("%s", format);
- return 0;
-}
+/*********************/
+/*** Macro Defines ***/
+/*********************/
-int CWM_OS_dbgPrintf(const char * format,...) {
- va_list argList;
- int size = 0;
- static char tBuffer[256];
- va_start(argList, format);
- size = vsnprintf(tBuffer, sizeof(tBuffer), format, argList);
- va_end(argList);
-
- //strcat(tBuffer, "\n");
- CWM_OS_dbgOutput(tBuffer);
- return size;
-}
+/*************************/
+/*** Variables Defines ***/
+/*************************/
+static const char* REQ_SENS_NAME[] = {"acc", "gyro", "mag", "baro", "temp", "hr", "gnss", "ob", "oc", "accany"};
+static int m_req_sensor_state = 0;
-uint64_t CWM_OS_GetTimeNs(void) {
- uint64_t timeNow_us;
+/************************/
+/*** Function Defines ***/
+/************************/
- timeNow_us = 0;
+extern void board_init(void);
+extern void CWM_OS_uSleep(uint32_t time);
+extern uint64_t CWM_OS_GetTimeNs(void);
+extern void* CWM_OS_malloc(int size);
+extern void CWM_OS_free(void *ptr);
+extern int CWM_OS_dbgOutput(const char * format);
+extern int CWM_OS_dbgOutput_checkLog(const char * format);
+extern int CWM_OS_dbgPrintf(const char * format,...);
+extern void test_api(void);
- return timeNow_us * 1000;
+/********************************/
+/*** Function Implementations ***/
+/********************************/
+int getReqSensor(int index) {
+ if (m_req_sensor_state & (1<<index))
+ return 1;
+ return 0;
}
-
+/**
+ * @brief Sensor listen callback, when you register sensor listen,
+ * when sensor data is ready, sensor manager will call this function to send pSensorEVT_t.
+ * @param handle sensor register handle, if not setup this handle don't care.
+ * @sensorEVT Sensor data event.
+ * @retval None
+ */
void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) {
switch (sensorEVT->sensorType) {
- case 0:
- CWM_OS_dbgPrintf("acc: x=%.3f, y=%.3f, z=%.3f\n",
+ case IDX_REQUEST_SENSOR:
+ if (sensorEVT->fData[2] != 0)
+ m_req_sensor_state |= (1<<(int)sensorEVT->fData[1]);
+ else
+ m_req_sensor_state &= ~(1<<(int)sensorEVT->fData[1]);
+
+ CWM_OS_dbgPrintf("req_sensor input_sensor: %s(%.1f), switch: %.1f\n",\
+ REQ_SENS_NAME[(int)sensorEVT->fData[1]], sensorEVT->fData[1], sensorEVT->fData[2]);
+ CWM_OS_dbgPrintf("input_sensor now: acc=%d gyro=%d mag=%d baro=%d temp=%d hr=%d gnss=%d ob=%d oc=%d accany=%d\n",\
+ getReqSensor(0), getReqSensor(1), getReqSensor(2), getReqSensor(3), getReqSensor(4),\
+ getReqSensor(5), getReqSensor(6), getReqSensor(7), getReqSensor(8), getReqSensor(9));
+ break;
+
+ case IDX_ACCEL:
+ CWM_OS_dbgPrintf("%s: %.4f, %.4f, %.4f\n", "accel",
sensorEVT->fData[0],
sensorEVT->fData[1],
- sensorEVT->fData[2]
- );
- break;
+ sensorEVT->fData[2]);
+ break;
- case 1:
- CWM_OS_dbgPrintf("gyro: x=%.3f, y=%.3f, z=%.3f\n",
+ case IDX_ALGO_ACTIVITY_OUTPUT:
+ CWM_OS_dbgPrintf("%s: %.4f, %.4f, %.4f, %.4f, "\
+ "%.4f, %.4f, %.4f, %.4f, "\
+ "%.4f, %.4f, %.4f, %.4f, "\
+ "%.4f, %.4f, %.4f, %.4f\n", "activity output",
sensorEVT->fData[0],
sensorEVT->fData[1],
- sensorEVT->fData[2]
- );
- break;
+ sensorEVT->fData[2],
+ sensorEVT->fData[3],
+ sensorEVT->fData[4],
+ sensorEVT->fData[5],
+ sensorEVT->fData[6],
+ sensorEVT->fData[7],
+ sensorEVT->fData[8],
+ sensorEVT->fData[9],
+ sensorEVT->fData[10],
+ sensorEVT->fData[11],
+ sensorEVT->fData[12],
+ sensorEVT->fData[13],
+ sensorEVT->fData[14],
+ sensorEVT->fData[15]);
+ break;
default:
- CWM_OS_dbgPrintf("IDX[%d]: %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f\n", sensorEVT->sensorType,
+ CWM_OS_dbgPrintf("%d: %.4f, %.4f, %.4f, %.4f, "\
+ "%.4f, %.4f, %.4f, %.4f, "\
+ "%.4f, %.4f, %.4f, %.4f, "\
+ "%.4f, %.4f, %.4f, %.4f", sensorEVT->sensorType,
sensorEVT->fData[0],
sensorEVT->fData[1],
sensorEVT->fData[2],
sensorEVT->fData[4],
sensorEVT->fData[5],
sensorEVT->fData[6],
- sensorEVT->fData[7]
- );
+ sensorEVT->fData[7],
+ sensorEVT->fData[8],
+ sensorEVT->fData[9],
+ sensorEVT->fData[10],
+ sensorEVT->fData[11],
+ sensorEVT->fData[12],
+ sensorEVT->fData[13],
+ sensorEVT->fData[14],
+ sensorEVT->fData[15]);
+ break;
+ }
+}
+
+#ifdef SIGNAL_SIMULATE_PROCESS
+#define SIGNAL_SIMULATE_FIFO_COUNT 10
+
+static void sample_fifo_input_data(time_axis_data *taxis) {
+ int i;
+ float acc[3];
+ CWM_CustomSensorInput_Fifo_Start(CUSTOM_ACC,
+ simulate_fake_get_time_ns(),
+ 20 * 1000000);
+
+ for (i=0; i<SIGNAL_SIMULATE_FIFO_COUNT; i++) {
+ if (simulate_time_axis(taxis, acc) != 0) {
+ CWM_CustomSensorInput_Fifo_End(CUSTOM_ACC);
+ return;
+ }
+ CustomSensorData data;
+ memset(&data, 0, sizeof(data));
+ data.sensorType = CUSTOM_ACC;
+ memcpy(data.fData, acc, sizeof(float) *3);
+ CWM_CustomSensorInput(&data);
+ }
+ CWM_CustomSensorInput_Fifo_End(CUSTOM_ACC);
+}
+
+static void sample_polling_input_data(time_axis_data *taxis) {
+ float acc[3];
+ if (simulate_time_axis(taxis, acc) != 0) {
+ return;
}
+ CustomSensorData data;
+ memset(&data, 0, sizeof(data));
+ data.sensorType = CUSTOM_ACC;
+ memcpy(data.fData, acc, sizeof(float) *3);
+ CWM_CustomSensorInput(&data);
+}
+
+void sample_data_input() {
+ time_axis_data taxis;
+ memset(&taxis, 0, sizeof(time_axis_data));
+
+ simulate_action actions[] = {
+ { simulate_pedo_moving_step, 200, 66, 0, NULL },
+ { simulate_pedo_moving_step, 1000, 150, 0, NULL },
+ { simulate_pedo_moving_time, 300, 66, 0, NULL },
+ { simulate_no_move_time, 3600 * 2, 0, 0, NULL },
+ { simulate_pedo_moving_step, 100, 66, 0, NULL },
+ { NULL, 0, 0, 0, NULL },
+ };
+
+ taxis.actions = actions;
+
+
+#ifdef INPUT_DATA_WITH_FIFO_MODE
+ sample_fifo_input_data(&taxis);
+#else
+ sample_polling_input_data(&taxis);
+#endif
}
+#endif
+
+int main(void)
+{
+ OsAPI device_func =
+ {
+ .malloc = CWM_OS_malloc,
+ .free = CWM_OS_free,
+ .GetTimeNs = CWM_OS_GetTimeNs,
+ .dbgOutput = CWM_OS_dbgOutput,
+ };
+
+#ifdef CHECK_LOG_TOOL
+ device_func.dbgOutput = CWM_OS_dbgOutput_checkLog;
+#endif
-int main(int argc, char* argv[]) {
- int ret, loopIndex;
SettingControl_t scl;
+ board_init();
+
+#ifdef BUILD_IAR
+ CWM_OS_dbgPrintf("Use IAR\n");
+#elif defined(BUILD_KEIL)
+ CWM_OS_dbgPrintf("Use KEIL\n");
+#endif
+
+#ifdef SIGNAL_SIMULATE_PROCESS
+ device_func.GetTimeNs = simulate_fake_get_time_ns;
+# ifdef INPUT_DATA_WITH_FIFO_MODE
+ CWM_CustomSensorInput_Fifo_Init(SIGNAL_SIMULATE_FIFO_COUNT);
+# endif
+#endif
+
+#ifdef RUN_TEST_API_PROCESS
+ test_api();
+ return 0;
+#endif
+
//get lib version information
memset(&scl, 0, sizeof(scl));
scl.iData[0] = 1;
CWM_SettingControl(SCL_GET_LIB_INFO, &scl);
CWM_OS_dbgPrintf("version:%d.%d.%d.%d product:%d model:%d\n", scl.iData[1], scl.iData[2], scl.iData[3], scl.iData[4], scl.iData[5], scl.iData[6]);
- os_api api = {0};
- api.dbgOutput = CWM_OS_dbgOutput;
- //api.GetTimeNs = CWM_OS_GetTimeNs;
-
- CWM_LibPreInit(&api);
+ CWM_LibPreInit(&device_func);
- //set mcu_chip information, must call this before CWM_LibPostInit()
memset(&scl, 0, sizeof(scl));
scl.iData[0] = 1;
- scl.iData[1] = 2; // 0: mcu_auto_detect 2: skip_mcu_auto_detect
+ scl.iData[1] = 0;
+ scl.iData[2] = 0;
+ scl.iData[3] = 0;
CWM_SettingControl(SCL_CHIP_VENDOR_CONFIG, &scl);
+ memset(&scl, 0, sizeof(scl));
+ scl.iData[0] = 1;
+ scl.iData[1] = 0;
+ //CWM_SettingControl(SCL_LIB_DEBUG, &scl);
+
+ memset(&scl, 0, sizeof(scl));
+ scl.iData[0] = 1;
+ scl.iData[1] = 25;
+ CWM_SettingControl(SCL_ALGO_PROC_CONFIG, &scl);
+
CWM_LibPostInit(CWM_AP_SensorListen);
//get chip information
CWM_OS_dbgPrintf("chip_settings = %d, %d, %d\n", scl.iData[9], scl.iData[10], scl.iData[11]);
CWM_OS_dbgPrintf("secFileId = %08X\n", scl.iData[7]);
+#if 0
+ //turn on input log
+ memset(&scl, 0, sizeof(scl));
+ scl.iData[0] = 1;
+ scl.iData[3] = 1;
+ scl.iData[4] = 5;
+ CWM_SettingControl(SCL_LOG, &scl);
+#endif
+
+ //initial request_sensor to receive hardware_sensor on/off event
+ CWM_Sensor_Enable(IDX_REQUEST_SENSOR);
+
memset(&scl, 0, sizeof(scl));
scl.iData[0] = 1;
- scl.iData[3] = 3;
- scl.iData[4] = 15 + 64;
- //scl.iData[6] = 64 + 128 + 256 + 512 + 1024 + 2048 + 4096 + 8192 + 16384;
- //CWM_SettingControl(SCL_LOG, &scl);
-
- CWM_Sensor_Enable(0); //IDX_ACCEL
- CWM_Sensor_Enable(1); //IDX_GYRO
-
-/*
- CWM_Sensor_Disable(0);
- CWM_Sensor_Disable(1);
-*/
-
- for (loopIndex = 0; loopIndex < 101; loopIndex ++) {
- int dt_us;
-
- dt_us = 20000;
-
- CustomSensorData csd;
-
- memset(&csd, 0, sizeof(CustomSensorData));
- csd.sensorType = CUSTOM_ACC;
- csd.fData[0] = 0;
- csd.fData[1] = 0;
- csd.fData[2] = 9.80665;
- CWM_CustomSensorInput(&csd);
-
- memset(&csd, 0, sizeof(CustomSensorData));
- csd.sensorType = CUSTOM_GYRO;
- csd.fData[0] = 0;
- csd.fData[1] = 0;
- csd.fData[2] = -3.1415926;
- CWM_CustomSensorInput(&csd);
-
- ret = CWM_process2(dt_us);
- if (ret < 0) {
- CWM_OS_dbgPrintf("FATAL ERROR! ret=%d\n", ret);
+ CWM_SettingControl(SCL_REQ_ACTIVITY_EXIT, &scl);
+
+ memset(&scl, 0, sizeof(scl));
+ scl.iData[0] = 1;
+ scl.iData[1] = 1001;
+ CWM_SettingControl(SCL_SET_ACTIVITY_MODE, &scl);
+
+ memset(&scl, 0, sizeof(scl));
+ scl.iData[0] = 1;
+ scl.iData[1] = 2021;
+ scl.iData[2] = 10;
+ scl.iData[3] = 8;
+ scl.iData[4] = 12;
+ scl.iData[5] = 0;
+ CWM_SettingControl(SCL_DATE_TIME, &scl);
+
+
+ //CWM_Sensor_Enable(IDX_ACCEL);
+ CWM_Sensor_Enable(IDX_ALGO_ACTIVITY_OUTPUT);
+
+ while (1)
+ {
+ int64_t next_duration = CWM_GetNextActionDuration_ns();
+
+#ifdef SIGNAL_SIMULATE_PROCESS
+ sample_data_input();
+ next_duration = 0;
+#endif
+
+ if (next_duration > 0) {
+ /* Do Low power process here
+ */
+
+ CWM_OS_uSleep(next_duration / 1000);
}
- }
- return 0;
+ CWM_process();
+ }
}
-
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
-#include "cmsis_os2.h"
-#include "errcode.h"
-#include "los_task_base.h"
extern void CWM_OS_uSleep(uint32_t time);
extern uint64_t CWM_OS_GetTimeNs(void);
return 0;
}
-int test_free_1(void)
-{
+int test_free_1(void) {
char *pBuf1;
char *pBuf2;
int alloc_size;
return 0;
}
-void test_GetTimeNs_0(void)
-{
+void test_GetTimeNs_0(void) {
uint64_t timeNow;
CWM_OS_dbgPrintf("[test_GetTimeNs_0] test up_time start\r\n");
}
}
-void test_GetTimeNs_1(void)
-{
+void test_GetTimeNs_1(void) {
uint64_t timeNow, timeLast, timeDiff;
CWM_OS_dbgPrintf("[test_GetTimeNs_1] test 10 seconds start\r\n");
}
}
-void test_GetTimeNs_2(void)
-{
+void test_GetTimeNs_2(void) {
uint64_t timeNow, timeLast, timeDiff;
uint64_t count;
}
}
-void test_GetTimeNs_3(void)
-{
+void test_GetTimeNs_3(void) {
uint64_t timeNow, timeLast, timeDiff;
CWM_OS_dbgPrintf("[test_GetTimeNs_3] test 20 minutes start\r\n");
timeNow = CWM_OS_GetTimeNs();
timeDiff = timeNow - timeLast;
//CWM_OS_dbgPrintf("timeNow=%lld\ttimeLast=%lld\ttimeDiff=%lld\n", timeNow, timeLast, timeDiff);
- if (timeDiff >= (uint64_t)1 * 60 * 1000000000) {
+ if (timeDiff >= (uint64_t)20 * 60 * 1000000000) {
CWM_OS_dbgPrintf("[test_GetTimeNs_3] test 20 minutes end\r\n");
break;
}
}
}
-void test_uSleep_1(void)
-{
+void test_uSleep_1(void) {
CWM_OS_dbgPrintf("[test_uSleep_1] test 10 seconds start\r\n");
void test_uSleep_3(void) {
int i, j, k;
- //CWM_OS_uSleep 只能到ms,所以实际上等于10000秒
+
CWM_OS_dbgPrintf("[test_uSleep_3] test 10 seconds start\r\n");
for (j = 0; j < 10; j ++) {
- CWM_OS_dbgPrintf("j=%d\n",j);
for (i = 0; i < 1000; i ++) {
- if (i%10 == 0) CWM_OS_dbgPrintf("i=%d\n",i);
for (k = 0; k < 1000; k ++) {
- // if (k%100 == 0) CWM_OS_dbgPrintf("k=%d\n",k);
CWM_OS_uSleep(1);
}
}
}
#ifndef CHECK_STACK_TIME_MS
-#define CHECK_STACK_TIME_MS (uint64_t)(1 * 60 * 1000)
+#define CHECK_STACK_TIME_MS (uint64_t)(5 * 60 * 1000)
#endif
void test_stack(void) {
while (1) {
for (int i=0; i< sizeof(buff); i++) {
- if ( (buff[i]&0xFF) != 0x96) {
- CWM_OS_dbgPrintf("[test_stack] somebody touch my stack!!! buf[%d]=0x%X\r\n",i, buff[i]);
+ if (buff[i] != 0x96) {
+ CWM_OS_dbgPrintf("[test_stack] somebody touch my stack!!!\r\n");
CWM_OS_dbgPrintf("[test_stack] test for %lld ms end\r\n", CHECK_STACK_TIME_MS);
return;
}
CWM_OS_dbgPrintf("[test_stack] test for %lld ms end\r\n", CHECK_STACK_TIME_MS);
}
-
-static errcode_t pcm_stream_task_body(void *data)
-{
-
-
- test_malloc_1();
- test_free_1();
+void test_api(void) {
test_GetTimeNs_0(); // up_time, accumulate ts_ns from zero
test_GetTimeNs_1(); // 10 seconds
test_GetTimeNs_2(); // 10 seconds, accurate to 1ms
+ test_GetTimeNs_3(); // 20 minutes
+
+ test_malloc_1();
+ test_free_1();
test_uSleep_1(); // 10 seconds
test_uSleep_2(); // 10 seconds, accurate to 1ms
-
- test_stack();
- test_GetTimeNs_3(); // 20 minutes
test_uSleep_3(); // 10 seconds, accurate to 1us
-
- return ERRCODE_SUCC;
}
-
-#define TASK_PRIORITY_PCM_STREAM (osPriority_t)(osPriorityLow3)
-#define PCM_STREAM_MSG_STACK_SIZE 0x1C00
-static osThreadId_t g_test_thread = NULL;
-void test_api(void) {
-
- if (g_test_thread == NULL)
- {
- osThreadAttr_t attr = {"cywee_test", 0, NULL, 0, NULL, PCM_STREAM_MSG_STACK_SIZE, TASK_PRIORITY_PCM_STREAM, 0, 0 };
- g_test_thread = osThreadNew((osThreadFunc_t)pcm_stream_task_body, NULL, &attr);
- if (g_test_thread == NULL) {
- CWM_OS_dbgPrintf( "create cywee_test task fail!\r\n");
- }else{
-
- }
- }else{
-
-
- osThreadTerminate(g_test_thread);
- g_test_thread = NULL;
- CWM_OS_dbgPrintf( "create cywee_test task already running stop it !\r\n");
-
- }
-
-
-}
-
-
-
-
-
\ No newline at end of file