Verified Commit a611212e authored by Hugo L'hostis's avatar Hugo L'hostis Committed by Vincent Coubard
Browse files

Convert application_helpers.c and print_log.c to CMSIS


Signed-off-by: Vincent Coubard's avatarVincent Coubard <vincent.coubard@arm.com>
parent f8aafe36
......@@ -100,8 +100,9 @@ target_link_libraries(${LIB_NAME}
PRIVATE
mcu-driver-hal
FreeRTOS-Plus-TCP
freertos-kernel
tfm-ns-interface
mcu-driver-hal
freertos-cmsis-rtos
)
target_compile_definitions(${LIB_NAME}
......
......@@ -13,4 +13,10 @@
#define OS_MUTEX_OBJ_MEM 1
#define OS_MUTEX_NUM 4
// Memory allocation related definitions.
#define configSUPPORT_STATIC_ALLOCATION 1
#define configSUPPORT_DYNAMIC_ALLOCATION 1
#define configTOTAL_HEAP_SIZE 512000 // should be enough
#define configAPPLICATION_ALLOCATED_HEAP 1
#endif // RTE_COMPONENTS_H
......@@ -6,10 +6,8 @@
#include <string.h>
#include "bsp_serial.h"
#include "print_log.h"
#include "FreeRTOS.h"
#include "task.h"
#include "cmsis_os2.h"
#include "RTE_Components.h"
/* includes for TFM */
#include "tfm_ns_interface.h"
#include "psa/protected_storage.h"
......@@ -42,10 +40,17 @@ mdh_emac_t *lwip_emac_get_default_instance(void)
void vAssertCalled( const char * pcFile, unsigned long ulLine )
{
print_log("Assert called %s:%lu", pcFile, ulLine);
print_log("Assert failed %s:%lu", pcFile, ulLine);
while(1);
}
void configASSERT(uint32_t condition)
{
if ( condition == 0 ) {
vAssertCalled( __FILE__, __LINE__ );
}
}
/**
* This function is only used in the PKCS#11 test case. In the PKCS#11 test,
......
/*
* Copyright (c) 2018-2019 Arm Limited. All Rights Reserved.
* Copyright (c) 2018-2022 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
......@@ -23,14 +23,14 @@
#include <stdio.h>
#include <stdarg.h>
#include "FreeRTOS.h"
#include "cmsis_os2.h"
#include "print_log.h"
#include "mpu_wrappers.h"
SemaphoreHandle_t xUARTMutex __attribute__(( section( "tasks_share" ) )) = NULL;
osMutexId_t xUARTMutex __attribute__(( section( "tasks_share" ) )) = NULL;
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
StaticSemaphore_t xUARTMutexBuffer;
osMutexId_t xUARTMutexBuffer;
#endif
//extern BaseType_t xPortRaisePrivilege( void );
......@@ -39,15 +39,21 @@ StaticSemaphore_t xUARTMutexBuffer;
#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
/*
* @brief Dynamically create an instance of UART mutex, and return
* a handle to the mutex.
* the mutex id.
*
* @return If the mutex is successfully created then a handle to the created
* mutex is returned. Otherwise, NULL is returned.
* @return If the mutex is successfully created then the id of the created
* mutex is returned. Otherwise, 0 is returned.
*/
static SemaphoreHandle_t prvCreateUARTMutex( void )
static osMutexId_t prvCreateUARTMutex( void )
{
SemaphoreHandle_t xMutexHandle;
xMutexHandle = xSemaphoreCreateMutex();
osMutexId_t xMutexHandle = 0;
const osMutexAttr_t Mutex_attr = {
"UARTMutex", // human readable mutex name
osMutexPrioInherit, // attr_bits
NULL, // memory for control block
0U // size for control block
};
xMutexHandle = osMutexNew( &Mutex_attr );
configASSERT( xMutexHandle );
return xMutexHandle;
}
......@@ -56,15 +62,21 @@ SemaphoreHandle_t xMutexHandle;
#elif( configSUPPORT_STATIC_ALLOCATION == 1 )
/*
* @brief Statically create an instance of UART mutex, and return
* a handle to the mutex.
* the mutex id.
*
* @return If the mutex is successfully created then a handle to the created
* mutex is returned. Otherwise, NULL is returned.
* @return If the mutex is successfully created then the id of the created
* mutex is returned. Otherwise, 0 is returned.
*/
static SemaphoreHandle_t prvCreateUARTMutex( void )
static osMutexId_t prvCreateUARTMutex( void )
{
SemaphoreHandle_t xMutexHandle;
xMutexHandle = xSemaphoreCreateMutexStatic( &xUARTMutexBuffer );
osMutexId_t xMutexHandle = 0;
const osMutexAttr_t Mutex_attr = {
"UARTMutex", // human readable mutex name
osMutexPrioInherit, // attr_bits
&xUARTMutexBuffer, // memory for control block
sizeof(osMutexId_t) // size for control block
};
xMutexHandle = osMutexNew( Mutex_attr );
configASSERT( xMutexHandle );
return xMutexHandle;
}
......@@ -84,39 +96,37 @@ void vUARTLockInit( void )
* @param xBlockTime The time in ticks to wait for the mutex to become
* available. The macro portTICK_PERIOD_MS can be used to
* convert this to a real time. A block time of zero can be
* used to poll the semaphore. A block time of portMAX_DELAY
* can be used to block indefinitely (provided
* INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h).
* used to poll the semaphore. A block time of osWaitForever
* can be used to block indefinitely.
*
* @return pdTRUE if the mutex was obtained. pdFALSE if xBlockTime expired
* without the mutex becoming available.
* @return osOK if the mutex was obtained. the returned status if the mutex couldn't
* be acquired.
*/
static BaseType_t xUARTLockAcquire( TickType_t xBlockTime )
static osStatus_t xUARTLockAcquire( uint32_t xBlockTime )
{
return xSemaphoreTake( xUARTMutex, xBlockTime );
return osMutexAcquire( xUARTMutex, xBlockTime );
}
/*-----------------------------------------------------------*/
/*
* @brief Release the UART mutex previously obtained.
*
* @return pdTRUE if the mutex was released. pdFALSE if an error occurred.
* @return osOK if the mutex was released. the returned status if an error
* occurred.
*/
static BaseType_t xUARTLockRelease( void )
static osStatus_t xUARTLockRelease( void )
{
return xSemaphoreGive( xUARTMutex );
return osMutexRelease( xUARTMutex );
}
/*-----------------------------------------------------------*/
void print_log( const char *format, ... )
{
va_list args;
//BaseType_t xRunningPrivileged;
/* A UART lock is used here to ensure that there is
* at most one task accessing UART at a time.
*/
xUARTLockAcquire( portMAX_DELAY );
xUARTLockAcquire( osWaitForever );
/* Raise to privilidge mode to access related data and device. */
//xRunningPrivileged = xPortRaisePrivilege();
......@@ -124,8 +134,6 @@ va_list args;
vprintf( format, args );
va_end ( args );
printf("\r\n");
/* Reset privilidge mode if it is raised. */
//vPortResetPrivilege( xRunningPrivileged );
xUARTLockRelease();
}
// void print_log( const char *format, ... )
......
/*
* Copyright (c) 2018-2019 Arm Limited. All Rights Reserved.
* Copyright (c) 2018-2022 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
......@@ -27,8 +27,8 @@
extern "C" {
#endif
#include "FreeRTOS.h"
#include "semphr.h"
#include "cmsis_os2.h"
#include "RTE_Components.h"
#define ERR_LEVEL 3
#define WARN_LEVEL 2
......@@ -46,7 +46,7 @@ extern "C" {
/**
* @brief Initialize the mutex of UART.
*/
void vUARTLockInit( void ) PRIVILEGED_FUNCTION;
void vUARTLockInit( void ) __attribute__( ( section( "privileged_functions" ) ) );
void print_log( const char *format, ... );
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment