This is a mbed 5.2 Release

Dependencies:   USBDevice

Fork of mbed-os-test by Jerry Bradshaw

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers S25FS512_RPC.cpp Source File

S25FS512_RPC.cpp

00001 /*******************************************************************************
00002  * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a
00005  * copy of this software and associated documentation files (the "Software"),
00006  * to deal in the Software without restriction, including without limitation
00007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008  * and/or sell copies of the Software, and to permit persons to whom the
00009  * Software is furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included
00012  * in all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00015  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00016  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00017  * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
00018  * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00020  * OTHER DEALINGS IN THE SOFTWARE.
00021  *
00022  * Except as contained in this notice, the name of Maxim Integrated
00023  * Products, Inc. shall not be used except as stated in the Maxim Integrated
00024  * Products, Inc. Branding Policy.
00025  *
00026  * The mere transfer of this software does not imply any licenses
00027  * of trade secrets, proprietary technology, copyrights, patents,
00028  * trademarks, maskwork rights, or any other form of intellectual
00029  * property whatsoever. Maxim Integrated Products, Inc. retains all
00030  * ownership rights.
00031  *******************************************************************************
00032  */
00033 
00034 #include "S25FS512_RPC.h"
00035 #include "S25FS512.h"
00036 #include "StringInOut.h"
00037 #include "StringHelper.h"
00038 #include "Peripherals.h"
00039 
00040 int S25FS512_Reset(char argStrs[32][32], char replyStrs[32][32]) {
00041   uint32_t reply[1];
00042   Peripherals::s25FS512()->reset();
00043   reply[0] = 0x80;
00044   FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs);
00045   return 0;
00046 }
00047 
00048 int S25FS512_EnableHWReset(char argStrs[32][32], char replyStrs[32][32]) {
00049   uint32_t reply[1];
00050   Peripherals::s25FS512()->enableHWReset();
00051   reply[0] = 0x80;
00052   FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs);
00053   return 0;
00054 }
00055 
00056 int S25FS512_SpiWriteRead(char argStrs[32][32], char replyStrs[32][32]) {
00057   uint8_t args[16];
00058   uint8_t reply[16];
00059   uint8_t writeNumber;
00060   uint8_t readNumber;
00061   // get the number of bytes to write
00062   ProcessArgs(argStrs, args, 1);
00063   writeNumber = args[0];
00064   ProcessArgs(argStrs, args, writeNumber + 2);
00065   readNumber = args[writeNumber + 1];
00066   FormatReply(reply, readNumber, replyStrs);
00067   return 0;
00068 }
00069 
00070 int S25FS512_SpiWriteRead4Wire(char argStrs[32][32], char replyStrs[32][32]) {
00071   uint8_t args[16];
00072   uint8_t reply[16];
00073   uint8_t writeNumber;
00074   uint8_t readNumber;
00075   // get the number of bytes to write
00076   ProcessArgs(argStrs, args, 1);
00077   writeNumber = args[0];
00078   ProcessArgs(argStrs, args, writeNumber + 2);
00079   readNumber = args[writeNumber + 1];
00080   FormatReply(reply, readNumber, replyStrs);
00081   return 0;
00082 }
00083 
00084 int S25FS512_ReadPage(char argStrs[32][32], char replyStrs[32][32]) {
00085   uint32_t args[2];
00086   uint32_t reply[1];
00087   ProcessArgs32(argStrs, args, sizeof(args) / sizeof(uint32_t));
00088   reply[0] = 0x80;
00089   FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs);
00090   return 0;
00091 }
00092 
00093 int S25FS512_ReadPagesBinary(char argStrs[32][32], char replyStrs[32][32]) {
00094   uint32_t args[2];
00095   uint32_t reply[1];
00096   uint8_t pageData[256];
00097 
00098   uint32_t startPage;
00099   uint32_t endPage;
00100   uint32_t page;
00101 
00102   ProcessArgs32(argStrs, args, sizeof(args) / sizeof(uint32_t));
00103   startPage = args[0];
00104   endPage = args[1];
00105   for (page = startPage; page <= endPage; page++) {
00106     Peripherals::s25FS512()->readPages_Helper(page, page, pageData, 0);
00107     putBytes256Block(pageData, 1);
00108   }
00109   reply[0] = 0x80;
00110   FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs);
00111   return 0;
00112 }
00113 
00114 int S25FS512_ReadId(char argStrs[32][32], char replyStrs[32][32]) {
00115   char str[32];
00116   uint8_t data[128];
00117   Peripherals::s25FS512()->readIdentification(data, sizeof(data));
00118   Peripherals::s25FS512()->readIdentification(data, sizeof(data));
00119   sprintf(str, "%02X%02X%02X%02X", data[0], data[1], data[2], data[3]);
00120   strcpy(replyStrs[0], str);
00121   return 0;
00122 }