|
@@ -1,134 +1,49 @@
|
|
|
#include <stdio.h>
|
|
|
-#include <string.h>
|
|
|
-#include <ctype.h>
|
|
|
-#include <byteswap.h>
|
|
|
-#include <unistd.h>
|
|
|
-#include <stddef.h>
|
|
|
-#include <time.h>
|
|
|
-#include <errno.h>
|
|
|
-#include <gfaserial.h>
|
|
|
-#include <gfabootlmast.h>
|
|
|
-#include "../libmininet/dbghlp.h"
|
|
|
+#include <string.h> // memset
|
|
|
+#include <gfa/gfaserial.h>
|
|
|
+#include <gfa/gfamininetmst.h>
|
|
|
+#include "../src/dbghlp.h"
|
|
|
|
|
|
-#ifdef _TARGET_BUILD
|
|
|
-#define _DEVICE_NAME "/dev/ttyO4"
|
|
|
-#else
|
|
|
-#define _DEVICE_NAME "/dev/tty0"
|
|
|
-#endif // _TARGET_BUILD
|
|
|
+////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
+#define _DEVICE_NAME "/dev/ttyO4"
|
|
|
#define _NODE_ADDR 0x11
|
|
|
-#define _BL_MATERIAL "G.Z.40015 P01"
|
|
|
-#define _BL_SERIAL "18-080015 1409"
|
|
|
-#define _IMG_FILE_PATH "/opt/sflash/OLS-1V1_0009_crc.bin"
|
|
|
-//#define _IMG_FILE_PATH "/opt/sflash/test.jpg"
|
|
|
+#define _BAUD_RATE 19200
|
|
|
+#define _DATA_BITS 8
|
|
|
+#define _STOP_BITS 1
|
|
|
+#define _PARITY 'N'
|
|
|
|
|
|
-#define _BAUD_HI 115200 // 921600 460800 230400 115200
|
|
|
-#define _BAUD_LO 19200
|
|
|
-
|
|
|
-// gfativaflashutil
|
|
|
-/////////////////////////////////////////////////////////////////////////////
|
|
|
+////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
-static uint64_t _Timespec2Ns(const struct timespec *pts)
|
|
|
+static int _BootloaderGetExecutionContext(HGFAMINEMST hMinem, uint8_t nNodeAddr)
|
|
|
{
|
|
|
- if(pts)
|
|
|
- return (uint64_t)pts->tv_sec * 1000000000 + (uint64_t)pts->tv_nsec;
|
|
|
- return (uint64_t)-1;
|
|
|
-}
|
|
|
+ if(hMinem && !NODE_IS_MULTICAST(nNodeAddr))
|
|
|
+ {
|
|
|
+ uint8_t nIndex;
|
|
|
+ ssize_t nRet, nLen;
|
|
|
+ char txb[32], rxb[256];
|
|
|
|
|
|
-/////////////////////////////////////////////////////////////////////////////
|
|
|
+ nLen = GfaMininetMasterBuildFrame(hMinem, nNodeAddr, 0, "BU", 2, txb, sizeof(txb));
|
|
|
|
|
|
-static int64_t _TimespecDiff(const struct timespec *pts1, const struct timespec *pts2)
|
|
|
-{
|
|
|
- int64_t nRet = 0;
|
|
|
+ if((nRet = GfaMininetMasterTransmitFrame(hMinem, txb, nLen)) != nLen)
|
|
|
+ return -1;
|
|
|
|
|
|
- if(pts1 && pts2)
|
|
|
- {
|
|
|
- uint64_t t1 = _Timespec2Ns(pts1);
|
|
|
- uint64_t t2 = _Timespec2Ns(pts2);
|
|
|
- nRet = (int64_t)(t1 - t2);
|
|
|
- }
|
|
|
+ if((nLen = GfaMininetMasterReceiveFrame(hMinem, rxb, sizeof(rxb), true)) <= 0)
|
|
|
+ return -1;
|
|
|
|
|
|
- return nRet;
|
|
|
-}
|
|
|
+ nRet = GfaMininetMasterEvaluateSlaveResponse(hMinem, nNodeAddr, rxb, nLen, true, &nIndex);
|
|
|
|
|
|
-#ifdef _DEBUG
|
|
|
-static void _BuCmdDownloadStatus(const char *pszFile, int nLine, uint8_t nNodeAddr, uint32_t nFlashStartAddr, uint32_t nCbData, int nCtx, int nErrorCode)
|
|
|
-#else // _DEBUG
|
|
|
-static void _BuCmdDownloadStatus(uint8_t nNodeAddr, uint32_t nFlashStartAddr, uint32_t nCbData, int nCtx, int nErrorCode)
|
|
|
-#endif // _DEBUG
|
|
|
-{
|
|
|
- static struct timespec tsStart, tsEnd;
|
|
|
- int64_t nInterval;
|
|
|
-
|
|
|
- switch(nCtx)
|
|
|
- {
|
|
|
- case 0:
|
|
|
- TRACE("\n%s:%d: %s!\n", pszFile, nLine, GfaBlmStrError(nErrorCode));
|
|
|
- break;
|
|
|
- case 1:
|
|
|
- clock_gettime(CLOCK_MONOTONIC, &tsStart);
|
|
|
- TRACE("Start download of %u Bytes to Node 0x%02hhX @ 0x%X.\n", nCbData, nNodeAddr, nFlashStartAddr);
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- break;
|
|
|
- case 3:
|
|
|
- clock_gettime(CLOCK_MONOTONIC, &tsEnd);
|
|
|
- nInterval = _TimespecDiff(&tsEnd, &tsStart);
|
|
|
- TRACE("Erased Flash in %lld ms.\n", nInterval / 1000000);
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
-}
|
|
|
+ if(nRet == MINET_SLAVE_RESPONSE_SUCCESS)
|
|
|
+ return -1; // Slave is neither a Bootloader nor an App
|
|
|
+ if(nRet == MINET_SLAVE_RESPONSE_ACK)
|
|
|
+ return 0; // Bootloader responding
|
|
|
+ else if(nRet == MINET_SLAVE_RESPONSE_INDEX_IS_STATUS_CODE)
|
|
|
+ return 1; // Application responding
|
|
|
|
|
|
-#ifdef _DEBUG
|
|
|
-static void _BuCmdSendDataStatus(const char *pszFile, int nLine, uint8_t nNodeAddr, uint32_t nCbBlock, uint32_t nCbData, int nCtx, int nErrorCode)
|
|
|
-#else // _DEBUG
|
|
|
-static void _BuCmdSendDataStatus(uint8_t nNodeAddr, uint32_t nCbBlock, uint32_t nCbData, int nCtx, int nErrorCode)
|
|
|
-#endif // _DEBUG
|
|
|
-{
|
|
|
- static struct timespec tsStart, tsEnd;
|
|
|
- static uint32_t nBlockNr;
|
|
|
- int64_t nInterval;
|
|
|
-
|
|
|
- switch(nCtx)
|
|
|
- {
|
|
|
- case 0:
|
|
|
- TRACE("\n%s:%d: %s!\n", pszFile, nLine, GfaBlmStrError(nErrorCode));
|
|
|
- break;
|
|
|
- case 1:
|
|
|
- nBlockNr = 0;
|
|
|
- clock_gettime(CLOCK_MONOTONIC, &tsStart);
|
|
|
- TRACE("Start sending data to Node 0x%02hhX - block size: %u bytes.\n", nNodeAddr, nCbBlock);
|
|
|
- break;
|
|
|
- case 2:
|
|
|
-#if 1
|
|
|
- if(nBlockNr > 0)
|
|
|
- TRACE("\b\b\b\b\b\b");
|
|
|
- TRACE("%06u", nCbData);
|
|
|
-#endif
|
|
|
- ++nBlockNr;
|
|
|
- break;
|
|
|
- case 3:
|
|
|
- clock_gettime(CLOCK_MONOTONIC, &tsEnd);
|
|
|
- nInterval = _TimespecDiff(&tsEnd, &tsStart);
|
|
|
- TRACE("\nSent %u blocks to Node 0x%02hhX in %llu ms.\n", nBlockNr, nNodeAddr, nInterval / 1000000);
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
+ return -1;
|
|
|
}
|
|
|
-}
|
|
|
|
|
|
-static void _TraceImageInfo(const char *pszContext, LPCGFA_IMG_INFO pii)
|
|
|
-{
|
|
|
- if(pszContext && pii && pii->nImgLength != 0xFFFFFFFF && pii->nImgCRC32 != 0xFFFFFFFF)
|
|
|
- {
|
|
|
- TRACE("%s Image Information:\n", pszContext);
|
|
|
- TRACE(" Length: %u\n", pii->nImgLength);
|
|
|
- TRACE(" CRC32: 0x%08X\n", pii->nImgCRC32);
|
|
|
- TRACE(" Mat.Nr.: %s\n", pii->szImgMaterialNum);
|
|
|
- TRACE(" Build: %s\n", pii->szImgNameBuild);
|
|
|
- }
|
|
|
+ return -1;
|
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
@@ -136,129 +51,54 @@ static void _TraceImageInfo(const char *pszContext, LPCGFA_IMG_INFO pii)
|
|
|
|
|
|
int main(void)
|
|
|
{
|
|
|
- ssize_t nRet = 0;
|
|
|
+ int nRet = 0;
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
- GFA_BLM_CFG_PARAMS blmcp;
|
|
|
- memset(&blmcp, 0, sizeof(blmcp));
|
|
|
+ GFA_MININET_MST_CFG_PARAMS mmcp;
|
|
|
+ memset(&mmcp, 0, sizeof(mmcp));
|
|
|
|
|
|
- if(GfaSerialGetDeviceInterface(&blmcp.mmcp.devcfg.itf))
|
|
|
+ if(GfaSerialGetDeviceInterface(&mmcp.devcfg.itf))
|
|
|
{
|
|
|
- HGFABLM hBlm;
|
|
|
+ HGFAMINEMST hMinem;
|
|
|
GFA_SER_CFG_PARAMS scp;
|
|
|
memset(&scp, 0, sizeof(scp));
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
- // serial interface parameters
|
|
|
+ // serial interface configuration
|
|
|
|
|
|
- scp.baud = _BAUD_LO;
|
|
|
- scp.data = 8;
|
|
|
- scp.stop = 1;
|
|
|
- scp.parity = 'N';
|
|
|
-#ifdef _TARGET_BUILD
|
|
|
+ scp.baud = _BAUD_RATE;
|
|
|
+ scp.data = _DATA_BITS;
|
|
|
+ scp.stop = _STOP_BITS;
|
|
|
+ scp.parity = _PARITY;
|
|
|
scp.bHandleTxEcho = true;
|
|
|
-#endif // _TARGET_BUILD
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
// mininet master configuration
|
|
|
|
|
|
- blmcp.mmcp.devcfg.pszDeviceName = _DEVICE_NAME;
|
|
|
- blmcp.mmcp.devcfg.pDevParams = &scp;
|
|
|
- blmcp.mmcp.devcfg.nSizeDevParams = sizeof(scp);
|
|
|
- blmcp.pfnBuCmdDownloadStatus = _BuCmdDownloadStatus;
|
|
|
- blmcp.pfnBuCmdSendDataStatus = _BuCmdSendDataStatus;
|
|
|
+ mmcp.devcfg.pszDeviceName = _DEVICE_NAME;
|
|
|
+ mmcp.devcfg.pDevParams = &scp;
|
|
|
+ mmcp.devcfg.nSizeDevParams = sizeof(scp);
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
- ////////////////////////////////////////////////////////////////////////////
|
|
|
- ////////////////////////////////////////////////////////////////////////////
|
|
|
+ //
|
|
|
|
|
|
- if((hBlm = GfaBlmOpen(&blmcp)))
|
|
|
+ if((hMinem = GfaMininetMasterOpen(&mmcp)))
|
|
|
{
|
|
|
- uint32_t nImgCRC32;
|
|
|
- GFA_BL_APP_IMG_INFO aii;
|
|
|
- GFA_BLM_EXEC_CONTEXT ctx;
|
|
|
- char szMaterial[16], szSerial[16];
|
|
|
-
|
|
|
do
|
|
|
{
|
|
|
-// GfaBlmSetVerbosity(hBlm, 4);
|
|
|
-
|
|
|
- if((nRet = GfaBlmResetSlaveIndex(hBlm, _NODE_ADDR)) != 0)
|
|
|
- {
|
|
|
- TRACE("%s!\n", GfaBlmStrError(errno));
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- if((ctx = GfaBlmGetExecutionContext(hBlm, _NODE_ADDR)) == GfaBlmCtx_Err)
|
|
|
- {
|
|
|
- TRACE("%s!\n", GfaBlmStrError(errno));
|
|
|
+ if((nRet = GfaMininetMasterSetVerbosity(hMinem, 4)) < 0) // enable output of frames
|
|
|
break;
|
|
|
- }
|
|
|
-
|
|
|
- TRACE("Currently running: %s\n", (ctx == GfaBlmCtx_App) ? "Application" : "Bootloader");
|
|
|
-
|
|
|
- if(ctx == GfaBlmCtx_App)
|
|
|
- {
|
|
|
- if((nRet = GfaBlmBootloaderExecute(hBlm, _NODE_ADDR, &nImgCRC32, 500)) != 0)
|
|
|
- {
|
|
|
- TRACE("%s!\n", GfaBlmStrError(errno));
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if((nRet = GfaBlmBootloaderSetBaudrate(hBlm, _NODE_ADDR, _BAUD_HI)) != 0)
|
|
|
- {
|
|
|
- TRACE("%s!\n", GfaBlmStrError(errno));
|
|
|
+ if((nRet = GfaMininetMasterResetSlaveIndex(hMinem, _NODE_ADDR)) < 0)
|
|
|
break;
|
|
|
- }
|
|
|
-
|
|
|
- // GfaBlmSetVerbosity(hBlm, 3);
|
|
|
-
|
|
|
- if((nRet = GfaBlmBUCmdSendDataFile(hBlm, _NODE_ADDR, _IMG_FILE_PATH, 0x2000, 76, 5000)) == 0)
|
|
|
- {
|
|
|
- // GfaBlmSetVerbosity(hBlm, 4);
|
|
|
-
|
|
|
- TRACE("Resetting slave ...\n");
|
|
|
-
|
|
|
- if((nRet = GfaBlmBUCmdReset(hBlm, _NODE_ADDR, 500)) != 0)
|
|
|
- {
|
|
|
- TRACE("%s!\n", GfaBlmStrError(errno));
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- // GfaBlmSetVerbosity(hBlm, 0);
|
|
|
-
|
|
|
- if((ctx = GfaBlmGetExecutionContext(hBlm, _NODE_ADDR)) == GfaBlmCtx_Err)
|
|
|
- {
|
|
|
- TRACE("%s!\n", GfaBlmStrError(errno));
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- TRACE("%s\n", (ctx == GfaBlmCtx_App) ? "Application started." : "Application failed to start!");
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- TRACE("%s!\n", GfaBlmStrError(errno));
|
|
|
+ if((nRet = GfaMininetMasterPingSlave(hMinem, _NODE_ADDR)) < 0)
|
|
|
break;
|
|
|
- }
|
|
|
-
|
|
|
- // GfaBlmSetVerbosity(hBlm, 4);
|
|
|
|
|
|
- if((nRet = GfaBlmGetInfoBI(hBlm, _NODE_ADDR, &aii)) == 0)
|
|
|
- {
|
|
|
- _TraceImageInfo("Bootloader", &aii.bl);
|
|
|
- _TraceImageInfo("Application", &aii.app);
|
|
|
- }
|
|
|
- else if((nRet = GfaBlmGetInfoBD(hBlm, _NODE_ADDR, &aii)) > -2)
|
|
|
- {
|
|
|
- _TraceImageInfo("Bootloader", &aii.bl);
|
|
|
- _TraceImageInfo("Application", &aii.app);
|
|
|
- }
|
|
|
- }
|
|
|
- while(false);
|
|
|
+ nRet = _BootloaderGetExecutionContext(hMinem, _NODE_ADDR); // demonstrates the implementation of commands
|
|
|
+ }
|
|
|
+ while(0);
|
|
|
|
|
|
- GfaBlmClose(hBlm); // important!!!
|
|
|
+ GfaMininetMasterClose(hMinem);
|
|
|
}
|
|
|
}
|
|
|
|