Skip to content

Commit 6ef5fb1

Browse files
Update abstraction rtos with improved documentation and utilities.
1 parent 7649d92 commit 6ef5fb1

File tree

3 files changed

+90
-63
lines changed

3 files changed

+90
-63
lines changed

targets/TARGET_Cypress/TARGET_PSOC6/psoc6csp/abstraction/rtos/include/COMPONENT_RTX/cyabs_rtos_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ typedef enum
6060
} cy_thread_priority_t ;
6161

6262
typedef osThreadId_t cy_thread_t; /** CMSIS definition of a thread handle */
63-
typedef uint32_t cy_thread_arg_t; /** Argument passed to the entry function of a thread */
63+
typedef void * cy_thread_arg_t; /** Argument passed to the entry function of a thread */
6464
typedef osMutexId_t cy_mutex_t; /** CMSIS definition of a mutex */
6565
typedef osSemaphoreId_t cy_semaphore_t; /** CMSIS definition of a semaphore */
6666
typedef osEventFlagsId_t cy_event_t; /** CMSIS definition of an event */

targets/TARGET_Cypress/TARGET_PSOC6/psoc6csp/abstraction/rtos/include/cyabs_rtos.h

Lines changed: 59 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#define INCLUDED_CY_RTOS_INTERFACE_H_
3030

3131
#include "cyabs_rtos_impl.h"
32-
#include <cy_result.h>
32+
#include "cy_result.h"
3333
#include <stdint.h>
3434
#include <stdbool.h>
3535

@@ -72,6 +72,8 @@ extern "C"
7272
#define CY_RTOS_GENERAL_ERROR CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_ABSTRACTION_OS, 2)
7373
/** A bad argument was passed into the APIs */
7474
#define CY_RTOS_BAD_PARAM CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_ABSTRACTION_OS, 5)
75+
/** A memory alignment issue was detected. Ensure memory provided is aligned per CY_RTOS_ALIGNMENT */
76+
#define CY_RTOS_ALIGNMENT_ERROR CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_ABSTRACTION_OS, 6)
7577

7678
/** \} group_abstraction_rtos_common */
7779

@@ -146,7 +148,7 @@ typedef void (*cy_timer_callback_t)(cy_timer_callback_arg_t arg);
146148
*
147149
* \ingroup group_abstraction_rtos_common
148150
*/
149-
extern cy_rtos_error_t cy_rtos_last_error();
151+
cy_rtos_error_t cy_rtos_last_error();
150152

151153
/*********************************************** Threads **********************************************/
152154

@@ -179,7 +181,7 @@ extern cy_rtos_error_t cy_rtos_last_error();
179181
*
180182
* @return The status of thread create request. [CY_RSLT_SUCCESS, CY_RTOS_NO_MEMORY, CY_RTOS_GENERAL_ERROR]
181183
*/
182-
extern cy_rslt_t cy_rtos_create_thread(cy_thread_t *thread, cy_thread_entry_fn_t entry_function,
184+
cy_rslt_t cy_rtos_create_thread(cy_thread_t *thread, cy_thread_entry_fn_t entry_function,
183185
const char *name, void *stack, uint32_t stack_size, cy_thread_priority_t priority, cy_thread_arg_t arg);
184186

185187

@@ -196,7 +198,7 @@ extern cy_rslt_t cy_rtos_create_thread(cy_thread_t *thread, cy_thread_entry_fn_t
196198
*
197199
* @return The status of thread exit request. [CY_RSLT_SUCCESS, CY_RTOS_GENERAL_ERROR]
198200
*/
199-
extern cy_rslt_t cy_rtos_exit_thread();
201+
cy_rslt_t cy_rtos_exit_thread();
200202

201203
/** Terminates another thread.
202204
*
@@ -212,40 +214,51 @@ extern cy_rslt_t cy_rtos_exit_thread();
212214
*
213215
* @returns The status of the thread terminate. [CY_RSLT_SUCCESS, CY_RTOS_GENERAL_ERROR]
214216
*/
215-
extern cy_rslt_t cy_rtos_terminate_thread(cy_thread_t *thread);
217+
cy_rslt_t cy_rtos_terminate_thread(cy_thread_t *thread);
218+
219+
/** Waits for a thread to complete.
220+
*
221+
* This must be called on any thread that can complete to ensure that any resources that
222+
* were allocated for it are cleaned up.
223+
*
224+
* @param[in] thread Handle of the thread to wait for
225+
*
226+
* @returns The status of thread join request. [CY_RSLT_SUCCESS, CY_RTOS_GENERAL_ERROR]
227+
*/
228+
cy_rslt_t cy_rtos_join_thread(cy_thread_t *thread);
216229

217230
/** Checks if the thread is running
218231
*
219-
* This function is called to determine if a thread is running or not.
232+
* This function is called to determine if a thread is running or not. For information on
233+
* the thread state, use the cy_rtos_get_thread_state() function.
220234
*
221-
* @param[in] thread handle of the terminated thread to delete
222-
* @param[out] running returns true if the thread is running, otherwise false
235+
* @param[in] thread Handle of the terminated thread to delete
236+
* @param[out] running Returns true if the thread is running, otherwise false
223237
*
224238
* @returns The status of the thread running check. [CY_RSLT_SUCCESS, CY_RTOS_GENERAL_ERROR]
225239
*/
226-
extern cy_rslt_t cy_rtos_is_thread_running(cy_thread_t *thread, bool *running);
240+
cy_rslt_t cy_rtos_is_thread_running(cy_thread_t *thread, bool *running);
227241

228242
/** Gets the state the thread is currently in
229243
*
230-
* This function is called to determine if a thread is running or not.
244+
* This function is called to determine if a thread is running/blocked/inactive/ready etc.
231245
*
232-
* @param[in] thread handle of the terminated thread to delete
233-
* @param[out] state returns the state the thread is currently in
246+
* @param[in] thread Handle of the terminated thread to delete
247+
* @param[out] state Returns the state the thread is currently in
234248
*
235249
* @returns The status of the thread state check. [CY_RSLT_SUCCESS, CY_RTOS_GENERAL_ERROR]
236250
*/
237-
extern cy_rslt_t cy_rtos_get_thread_state(cy_thread_t *thread, cy_thread_state_t *state);
251+
cy_rslt_t cy_rtos_get_thread_state(cy_thread_t *thread, cy_thread_state_t *state);
238252

239-
/** Waits for a thread to complete.
253+
/** Get current thread handle
240254
*
241-
* This must be called on any thread that can complete to ensure that any resources that
242-
* were allocated for it are cleaned up.
255+
* Returns the unique thread handle of the current running thread.
243256
*
244-
* @param[in] thread Handle of the thread to wait for
257+
* @param[out] thread Handle of the current running thread
245258
*
246259
* @returns The status of thread join request. [CY_RSLT_SUCCESS, CY_RTOS_GENERAL_ERROR]
247260
*/
248-
extern cy_rslt_t cy_rtos_join_thread(cy_thread_t *thread);
261+
cy_rslt_t cy_rtos_get_thread_handle(cy_thread_t *thread);
249262

250263
/** \} group_abstraction_rtos_threads */
251264

@@ -265,7 +278,7 @@ extern cy_rslt_t cy_rtos_join_thread(cy_thread_t *thread);
265278
*
266279
* @return The status of mutex creation request. [CY_RSLT_SUCCESS, CY_RTOS_NO_MEMORY, CY_RTOS_GENERAL_ERROR]
267280
*/
268-
extern cy_rslt_t cy_rtos_init_mutex(cy_mutex_t *mutex);
281+
cy_rslt_t cy_rtos_init_mutex(cy_mutex_t *mutex);
269282

270283
/** Get a mutex.
271284
*
@@ -283,7 +296,7 @@ extern cy_rslt_t cy_rtos_init_mutex(cy_mutex_t *mutex);
283296
* @return The status of the get mutex. Returns timeout if mutex was not acquired
284297
* before timeout_ms period. [CY_RSLT_SUCCESS, CY_RTOS_TIMEOUT]
285298
*/
286-
extern cy_rslt_t cy_rtos_get_mutex(cy_mutex_t *mutex, cy_time_t timeout_ms);
299+
cy_rslt_t cy_rtos_get_mutex(cy_mutex_t *mutex, cy_time_t timeout_ms);
287300

288301
/** Set a mutex.
289302
*
@@ -295,7 +308,7 @@ extern cy_rslt_t cy_rtos_get_mutex(cy_mutex_t *mutex, cy_time_t timeout_ms);
295308
* @return The status of the set mutex request. [CY_RSLT_SUCCESS, CY_RTOS_TIMEOUT]
296309
*
297310
*/
298-
extern cy_rslt_t cy_rtos_set_mutex(cy_mutex_t *mutex);
311+
cy_rslt_t cy_rtos_set_mutex(cy_mutex_t *mutex);
299312

300313
/** Deletes a mutex.
301314
*
@@ -305,7 +318,7 @@ extern cy_rslt_t cy_rtos_set_mutex(cy_mutex_t *mutex);
305318
*
306319
* @return The status to the delete request. [CY_RSLT_SUCCESS, CY_RTOS_TIMEOUT]
307320
*/
308-
extern cy_rslt_t cy_rtos_deinit_mutex(cy_mutex_t *mutex);
321+
cy_rslt_t cy_rtos_deinit_mutex(cy_mutex_t *mutex);
309322

310323
/** \} group_abstraction_rtos_mutex */
311324

@@ -327,7 +340,7 @@ extern cy_rslt_t cy_rtos_deinit_mutex(cy_mutex_t *mutex);
327340
*
328341
* @return The status of the sempahore creation. [CY_RSLT_SUCCESS, CY_RTOS_NO_MEMORY, CY_RTOS_GENERAL_ERROR]
329342
*/
330-
extern cy_rslt_t cy_rtos_init_semaphore(cy_semaphore_t *semaphore, uint32_t maxcount, uint32_t initcount);
343+
cy_rslt_t cy_rtos_init_semaphore(cy_semaphore_t *semaphore, uint32_t maxcount, uint32_t initcount);
331344

332345
/**
333346
* Get/Acquire a semaphore
@@ -343,7 +356,7 @@ extern cy_rslt_t cy_rtos_init_semaphore(cy_semaphore_t *semaphore, uint32_t maxc
343356
* @param[in] in_isr true if we are trying to get the semaphore from with an ISR
344357
* @return The status of get semaphore operation [CY_RSLT_SUCCESS, CY_RTOS_NO_MEMORY, CY_RTOS_GENERAL_ERROR]
345358
*/
346-
extern cy_rslt_t cy_rtos_get_semaphore(cy_semaphore_t *semaphore, cy_time_t timeout_ms, bool in_isr);
359+
cy_rslt_t cy_rtos_get_semaphore(cy_semaphore_t *semaphore, cy_time_t timeout_ms, bool in_isr);
347360

348361
/**
349362
* Set/Release a semaphore
@@ -355,7 +368,7 @@ extern cy_rslt_t cy_rtos_get_semaphore(cy_semaphore_t *semaphore, cy_time_t time
355368
* Value of false indicates calling from normal thread context
356369
* @return The status of set semaphore operation [CY_RSLT_SUCCESS, CY_RTOS_NO_MEMORY, CY_RTOS_GENERAL_ERROR]
357370
*/
358-
extern cy_rslt_t cy_rtos_set_semaphore(cy_semaphore_t *semaphore, bool in_isr);
371+
cy_rslt_t cy_rtos_set_semaphore(cy_semaphore_t *semaphore, bool in_isr);
359372

360373
/**
361374
* Deletes a sempahore
@@ -366,7 +379,7 @@ extern cy_rslt_t cy_rtos_set_semaphore(cy_semaphore_t *semaphore, bool in_isr);
366379
*
367380
* @return The status of semaphore deletion [CY_RSLT_SUCCESS, CY_RTOS_NO_MEMORY, CY_RTOS_GENERAL_ERROR]
368381
*/
369-
extern cy_rslt_t cy_rtos_deinit_semaphore(cy_semaphore_t *semaphore);
382+
cy_rslt_t cy_rtos_deinit_semaphore(cy_semaphore_t *semaphore);
370383

371384
/** \} group_abstraction_rtos_semaphore */
372385

@@ -387,7 +400,7 @@ extern cy_rslt_t cy_rtos_deinit_semaphore(cy_semaphore_t *semaphore);
387400
* @return The status of the event initialization request.
388401
* [CY_RSLT_SUCCESS, CY_RTOS_NO_MEMORY, CY_RTOS_GENERAL_ERROR]
389402
*/
390-
extern cy_rslt_t cy_rtos_init_event(cy_event_t *event);
403+
cy_rslt_t cy_rtos_init_event(cy_event_t *event);
391404

392405
/** Set the event flag bits.
393406
*
@@ -400,7 +413,7 @@ extern cy_rslt_t cy_rtos_init_event(cy_event_t *event);
400413
*
401414
* @return The status of the set request. [CY_RSLT_SUCCESS, CY_RTOS_NO_MEMORY, CY_RTOS_GENERAL_ERROR]
402415
*/
403-
extern cy_rslt_t cy_rtos_setbits_event(cy_event_t *event, uint32_t bits, bool in_isr) ;
416+
cy_rslt_t cy_rtos_setbits_event(cy_event_t *event, uint32_t bits, bool in_isr) ;
404417

405418
/**
406419
* Clear the event flag bits
@@ -413,7 +426,7 @@ extern cy_rslt_t cy_rtos_setbits_event(cy_event_t *event, uint32_t bits, bool in
413426
*
414427
* @return The status of the clear flags request. [CY_RSLT_SUCCESS, CY_RTOS_NO_MEMORY, CY_RTOS_GENERAL_ERROR]
415428
*/
416-
extern cy_rslt_t cy_rtos_clearbits_event(cy_event_t *event, uint32_t bits, bool in_isr) ;
429+
cy_rslt_t cy_rtos_clearbits_event(cy_event_t *event, uint32_t bits, bool in_isr) ;
417430

418431
/** Get the event bits.
419432
*
@@ -424,7 +437,7 @@ extern cy_rslt_t cy_rtos_clearbits_event(cy_event_t *event, uint32_t bits, bool
424437
*
425438
* @return The status of the get request. [CY_RSLT_SUCCESS, CY_RTOS_NO_MEMORY, CY_RTOS_GENERAL_ERROR]
426439
*/
427-
extern cy_rslt_t cy_rtos_getbits_event(cy_event_t *event, uint32_t *bits);
440+
cy_rslt_t cy_rtos_getbits_event(cy_event_t *event, uint32_t *bits);
428441

429442
/** Wait for the event and return bits.
430443
*
@@ -442,7 +455,7 @@ extern cy_rslt_t cy_rtos_getbits_event(cy_event_t *event, uint32_t *bits);
442455
*
443456
* @return The status of the wait for event request. [CY_RSLT_SUCCESS, CY_RTOS_NO_MEMORY, CY_RTOS_GENERAL_ERROR]
444457
*/
445-
extern cy_rslt_t cy_rtos_waitbits_event(cy_event_t *event, uint32_t *bits, bool clear, bool all, cy_time_t timeout);
458+
cy_rslt_t cy_rtos_waitbits_event(cy_event_t *event, uint32_t *bits, bool clear, bool all, cy_time_t timeout);
446459

447460
/** Deinitialize a event.
448461
*
@@ -452,7 +465,7 @@ extern cy_rslt_t cy_rtos_waitbits_event(cy_event_t *event, uint32_t *bits, bool
452465
*
453466
* @return The status of the deletion request. [CY_RSLT_SUCCESS, CY_RTOS_GENERAL_ERROR]
454467
*/
455-
extern cy_rslt_t cy_rtos_deinit_event(cy_event_t *event);
468+
cy_rslt_t cy_rtos_deinit_event(cy_event_t *event);
456469

457470
/** \} group_abstraction_rtos_event */
458471

@@ -474,7 +487,7 @@ extern cy_rslt_t cy_rtos_deinit_event(cy_event_t *event);
474487
*
475488
* @return The status of the creation request. [CY_RSLT_SUCCESS, CY_RTOS_NO_MEMORY, CY_RTOS_GENERAL_ERROR]
476489
*/
477-
extern cy_rslt_t cy_rtos_init_queue(cy_queue_t *queue, size_t length, size_t itemsize);
490+
cy_rslt_t cy_rtos_init_queue(cy_queue_t *queue, size_t length, size_t itemsize);
478491

479492
/** Put an item in a queue.
480493
*
@@ -491,7 +504,7 @@ extern cy_rslt_t cy_rtos_init_queue(cy_queue_t *queue, size_t length, size_t ite
491504
*
492505
* @return The status of the creation request. [CY_RSLT_SUCCESS, CY_RTOS_NO_MEMORY, CY_RTOS_GENERAL_ERROR, CY_RTOS_QUEUE_FULL]
493506
*/
494-
extern cy_rslt_t cy_rtos_put_queue(cy_queue_t *queue, const void *item_ptr, cy_time_t timeout_ms, bool in_isr);
507+
cy_rslt_t cy_rtos_put_queue(cy_queue_t *queue, const void *item_ptr, cy_time_t timeout_ms, bool in_isr);
495508

496509
/** Gets an item in a queue.
497510
*
@@ -508,7 +521,7 @@ extern cy_rslt_t cy_rtos_put_queue(cy_queue_t *queue, const void *item_ptr, cy_t
508521
*
509522
* @return The status of the creation request. [CY_RSLT_SUCCESS, CY_RTOS_NO_MEMORY, CY_RTOS_GENERAL_ERROR, CY_RTOS_QUEUE_EMPTY]
510523
*/
511-
extern cy_rslt_t cy_rtos_get_queue(cy_queue_t *queue, void *item_ptr, cy_time_t timeout_ms, bool in_isr);
524+
cy_rslt_t cy_rtos_get_queue(cy_queue_t *queue, void *item_ptr, cy_time_t timeout_ms, bool in_isr);
512525

513526
/** Return the number of items in the queue.
514527
*
@@ -519,7 +532,7 @@ extern cy_rslt_t cy_rtos_get_queue(cy_queue_t *queue, void *item_ptr, cy_time_t
519532
*
520533
* @return The status of the creation request. [CY_RSLT_SUCCESS, CY_RTOS_GENERAL_ERROR]
521534
*/
522-
extern cy_rslt_t cy_rtos_count_queue(cy_queue_t *queue, size_t *num_waiting);
535+
cy_rslt_t cy_rtos_count_queue(cy_queue_t *queue, size_t *num_waiting);
523536

524537
/** Return the amount of empty space in the queue.
525538
*
@@ -532,7 +545,7 @@ extern cy_rslt_t cy_rtos_count_queue(cy_queue_t *queue, size_t *num_waiting);
532545
*
533546
* @return The status of the creation request. [CY_RSLT_SUCCESS, CY_RTOS_GENERAL_ERROR]
534547
*/
535-
extern cy_rslt_t cy_rtos_space_queue(cy_queue_t *queue, size_t *num_spaces);
548+
cy_rslt_t cy_rtos_space_queue(cy_queue_t *queue, size_t *num_spaces);
536549

537550
/** Reset the queue.
538551
*
@@ -542,7 +555,7 @@ extern cy_rslt_t cy_rtos_space_queue(cy_queue_t *queue, size_t *num_spaces);
542555
*
543556
* @return The status of the creation request. [CY_RSLT_SUCCESS, CY_RTOS_GENERAL_ERROR]
544557
*/
545-
extern cy_rslt_t cy_rtos_reset_queue(cy_queue_t *queue);
558+
cy_rslt_t cy_rtos_reset_queue(cy_queue_t *queue);
546559

547560
/** Deinitialize the queue handle.
548561
*
@@ -553,7 +566,7 @@ extern cy_rslt_t cy_rtos_reset_queue(cy_queue_t *queue);
553566
*
554567
* @return The status of the creation request. [CY_RSLT_SUCCESS, CY_RTOS_GENERAL_ERROR]
555568
*/
556-
extern cy_rslt_t cy_rtos_deinit_queue(cy_queue_t *queue);
569+
cy_rslt_t cy_rtos_deinit_queue(cy_queue_t *queue);
557570

558571
/** \} group_abstraction_rtos_queue */
559572

@@ -576,7 +589,7 @@ extern cy_rslt_t cy_rtos_deinit_queue(cy_queue_t *queue);
576589
*
577590
* @return The status of the creation request. [CY_RSLT_SUCCESS, CY_RTOS_GENERAL_ERROR]
578591
*/
579-
extern cy_rslt_t cy_rtos_init_timer(cy_timer_t *timer, cy_timer_trigger_type_t type,
592+
cy_rslt_t cy_rtos_init_timer(cy_timer_t *timer, cy_timer_trigger_type_t type,
580593
cy_timer_callback_t fun, cy_timer_callback_arg_t arg);
581594

582595
/** Start a timer.
@@ -588,15 +601,15 @@ extern cy_rslt_t cy_rtos_init_timer(cy_timer_t *timer, cy_timer_trigger_type_t t
588601
*
589602
* @return The status of the creation request. [CY_RSLT_SUCCESS, CY_RTOS_GENERAL_ERROR]
590603
*/
591-
extern cy_rslt_t cy_rtos_start_timer(cy_timer_t *timer, cy_time_t num_ms);
604+
cy_rslt_t cy_rtos_start_timer(cy_timer_t *timer, cy_time_t num_ms);
592605

593606
/** Stop a timer.
594607
*
595608
* @param[in] timer Pointer to the timer handle
596609
*
597610
* @return The status of the creation request. [CY_RSLT_SUCCESS, CY_RTOS_GENERAL_ERROR]
598611
*/
599-
extern cy_rslt_t cy_rtos_stop_timer(cy_timer_t *timer);
612+
cy_rslt_t cy_rtos_stop_timer(cy_timer_t *timer);
600613

601614
/** Returns state of a timer.
602615
*
@@ -605,7 +618,7 @@ extern cy_rslt_t cy_rtos_stop_timer(cy_timer_t *timer);
605618
*
606619
* @return The status of the creation request. [CY_RSLT_SUCCESS, CY_RTOS_GENERAL_ERROR]
607620
*/
608-
extern cy_rslt_t cy_rtos_is_running_timer(cy_timer_t *timer, bool *state);
621+
cy_rslt_t cy_rtos_is_running_timer(cy_timer_t *timer, bool *state);
609622

610623
/** Deinit the timer.
611624
*
@@ -616,7 +629,7 @@ extern cy_rslt_t cy_rtos_is_running_timer(cy_timer_t *timer, bool *state);
616629
*
617630
* @return The status of the creation request. [CY_RSLT_SUCCESS, CY_RTOS_GENERAL_ERROR]
618631
*/
619-
extern cy_rslt_t cy_rtos_deinit_timer(cy_timer_t *timer);
632+
cy_rslt_t cy_rtos_deinit_timer(cy_timer_t *timer);
620633

621634
/** \} group_abstraction_rtos_timer */
622635

@@ -635,7 +648,7 @@ extern cy_rslt_t cy_rtos_deinit_timer(cy_timer_t *timer);
635648
*
636649
* @returns Time in milliseconds since the RTOS started.
637650
*/
638-
extern cy_rslt_t cy_rtos_get_time(cy_time_t *tval);
651+
cy_rslt_t cy_rtos_get_time(cy_time_t *tval);
639652

640653
/** Delay for a number of milliseconds.
641654
*
@@ -648,7 +661,7 @@ extern cy_rslt_t cy_rtos_get_time(cy_time_t *tval);
648661
*
649662
* @return The status of the creation request. [CY_RSLT_SUCCESS, CY_RTOS_GENERAL_ERROR]
650663
*/
651-
extern cy_rslt_t cy_rtos_delay_milliseconds(cy_time_t num_ms);
664+
cy_rslt_t cy_rtos_delay_milliseconds(cy_time_t num_ms);
652665

653666
/** \} group_abstraction_rtos_timer */
654667

0 commit comments

Comments
 (0)