/** ******************************************************************************* * * @file common.c * @authors fatih.bellachia@lapp.in2p3.fr * @date 15/04/2013 * @version v0r1 * @bref Set of common features * *------------------------------------------------------------------------------ * * @copyright Copyright © 2013, LAPP/CNRS * * @section LICENSE * * This software is governed by the CeCILL-C license under French law and * abiding by the rules of distribution of free software. You can use, * modify and/or redistribute the software under the terms of the CeCILL-C * license as circulated by CEA, CNRS and INRIA at the following URL * "http://www.cecill.info". * * As a counterpart to the access to the source code and rights to copy, * modify and redistribute granted by the license, users are provided only * with a limited warranty and the software's author, the holder of the * economic rights, and the successive licensors have only limited * liability. * * In this respect, the user's attention is drawn to the risks associated * with loading, using, modifying and/or developing or reproducing the * software by the user in light of its specific status of free software, * that may mean that it is complicated to manipulate, and that also * therefore means that it is reserved for developers and experienced * professionals having in-depth computer knowledge. Users are therefore * encouraged to load and test the software's suitability as regards their * requirements in conditions enabling the security of their systems and/or * data to be ensured and, more generally, to use and operate it in the * same conditions as regards security. * * The fact that you are presently reading this means that you have had * knowledge of the CeCILL-C license and that you accept its terms. * ******************************************************************************* */ /* Includes ------------------------------------------------------------------*/ /** * libc */ #include #include #include /** * ICARE */ #include #include #include #include #include /** * IPMB */ #include "ipmb/ipmblib.h" /** @addtogroup Middleware * @{ */ /** @defgroup IPMB * @{ */ /* Private typedef -----------------------------------------------------------*/ typedef struct { IPMBPacketHeader_t m_stHeader; // IPMB Header uint8_t m_aucData[0]; // Place-holder for IPMB data } Packet_t; /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ #define IPMB_SEQ(seq) ((seq) << 2) /* Private variables ---------------------------------------------------------*/ uint32_t g_uiMallocCnt = 0U; uint32_t g_uiFreeCnt = 0U; /* Private function prototypes -----------------------------------------------*/ /* Public variables ----------------------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /*----------------------------------------------------------------------------*/ static void DisplayMallInfo(const char *pcPrompt) /*----------------------------------------------------------------------------*/ { struct mallinfo stMI; stMI = mallinfo(); printf(" >>>>>>======================== %s ===\n", pcPrompt); printf(" DEBUG> # of malloc call: %lu\n", g_uiMallocCnt); printf(" DEBUG> # of free call: %lu\n", g_uiFreeCnt); printf(" DEBUG> Total non-mmapped bytes (arena): %d\n", stMI.arena); printf(" DEBUG> # of free chunks (ordblks): %d\n", stMI.ordblks); printf(" DEBUG> # of free fastbin blocks (smblks): %d\n", stMI.smblks); printf(" DEBUG> # of mapped regions (hblks): %d\n", stMI.hblks); printf(" DEBUG> Bytes in mapped regions (hblkhd): %d\n", stMI.hblkhd); printf(" DEBUG> Max. total allocated space (usmblks): %d\n", stMI.usmblks); printf(" DEBUG> Free bytes held in fastbins (fsmblks): %d\n", stMI.fsmblks); printf(" DEBUG> Total allocated space (uordblks): %d\n", stMI.uordblks); printf(" DEBUG> Total free space (fordblks): %d\n", stMI.fordblks); printf(" DEBUG> Topmost releasable block (keepcost): %d\n", stMI.keepcost); printf(" ==============================================<<<<<<\n\n"); } /* Public functions ----------------------------------------------------------*/ /*----------------------------------------------------------------------------*/ void PrintBanner(const char* cName) /*----------------------------------------------------------------------------*/ { char *szMessage = { "+-------------------------------------------------------------+\n" \ "| _ |\n" \ "| | | __ _ _ __ _ __ |\n" \ "| | |/ _` | '_ \\| '_ \\ |\n" \ "| | | (_| | |_) | |_) | |\n" \ "| |_|\\__,_| .__/| .__/ |\n" \ "| |_| |_| |\n" \ "| |\n" \ "| SIMPLE INTELLIGENT PLATEFORM BUS %-9s |\n" \ "| |\n" \ "+-------------------------------------------------------------+\n" }; /* Banner */ printf("\033[2J"); printf(szMessage, cName); printf("%s - %s, %s\n", versions[COMPILER_VERSION], versions[BUILD_DATE], versions[BUILD_TIME]); printf("Copyright © 2013 LAPP/CNRS. All rights reserved.\n"); /* Version of Packages */ { unsigned long idx; for(idx = BEGIN_USE_PKG; versions[idx][0] != '\0'; idx++) { printf(" use> %s\n", versions[idx]); } printf("\n\n"); } } /*----------------------------------------------------------------------------*/ void DumpPacket(Packet_t *pstPacket, uint32_t uiLength) /*----------------------------------------------------------------------------*/ { bool bResponse = pstPacket->m_stHeader.m_netFn & 0x1; unsigned int idx; printf(">>>-----------------------------\n"); printf("Connection Header:\n"); printf(" %2sSA: 0x%02x\n", bResponse? "rq": "rs", pstPacket->m_stHeader.m_ucAddress); printf(" netFn: 0x%02x, %2sLUN: 0x%02x\n", pstPacket->m_stHeader.m_netFn, bResponse? "rq": "rs", pstPacket->m_stHeader.m_lun); printf(" checksum: 0x%02x\n", pstPacket->m_stHeader.m_ucChecksum); printf("Message body:\n"); printf(" %2sSA: 0x%02x\n", bResponse? "rs": "rq", pstPacket->m_stHeader.m_ucSlaveAddress); printf(" rqSeq: 0x%02x, %2sLUN: 0x%02x\n", pstPacket->m_stHeader.m_seq, bResponse? "rs": "rq", pstPacket->m_stHeader.m_bridge); printf(" cmd: 0x%02x\n", pstPacket->m_stHeader.m_ucCommand); printf(" data:"); for(idx = 0; idx < (uiLength - sizeof(IPMBPacketHeader_t) - 1); idx++) { printf(" 0x%02x", pstPacket->m_aucData[idx]); } printf("\n checksum: 0x%02x\n", pstPacket->m_aucData[idx]); printf("-----------------------------<<<\n\n"); } /*----------------------------------------------------------------------------*/ void Dump(void *pvArg) /*----------------------------------------------------------------------------*/ { IPMBBus_t eBus = (IPMBBus_t)pvArg; if (USART_RecvReady()) { getchar(); IPMB_DumpStats(eBus); } } /*----------------------------------------------------------------------------*/ void TimeoutCallback(void *pvParameter, void *pvBuffer, uint32_t uiLength) /*----------------------------------------------------------------------------*/ { if (pvBuffer != NULL) { printf("Request timed out:\n"); DumpPacket(pvBuffer, uiLength); } } /*----------------------------------------------------------------------------*/ void ErrorCallback(void *pvParameter, IPMBError_t eError) /*----------------------------------------------------------------------------*/ { IPMBBus_t eBus = (IPMBBus_t)pvParameter; switch(eError) { case IPMB_ERROR_NOT_INITIALIZED: printf(" ERROR> [IPMB-x] library not initialized.\n"); break; case IPMB_ERROR_INVALID_ARGUMENT: printf(" ERROR> [IPMB-x] Invalid argument.\n"); break; case IPMB_ERROR_NO_MEMORY: printf(" ERROR> [IPMB-x] Not enough space.\n"); DisplayMallInfo("In error callback"); for(;;); break; case IPMB_ERROR_READY_TIMEOUT: printf(" ERROR> [IPMB-x] I2C buffer ready timed out.\n"); break; case IPMB_ERROR_SEQ_NOT_AVAILABLE: printf(" ERROR> [IPMB-x] Sequence number not available.\n"); break; case IPMB_ERROR_IPMB_DISABLED: printf(" ERROR> [IPMB-x] IPMB disabled.\n"); break; case IPMB_ERROR_I2C_ERROR: printf(" ERROR> [IPMB-x] I2C error -> %s.\n", IPMB_GetI2CStrError(eBus)); break; case IPMB_ERROR_FIFO_FULL: printf(" ERROR> [IPMB-x] internal FIFO full.\n"); break; default: break; } } /*---------------------------------------------------------------------------*/ static inline void delay(volatile uint32_t uiMicroSeconds) /*---------------------------------------------------------------------------*/ { uiMicroSeconds *= 56; /* fudge for function call overhead */ uiMicroSeconds--; __asm volatile (" mov r0, %[uiMicroSeconds] \n\t" "loop: subs r0, #1 \n\t" " bhi loop \n\t" : : [uiMicroSeconds] "r" (uiMicroSeconds) : "r0"); } /*----------------------------------------------------------------------------*/ char *StrTime(void) /*----------------------------------------------------------------------------*/ { static char szBuf[64]; time_t lTime = RCC_Seconds(); strftime(szBuf, sizeof szBuf, "%T", localtime(&lTime)); return szBuf; } /** * @} */ /** * @} */