SEGGER Semihosting
SEGGER Semihosting is a standard for Semihosting, defined by SEGGER and compatible to an older standard defined by ARM.
File structure of reference implementation
The reference implementation is provided as a ZIP file, containing a complete project for SEGGER Embedded Studio. The relevant sources are 3 files which are completely generic, so can be compiled on any system using any C- compiler:
- SEGGER_SEMIHOST.h - Interface definition
- SEGGER_SEMIHOST.c - Implementation of the Semihosting interface functions
- SEGGER_SEMIHOST_Generic.c - Implementation of the SEGGER_SEMIHOST_X_Request routine to call SEGGER_SEMIHOST_DebugHalt
The reference project is available for download here: sources
Interface
The below is an exert from SEGGER_SEMIHOST.h, containg the API of the the SEGGER implementation.
int SEGGER_SEMIHOST_Open (const char* sFilename, int Mode, int LenFilename);
int SEGGER_SEMIHOST_Close (int hFile);
int SEGGER_SEMIHOST_WriteC (char c);
int SEGGER_SEMIHOST_Write0 (const char* s);
int SEGGER_SEMIHOST_Write (int hFile, const char* pBuffer, int NumBytesToWrite);
int SEGGER_SEMIHOST_Writef (const char* pFormat, va_list* pArg);
int SEGGER_SEMIHOST_Read (int hFile, char* pBuffer, int NumBytesToRead);
int SEGGER_SEMIHOST_ReadC (void);
int SEGGER_SEMIHOST_IsTTY (int hFile);
int SEGGER_SEMIHOST_Seek (int hFile, int Pos);
int SEGGER_SEMIHOST_FLen (int hFile);
int SEGGER_SEMIHOST_TmpName (char* pBuffer, int hFile, int pNumBytesName);
int SEGGER_SEMIHOST_Remove (const char* pPath, int NumBytesPath);
int SEGGER_SEMIHOST_Rename (const char* pFileName, int NumBytesFileName, const char* pNewName, int NumBytesNewName);
int SEGGER_SEMIHOST_Clock (void);
int SEGGER_SEMIHOST_Time (void);
int SEGGER_SEMIHOST_System (const char* pCommand, int NumBytesCommand);
int SEGGER_SEMIHOST_Errno (void);
int SEGGER_SEMIHOST_GetCmdLine (char* pBuffer, char** psCmdLine, int* pNumBytesCmdLine);
int SEGGER_SEMIHOST_Elapsed (unsigned long long* pTicks);
int SEGGER_SEMIHOST_HeapInfo (char* pDataBlock);
int SEGGER_SEMIHOST_TickFreq (void);
int SEGGER_SEMIHOST_Exit (int ExitCode);
int SEGGER_SEMIHOST_IsConnected (void);
int SEGGER_SEMIHOST_X_Request (int Op, SEGGER_SEMIHOST_PARA* pPara);