varch/doc/oscp.md

72 lines
1.5 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## 介绍
`oscp`是一个用于C语言的简单模拟示波器模块相关它定义了一些与示波器功能相关的常量以及提供了几个关键的函数接口可用于设置要监测的值的地址、设置时间尺度还有一个需定期调用的显示处理任务函数方便开发者在C语言项目中实现模拟示波器相关的功能比如对特定数据的监测及按设定时间尺度展示等操作。
## 接口
### 函数
```c
void oscp_handle(void);
int oscp_set_monitor(int *m);
int oscp_set_scale(int s);
```
使用例子:
```c
int level = 0;
static unsigned int get_msec(void)
{
struct timeval mstime;
unsigned int ms = 0;
gettimeofday(&mstime, NULL);
ms = mstime.tv_sec * 1000 + mstime.tv_usec / 1000;
return ms;
}
static void task1(void)
{
oscp_handle();
}
static void task2(void)
{
static int count = 0;
count++;
if (count > 628) count = 0;
level = RESOLUTION / 2 * sin((double)count / 10) + RESOLUTION / 2;
}
static void test_base(void)
{
#if defined(TEST_TARGET_oscp)
uint32_t count = 0;
oscp_set_scale(O_SCALE_50MS);
oscp_set_monitor(&level);
while (1)
{
count++;
if (count >= 25200000) count = 0;
if (count % 5 == 0) task1();
if (count % 50 == 0) task2();
usleep(1000);
}
#else
printf("create task %d\r\n", task_create(5, task1));
printf("create task %d\r\n", task_create(50, task2));
oscp_set_scale(O_SCALE_50MS);
oscp_set_monitor(&level);
#endif
}
```