/** ******************************************************************************* * * @file ipmb_responder.c * @authors fatih.bellachia@lapp.in2p3.fr * @date 15/04/2013 * @version v0r1 * @bref Simple Intelligent Plateform Management Bus responder * *------------------------------------------------------------------------------ * * @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 /** * Common */ #include "test/template/common.c" /** @addtogroup Middleware * @{ */ /** @defgroup IPMB * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ #define OWN_ADDRESS 0x10 #define IPMB_CC_NORMALLY 0x00 #define IPMB_REPONSE_LENGTH 12 /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ static char s_aucData[] = { IPMB_CC_NORMALLY, 0x03, 0x02, 0x01, 0x05, 0x10 }; static Packet_t *s_pstRequest = NULL; /* Private function prototypes -----------------------------------------------*/ /* Public variables ----------------------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /* Public functions ----------------------------------------------------------*/ /*----------------------------------------------------------------------------*/ void ReceiveCallback(void *pvParameter, void *pvBuffer, uint32_t uiLength) /*----------------------------------------------------------------------------*/ { if (pvBuffer != NULL) { //printf("Receive packet:\n"); //DumpPacket(pvBuffer, uiLength); s_pstRequest = (Packet_t *)malloc(uiLength); g_uiMallocCnt++; if (s_pstRequest != NULL) { memcpy(s_pstRequest, pvBuffer, uiLength); } LED_Toggle(LED_1); } else { printf("ERROR> receive buffer is NULL.\n"); } } /*----------------------------------------------------------------------------*/ void SendResponse(void *pvArg) /*----------------------------------------------------------------------------*/ { if (s_pstRequest != NULL) { Packet_t *pstResponse = (Packet_t *)malloc(IPMB_REPONSE_LENGTH); g_uiMallocCnt++; if (pstResponse != NULL) { pstResponse->m_stHeader.m_ucAddress = s_pstRequest->m_stHeader.m_ucSlaveAddress; pstResponse->m_stHeader.m_netFn = s_pstRequest->m_stHeader.m_netFn | 0x1; pstResponse->m_stHeader.m_lun = s_pstRequest->m_stHeader.m_bridge; pstResponse->m_stHeader.m_ucChecksum = 0; pstResponse->m_stHeader.m_ucSlaveAddress = s_pstRequest->m_stHeader.m_ucAddress; pstResponse->m_stHeader.m_seq = s_pstRequest->m_stHeader.m_seq; pstResponse->m_stHeader.m_bridge = s_pstRequest->m_stHeader.m_lun; pstResponse->m_stHeader.m_ucCommand = s_pstRequest->m_stHeader.m_ucCommand; memcpy(pstResponse->m_aucData, s_aucData, 6); IPMB_SendMessage(IPMB_BUS, pstResponse, IPMB_REPONSE_LENGTH); LED_Toggle(LED_2); free(pstResponse); g_uiFreeCnt++; } free(s_pstRequest); s_pstRequest = NULL; g_uiFreeCnt++; } } /*----------------------------------------------------------------------------*/ int main(void) /*----------------------------------------------------------------------------*/ { RCC_Open(); USART_Init(); TaskQueueInit(); PrintBanner("RESPONDER"); IPMB_SetDebugLevel(1); IPMB_Init(IPMB_BUS, OWN_ADDRESS); IPMB_RegisterMsgCallback(IPMB_BUS, IPMB_RECEIVE_CALLBACK, ReceiveCallback, NULL); IPMB_RegisterMsgCallback(IPMB_BUS, IPMB_TIMEOUT_CALLBACK, TimeoutCallback, NULL); IPMB_RegisterErrorCallback(IPMB_BUS, ErrorCallback, NULL); TaskCreate(SendResponse, NULL); TaskCreate(Dump, (void *)IPMB_BUS); IPMB_Enable(IPMB_BUS, IPMB_CHANNEL); IPMB_BufferEnable(IPMB_BUS, IPMB_CHANNEL, 1); /* do forever */ for (;;) { TaskQueueProcess(); } return 0; } /** * @} */ /** * @} */