Task protection

The task must have read access to the data of the Dinkumware and libos libraries. Setting the read-only access is essential, as we assume that the print functions do not modify global data. If they would, the application will cause the MPU trap, informing us about possibly using a non-thread-safe function.

The read-only data access to the library data can be provided by setting either the task context or the extended memory regions. The decision of which approach to use depends on how efficient the access needs to be:

  • using the task context results in fast data access (without any overhead by the Kernel interference)

  • the use of extended memory regions may cause data access delay (the impact on application performance depends on the number of additional extended memory regions and other runtime factors).

Code 1. Task protection — task context
extern PxUInt_t LIBRARY_DATA_BASE[];
extern PxUInt_t LIBRARY_DATA_END[];

/* TASK DATA CONTEXT
 * Data regions that stay permanently programmed in Task MPU regions
 * Notes:
 * .lowerbound = 0 : region inherited from the parent
 */
static const PxTaskContext_T task_Context =
{
	.protection[0] =
	{
		.lowerBound = 0,
		.upperBound = 0,
		.prot = NoAccessProtection
	},
	.protection[1] =
	{
		.lowerBound = LIBRARY_DATA_BASE,
		.upperBound = LIBRARY_DATA_END,
		.prot = ReadProtection
	}
};
Code 2. Task protection — extended regions
extern PxUInt_t LIBRARY_DATA_BASE[];
extern PxUInt_t LIBRARY_DATA_END[];

/* TASK EXTENDED MEMORY REGIONS
 */
static const PxProtectRegion_T  taskAPRegions[] =
{
	{(unsigned int) &LIBRARY_DATA_BASE, (unsigned int) &LIBRARY_DATA_END, ReadProtection},
    {0, 0, NoAccessProtection}
};