MAX32620HSP (MAXREFDES100) RPC Example for Graphical User Interface

Dependencies:   USBDevice

Fork of HSP_Release by Jerry Bradshaw

This is an example program for the MAX32620HSP (MAXREFDES100 Health Sensor Platform). It demonstrates all the features of the platform and works with a companion graphical user interface (GUI) to help evaluate/configure/monitor the board. Go to the MAXREFDES100 product page and click on "design resources" to download the companion software. The GUI connects to the board through an RPC interface on a virtual serial port over the USB interface.

The RPC interface provides access to all the features of the board and is available to interface with other development environments such Matlab. This firmware provides realtime data streaming through the RPC interface over USB, and also provides the ability to log the data to flash for untethered battery operation. The data logging settings are configured through the GUI, and the GUI also provides the interface to download logged data.

Details on the RPC interface can be found here: HSP RPC Interface Documentation

Windows

With this program loaded, the MAX32620HSP will appear on your computer as a serial port. On Mac and Linux, this will happen by default. For Windows, you need to install a driver: HSP serial port windows driver

For more details about this platform and how to use it, see the MAXREFDES100 product page.

HSP/LoggingService/Logging_RPC.cpp

Committer:
jbradshaw
Date:
2017-04-21
Revision:
2:d483f896c7a9
Parent:
1:9490836294ea
Child:
3:8e9b9f5818aa

File content as of revision 2:d483f896c7a9:

/*******************************************************************************
 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * Except as contained in this notice, the name of Maxim Integrated
 * Products, Inc. shall not be used except as stated in the Maxim Integrated
 * Products, Inc. Branding Policy.
 *
 * The mere transfer of this software does not imply any licenses
 * of trade secrets, proprietary technology, copyrights, patents,
 * trademarks, maskwork rights, or any other form of intellectual
 * property whatsoever. Maxim Integrated Products, Inc. retains all
 * ownership rights.
 ******************************************************************************
 */
#include "StringHelper.h"
#include <stdint.h>
#include "Streaming.h"
#include "StringInOut.h"
#include "DataLoggingService.h"
#include "Peripherals.h"
#include "Logging.h"

extern char loggingMissionCmds[4096];
uint32_t missionCmdIndex;

 //******************************************************************************
 int Logging_RPC_StartMissionDefine(char argStrs[32][32],
                                   char replyStrs[32][32]) {
  uint32_t i;
  uint32_t reply[1];

  // reset the missionCmdIndex to the beginning of the cmd buffer
  missionCmdIndex = 0;
  // clear the mission command buffer, fill with zeros
  for (i = 0; i < sizeof(loggingMissionCmds); i++) {
    loggingMissionCmds[i] = 0;
  }

  reply[0] = 0x80;
  FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs);
  return 0;
}

//******************************************************************************
int Logging_RPC_AppendMissionCmd(char argStrs[32][32], char replyStrs[32][32]) {
  uint32_t reply[1];
  char *strPtr;
  uint32_t count = 0;
  uint8_t result = 0x80;
  // append the string to the mission cmd log
  strPtr = argStrs[0];
  while (*strPtr != 0) {
    loggingMissionCmds[missionCmdIndex] = *strPtr;
    missionCmdIndex++;
    strPtr++;
    // do not overrun buffer
    if (missionCmdIndex > (sizeof(loggingMissionCmds) - 2)) {
      result = 0xFF;
      break;
    }
    count++;
    // do not read more than max count in incoming string
    if (count > (32 * 32)) {
      result = 0xFF;
      break;
    }
  }
  if (result != 0x80) {
    reply[0] = 0xFF;
    FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs);
    return 0;
  }
  // add cr/lf to the end of this cmd string
  loggingMissionCmds[missionCmdIndex++] = 13;
  loggingMissionCmds[missionCmdIndex++] = 10;

  reply[0] = 0x80;
  FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs);
  return 0;
}

//******************************************************************************
int Logging_RPC_EndMissionDefine(char argStrs[32][32], char replyStrs[32][32]) {
  uint32_t reply[1];
  reply[0] = 0x80;
  FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs);
  return 0;
}

//******************************************************************************
int Logging_RPC_WriteMission(char argStrs[32][32], char replyStrs[32][32]) {
  uint8_t page;
  char *ptr;
  uint32_t reply[1];

  Peripherals::s25FS512()->parameterSectorErase_Helper(0x0);
  ptr = loggingMissionCmds;
  for (page = 0; page < 16; page++) {
    Peripherals::s25FS512()->writePage_Helper(page, (uint8_t *)ptr, 0);
    ptr += 256;
  }

  reply[0] = 0x80;
  FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs);
  return 0;
}

//******************************************************************************
int Logging_RPC_ReadMission(char argStrs[32][32], char replyStrs[32][32]) {
  char *ptr;
  uint32_t i;
  // read sector 0
  ptr = loggingMissionCmds;
  for (i = 0; i < 16; i++) {
    Peripherals::s25FS512()->readPages_Helper(i, i, (uint8_t *)ptr, 0);
    ptr += 256;
  }
  // strip header by shifting payload left
  ptr = loggingMissionCmds;
  for (i = 0; i < sizeof(loggingMissionCmds); i++) {
    if (*ptr == 13) {
      *ptr = ':';
    } else if (*ptr == 10) {
      *ptr = ' ';
    } 
    ptr++;
  }
  if (loggingMissionCmds[0] == 0xFF || loggingMissionCmds[0] == 0x0) {
    sprintf(loggingMissionCmds, "%s", "null ");
  }
  // send it out via uart
  putStr(loggingMissionCmds);
  replyStrs[0][0] = 0;
  return 0;
}

//******************************************************************************
int Logging_RPC_EraseMission(char argStrs[32][32], char replyStrs[32][32]) {
  uint32_t reply[1];
  Peripherals::s25FS512()->parameterSectorErase_Helper(0x0);
  reply[0] = 0x80;
  FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs);
  return 0;
}

#define SECTOR_SIZE_256K 0x10000
#define PAGE_INC_256K 0x400
#define SECTOR_SIZE_4K 0x1000
#define PAGE_INC_4K 0x10
#define TOTAL_SECTOR_NUMBER 263


#define ADDRESS_INC_4K      0x1000
#define ADDRESS_INC_32K     0x8000
#define ADDRESS_INC_64K     0x10000

#define ADDRESS_4K_START      0x0
#define ADDRESS_4K_END        0x8000  
  
#define ADDRESS_32K_START     0x8000
#define ADDRESS_32k_END       0x10000  
  
#define ADDRESS_64K_START     0x10000
#define ADDRESS_64k_END       0x2000000  

#define SIZE_OF_EXTERNAL_FLASH  0x2000000 // 33,554,432 Bytes

//******************************************************************************
int Logging_EraseWrittenSectors(char argStrs[32][32], char replyStrs[32][32]) {
  Peripherals::s25FS512()->bulkErase_Helper();
  return 0;
}

//******************************************************************************
int Logging_Start(char argStrs[32][32], char replyStrs[32][32]) {
  uint32_t reply[1];
  Logging_SetStart(true);
  reply[0] = 0x80; // indicate success
  FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs);
  return 0;
}

//******************************************************************************
int Logging_GetLastWrittenPage(char argStrs[32][32], char replyStrs[32][32]) {
  uint32_t reply[1];

  uint32_t page;
  uint32_t lastPage;
  uint32_t pageEmpty;
  uint8_t data[512];

  printf("Logging_GetLastWrittenPage ");
  fflush(stdout);
  lastPage = Logging_GetLoggingEndPage();
  for (page = 2; page <= lastPage; page++) {
    // Peripherals::serial()->printf("checking page %d ",page); fflush(stdout);
    // sample the page
    Peripherals::s25FS512()->readPages_Helper(page, page, data, 0);
    pageEmpty = Peripherals::s25FS512()->isPageEmpty(data);
    if (pageEmpty != 0) {
      break;
    }
  }
  if (page > lastPage)
    page = lastPage;
  printf("last page %d, 0x%X ", (unsigned int)page, (unsigned int)page);
  fflush(stdout);
  reply[0] = page;
  FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs);
  return 0;
}

extern int highDataRate;
//******************************************************************************
int Logging_StartLoggingUsb(char argStrs[32][32], char replyStrs[32][32]) {
  uint32_t reply[1];
  // highDataRate = 0;
  LoggingService_StartLoggingUsb();
  reply[0] = 0x80;
  FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs);
  return 0;
}
//******************************************************************************
int Logging_StartLoggingFlash(char argStrs[32][32], char replyStrs[32][32]) {
  uint32_t reply[1];
  // highDataRate = 0;
  LoggingService_StartLoggingFlash();
  reply[0] = 0x80;
  FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs);
  return 0;
}