Industrielle Fertigung
Industrielles Internet der Dinge | Industrielle Materialien | Gerätewartung und Reparatur | Industrielle Programmierung |
home  MfgRobots >> Industrielle Fertigung >  >> Industrial Internet of Things >> Eingebettet

Semaphores in Nucleus RTOS: Utility Services & Data Structures

Semaphores in Nucleus RTOS: Utility Services & Data Structures
View the RTOS Revealed series

Dieser Artikel setzt den Blick auf Semaphores fort.

Semaphore Utility Services

Nucleus RTOS bietet vier API Calls, die essenzielle Utilities für Semaphore Management bereitstellen: Reset eines Semaphores, Retrieval detaillierter Semaphore Information, Zählen der Gesamtzahl Semaphores in einer Applikation, und Erhalten von Pointern zu allen Semaphore Objects. Die ersten drei Funktionen sind in Nucleus SE voll implementiert.

Einen Semaphore Resetten

Anders als die meisten Kernel Objects, restored resetting einen Semaphore ihn zu einem spezifizierten Initial Count, statt ihn einfach zu seinem Compile-Time Value zu reinitialisieren. Jegliche Tasks, die auf dem Semaphore blocked sind, werden sofort geweckt und erhalten den Return Code NUSE_SEMAPHORE_WAS_RESET (oder NU_SEMAPHORE_RESET in Nucleus RTOS).

Nucleus RTOS API Call für Resetting eines Semaphores

Service Call Prototype:

STATUS NU_Reset_Semaphore(NU_SEMAPHORE *semaphore,
UNSIGNED initial_count);

Parameter:

semaphore – Pointer zum Semaphore Control Block, supplied by the user.

initial_count – Der Wert, auf den der Semaphore Counter gesetzt werden soll.

Returns:

NU_SUCCESS – Operation completed successfully.

NU_INVALID_SEMAPHORE – Semaphore Pointer ist nicht valid.

Nucleus SE API Call für Resetting eines Semaphores

Service Call Prototype:

STATUS NUSE_Semaphore_Reset(NUSE_SEMAPHORE semaphore,
U8 initial_count);

Parameter:

semaphore – Der Index (ID) des zu resettenden Semaphores.

initial_count – Der Wert, auf den der Semaphore Counter gesetzt werden soll.

Returns:

NUSE_SUCCESS – Operation completed successfully.

NUSE_INVALID_SEMAPHORE – Semaphore Index ist nicht valid.

Nucleus SE Implementation of Semaphore Reset

Die NUSE_Semaphore_Reset() Routine validiert ihre Argumente und schreibt dann den neuen Count in das NUSE_Semaphore_Counter[] Array. Wenn Blocking enabled ist, loopt es durch die Task Table, um Tasks zu lokalisieren, die auf dem Semaphore suspended sind, markiert sie als ready, assigned den NUSE_SEMAPHORE_WAS_RESET Return Code, und triggert abschließend einen Reschedule, wenn ein Priority Scheduler aktiv ist.

while (NUSE_Semaphore_Blocking_Count[semaphore] != 0) { U8 index; for (index = 0; index < NUSE_TASK_NUMBER; index++) { if ((LONIB(NUSE_Task_Status[index]) == NUSE_SEMAPHORE_SUSPEND) && (HINIB(NUSE_Task_Status[index]) == semaphore)) { NUSE_Task_Blocking_Return[index] = NUSE_SEMAPHORE_WAS_RESET; NUSE_Task_Status[index] = NUSE_READY; break; } } NUSE_Semaphore_Blocking_Count[semaphore]--; } #if NUSE_SCHEDULER_TYPE == NUSE_PRIORITY_SCHEDULER NUSE_Reschedule(NUSE_NO_TASK); #endif

Alle suspended Tasks werden daher in den Ready State transitioniert mit dem appropriate Return Code. Wenn der Priority Scheduler aktiv ist, stellt NUSE_Reschedule() sicher, dass höher-priorisierte Tasks niedrigere preempten können.

Semaphore Information

Dieser Service Call retrievet Schlüsseldetails über einen Semaphore. In Nucleus SE werden weniger Fields returned, weil Object Naming, Suspend Ordering und Task Suspend nicht supported sein mögen.

Nucleus RTOS API Call für Semaphore Information

Service Call Prototype:

STATUS NU_Semaphore_Information(NU_SEMAPHORE *semaphore,
CHAR *name, UNSIGNED *current_count, OPTION *suspend_type,
UNSIGNED *tasks_waiting, NU_TASK **first_task);

Parameter:

semaphore – Pointer zum requested Semaphore Control Block.

name – Destination Buffer für den Semaphore Namen (8 Characters plus Null Terminator).

current_count – Receives den aktuellen Semaphore Counter Wert.

suspend_type – Receives die Suspend Policy (z. B. NU_FIFO oder NU_PRIORITY).

tasks_waiting – Receives die Anzahl Tasks, suspended auf dem Semaphore.

first_task – Receives Pointer zum ersten suspended Task's Control Block.

Returns:

NU_SUCCESS – Call completed successfully.

NU_INVALID_SEMAPHORE – Semaphore Pointer ist invalid.

Nucleus SE API Call für Semaphore Information

Service Call Prototype:

STATUS NUSE_Semaphore_Information(NUSE_SEMAPHORE semaphore,
U8 *current_count, U8 *tasks_waiting, NUSE_TASK *first_task);

Parameter:

semaphore – Der Index des Semaphores.

current_count – Receives den aktuellen Counter Wert.

tasks_waiting – Receives die Anzahl suspended Tasks (falls Task Suspend enabled).

first_task – Receives den Index des ersten suspended Tasks (falls Task Suspend enabled).

Returns:

NUSE_SUCCESS – Call completed successfully.

NUSE_INVALID_SEMAPHORE – Semaphore Index ist invalid.

NUSE_INVALID_POINTER – Ein oder mehrere Pointer Argumente sind invalid.

Nucleus SE Implementation of Semaphore Information

Die Implementation ist concise: Sie enteret einen Critical Section, kopiert den Counter Wert, und, wenn Blocking enabled ist, enumeriert die Task Table um wartende Tasks zu zählen und den ersten suspended Task zu identifizieren. Andernfalls werden Waiting Count und First Task auf Null gesetzt.

NUSE_CS_Enter(); *current_count = NUSE_Semaphore_Counter[semaphore]; #if NUSE_BLOCKING_ENABLE *tasks_waiting = NUSE_Semaphore_Blocking_Count[semaphore]; if (NUSE_Semaphore_Blocking_Count[semaphore] != 0) { U8 index; for (index = 0; index < NUSE_TASK_NUMBER; index++) { if ((LONIB(NUSE_Task_Status[index]) == NUSE_SEMAPHORE_SUSPEND) && (HINIB(NUSE_Task_Status[index]) == semaphore)) { *first_task = index; break; } } } else { *first_task = 0; } #else *tasks_waiting = 0; *first_task = 0; #endif NUSE_CS_Exit(); return NUSE_SUCCESS;

Anzahl der Semaphores erhalten

Dieser Service returned die Gesamtzahl der in der Applikation definierten Semaphores. In Nucleus RTOS kann der Wert zur Runtime wechseln; in Nucleus SE ist er zur Build Time fixiert.

Nucleus RTOS API Call für Semaphore Count

Service Call Prototype:

UNSIGNED NU_Established_Semaphores(VOID);

Returns:

Die Anzahl der in der Applikation erstellten Semaphores.

Nucleus SE API Call für Semaphore Count

Service Call Prototype:

U8 NUSE_Semaphore_Count(void);

Returns:

Die Anzahl der in der Applikation konfigurierten Semaphores.

Nucleus SE Implementation of Semaphore Count

Die Routine returned einfach den Wert der Compile-Time Constant NUSE_SEMAPHORE_NUMBER.

Continue to page two: “Data Structures” >>

Eingebettet

  1. Cloud vs. In-House Server: Die richtige Hosting-Lösung wählen
  2. Microsoft Azure kündigt Blockchain-Tokenisierung & Data Management Services an
  3. Digitaler Speicher Grundlagen: Adressierung, Zugriff und Volatilität
  4. C# Variablen & Primitive Datentypen meistern: Der komplette Guide
  5. C++ Structures vs. Classes: Praktischer Leitfaden für Embedded-Entwickler
  6. Mailboxes in Nucleus SE: Praktischer Guide zu Konfiguration und Nutzung
  7. Semaphores in Nucleus SE: Überblick, Konfiguration und API Essentials
  8. Event Flag Groups meistern: Utility Services & Data Structures in Nucleus RTOS/SE
  9. Event Flag Groups in Nucleus SE: Einführender Guide zu Konfiguration und API Usage
  10. Queues in Nucleus SE: Einführung und Core Service Calls