Skip to content

Commit 5db9bdb

Browse files
authored
Merge pull request #654 from jphickey/fix-635-osal-add-task-typedefs
Fix #635, Reduce use of uint32, add more OSAL typedefs
2 parents 7c1b59a + 9c081dc commit 5db9bdb

File tree

212 files changed

+1476
-1345
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

212 files changed

+1476
-1345
lines changed

src/bsp/generic-linux/src/bsp_console.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static void OS_BSP_ExecTput(const char *cap, const char *param)
7272
OS_BSP_ConsoleOutput_Impl
7373
See full description in header
7474
------------------------------------------------------------------*/
75-
void OS_BSP_ConsoleOutput_Impl(const char *Str, uint32 DataLen)
75+
void OS_BSP_ConsoleOutput_Impl(const char *Str, size_t DataLen)
7676
{
7777
ssize_t WriteLen;
7878

src/bsp/generic-linux/src/bsp_start.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void OS_BSP_Initialize(void)
6969
{
7070
if (fgets(buffer, sizeof(buffer), fp) != NULL)
7171
{
72-
OS_BSP_Global.MaxQueueDepth = strtoul(buffer, NULL, 10);
72+
OS_BSP_Global.MaxQueueDepth = OSAL_BLOCKCOUNT_C(strtoul(buffer, NULL, 10));
7373
BSP_DEBUG("Maximum user msg queue depth = %u\n", (unsigned int)OS_BSP_Global.MaxQueueDepth);
7474
}
7575
fclose(fp);

src/bsp/generic-vxworks/src/bsp_console.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
OS_BSP_ConsoleOutput_Impl
4141
See full description in header
4242
------------------------------------------------------------------*/
43-
void OS_BSP_ConsoleOutput_Impl(const char *Str, uint32 DataLen)
43+
void OS_BSP_ConsoleOutput_Impl(const char *Str, size_t DataLen)
4444
{
4545
while (DataLen > 0)
4646
{

src/bsp/shared/inc/bsp-impl.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@
9090
*/
9191
typedef struct
9292
{
93-
uint32 ArgC; /* number of boot/startup parameters in ArgV */
94-
char **ArgV; /* strings for boot/startup parameters */
95-
int32 AppStatus; /* value which can be returned to the OS (0=nominal) */
96-
uint32 MaxQueueDepth; /* Queue depth limit supported by BSP (0=no limit) */
93+
uint32 ArgC; /* number of boot/startup parameters in ArgV */
94+
char ** ArgV; /* strings for boot/startup parameters */
95+
int32 AppStatus; /* value which can be returned to the OS (0=nominal) */
96+
osal_blockcount_t MaxQueueDepth; /* Queue depth limit supported by BSP (0=no limit) */
9797
} OS_BSP_GlobalData_t;
9898

9999
/*
@@ -118,7 +118,7 @@ extern OS_BSP_GlobalData_t OS_BSP_Global;
118118
119119
Note: This should write the string as-is without buffering.
120120
------------------------------------------------------------------*/
121-
void OS_BSP_ConsoleOutput_Impl(const char *Str, uint32 DataLen);
121+
void OS_BSP_ConsoleOutput_Impl(const char *Str, size_t DataLen);
122122

123123
/*----------------------------------------------------------------
124124
Function: OS_BSP_ConsoleSetMode_Impl

src/os/inc/common_types.h

+36
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,28 @@ extern "C"
101101
*/
102102
typedef uint32_t osal_id_t;
103103

104+
/**
105+
* A type used to represent a number of blocks or buffers
106+
*
107+
* This is used with file system and queue implementations.
108+
*/
109+
typedef size_t osal_blockcount_t;
110+
111+
/**
112+
* A type used to represent an index into a table structure
113+
*
114+
* This is used when referring directly to a table index as
115+
* opposed to an object ID. It is primarily intended for
116+
* internal use, but is also output from public APIs such as
117+
* OS_ObjectIdToArrayIndex().
118+
*/
119+
typedef uint32 osal_index_t;
120+
121+
/**
122+
* A type used to represent the runtime type or category of an OSAL object
123+
*/
124+
typedef uint32 osal_objtype_t;
125+
104126
#ifndef NULL /* pointer to nothing */
105127
#define NULL ((void *)0)
106128
#endif
@@ -150,4 +172,18 @@ extern "C"
150172
}
151173
#endif
152174

175+
/*
176+
* Type macros for literals
177+
*
178+
* These macros enforce that a literal or other value is
179+
* interpreted as the intended type. Although implicit
180+
* conversions between these types are often possible, using
181+
* this makes it explicit in the code where a type conversion
182+
* is expected.
183+
*/
184+
#define OSAL_SIZE_C(X) ((size_t)(X))
185+
#define OSAL_BLOCKCOUNT_C(X) ((osal_blockcount_t)(X))
186+
#define OSAL_INDEX_C(X) ((osal_index_t)(X))
187+
#define OSAL_OBJTYPE_C(X) ((osal_objtype_t)(X))
188+
153189
#endif /* _common_types_ */

src/os/inc/osapi-os-core.h

+39-18
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,34 @@
8686
*/
8787
#define OS_ERROR_NAME_LENGTH 35
8888

89+
/**
90+
* @brief Type to be used for OSAL task priorities.
91+
*
92+
* OSAL priorities are in reverse order, and range
93+
* from 0 (highest; will preempt all other tasks) to
94+
* 255 (lowest; will not preempt any other task).
95+
*/
96+
typedef uint8_t osal_priority_t;
97+
98+
#define OSAL_PRIORITY_C(X) ((osal_priority_t) {X})
99+
100+
/**
101+
* @brief Type to be used for OSAL stack pointer.
102+
*/
103+
typedef void *osal_stackptr_t;
104+
105+
#define OSAL_STACKPTR_C(X) ((osal_stackptr_t) {X})
106+
#define OSAL_TASK_STACK_ALLOCATE OSAL_STACKPTR_C(NULL)
107+
89108
/* Object property structures */
90109

91110
/** @brief OSAL task properties */
92111
typedef struct
93112
{
94-
char name[OS_MAX_API_NAME];
95-
osal_id_t creator;
96-
uint32 stack_size;
97-
uint32 priority;
113+
char name[OS_MAX_API_NAME];
114+
osal_id_t creator;
115+
size_t stack_size;
116+
osal_priority_t priority;
98117
} OS_task_prop_t;
99118

100119
/** @brief OSAL queue properties */
@@ -140,9 +159,9 @@ typedef struct
140159
*/
141160
typedef struct
142161
{
143-
uint32 free_bytes;
144-
uint32 free_blocks;
145-
uint32 largest_free_block;
162+
size_t free_bytes;
163+
osal_blockcount_t free_blocks;
164+
size_t largest_free_block;
146165
} OS_heap_prop_t;
147166

148167
/**
@@ -467,7 +486,7 @@ static inline bool OS_ObjectIdDefined(osal_id_t object_id)
467486
* #OS_INVALID_POINTER if the passed-in buffer is invalid
468487
* #OS_ERR_NAME_TOO_LONG if the name will not fit in the buffer provided
469488
*/
470-
int32 OS_GetResourceName(osal_id_t object_id, char *buffer, uint32 buffer_size);
489+
int32 OS_GetResourceName(osal_id_t object_id, char *buffer, size_t buffer_size);
471490

472491
/*-------------------------------------------------------------------------------------*/
473492
/**
@@ -480,7 +499,7 @@ int32 OS_GetResourceName(osal_id_t object_id, char *buffer, uint32 buffer_size);
480499
* @return The object type portion of the object_id, see @ref OSObjectTypes for
481500
* expected values
482501
*/
483-
uint32 OS_IdentifyObject(osal_id_t object_id);
502+
osal_objtype_t OS_IdentifyObject(osal_id_t object_id);
484503

485504
/*-------------------------------------------------------------------------------------*/
486505
/**
@@ -506,7 +525,7 @@ uint32 OS_IdentifyObject(osal_id_t object_id);
506525
* @retval #OS_SUCCESS @copybrief OS_SUCCESS
507526
* @retval #OS_ERR_INCORRECT_OBJ_TYPE @copybrief OS_ERR_INCORRECT_OBJ_TYPE
508527
*/
509-
int32 OS_ConvertToArrayIndex(osal_id_t object_id, uint32 *ArrayIndex);
528+
int32 OS_ConvertToArrayIndex(osal_id_t object_id, osal_index_t *ArrayIndex);
510529

511530
/*-------------------------------------------------------------------------------------*/
512531
/**
@@ -537,7 +556,7 @@ int32 OS_ConvertToArrayIndex(osal_id_t object_id, uint32 *ArrayIndex);
537556
* @retval #OS_SUCCESS @copybrief OS_SUCCESS
538557
* @retval #OS_ERR_INCORRECT_OBJ_TYPE @copybrief OS_ERR_INCORRECT_OBJ_TYPE
539558
* */
540-
int32 OS_ObjectIdToArrayIndex(uint32 idtype, osal_id_t object_id, uint32 *ArrayIndex);
559+
int32 OS_ObjectIdToArrayIndex(osal_objtype_t idtype, osal_id_t object_id, osal_index_t *ArrayIndex);
541560

542561
/*-------------------------------------------------------------------------------------*/
543562
/**
@@ -566,7 +585,8 @@ void OS_ForEachObject(osal_id_t creator_id, OS_ArgCallback_t callback_ptr, void
566585
* @param[in] callback_ptr Function to invoke for each matching object ID
567586
* @param[in] callback_arg Opaque Argument to pass to callback function
568587
*/
569-
void OS_ForEachObjectOfType(uint32 objtype, osal_id_t creator_id, OS_ArgCallback_t callback_ptr, void *callback_arg);
588+
void OS_ForEachObjectOfType(osal_objtype_t objtype, osal_id_t creator_id, OS_ArgCallback_t callback_ptr,
589+
void *callback_arg);
570590

571591
/*-------------------------------------------------------------------------------------*/
572592
/**
@@ -617,8 +637,8 @@ int32 OS_RegisterEventHandler(OS_EventHandler_t handler);
617637
* @retval #OS_ERR_NAME_TAKEN if the name specified is already used by a task
618638
* @retval #OS_ERROR if an unspecified/other error occurs
619639
*/
620-
int32 OS_TaskCreate(osal_id_t *task_id, const char *task_name, osal_task_entry function_pointer, uint32 *stack_pointer,
621-
uint32 stack_size, uint32 priority, uint32 flags);
640+
int32 OS_TaskCreate(osal_id_t *task_id, const char *task_name, osal_task_entry function_pointer,
641+
osal_stackptr_t stack_pointer, size_t stack_size, osal_priority_t priority, uint32 flags);
622642

623643
/*-------------------------------------------------------------------------------------*/
624644
/**
@@ -687,7 +707,7 @@ int32 OS_TaskDelay(uint32 millisecond);
687707
* @retval #OS_ERR_INVALID_PRIORITY if the priority is greater than the max allowed
688708
* @retval #OS_ERROR if the OS call to change the priority fails
689709
*/
690-
int32 OS_TaskSetPriority(osal_id_t task_id, uint32 new_priority);
710+
int32 OS_TaskSetPriority(osal_id_t task_id, osal_priority_t new_priority);
691711

692712
/*-------------------------------------------------------------------------------------*/
693713
/**
@@ -797,7 +817,8 @@ int32 OS_TaskFindIdBySystemData(osal_id_t *task_id, const void *sysdata, size_t
797817
* @retval #OS_QUEUE_INVALID_SIZE if the queue depth exceeds the limit
798818
* @retval #OS_ERROR if the OS create call fails
799819
*/
800-
int32 OS_QueueCreate(osal_id_t *queue_id, const char *queue_name, uint32 queue_depth, uint32 data_size, uint32 flags);
820+
int32 OS_QueueCreate(osal_id_t *queue_id, const char *queue_name, osal_blockcount_t queue_depth, size_t data_size,
821+
uint32 flags);
801822

802823
/*-------------------------------------------------------------------------------------*/
803824
/**
@@ -839,7 +860,7 @@ int32 OS_QueueDelete(osal_id_t queue_id);
839860
* @retval #OS_QUEUE_TIMEOUT if the timeout was OS_PEND and the time expired
840861
* @retval #OS_QUEUE_INVALID_SIZE if the size copied from the queue was not correct
841862
*/
842-
int32 OS_QueueGet(osal_id_t queue_id, void *data, uint32 size, uint32 *size_copied, int32 timeout);
863+
int32 OS_QueueGet(osal_id_t queue_id, void *data, size_t size, size_t *size_copied, int32 timeout);
843864

844865
/*-------------------------------------------------------------------------------------*/
845866
/**
@@ -857,7 +878,7 @@ int32 OS_QueueGet(osal_id_t queue_id, void *data, uint32 size, uint32 *size_copi
857878
* @retval #OS_QUEUE_FULL if the queue cannot accept another message
858879
* @retval #OS_ERROR if the OS call returns an error
859880
*/
860-
int32 OS_QueuePut(osal_id_t queue_id, const void *data, uint32 size, uint32 flags);
881+
int32 OS_QueuePut(osal_id_t queue_id, const void *data, size_t size, uint32 flags);
861882

862883
/*-------------------------------------------------------------------------------------*/
863884
/**

src/os/inc/osapi-os-filesys.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ typedef struct
112112
{
113113
uint32 FileModeBits;
114114
int32 FileTime;
115-
uint32 FileSize;
115+
size_t FileSize;
116116
} os_fstat_t;
117117

118118
/**
@@ -285,7 +285,7 @@ int32 OS_close(osal_id_t filedes);
285285
* @retval #OS_ERROR if OS call failed
286286
* @retval #OS_ERR_INVALID_ID if the file descriptor passed in is invalid
287287
*/
288-
int32 OS_read(osal_id_t filedes, void *buffer, uint32 nbytes);
288+
int32 OS_read(osal_id_t filedes, void *buffer, size_t nbytes);
289289

290290
/*-------------------------------------------------------------------------------------*/
291291
/**
@@ -306,7 +306,7 @@ int32 OS_read(osal_id_t filedes, void *buffer, uint32 nbytes);
306306
* @retval #OS_ERROR if OS call failed
307307
* @retval #OS_ERR_INVALID_ID if the file descriptor passed in is invalid
308308
*/
309-
int32 OS_write(osal_id_t filedes, const void *buffer, uint32 nbytes);
309+
int32 OS_write(osal_id_t filedes, const void *buffer, size_t nbytes);
310310

311311
/*-------------------------------------------------------------------------------------*/
312312
/**
@@ -337,7 +337,7 @@ int32 OS_write(osal_id_t filedes, const void *buffer, uint32 nbytes);
337337
* @return Byte count on success, zero for timeout, or appropriate error code,
338338
* see @ref OSReturnCodes
339339
*/
340-
int32 OS_TimedRead(osal_id_t filedes, void *buffer, uint32 nbytes, int32 timeout);
340+
int32 OS_TimedRead(osal_id_t filedes, void *buffer, size_t nbytes, int32 timeout);
341341

342342
/*-------------------------------------------------------------------------------------*/
343343
/**
@@ -368,7 +368,7 @@ int32 OS_TimedRead(osal_id_t filedes, void *buffer, uint32 nbytes, int32 timeout
368368
* @return Byte count on success, zero for timeout, or appropriate error code,
369369
* see @ref OSReturnCodes
370370
*/
371-
int32 OS_TimedWrite(osal_id_t filedes, const void *buffer, uint32 nbytes, int32 timeout);
371+
int32 OS_TimedWrite(osal_id_t filedes, const void *buffer, size_t nbytes, int32 timeout);
372372

373373
/*-------------------------------------------------------------------------------------*/
374374
/**
@@ -715,7 +715,7 @@ int32 OS_FileSysAddFixedMap(osal_id_t *filesys_id, const char *phys_path, const
715715
* @retval #OS_FS_ERR_DEVICE_NOT_FREE if the volume table is full
716716
* @retval #OS_SUCCESS on creating the disk
717717
*/
718-
int32 OS_mkfs(char *address, const char *devname, const char *volname, uint32 blocksize, uint32 numblocks);
718+
int32 OS_mkfs(char *address, const char *devname, const char *volname, size_t blocksize, osal_blockcount_t numblocks);
719719
/*-------------------------------------------------------------------------------------*/
720720
/**
721721
* @brief Mounts a file system
@@ -754,7 +754,7 @@ int32 OS_mount(const char *devname, const char *mountpoint);
754754
* @retval #OS_FS_ERR_DEVICE_NOT_FREE if the volume table is full
755755
* @retval #OS_FS_ERR_DRIVE_NOT_CREATED on error
756756
*/
757-
int32 OS_initfs(char *address, const char *devname, const char *volname, uint32 blocksize, uint32 numblocks);
757+
int32 OS_initfs(char *address, const char *devname, const char *volname, size_t blocksize, osal_blockcount_t numblocks);
758758

759759
/*-------------------------------------------------------------------------------------*/
760760
/**

src/os/inc/osapi-os-loader.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ int32 OS_ModuleSymbolLookup(osal_id_t module_id, cpuaddr *symbol_address, const
176176
* @retval #OS_ERR_NOT_IMPLEMENTED @copybrief OS_ERR_NOT_IMPLEMENTED
177177
* @retval #OS_ERROR if the symbol table could not be read or dumped
178178
*/
179-
int32 OS_SymbolTableDump(const char *filename, uint32 size_limit);
179+
int32 OS_SymbolTableDump(const char *filename, size_t size_limit);
180180

181181
/*-------------------------------------------------------------------------------------*/
182182
/**

src/os/inc/osapi-os-net.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ typedef union
102102
*/
103103
typedef struct
104104
{
105-
uint32 ActualLength; /**< @brief Length of the actual address data */
105+
size_t ActualLength; /**< @brief Length of the actual address data */
106106
OS_SockAddrData_t AddrData; /**< @brief Abstract Address data */
107107
} OS_SockAddr_t;
108108

@@ -162,7 +162,7 @@ int32 OS_SocketAddrInit(OS_SockAddr_t *Addr, OS_SocketDomain_t Domain);
162162
*
163163
* @return Execution status, see @ref OSReturnCodes
164164
*/
165-
int32 OS_SocketAddrToString(char *buffer, uint32 buflen, const OS_SockAddr_t *Addr);
165+
int32 OS_SocketAddrToString(char *buffer, size_t buflen, const OS_SockAddr_t *Addr);
166166

167167
/*-------------------------------------------------------------------------------------*/
168168
/**
@@ -317,7 +317,7 @@ int32 OS_SocketAccept(osal_id_t sock_id, osal_id_t *connsock_id, OS_SockAddr_t *
317317
*
318318
* @return Count of actual bytes received or error status, see @ref OSReturnCodes
319319
*/
320-
int32 OS_SocketRecvFrom(osal_id_t sock_id, void *buffer, uint32 buflen, OS_SockAddr_t *RemoteAddr, int32 timeout);
320+
int32 OS_SocketRecvFrom(osal_id_t sock_id, void *buffer, size_t buflen, OS_SockAddr_t *RemoteAddr, int32 timeout);
321321

322322
/*-------------------------------------------------------------------------------------*/
323323
/**
@@ -334,7 +334,7 @@ int32 OS_SocketRecvFrom(osal_id_t sock_id, void *buffer, uint32 buflen, OS_SockA
334334
*
335335
* @return Count of actual bytes sent or error status, see @ref OSReturnCodes
336336
*/
337-
int32 OS_SocketSendTo(osal_id_t sock_id, const void *buffer, uint32 buflen, const OS_SockAddr_t *RemoteAddr);
337+
int32 OS_SocketSendTo(osal_id_t sock_id, const void *buffer, size_t buflen, const OS_SockAddr_t *RemoteAddr);
338338

339339
/*-------------------------------------------------------------------------------------*/
340340
/**
@@ -400,7 +400,7 @@ int32 OS_NetworkGetID(void);
400400
*
401401
* @return Execution status, see @ref OSReturnCodes
402402
*/
403-
int32 OS_NetworkGetHostName(char *host_name, uint32 name_len);
403+
int32 OS_NetworkGetHostName(char *host_name, size_t name_len);
404404
/**@}*/
405405

406406
#endif

src/os/inc/osapi-os-timer.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
/*
3434
** Typedefs
3535
*/
36-
typedef void (*OS_TimerCallback_t)(osal_id_t timer_id); /**< @brief Timer callback */
37-
typedef uint32 (*OS_TimerSync_t)(uint32 timer_id); /**< @brief Timer sync */
36+
typedef void (*OS_TimerCallback_t)(osal_id_t timer_id); /**< @brief Timer callback */
37+
typedef uint32 (*OS_TimerSync_t)(osal_index_t timer_id); /**< @brief Timer sync */
3838

3939
/** @brief Timer properties */
4040
typedef struct

0 commit comments

Comments
 (0)