commit
4a07f534d8
|
@ -29,7 +29,7 @@ void Pm10Ps5308(void)
|
|||
{
|
||||
struct SensorQuantity *pm1_0 = SensorQuantityFind(SENSOR_QUANTITY_PS5308_PM1_0, SENSOR_QUANTITY_PM);
|
||||
SensorQuantityOpen(pm1_0);
|
||||
UserTaskDelay(2000);
|
||||
PrivTaskDelay(2000);
|
||||
printf("PM1.0 : %d ug/m³\n", SensorQuantityRead(pm1_0));
|
||||
SensorQuantityClose(pm1_0);
|
||||
}
|
|
@ -29,7 +29,7 @@ void VoiceD124(void)
|
|||
{
|
||||
struct SensorQuantity *voice = SensorQuantityFind(SENSOR_QUANTITY_D124_VOICE, SENSOR_QUANTITY_VOICE);
|
||||
SensorQuantityOpen(voice);
|
||||
UserTaskDelay(2000);
|
||||
PrivTaskDelay(2000);
|
||||
uint16 result = SensorQuantityRead(voice);
|
||||
printf("voice : %d.%d dB\n", result/(10*voice->value.decimal_places), result%(10*voice->value.decimal_places));
|
||||
SensorQuantityClose(voice);
|
||||
|
|
|
@ -81,7 +81,7 @@ static int SensorDeviceRead(struct SensorDevice *sdev, size_t len)
|
|||
PrivRead(sdev->fd, &tmp, 1);
|
||||
if ((tmp == 0xFE) || (timeout >= 1000))
|
||||
break;
|
||||
UserTaskDelay(10);
|
||||
PrivTaskDelay(10);
|
||||
++timeout;
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ static int SensorDeviceRead(struct SensorDevice *sdev, size_t len)
|
|||
if (PrivWrite(sdev->fd, NULL, 0) != 1)
|
||||
return -1;
|
||||
|
||||
UserTaskDelay(50);
|
||||
PrivTaskDelay(50);
|
||||
|
||||
if (PrivRead(sdev->fd, sdev->buffer, len) != 1)
|
||||
return -1;
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
#include <sensor.h>
|
||||
|
||||
static struct SensorDevice ps5308;
|
||||
static int32_t active_task_id;
|
||||
static int buff_lock;
|
||||
static pthread_t active_task_id;
|
||||
static pthread_mutex_t buff_lock;
|
||||
|
||||
static struct SensorProductInfo info =
|
||||
{
|
||||
|
@ -35,13 +35,14 @@ static struct SensorProductInfo info =
|
|||
* @description: Read sensor task
|
||||
* @param sdev - sensor device pointer
|
||||
*/
|
||||
static void ReadTask(struct SensorDevice *sdev)
|
||||
static void *ReadTask(void *parameter)
|
||||
{
|
||||
struct SensorDevice *sdev = (struct SensorDevice *)parameter;
|
||||
while (1) {
|
||||
UserMutexObtain(buff_lock, WAITING_FOREVER);
|
||||
PrivMutexObtain(&buff_lock);
|
||||
sdev->done->read(sdev, 32);
|
||||
UserMutexAbandon(buff_lock);
|
||||
UserTaskDelay(750);
|
||||
PrivMutexAbandon(&buff_lock);
|
||||
PrivTaskDelay(750);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,7 +55,7 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
|
|||
{
|
||||
int result = 0;
|
||||
|
||||
buff_lock = UserMutexCreate();
|
||||
PrivMutexCreate(&buff_lock, 0);
|
||||
|
||||
sdev->fd = open(SENSOR_DEVICE_PS5308_DEV, O_RDWR);
|
||||
|
||||
|
@ -73,17 +74,8 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
|
|||
|
||||
result = ioctl(sdev->fd, OPE_INT, &cfg);
|
||||
|
||||
UtaskType active_task;
|
||||
const char name[NAME_NUM_MAX] = "ps5308_task";
|
||||
|
||||
strncpy(active_task.name, name, strlen(name));
|
||||
active_task.func_entry = ReadTask;
|
||||
active_task.func_param = sdev;
|
||||
active_task.prio = KTASK_PRIORITY_MAX/2;
|
||||
active_task.stack_size = 1024;
|
||||
|
||||
active_task_id = UserTaskCreate(active_task);
|
||||
result = UserTaskStartup(active_task_id);
|
||||
PrivTaskCreate(&active_task_id, NULL, &ReadTask, sdev);
|
||||
PrivTaskStartup(&active_task_id);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -95,8 +87,8 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
|
|||
*/
|
||||
static int SensorDeviceClose(struct SensorDevice *sdev)
|
||||
{
|
||||
UserTaskDelete(active_task_id);
|
||||
UserMutexDelete(buff_lock);
|
||||
PrivTaskDelete(active_task_id, 0);
|
||||
PrivMutexDelete(&buff_lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -114,7 +106,7 @@ static int SensorDeviceRead(struct SensorDevice *sdev, size_t len)
|
|||
read(sdev->fd, &tmp, 1);
|
||||
if ((tmp == 0x44) || (timeout >= 1000))
|
||||
break;
|
||||
UserTaskDelay(10);
|
||||
PrivTaskDelay(10);
|
||||
++timeout;
|
||||
}
|
||||
|
||||
|
@ -175,7 +167,7 @@ static int32_t ReadPm1_0(struct SensorQuantity *quant)
|
|||
uint32_t result;
|
||||
if (quant->sdev->done->read != NULL) {
|
||||
uint16_t checksum = 0;
|
||||
UserMutexObtain(buff_lock, WAITING_FOREVER);
|
||||
PrivMutexObtain(&buff_lock);
|
||||
|
||||
for (uint8_t i = 0; i < 30; i++)
|
||||
checksum += quant->sdev->buffer[i];
|
||||
|
@ -242,7 +234,7 @@ static int32_t ReadPm2_5(struct SensorQuantity *quant)
|
|||
uint32_t result;
|
||||
if (quant->sdev->done->read != NULL) {
|
||||
uint16_t checksum = 0;
|
||||
UserMutexObtain(buff_lock, WAITING_FOREVER);
|
||||
PrivMutexObtain(&buff_lock);
|
||||
|
||||
for (uint i = 0; i < 30; i++)
|
||||
checksum += quant->sdev->buffer[i];
|
||||
|
@ -309,7 +301,7 @@ static int32_t ReadPm10(struct SensorQuantity *quant)
|
|||
uint32_t result;
|
||||
if (quant->sdev->done->read != NULL) {
|
||||
uint16_t checksum = 0;
|
||||
UserMutexObtain(buff_lock, WAITING_FOREVER);
|
||||
PrivMutexObtain(&buff_lock);
|
||||
|
||||
for (uint i = 0; i < 30; i++)
|
||||
checksum += quant->sdev->buffer[i];
|
||||
|
|
|
@ -52,7 +52,7 @@ static int SensorDeviceRead(struct SensorDevice *sdev, size_t len)
|
|||
if (PrivWrite(sdev->fd, NULL, 0) != 1)
|
||||
return -1;
|
||||
|
||||
UserTaskDelay(50);
|
||||
PrivTaskDelay(50);
|
||||
|
||||
if (PrivRead(sdev->fd, sdev->buffer, len) != 1)
|
||||
return -1;
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
static struct SensorDevice d124;
|
||||
static int32_t active_task_id;
|
||||
static int buff_lock;
|
||||
static pthread_mutex_t buff_lock;
|
||||
|
||||
static struct SensorProductInfo info =
|
||||
{
|
||||
|
@ -35,13 +35,14 @@ static struct SensorProductInfo info =
|
|||
* @description: Read sensor task
|
||||
* @param sdev - sensor device pointer
|
||||
*/
|
||||
static void ReadTask(struct SensorDevice *sdev)
|
||||
static void *ReadTask(void *parameter)
|
||||
{
|
||||
struct SensorDevice *sdev = (struct SensorDevice *)parameter;
|
||||
while (1) {
|
||||
UserMutexObtain(buff_lock, WAITING_FOREVER);
|
||||
PrivMutexObtain(&buff_lock);
|
||||
sdev->done->read(sdev, 5);
|
||||
UserMutexAbandon(buff_lock);
|
||||
UserTaskDelay(750);
|
||||
PrivMutexAbandon(&buff_lock);
|
||||
PrivTaskDelay(750);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,8 +54,9 @@ static void ReadTask(struct SensorDevice *sdev)
|
|||
static int SensorDeviceOpen(struct SensorDevice *sdev)
|
||||
{
|
||||
int result = 0;
|
||||
pthread_attr_t attr;
|
||||
|
||||
buff_lock = UserMutexCreate();
|
||||
PrivMutexCreate(&buff_lock, 0);
|
||||
|
||||
sdev->fd = PrivOpen(SENSOR_DEVICE_D124_DEV, O_RDWR);
|
||||
|
||||
|
@ -76,17 +78,11 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
|
|||
ioctl_cfg.args = &cfg;
|
||||
result = PrivIoctl(sdev->fd, OPE_INT, &ioctl_cfg);
|
||||
|
||||
UtaskType active_task;
|
||||
const char name[NAME_NUM_MAX] = "d124_task";
|
||||
attr.schedparam.sched_priority = 20;
|
||||
attr.stacksize = 2048;
|
||||
|
||||
strncpy(active_task.name, name, strlen(name));
|
||||
active_task.func_entry = ReadTask;
|
||||
active_task.func_param = sdev;
|
||||
active_task.prio = KTASK_PRIORITY_MAX/2;
|
||||
active_task.stack_size = 2048;
|
||||
|
||||
active_task_id = UserTaskCreate(active_task);
|
||||
result = UserTaskStartup(active_task_id);
|
||||
PrivTaskCreate(&active_task_id, &attr, &ReadTask, sdev);
|
||||
PrivTaskStartup(&active_task_id);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -98,8 +94,8 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
|
|||
*/
|
||||
static int SensorDeviceClose(struct SensorDevice *sdev)
|
||||
{
|
||||
UserTaskDelete(active_task_id);
|
||||
UserMutexDelete(buff_lock);
|
||||
PrivTaskDelete(active_task_id, 0);
|
||||
PrivMutexDelete(&buff_lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -117,7 +113,7 @@ static int SensorDeviceRead(struct SensorDevice *sdev, size_t len)
|
|||
PrivRead(sdev->fd, &tmp, 1);
|
||||
if ((tmp == 0xAA) || (timeout >= 1000))
|
||||
break;
|
||||
UserTaskDelay(10);
|
||||
PrivTaskDelay(10);
|
||||
++timeout;
|
||||
}
|
||||
|
||||
|
@ -176,7 +172,7 @@ static int32_t ReadVoice(struct SensorQuantity *quant)
|
|||
|
||||
uint32_t result;
|
||||
if (quant->sdev->done->read != NULL) {
|
||||
UserMutexObtain(buff_lock, WAITING_FOREVER);
|
||||
PrivMutexObtain(&buff_lock);
|
||||
|
||||
if (quant->sdev->buffer[3] == quant->sdev->buffer[1] + quant->sdev->buffer[2]) {
|
||||
result = ((uint16_t)quant->sdev->buffer[1] << 8) + (uint16_t)quant->sdev->buffer[2];
|
||||
|
|
|
@ -18,7 +18,8 @@
|
|||
* @date: 2020/4/20
|
||||
*
|
||||
*/
|
||||
#include<string.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "include/pthread.h"
|
||||
|
||||
int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
|
||||
|
@ -26,12 +27,22 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
|
|||
{
|
||||
int ret ;
|
||||
int pid ;
|
||||
char task_name[32] = {0};
|
||||
static int utask_id = 0;
|
||||
UtaskType task ;
|
||||
|
||||
if (NULL == attr) {
|
||||
task.prio = KTASK_PRIORITY_MAX / 2;
|
||||
task.stack_size = 1024 ;
|
||||
} else {
|
||||
task.prio = attr->schedparam.sched_priority ;
|
||||
task.stack_size = attr->stacksize ;
|
||||
}
|
||||
|
||||
task.func_entry = start_routine ;
|
||||
task.func_param = arg ;
|
||||
memcpy(task.name , "utask", 6);
|
||||
task.prio = 20 ;
|
||||
task.stack_size = 1024 ;
|
||||
task.func_param = arg;
|
||||
snprintf(task_name, sizeof(task_name) - 1, "utask%02d",utask_id++);
|
||||
memcpy(task.name , task_name, sizeof(task_name) - 1);
|
||||
|
||||
pid = UserTaskCreate(task);
|
||||
if (pid < 0)
|
||||
|
|
Loading…
Reference in New Issue