## **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
Defines the kernel adaptation layer (KAL), which provides compatible interfaces across different types of OpenHarmony devices. |
## Data Structures
## Macros
Indicates the maximum length of a thread name. |
## Enumerations
KalTimerType { KAL_TIMER_ONCE = 0, KAL_TIMER_PERIODIC = 1 } | |
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
KalThreadGetInfo (unsigned int threadId, ThreadInfo *info) | |
KalDelayUs (unsigned int us) | |
KalTimerCreate (KalTimerProc func, KalTimerType type, void *arg, unsigned int ticks) | |
KalTimerStart (KalTimerId timerId) | |
KalTimerChange (KalTimerId timerId, unsigned int ticks) | Changes the duration of a timer. |
KalTimerStop (KalTimerId timerId) | |
KalTimerDelete (KalTimerId timerId) | |
KalTimerIsRunning (KalTimerId timerId) | Checks whether a timer is running. |
KalTickToMs (unsigned int ticks) | Converts system ticks into milliseconds. |
KalMsToTick (unsigned int millisec) | Converts milliseconds into system ticks. |
KalGetMemInfo (MemInfo *pmemInfo) |
## **Details**
## **Enumeration Type Documentation**
## KalErrCode
```
enum [KalErrCode](kal.md#ga595e811b5dcad5dc834be507d6839c36)
```
**Description:**
Enumerates return values of the KAL function.
## KalTimerType
```
enum [KalTimerType](kal.md#gacde4b0c553c297f66311b87c4bbbb27d)
```
**Description:**
Enumerates timer types.
## **Function Documentation**
## KalDelayUs\(\)
```
void KalDelayUs (unsigned int us)
```
**Description:**
Delays a thread.
The delay unit is microsecond. The actual delay precision can reach only the tick level.
**Parameters:**
Indicates the number of microseconds to delay. The actual delay precision is one tick. |
## KalGetMemInfo\(\)
```
[KalErrCode](kal.md#ga595e811b5dcad5dc834be507d6839c36) KalGetMemInfo ([MemInfo](meminfo.md) * pmemInfo)
```
**Description:**
Obtains memory information.
**Parameters:**
Indicates the pointer to the memory information. |
**Returns:**
Returns an enumerated value defined by [KalErrCode](kal.md#ga595e811b5dcad5dc834be507d6839c36), where [KAL\_OK](kal.md#gga595e811b5dcad5dc834be507d6839c36a249642877a22187565c646fcb4c43228) indicates a success.
## KalMsToTick\(\)
```
unsigned int KalMsToTick (unsigned int millisec)
```
**Description:**
Converts milliseconds into system ticks.
**Parameters:**
Indicates the milliseconds to convert. |
**Returns:**
Returns the system ticks generated.
## KalThreadGetInfo\(\)
```
unsigned int KalThreadGetInfo (unsigned int threadId, [ThreadInfo](threadinfo.md) * info )
```
**Description:**
Obtains thread information.
**Parameters:**
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\(\)
```
unsigned int KalTickToMs (unsigned int ticks)
```
**Description:**
Converts system ticks into milliseconds.
**Parameters:**
Indicates the number of ticks to convert. |
**Returns:**
Returns the milliseconds generated.
## KalTimerChange\(\)
```
[KalErrCode](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:**
Indicates the ID of the timer whose duration is to change, which is the value returned by KalTimerCreate. | |
Indicates the new duration of the timer. |
**Returns:**
Returns an enumerated value defined by [KalErrCode](kal.md#ga595e811b5dcad5dc834be507d6839c36), where [KAL\_OK](kal.md#gga595e811b5dcad5dc834be507d6839c36a249642877a22187565c646fcb4c43228) indicates a success.
## KalTimerCreate\(\)
```
KalTimerId KalTimerCreate (KalTimerProc func, [KalTimerType](kal.md#gacde4b0c553c297f66311b87c4bbbb27d) type, void * arg, unsigned int ticks )
```
**Description:**
Creates a timer.
**Parameters:**
Indicates the entry to timer callback. The callback is triggered when the timer expires. | |
Indicates the pointer to the argument used in timer callback. | |
Indicates the duration of the timer to create. |
**Returns:**
Returns the timer ID; returns **NULL** in the case of an error.
## KalTimerDelete\(\)
```
[KalErrCode](kal.md#ga595e811b5dcad5dc834be507d6839c36) KalTimerDelete (KalTimerId timerId)
```
**Description:**
Deletes a timer.
**Parameters:**
Indicates the ID of the timer to delete, which is the value returned by KalTimerCreate. |
**Returns:**
Returns an enumerated value defined by [KalErrCode](kal.md#ga595e811b5dcad5dc834be507d6839c36), where [KAL\_OK](kal.md#gga595e811b5dcad5dc834be507d6839c36a249642877a22187565c646fcb4c43228) indicates a success.
## KalTimerIsRunning\(\)
```
unsigned int KalTimerIsRunning (KalTimerId timerId)
```
**Description:**
Checks whether a timer is running.
**Parameters:**
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\(\)
```
[KalErrCode](kal.md#ga595e811b5dcad5dc834be507d6839c36) KalTimerStart (KalTimerId timerId)
```
**Description:**
Starts a timer.
**Parameters:**
Indicates the ID of the timer to start, which is the value returned by KalTimerCreate. |
**Returns:**
Returns an enumerated value defined by [KalErrCode](kal.md#ga595e811b5dcad5dc834be507d6839c36), where [KAL\_OK](kal.md#gga595e811b5dcad5dc834be507d6839c36a249642877a22187565c646fcb4c43228) indicates a success.
## KalTimerStop\(\)
```
[KalErrCode](kal.md#ga595e811b5dcad5dc834be507d6839c36) KalTimerStop (KalTimerId timerId)
```
**Description:**
Stops a timer.
**Parameters:**
Indicates the ID of the timer to stop, which is the value returned by KalTimerCreate. |
**Returns:**
Returns an enumerated value defined by [KalErrCode](kal.md#ga595e811b5dcad5dc834be507d6839c36), where [KAL\_OK](kal.md#gga595e811b5dcad5dc834be507d6839c36a249642877a22187565c646fcb4c43228) indicates a success.
## **Variable Documentation**
## bottomOfStack
```
unsigned int ThreadInfo::bottomOfStack
```
**Description:**
Thread stack bottom
## currUsed
```
unsigned int ThreadInfo::currUsed
```
**Description:**
Current stack space usage
## eventMask
```
unsigned int ThreadInfo::eventMask
```
**Description:**
Thread event mask
## eventStru
```
unsigned int ThreadInfo::eventStru[3]
```
**Description:**
Thread event
## free
```
unsigned int MemInfo::free
```
**Description:**
Available space of the memory pool, in bytes
## freeLmp
```
unsigned int MemInfo::freeLmp
```
**Description:**
Available space of the small memory pool, in bytes
## freeNodeNum
```
unsigned int MemInfo::freeNodeNum
```
**Description:**
Number of available nodes in the memory pool
## id
```
unsigned int ThreadInfo::id
```
**Description:**
Thread ID
## mallocFailCount
```
unsigned int MemInfo::mallocFailCount
```
**Description:**
Number of memory allocation failures
## maxFreeNodeSize
```
unsigned int MemInfo::maxFreeNodeSize
```
**Description:**
Size of the largest available node in the memory pool, in bytes
## mepc
```
unsigned int ThreadInfo::mepc
```
**Description:**
Current thread MEPC
## mstatus
```
unsigned int ThreadInfo::mstatus
```
**Description:**
Current thread status
## name
```
char ThreadInfo::name[[KAL_TASK_NAME_LEN](kal.md#ga5c36b53bd6e8cbdbcd79f702eda94fdc)]
```
**Description:**
Thread name
## overflowFlag
```
unsigned int ThreadInfo::overflowFlag
```
**Description:**
Thread stack overflow flag
## peakUsed
```
unsigned int ThreadInfo::peakUsed
```
**Description:**
Peak stack space usage
## peekSize
```
unsigned int MemInfo::peekSize
```
**Description:**
Peak memory usage of the memory pool
## priority
```
unsigned short ThreadInfo::priority
```
**Description:**
Thread priority
## ra
```
unsigned int ThreadInfo::ra
```
**Description:**
Current thread RA
## sp
```
unsigned int ThreadInfo::sp
```
**Description:**
Thread stack pointer
## stackSize
```
unsigned int ThreadInfo::stackSize
```
**Description:**
Thread stack size
## status
```
unsigned short ThreadInfo::status
```
**Description:**
Thread status
## taskMutex
```
void* ThreadInfo::taskMutex
```
**Description:**
Thread mutex
## taskSem
```
void* ThreadInfo::taskSem
```
**Description:**
Thread semaphore
## topOfStack
```
unsigned int ThreadInfo::topOfStack
```
**Description:**
Thread stack top
## total
```
unsigned int MemInfo::total
```
**Description:**
Total space of the memory pool, in bytes
## totalLmp
```
unsigned int MemInfo::totalLmp
```
**Description:**
Total space of the small memory pool, in bytes
## tp
```
unsigned int ThreadInfo::tp
```
**Description:**
Current thread TP
## used
```
unsigned int MemInfo::used
```
**Description:**
Used space of the memory pool, in bytes
## usedLmp
```
unsigned int MemInfo::usedLmp
```
**Description:**
Used space of the small memory pool, in bytes
## usedNodeNum
```
unsigned int MemInfo::usedNodeNum
```
**Description:**
Number of used nodes in the memory pool