KAL

Overview

Defines the kernel adaptation layer (KAL), which provides compatible interfaces across different types of OpenHarmony devices.

Since:

1.0

Version:

1.0

Summary

Files

File Name

Description

kal.h

Defines the kernel adaptation layer (KAL), which provides compatible interfaces across different types of OpenHarmony devices.

Data Structures

Data Structure Name

Description

ThreadInfo

Describes a thread.

MemInfo

Describes a memory pool.

Macros

Macro Name and Value

Description

KAL_TASK_NAME_LEN 32

Indicates the maximum length of a thread name.

Enumerations

Enumeration Name

Description

KalTimerType { KAL_TIMER_ONCE = 0, KAL_TIMER_PERIODIC = 1 }

Enumerates timer types.

KalErrCode { KAL_OK = 0, KAL_ERR_PARA = 1, KAL_ERR_INNER = 2, KAL_ERR_TIMER_STATE = 0x100 }

Enumerates return values of the KAL function.

Functions

Function Name

Description

KalThreadGetInfo (unsigned int threadId, ThreadInfoinfo)

unsigned int

Obtains thread information.

KalDelayUs (unsigned int us)

void

Delays a thread.

KalTimerCreate (KalTimerProc func, KalTimerType type, void arg, unsigned int ticks)

KalTimerId

Creates a timer.

KalTimerStart (KalTimerId timerId)

KalErrCode

Starts a timer.

KalTimerChange (KalTimerId timerId, unsigned int ticks)

KalErrCode

Changes the duration of a timer.

KalTimerStop (KalTimerId timerId)

KalErrCode

Stops a timer.

KalTimerDelete (KalTimerId timerId)

KalErrCode

Deletes a timer.

KalTimerIsRunning (KalTimerId timerId)

unsigned int

Checks whether a timer is running.

KalTickToMs (unsigned int ticks)

unsigned int

Converts system ticks into milliseconds.

KalMsToTick (unsigned int millisec)

unsigned int

Converts milliseconds into system ticks.

KalGetMemInfo (MemInfo *pmemInfo)

KalErrCode

Obtains memory information.

Details

Enumeration Type Documentation

KalErrCode

  1. enum[KalErrCode]($api-api-LinkIoT-KAL.md#ga595e811b5dcad5dc834be507d6839c36)

Description:

Enumerates return values of the KAL function.

Enumerator

Description

KAL_OK

A successful execution

KAL_ERR_PARA

Incorrect parameter

KAL_ERR_INNER

Internal execution error

KAL_ERR_TIMER_STATE

Timer status error

KalTimerType

  1. enum[KalTimerType]($api-api-LinkIoT-KAL.md#gacde4b0c553c297f66311b87c4bbbb27d)

Description:

Enumerates timer types.

Enumerator

Description

KAL_TIMER_ONCE

One-shot timer

KAL_TIMER_PERIODIC

Repetitive timer

Function Documentation

KalDelayUs()

  1. voidKalDelayUs(unsignedint us)

Description:

Delays a thread.

The delay unit is microsecond. The actual delay precision can reach only the tick level.

Parameters:

Name

Description

us

Indicates the number of microseconds to delay. The actual delay precision is one tick.

KalGetMemInfo()

  1. [KalErrCode]($api-api-LinkIoT-KAL.md#ga595e811b5dcad5dc834be507d6839c36) KalGetMemInfo ([MemInfo]($api-api-LinkIoT-MemInfo.md) * pmemInfo)

Description:

Obtains memory information.

Parameters:

Name

Description

pmemInfo

Indicates the pointer to the memory information.

Returns:

Returns an enumerated value defined by KalErrCode, where KAL_OK indicates a success.

KalMsToTick()

  1. unsignedintKalMsToTick(unsignedint millisec)

Description:

Converts milliseconds into system ticks.

Parameters:

Name

Description

millisec

Indicates the milliseconds to convert.

Returns:

Returns the system ticks generated.

KalThreadGetInfo()

  1. unsignedintKalThreadGetInfo(unsignedint threadId,[ThreadInfo]($api-api-LinkIoT-ThreadInfo.md)* info )

Description:

Obtains thread information.

Parameters:

Name

Description

threadId

Indicates the thread ID.

info

Indicates the pointer to the buffer for storing the obtained thread information.

Returns:

Returns 0 if the thread information is obtained; returns a negative value otherwise.

KalTickToMs()

  1. unsignedintKalTickToMs(unsignedint ticks)

Description:

Converts system ticks into milliseconds.

Parameters:

Name

Description

ticks

Indicates the number of ticks to convert.

Returns:

Returns the milliseconds generated.

KalTimerChange()

  1. [KalErrCode]($api-api-LinkIoT-KAL.md#ga595e811b5dcad5dc834be507d6839c36) KalTimerChange (KalTimerId timerId, unsigned int ticks )

Description:

Changes the duration of a timer.

The timer duration can be changed only before the timer is started.

Parameters:

Name

Description

timerId

Indicates the ID of the timer whose duration is to change, which is the value returned by KalTimerCreate.

ticks

Indicates the new duration of the timer.

Returns:

Returns an enumerated value defined by KalErrCode, where KAL_OK indicates a success.

KalTimerCreate()

  1. KalTimerIdKalTimerCreate(KalTimerProc func,[KalTimerType]($api-api-LinkIoT-KAL.md#gacde4b0c553c297f66311b87c4bbbb27d) type, void * arg, unsigned int ticks )

Description:

Creates a timer.

Parameters:

Name

Description

func

Indicates the entry to timer callback. The callback is triggered when the timer expires.

type

Indicates the timer type.

arg

Indicates the pointer to the argument used in timer callback.

ticks

Indicates the duration of the timer to create.

Returns:

Returns the timer ID; returns NULL in the case of an error.

KalTimerDelete()

  1. [KalErrCode]($api-api-LinkIoT-KAL.md#ga595e811b5dcad5dc834be507d6839c36) KalTimerDelete (KalTimerId timerId)

Description:

Deletes a timer.

Parameters:

Name

Description

timerId

Indicates the ID of the timer to delete, which is the value returned by KalTimerCreate.

Returns:

Returns an enumerated value defined by KalErrCode, where KAL_OK indicates a success.

KalTimerIsRunning()

  1. unsignedintKalTimerIsRunning(KalTimerId timerId)

Description:

Checks whether a timer is running.

Parameters:

Name

Description

timerId

Indicates the ID of the timer to check, which is the value returned by KalTimerCreate.

Returns:

Returns 1 if the timer is running; returns 0 if the timer is not running or the input parameter is incorrect.

KalTimerStart()

  1. [KalErrCode]($api-api-LinkIoT-KAL.md#ga595e811b5dcad5dc834be507d6839c36) KalTimerStart (KalTimerId timerId)

Description:

Starts a timer.

Parameters:

Name

Description

timerId

Indicates the ID of the timer to start, which is the value returned by KalTimerCreate.

Returns:

Returns an enumerated value defined by KalErrCode, where KAL_OK indicates a success.

KalTimerStop()

  1. [KalErrCode]($api-api-LinkIoT-KAL.md#ga595e811b5dcad5dc834be507d6839c36) KalTimerStop (KalTimerId timerId)

Description:

Stops a timer.

Parameters:

Name

Description

timerId

Indicates the ID of the timer to stop, which is the value returned by KalTimerCreate.

Returns:

Returns an enumerated value defined by KalErrCode, where KAL_OK indicates a success.

Variable Documentation

bottomOfStack

  1. unsignedintThreadInfo::bottomOfStack

Description:

Thread stack bottom

currUsed

  1. unsignedintThreadInfo::currUsed

Description:

Current stack space usage

eventMask

  1. unsignedintThreadInfo::eventMask

Description:

Thread event mask

eventStru

  1. unsignedintThreadInfo::eventStru[3]

Description:

Thread event

free

  1. unsignedintMemInfo::free

Description:

Available space of the memory pool, in bytes

freeLmp

  1. unsignedintMemInfo::freeLmp

Description:

Available space of the small memory pool, in bytes

freeNodeNum

  1. unsignedintMemInfo::freeNodeNum

Description:

Number of available nodes in the memory pool

id

  1. unsignedintThreadInfo::id

Description:

Thread ID

mallocFailCount

  1. unsignedintMemInfo::mallocFailCount

Description:

Number of memory allocation failures

maxFreeNodeSize

  1. unsignedintMemInfo::maxFreeNodeSize

Description:

Size of the largest available node in the memory pool, in bytes

mepc

  1. unsignedintThreadInfo::mepc

Description:

Current thread MEPC

mstatus

  1. unsignedintThreadInfo::mstatus

Description:

Current thread status

name

  1. charThreadInfo::name[[KAL_TASK_NAME_LEN](KAL.md#ga5c36b53bd6e8cbdbcd79f702eda94fdc)]

Description:

Thread name

overflowFlag

  1. unsignedintThreadInfo::overflowFlag

Description:

Thread stack overflow flag

peakUsed

  1. unsignedintThreadInfo::peakUsed

Description:

Peak stack space usage

peekSize

  1. unsignedintMemInfo::peekSize

Description:

Peak memory usage of the memory pool

priority

  1. unsignedshortThreadInfo::priority

Description:

Thread priority

ra

  1. unsignedintThreadInfo::ra

Description:

Current thread RA

sp

  1. unsignedintThreadInfo::sp

Description:

Thread stack pointer

stackSize

  1. unsignedintThreadInfo::stackSize

Description:

Thread stack size

status

  1. unsignedshortThreadInfo::status

Description:

Thread status

taskMutex

  1. void*ThreadInfo::taskMutex

Description:

Thread mutex

taskSem

  1. void*ThreadInfo::taskSem

Description:

Thread semaphore

topOfStack

  1. unsignedintThreadInfo::topOfStack

Description:

Thread stack top

total

  1. unsignedintMemInfo::total

Description:

Total space of the memory pool, in bytes

totalLmp

  1. unsignedintMemInfo::totalLmp

Description:

Total space of the small memory pool, in bytes

tp

  1. unsignedintThreadInfo::tp

Description:

Current thread TP

used

  1. unsignedintMemInfo::used

Description:

Used space of the memory pool, in bytes

usedLmp

  1. unsignedintMemInfo::usedLmp

Description:

Used space of the small memory pool, in bytes

usedNodeNum

  1. unsignedintMemInfo::usedNodeNum

Description:

Number of used nodes in the memory pool