Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
IoT
Open IoT SDK
examples
total-solutions
Commits
4014c3fa
Verified
Commit
4014c3fa
authored
May 20, 2022
by
Vincent Coubard
Browse files
Update kws to use CMSIS RTOS
Signed-off-by:
Vincent Coubard
<
vincent.coubard@arm.com
>
parent
5983709c
Changes
10
Hide whitespace changes
Inline
Side-by-side
kws/include/blink_task.h
View file @
4014c3fa
/*
* Copyright (c) 2021 Arm Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
/* Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef BLINK_TASK_H
#define BLINK_TASK_H
...
...
@@ -24,7 +13,7 @@ extern "C" {
/* Blinks LEDs according the ML model state.
*/
void
blink_task
(
void
*
pvParameters
);
void
blink_task
(
void
*
arg
);
#ifdef __cplusplus
}
...
...
kws/include/ml_interface.h
View file @
4014c3fa
/*
* Copyright (c) 2021 Arm Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
/* Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ML_INTERFACE_H
...
...
@@ -64,10 +52,10 @@ void on_ml_processing_change(ml_processing_change_handler_t handler, void *self)
void
ml_process_audio
(
const
int16_t
*
buffer
,
size_t
size
);
/* this task does actual ml processing and is gated by the net task which let's it run if no ota job is present */
void
ml_task
(
void
*
);
void
ml_task
(
void
*
arg
);
/* task used to communicate ml results via mqtt */
void
ml_mqtt_task
(
void
*
);
void
ml_mqtt_task
(
void
*
arg
);
#ifdef __cplusplus
}
...
...
kws/ota/ota_demo_core_mqtt.c
View file @
4014c3fa
/*
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (c) 2022, Arm Limited and Contributors. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
...
...
@@ -30,12 +31,8 @@
#include
<stdbool.h>
#include
<errno.h>
#include
"cmsis_os2.h"
#include
"aws_demo_config.h"
#include
"FreeRTOS.h"
#include
"task.h"
#include
"semphr.h"
#include
"iot_network.h"
/* CoreMQTT-Agent APIS for running MQTT in a multithreaded environment. */
...
...
@@ -80,7 +77,7 @@
#include
"ota_demo_config.h"
/* OTA Library Interface include. */
#include
"ota_os_
free
rtos.h"
#include
"ota_os_
cmsis
rtos.h"
#include
"ota_mqtt_interface.h"
/* PAL abstraction layer APIs. */
...
...
@@ -90,7 +87,6 @@
#include
"ota_appversion32.h"
#include
"ml_interface.h"
#include
"semphr.h"
/*------------- Demo configurations -------------------------*/
...
...
@@ -255,7 +251,7 @@
/**
* @brief Priority required for OTA agent task.
*/
#define otaexampleAGENT_TASK_PRIORITY (
tskIDLE_PRIORITY | portPRIVILEGE_BIT
)
#define otaexampleAGENT_TASK_PRIORITY (
osPriorityNormal
)
/**
* @brief The number of ticks to wait for the OTA Agent to complete the shutdown.
...
...
@@ -326,7 +322,7 @@
/**
* @brief Priority required for OTA statistics task.
*/
#define MQTT_AGENT_TASK_PRIORITY (
tskIDLE_PRIORITY | portPRIVILEGE_BIT
)
#define MQTT_AGENT_TASK_PRIORITY (
osPriorityNormal
)
/**
* @brief The maximum amount of time in milliseconds to wait for the commands
...
...
@@ -374,6 +370,10 @@
*/
#define MILLISECONDS_PER_TICK ( MILLISECONDS_PER_SECOND / configTICK_RATE_HZ )
#define THREAD_NOTIFICATION_FLAG 1
#define MsToSysTick(ms) (((uint64_t)ms * osKernelGetTickFreq()) / 1000)
/**
* @brief Each compilation unit that consumes the NetworkContext must define it.
* It should contain a single pointer to the type of your desired transport.
...
...
@@ -404,8 +404,7 @@ typedef struct OtaTopicFilterCallback
struct
MQTTAgentCommandContext
{
MQTTStatus_t
xReturnStatus
;
TaskHandle_t
xTaskToNotify
;
uint32_t
ulNotificationValue
;
osThreadId_t
xTaskToNotify
;
void
*
pArgs
;
};
...
...
@@ -456,7 +455,7 @@ static NetworkContext_t xNetworkContextMqtt;
/**
* @brief Semaphore for synchronizing buffer operations.
*/
static
SemaphoreHandle
_t
xBufferSemaphore
;
static
osMutexId
_t
xBufferSemaphore
;
/**
* @brief Update File path buffer.
...
...
@@ -793,14 +792,14 @@ static void prvMqttDataCallback( void * pContext,
static
void
prvMqttDefaultCallback
(
void
*
pvIncomingPublishCallbackContext
,
MQTTPublishInfo_t
*
pxPublishInfo
);
static
SemaphoreHandle
_t
mqtt_mutex
=
NULL
;
static
osMutexId
_t
mqtt_mutex
=
NULL
;
static
bool
mqtt_lock
()
{
bool
success
=
false
;
if
(
mqtt_mutex
)
{
if
(
xSemaphoreTak
e
(
mqtt_mutex
,
portMAX_DELAY
)
==
pdTRUE
)
if
(
osMutexAcquir
e
(
mqtt_mutex
,
osWaitForever
)
==
osOK
)
{
success
=
true
;
}
...
...
@@ -817,7 +816,7 @@ static bool mqtt_unlock()
bool
success
=
false
;
if
(
mqtt_mutex
)
{
if
(
xSemaphoreGiv
e
(
mqtt_mutex
)
==
pdTRUE
)
if
(
osMutexReleas
e
(
mqtt_mutex
)
==
osOK
)
{
success
=
true
;
}
...
...
@@ -882,10 +881,10 @@ static OtaTopicFilterCallback_t xOtaTopicFilterCallbacks[] =
static
void
prvOtaEventBufferFree
(
OtaEventData_t
*
const
pxBuffer
)
{
if
(
xSemaphoreTak
e
(
xBufferSemaphore
,
portMAX_DELAY
)
==
pdTRUE
)
if
(
osMutexAcquir
e
(
xBufferSemaphore
,
osWaitForever
)
==
osOK
)
{
pxBuffer
->
bufferUsed
=
false
;
(
void
)
xSemaphoreGiv
e
(
xBufferSemaphore
);
(
void
)
osMutexReleas
e
(
xBufferSemaphore
);
}
else
{
...
...
@@ -900,7 +899,7 @@ static OtaEventData_t * prvOtaEventBufferGet( void )
uint32_t
ulIndex
=
0
;
OtaEventData_t
*
pxFreeBuffer
=
NULL
;
if
(
xSemaphoreTak
e
(
xBufferSemaphore
,
portMAX_DELAY
)
==
pdTRUE
)
if
(
osMutexAcquir
e
(
xBufferSemaphore
,
osWaitForever
)
==
osOK
)
{
for
(
ulIndex
=
0
;
ulIndex
<
otaconfigMAX_NUM_OTA_DATA_BUFFERS
;
ulIndex
++
)
{
...
...
@@ -912,7 +911,7 @@ static OtaEventData_t * prvOtaEventBufferGet( void )
}
}
(
void
)
xSemaphoreGiv
e
(
xBufferSemaphore
);
(
void
)
osMutexReleas
e
(
xBufferSemaphore
);
}
else
{
...
...
@@ -1153,12 +1152,7 @@ static void prvMQTTAgentCmdCompleteCallback( MQTTAgentCommandContext_t * pxComma
if
(
pxCommandContext
->
xTaskToNotify
!=
NULL
)
{
/* Send the context's ulNotificationValue as the notification value so
* the receiving task can check the value it set in the context matches
* the value it receives in the notification. */
xTaskNotify
(
pxCommandContext
->
xTaskToNotify
,
pxCommandContext
->
ulNotificationValue
,
eSetValueWithOverwrite
);
osThreadFlagsSet
(
pxCommandContext
->
xTaskToNotify
,
THREAD_NOTIFICATION_FLAG
);
}
}
/*-----------------------------------------------------------*/
...
...
@@ -1221,12 +1215,7 @@ static void prvMQTTSubscribeCompleteCallback( MQTTAgentCommandContext_t * pxComm
if
(
pxCommandContext
->
xTaskToNotify
!=
NULL
)
{
/* Send the context's ulNotificationValue as the notification value so
* the receiving task can check the value it set in the context matches
* the value it receives in the notification. */
xTaskNotify
(
pxCommandContext
->
xTaskToNotify
,
pxCommandContext
->
ulNotificationValue
,
eSetValueWithOverwrite
);
osThreadFlagsSet
(
pxCommandContext
->
xTaskToNotify
,
THREAD_NOTIFICATION_FLAG
);
}
}
/*-----------------------------------------------------------*/
...
...
@@ -1257,12 +1246,7 @@ static void prvMQTTUnsubscribeCompleteCallback( MQTTAgentCommandContext_t * pxCo
if
(
pxCommandContext
->
xTaskToNotify
!=
NULL
)
{
/* Send the context's ulNotificationValue as the notification value so
* the receiving task can check the value it set in the context matches
* the value it receives in the notification. */
xTaskNotify
(
pxCommandContext
->
xTaskToNotify
,
pxCommandContext
->
ulNotificationValue
,
eSetValueWithOverwrite
);
osThreadFlagsSet
(
pxCommandContext
->
xTaskToNotify
,
THREAD_NOTIFICATION_FLAG
);
}
}
/*-----------------------------------------------------------*/
...
...
@@ -1286,7 +1270,7 @@ static BaseType_t prvBackoffForRetry( BackoffAlgorithmContext_t * pxRetryParams
uint32_t
ulRandomNum
=
0
;
if
(
xPkcs11GenerateRandomNumber
(
(
uint8_t
*
)
&
ulRandomNum
,
sizeof
(
ulRandomNum
)
)
==
pdPASS
)
sizeof
(
ulRandomNum
)
)
==
osOK
)
{
/* Get back-off value (in milliseconds) for the next retry attempt. */
xBackoffAlgStatus
=
BackoffAlgorithm_GetNextBackoff
(
pxRetryParams
,
ulRandomNum
,
&
usNextRetryBackOff
);
...
...
@@ -1298,7 +1282,7 @@ static BaseType_t prvBackoffForRetry( BackoffAlgorithmContext_t * pxRetryParams
else
if
(
xBackoffAlgStatus
==
BackoffAlgorithmSuccess
)
{
/* Perform the backoff delay. */
vTask
Delay
(
pdMS_TO_TICKS
(
usNextRetryBackOff
)
);
os
Delay
(
pdMS_TO_TICKS
(
usNextRetryBackOff
)
);
xReturnStatus
=
pdPASS
;
...
...
@@ -1318,11 +1302,11 @@ static BaseType_t prvBackoffForRetry( BackoffAlgorithmContext_t * pxRetryParams
static
uint32_t
prvGetTimeMs
(
void
)
{
TickType
_t
xTickCount
=
0
;
uint32
_t
xTickCount
=
0
;
uint32_t
ulTimeMs
=
0UL
;
/* Get the current tick count. */
xTickCount
=
xTask
GetTickCount
();
xTickCount
=
osKernel
GetTickCount
();
/* Convert the ticks to milliseconds. */
ulTimeMs
=
(
uint32_t
)
xTickCount
*
MILLISECONDS_PER_TICK
;
...
...
@@ -1341,13 +1325,11 @@ static MQTTStatus_t prvMqttAgentInit( void )
MQTTStatus_t
xReturn
;
MQTTFixedBuffer_t
xFixedBuffer
=
{
.
pBuffer
=
pucNetworkBuffer
,
.
size
=
MQTT_AGENT_NETWORK_BUFFER_SIZE
};
static
uint8_t
ucStaticQueueStorageArea
[
MQTT_AGENT_COMMAND_QUEUE_LENGTH
*
sizeof
(
MQTTAgentCommand_t
*
)
];
static
StaticQueue_t
xStaticQueueStructure
;
LogDebug
(
(
"Creating command queue."
)
);
xCommandQueue
.
queue
=
xQueueCreateStatic
(
MQTT_AGENT_COMMAND_QUEUE_LENGTH
,
sizeof
(
MQTTAgentCommand_t
*
),
ucStaticQueueStorageArea
,
&
xStaticQueueStructure
);
xCommandQueue
.
queue
=
osMessageQueueNew
(
MQTT_AGENT_COMMAND_QUEUE_LENGTH
,
sizeof
(
MQTTAgentCommand_t
*
),
NULL
);
/* Initialize the agent task pool. */
Agent_InitializePool
();
...
...
@@ -1542,18 +1524,17 @@ static void prvDisconnectFromMQTTBroker( void )
xCommandParams
.
blockTimeMs
=
MQTT_AGENT_SEND_BLOCK_TIME_MS
;
xCommandParams
.
cmdCompleteCallback
=
prvMQTTAgentCmdCompleteCallback
;
xCommandParams
.
pCmdCompleteCallbackContext
=
&
xCommandContext
;
xCommandContext
.
xTaskToNotify
=
xTaskGetCurrentTaskHandle
();
xCommandContext
.
xTaskToNotify
=
osThreadGetId
();
xCommandContext
.
pArgs
=
NULL
;
xCommandContext
.
xReturnStatus
=
MQTTSendFailed
;
/* Disconnect MQTT session. */
xCommandStatus
=
MQTTAgent_Disconnect
(
&
xGlobalMqttAgentContext
,
&
xCommandParams
);
configASSERT
(
xCommandStatus
==
MQTTSuccess
);
xTaskNotifyWait
(
0
,
0
,
NULL
,
pdMS_TO_TICKS
(
MQTT_AGENT_MS_TO_WAIT_FOR_NOTIFICATION
)
);
osThreadFlagsWait
(
THREAD_NOTIFICATION_FLAG
,
0
,
pdMS_TO_TICKS
(
MQTT_AGENT_MS_TO_WAIT_FOR_NOTIFICATION
)
);
/* End TLS session, then close TCP connection. */
(
void
)
SecureSocketsTransport_Disconnect
(
&
xNetworkContextMqtt
);
...
...
@@ -1585,7 +1566,7 @@ static OtaMqttStatus_t prvMqttSubscribe( const char * pcTopicFilter,
xCommandParams
.
blockTimeMs
=
MQTT_AGENT_SEND_BLOCK_TIME_MS
;
xCommandParams
.
cmdCompleteCallback
=
prvMQTTSubscribeCompleteCallback
;
xCommandParams
.
pCmdCompleteCallbackContext
=
&
xCommandContext
;
xCommandContext
.
xTaskToNotify
=
xTaskGetCurrentTaskHandle
();
xCommandContext
.
xTaskToNotify
=
osThreadGetId
();
xCommandContext
.
pArgs
=
&
xSubscribeArgs
;
xCommandContext
.
xReturnStatus
=
MQTTSendFailed
;
...
...
@@ -1593,10 +1574,9 @@ static OtaMqttStatus_t prvMqttSubscribe( const char * pcTopicFilter,
xCommandStatus
=
MQTTAgent_Subscribe
(
&
xGlobalMqttAgentContext
,
&
xSubscribeArgs
,
&
xCommandParams
);
configASSERT
(
xCommandStatus
==
MQTTSuccess
);
xTaskNotifyWait
(
0
,
0
,
NULL
,
pdMS_TO_TICKS
(
MQTT_AGENT_MS_TO_WAIT_FOR_NOTIFICATION
)
);
osThreadFlagsWait
(
THREAD_NOTIFICATION_FLAG
,
0
,
pdMS_TO_TICKS
(
MQTT_AGENT_MS_TO_WAIT_FOR_NOTIFICATION
)
);
if
(
xCommandContext
.
xReturnStatus
!=
MQTTSuccess
)
{
...
...
@@ -1636,17 +1616,17 @@ static OtaMqttStatus_t prvMqttPublish( const char * const pcTopic,
xCommandParams
.
blockTimeMs
=
MQTT_AGENT_SEND_BLOCK_TIME_MS
;
xCommandParams
.
cmdCompleteCallback
=
prvMQTTAgentCmdCompleteCallback
;
xCommandParams
.
pCmdCompleteCallbackContext
=
&
xCommandContext
;
xCommandContext
.
xTaskToNotify
=
xTaskGetCurrentTaskHandle
();
xCommandContext
.
xTaskToNotify
=
osThreadGetId
();
xCommandContext
.
pArgs
=
NULL
;
xCommandContext
.
xReturnStatus
=
MQTTSendFailed
;
xCommandStatus
=
MQTTAgent_Publish
(
&
xGlobalMqttAgentContext
,
&
xPublishInfo
,
&
xCommandParams
);
configASSERT
(
xCommandStatus
==
MQTTSuccess
);
xTaskNotifyWait
(
0
,
0
,
NULL
,
pdMS_TO_TICKS
(
MQTT_AGENT_MS_TO_WAIT_FOR_NOTIFICATION
)
);
osThreadFlagsWait
(
THREAD_NOTIFICATION_FLAG
,
0
,
pdMS_TO_TICKS
(
MQTT_AGENT_MS_TO_WAIT_FOR_NOTIFICATION
)
);
if
(
xCommandContext
.
xReturnStatus
!=
MQTTSuccess
)
{
...
...
@@ -1685,7 +1665,7 @@ static OtaMqttStatus_t prvMqttUnSubscribe( const char * pcTopicFilter,
xCommandParams
.
blockTimeMs
=
MQTT_AGENT_SEND_BLOCK_TIME_MS
;
xCommandParams
.
cmdCompleteCallback
=
prvMQTTUnsubscribeCompleteCallback
;
xCommandParams
.
pCmdCompleteCallbackContext
=
&
xCommandContext
;
xCommandContext
.
xTaskToNotify
=
xTaskGetCurrentTaskHandle
();
xCommandContext
.
xTaskToNotify
=
osThreadGetId
();
xCommandContext
.
pArgs
=
&
xSubscribeArgs
;
xCommandContext
.
xReturnStatus
=
MQTTSendFailed
;
...
...
@@ -1693,10 +1673,10 @@ static OtaMqttStatus_t prvMqttUnSubscribe( const char * pcTopicFilter,
xCommandStatus
=
MQTTAgent_Unsubscribe
(
&
xGlobalMqttAgentContext
,
&
xSubscribeArgs
,
&
xCommandParams
);
configASSERT
(
xCommandStatus
==
MQTTSuccess
);
xTaskNotifyWait
(
0
,
0
,
NULL
,
pdMS_TO_TICKS
(
MQTT_AGENT_MS_TO_WAIT_FOR_NOTIFICATION
)
);
osThreadFlagsWait
(
THREAD_NOTIFICATION_FLAG
,
0
,
pdMS_TO_TICKS
(
MQTT_AGENT_MS_TO_WAIT_FOR_NOTIFICATION
)
);
if
(
xCommandContext
.
xReturnStatus
!=
MQTTSuccess
)
{
...
...
@@ -1717,15 +1697,15 @@ static OtaMqttStatus_t prvMqttUnSubscribe( const char * pcTopicFilter,
static
void
prvSetOtaInterfaces
(
OtaInterfaces_t
*
pxOtaInterfaces
)
{
/* Initialize OTA library OS Interface. */
pxOtaInterfaces
->
os
.
event
.
init
=
OtaInitEvent_
Free
RTOS
;
pxOtaInterfaces
->
os
.
event
.
send
=
OtaSendEvent_
Free
RTOS
;
pxOtaInterfaces
->
os
.
event
.
recv
=
OtaReceiveEvent_
Free
RTOS
;
pxOtaInterfaces
->
os
.
event
.
deinit
=
OtaDeinitEvent_
Free
RTOS
;
pxOtaInterfaces
->
os
.
timer
.
start
=
OtaStartTimer_
Free
RTOS
;
pxOtaInterfaces
->
os
.
timer
.
stop
=
OtaStopTimer_
Free
RTOS
;
pxOtaInterfaces
->
os
.
timer
.
delete
=
OtaDeleteTimer_
Free
RTOS
;
pxOtaInterfaces
->
os
.
mem
.
malloc
=
Malloc_
Free
RTOS
;
pxOtaInterfaces
->
os
.
mem
.
free
=
Free_
Free
RTOS
;
pxOtaInterfaces
->
os
.
event
.
init
=
OtaInitEvent_
CMSIS
RTOS
;
pxOtaInterfaces
->
os
.
event
.
send
=
OtaSendEvent_
CMSIS
RTOS
;
pxOtaInterfaces
->
os
.
event
.
recv
=
OtaReceiveEvent_
CMSIS
RTOS
;
pxOtaInterfaces
->
os
.
event
.
deinit
=
OtaDeinitEvent_
CMSIS
RTOS
;
pxOtaInterfaces
->
os
.
timer
.
start
=
OtaStartTimer_
CMSIS
RTOS
;
pxOtaInterfaces
->
os
.
timer
.
stop
=
OtaStopTimer_
CMSIS
RTOS
;
pxOtaInterfaces
->
os
.
timer
.
delete
=
OtaDeleteTimer_
CMSIS
RTOS
;
pxOtaInterfaces
->
os
.
mem
.
malloc
=
Malloc_
CMSIS
RTOS
;
pxOtaInterfaces
->
os
.
mem
.
free
=
Free_
CMSIS
RTOS
;
/* Initialize the OTA library MQTT Interface.*/
pxOtaInterfaces
->
mqtt
.
subscribe
=
prvMqttSubscribe
;
...
...
@@ -1750,7 +1730,7 @@ static void prvOTAAgentTask( void * pParam )
OTA_EventProcessingTask
(
pParam
);
LogInfo
(
(
"OTA Agent stopped."
)
);
vTaskDelete
(
NULL
);
osThreadTerminate
(
osThreadGetId
()
);
}
/*-----------------------------------------------------------*/
...
...
@@ -1800,7 +1780,7 @@ static void prvMQTTAgentTask( void * pParam )
}
}
while
(
xMQTTStatus
!=
MQTTSuccess
);
vTaskDelete
(
NULL
);
osThreadTerminate
(
osThreadGetId
()
);
}
/*-----------------------------------------------------------*/
...
...
@@ -1820,7 +1800,7 @@ static BaseType_t prvSuspendOTA( void )
while
(
(
OTA_GetState
()
!=
OtaAgentStateSuspended
)
&&
(
ulSuspendTimeout
>
0
)
)
{
/* Wait for OTA Library state to suspend */
vTask
Delay
(
pdMS_TO_TICKS
(
otaexampleEXAMPLE_TASK_DELAY_MS
)
);
os
Delay
(
pdMS_TO_TICKS
(
otaexampleEXAMPLE_TASK_DELAY_MS
)
);
ulSuspendTimeout
-=
otaexampleEXAMPLE_TASK_DELAY_MS
;
}
...
...
@@ -1858,7 +1838,7 @@ static BaseType_t prvResumeOTA( void )
while
(
(
OTA_GetState
()
==
OtaAgentStateSuspended
)
&&
(
ulSuspendTimeout
>
0
)
)
{
/* Wait for OTA Library state to suspend */
vTask
Delay
(
pdMS_TO_TICKS
(
otaexampleEXAMPLE_TASK_DELAY_MS
)
);
os
Delay
(
pdMS_TO_TICKS
(
otaexampleEXAMPLE_TASK_DELAY_MS
)
);
ulSuspendTimeout
-=
otaexampleEXAMPLE_TASK_DELAY_MS
;
}
...
...
@@ -1919,15 +1899,17 @@ static BaseType_t prvRunOTADemo( void )
if
(
xStatus
==
pdPASS
)
{
xStatus
=
xTaskCreate
(
prvOTAAgentTask
,
"OTA Agent Task"
,
otaexampleAGENT_TASK_STACK_SIZE
,
NULL
,
otaexampleAGENT_TASK_PRIORITY
,
NULL
);
if
(
xStatus
!=
pdPASS
)
osThreadAttr_t
attr
=
{
.
name
=
"OTA Agent Task"
,
.
stack_size
=
otaexampleAGENT_TASK_STACK_SIZE
,
.
priority
=
osPriorityNormal
};
osThreadId_t
agent_task
=
osThreadNew
(
prvOTAAgentTask
,
NULL
,
&
attr
);
if
(
agent_task
==
NULL
)
{
xStatus
=
pdFAIL
;
LogError
(
(
"Failed to create OTA agent task:"
)
);
}
}
...
...
@@ -1960,7 +1942,7 @@ static BaseType_t prvRunOTADemo( void )
xOtaStatistics
.
otaPacketsDropped
)
);
}
#endif
/* OTA_STATISTICS_ENABLED */
vTask
Delay
(
pdMS_TO_TICKS
(
otaexampleEXAMPLE_TASK_DELAY_MS
)
);
os
Delay
(
pdMS_TO_TICKS
(
otaexampleEXAMPLE_TASK_DELAY_MS
)
);
}
}
...
...
@@ -2012,7 +1994,7 @@ int RunOtaCoreMqttDemo( bool xAwsIotMqttMode,
appFirmwareVersion
.
u
.
x
.
build
)
);
/* Initialize semaphore for buffer operations. */
xBufferSemaphore
=
xSemaphoreCreateMutex
(
);
xBufferSemaphore
=
osMutexNew
(
NULL
);
if
(
xBufferSemaphore
==
NULL
)
{
...
...
@@ -2023,7 +2005,7 @@ int RunOtaCoreMqttDemo( bool xAwsIotMqttMode,
xDemoStatus
=
pdPASS
;
}
mqtt_mutex
=
xSemaphoreCreateMutex
(
);
mqtt_mutex
=
osMutexNew
(
NULL
);
if
(
!
mqtt_lock
())
{
LogError
(
(
"Failed get mqtt lock, demo cannot start"
)
);
...
...
@@ -2052,12 +2034,14 @@ int RunOtaCoreMqttDemo( bool xAwsIotMqttMode,
if
(
xDemoStatus
==
pdPASS
)
{
if
(
xTaskCreate
(
prvMQTTAgentTask
,
"MQTT Agent Task"
,
MQTT_AGENT_TASK_STACK_SIZE
,
NULL
,
MQTT_AGENT_TASK_PRIORITY
,
NULL
)
!=
pdPASS
)
osThreadAttr_t
attr
=
{
.
stack_size
=
MQTT_AGENT_TASK_STACK_SIZE
,
.
priority
=
osPriorityNormal
};
osThreadId_t
agent_task
=
osThreadNew
(
prvMQTTAgentTask
,
NULL
,
&
attr
);
if
(
agent_task
==
NULL
)
{
xDemoStatus
=
pdFAIL
;
LogError
(
(
"Failed to create MQTT agent task:"
)
);
...
...
@@ -2094,7 +2078,7 @@ int RunOtaCoreMqttDemo( bool xAwsIotMqttMode,
if
(
xBufferSemaphore
!=
NULL
)
{
/* Cleanup semaphore created for buffer operations. */
vSemaphore
Delete
(
xBufferSemaphore
);
osMutex
Delete
(
xBufferSemaphore
);
}
return
(
(
xDemoStatus
==
pdPASS
)
?
EXIT_SUCCESS
:
EXIT_FAILURE
);
...
...
kws/ota/ota_pal_psa/version/application_version.c
View file @
4014c3fa
/*
* Copyright (c) 2020-202
1
Arm Limited. All rights reserved.
* Copyright (c) 2020-202
2
Arm Limited. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
...
...
@@ -29,8 +29,6 @@
/* C Runtime includes. */
#include
<stdlib.h>
/* Amazon FreeRTOS include. */
#include
"FreeRTOS.h"
#include
"application_version.h"
/* TF-M Firmware Update service. */
...
...
kws/source/blink_task.c
View file @
4014c3fa
/*
* Copyright (c) 2021 Arm Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
/* Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
#include
"stdio.h"
#include
"FreeRTOS.h"
#include
"semphr.h"
#include
"task.h"
#include
"queue.h"
#include
"timers.h"
#include
"tfm_ns_interface.h"
#include
"psa/protected_storage.h"
#include
"bsp_serial.h"
#include
<stdio.h>
#include
"blink_task.h"
#include
"ml_interface.h"
#include
"cmsis_os2.h"
#include
<stdbool.h>
#define BLINK_TIMER_PERIOD_MS 25
enum
{
LED1
=
1
<<
0
,
LED_YES
=
LED1
,
...
...
@@ -60,10 +45,10 @@ static ui_msg_t blink_event = {UI_EVENT_BLINK};
static
ui_msg_t
ml_state_change_event
=
{
UI_EVENT_ML_STATE_CHANGE
};
// Message queue
static
QueueHandle
_t
ui_msg_queue
=
NULL
;
static
osMessageQueueId
_t
ui_msg_queue
=
NULL
;
// Blinking timer
TimerHandle
_t
blink_timer
;
static
osTimerId
_t
blink_timer
=
NULL
;
void
led_on
(
uint8_t
bits
)
{
...
...
@@ -80,15 +65,20 @@ void led_toggle(uint8_t bits)
*
fpgaio_leds
^=
bits
;
}
static
void
blink_timer_cb
(
TimerHandle_t
xTimer
)
static
void
blink_timer_cb
(
void
*
arg
)
{
(
void
)
arg
;
// Schedule blink of the led in the event queue
xQueueSend
(
ui_msg_queue
,
(
void
*
)
&
blink_event
,
0
);
if
(
osMessageQueuePut
(
ui_msg_queue
,
(
void
*
)
&
blink_event
,
0
,
0
)
!=
osOK
)
{
printf
(
"Failed to send message to ui_msg_queue
\r\n
"
);
}
}
static
void
ml_change_handler
(
void
*
self
,
ml_processing_state_t
new_state
)
{
xQueueSend
(
ui_msg_queue
,
(
void
*
)
&
ml_state_change_event
,
(
TickType_t
)
0
);
if
(
osMessageQueuePut
(
ui_msg_queue
,
(
void
*
)
&
ml_state_change_event
,
0
,
0
)
!=
osOK
)
{
printf
(
"Failed to send message to ui_msg_queue
\r\n
"
);
}
}
void
process_ml_state_change
(
ml_processing_state_t
new_state
)
...
...
@@ -149,20 +139,25 @@ void process_ml_state_change(ml_processing_state_t new_state)
* LED1 off and LED2 off => heard NO
* LED1 off and LED2 blinking => no/unknown input
*/
void
blink_task
(
void
*
pvParameters
)
void
blink_task
(
void
*
arg
)
{
(
void
)
arg
;
printf
(
"Blink task started
\r\n
"
);
// Create the ui event queue
ui_msg_queue
=
xQueueCreate
(
10
,
// In practive at most two items (blink and ml state change) should be in the queue.
sizeof
(
ui_msg_t
));
ui_msg_queue
=
osMessageQueueNew
(
10
,
sizeof
(
ui_msg_t
),
NULL
);
if
(
!
ui_msg_queue
)