liuzhigang
2025-11-11 29cf7137d26f710bc9dab4e590d76181216d2f6c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "cmsis_os2.h"
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
#include "HIDO_Input.h"
#include "HIDO_Timer.h"
#include "GPS.h"
#include "DBG.h"
#include "Internet.h"
#include "global_param.h"
#include "MCUFlash.h"
#include "HIDO_ATLite.h"
#include "UDPClient.h"
#include "bluetooth.h"
 
static osSemaphoreId_t g_semaphoreHandle = NULL;
 
void app_task(void *pvParameters)
{
    GPS_Init();
    Internet_Init();
    UDPClient_Init();
 
    while (1)
    {
        HIDO_UINT32 timeout = HIDO_TimerGetNearestTimeout(1000);
        if (xSemaphoreTake(g_semaphoreHandle, timeout / portTICK_PERIOD_MS) == pdTRUE)
        {
            DBG_Poll();
            BT_Poll();
            HIDO_ATLitePoll();
            Internet_Poll();
            GPS_Poll();
            UDPClient_Poll();
        }
 
        HIDO_TimerPoll();
    }
}
 
void app_trigger_from_isr(void)
{
    BaseType_t xHigherPriorityTaskWoken = pdFALSE;
 
    if (g_semaphoreHandle != NULL)
    {
        BaseType_t result = xSemaphoreGiveFromISR(g_semaphoreHandle, &xHigherPriorityTaskWoken);
 
        if (xHigherPriorityTaskWoken == pdTRUE)
        {
            portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
        }
    }
}
 
void app_main(void)
{
    MCUFlash_Init();
    parameter_init();
    printf("demo run!\r\n");
    TaskHandle_t xTaskHandle = NULL;
 
    osSemaphoreAttr_t semaphore_attr = {
        .name = "MySemaphore",
        .attr_bits = 0,
        .cb_mem = NULL,
        .cb_size = 0};
 
    // ´´½¨¶þ½øÖÆÐźÅÁ¿£¨³õʼ¼ÆÊýΪ0£¬×î´ó¼ÆÊýΪ1£©
    g_semaphoreHandle = osSemaphoreNew(1, 0, &semaphore_attr);
 
    xTaskCreate(
        app_task,
        "AppTask",
        2048,
        NULL,
        tskIDLE_PRIORITY + 1,
        &xTaskHandle);
}