Wilson Tang
/
HSP_RPC_GUI
Fork of the offical HSP_RPC_GUI firmware
Fork of MAXREFDES100 firmware for MAX32620HSP
HSP/Devices/S25FS256/S25FS512_RPC.cpp@3:8e9b9f5818aa, 2017-04-25 (annotated)
- Committer:
- jbradshaw
- Date:
- Tue Apr 25 10:47:10 2017 -0500
- Revision:
- 3:8e9b9f5818aa
- Parent:
- 1:9490836294ea
Removed Bulk Erasing, instead a small number of bytes are sampled from each and every page to determine if sector is "dirty", if so sector is erased
Prevents device from sleeping when the firmware detects a series of binary flash page RPC transfers, this increases flash page transfers by %450
when 200mS elapse with the last flash page transfer, normal sleep behaviour is resumed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jbradshaw | 0:e4a10ed6eb92 | 1 | /******************************************************************************* |
jbradshaw | 0:e4a10ed6eb92 | 2 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
jbradshaw | 0:e4a10ed6eb92 | 3 | * |
jbradshaw | 0:e4a10ed6eb92 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
jbradshaw | 0:e4a10ed6eb92 | 5 | * copy of this software and associated documentation files (the "Software"), |
jbradshaw | 0:e4a10ed6eb92 | 6 | * to deal in the Software without restriction, including without limitation |
jbradshaw | 0:e4a10ed6eb92 | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
jbradshaw | 0:e4a10ed6eb92 | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
jbradshaw | 0:e4a10ed6eb92 | 9 | * Software is furnished to do so, subject to the following conditions: |
jbradshaw | 0:e4a10ed6eb92 | 10 | * |
jbradshaw | 0:e4a10ed6eb92 | 11 | * The above copyright notice and this permission notice shall be included |
jbradshaw | 0:e4a10ed6eb92 | 12 | * in all copies or substantial portions of the Software. |
jbradshaw | 0:e4a10ed6eb92 | 13 | * |
jbradshaw | 0:e4a10ed6eb92 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
jbradshaw | 0:e4a10ed6eb92 | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
jbradshaw | 0:e4a10ed6eb92 | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
jbradshaw | 0:e4a10ed6eb92 | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
jbradshaw | 0:e4a10ed6eb92 | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
jbradshaw | 0:e4a10ed6eb92 | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
jbradshaw | 0:e4a10ed6eb92 | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
jbradshaw | 0:e4a10ed6eb92 | 21 | * |
jbradshaw | 0:e4a10ed6eb92 | 22 | * Except as contained in this notice, the name of Maxim Integrated |
jbradshaw | 0:e4a10ed6eb92 | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
jbradshaw | 0:e4a10ed6eb92 | 24 | * Products, Inc. Branding Policy. |
jbradshaw | 0:e4a10ed6eb92 | 25 | * |
jbradshaw | 0:e4a10ed6eb92 | 26 | * The mere transfer of this software does not imply any licenses |
jbradshaw | 0:e4a10ed6eb92 | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
jbradshaw | 0:e4a10ed6eb92 | 28 | * trademarks, maskwork rights, or any other form of intellectual |
jbradshaw | 0:e4a10ed6eb92 | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
jbradshaw | 0:e4a10ed6eb92 | 30 | * ownership rights. |
jbradshaw | 0:e4a10ed6eb92 | 31 | ******************************************************************************* |
jbradshaw | 0:e4a10ed6eb92 | 32 | */ |
jbradshaw | 0:e4a10ed6eb92 | 33 | |
jbradshaw | 0:e4a10ed6eb92 | 34 | #include "S25FS512_RPC.h" |
jbradshaw | 0:e4a10ed6eb92 | 35 | #include "S25FS512.h" |
jbradshaw | 0:e4a10ed6eb92 | 36 | #include "StringInOut.h" |
jbradshaw | 0:e4a10ed6eb92 | 37 | #include "StringHelper.h" |
jbradshaw | 0:e4a10ed6eb92 | 38 | #include "Peripherals.h" |
jbradshaw | 3:8e9b9f5818aa | 39 | #include "RpcServer.h" |
jbradshaw | 0:e4a10ed6eb92 | 40 | |
jbradshaw | 0:e4a10ed6eb92 | 41 | int S25FS512_Reset(char argStrs[32][32], char replyStrs[32][32]) { |
jbradshaw | 0:e4a10ed6eb92 | 42 | uint32_t reply[1]; |
jbradshaw | 0:e4a10ed6eb92 | 43 | Peripherals::s25FS512()->reset(); |
jbradshaw | 0:e4a10ed6eb92 | 44 | reply[0] = 0x80; |
jbradshaw | 0:e4a10ed6eb92 | 45 | FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); |
jbradshaw | 0:e4a10ed6eb92 | 46 | return 0; |
jbradshaw | 0:e4a10ed6eb92 | 47 | } |
jbradshaw | 0:e4a10ed6eb92 | 48 | |
jbradshaw | 1:9490836294ea | 49 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 50 | int S25FS512_EnableHWReset(char argStrs[32][32], char replyStrs[32][32]) { |
jbradshaw | 0:e4a10ed6eb92 | 51 | uint32_t reply[1]; |
jbradshaw | 0:e4a10ed6eb92 | 52 | Peripherals::s25FS512()->enableHWReset(); |
jbradshaw | 0:e4a10ed6eb92 | 53 | reply[0] = 0x80; |
jbradshaw | 0:e4a10ed6eb92 | 54 | FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); |
jbradshaw | 0:e4a10ed6eb92 | 55 | return 0; |
jbradshaw | 0:e4a10ed6eb92 | 56 | } |
jbradshaw | 0:e4a10ed6eb92 | 57 | |
jbradshaw | 1:9490836294ea | 58 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 59 | int S25FS512_SpiWriteRead(char argStrs[32][32], char replyStrs[32][32]) { |
jbradshaw | 0:e4a10ed6eb92 | 60 | uint8_t args[16]; |
jbradshaw | 0:e4a10ed6eb92 | 61 | uint8_t reply[16]; |
jbradshaw | 0:e4a10ed6eb92 | 62 | uint8_t writeNumber; |
jbradshaw | 0:e4a10ed6eb92 | 63 | uint8_t readNumber; |
jbradshaw | 0:e4a10ed6eb92 | 64 | // get the number of bytes to write |
jbradshaw | 0:e4a10ed6eb92 | 65 | ProcessArgs(argStrs, args, 1); |
jbradshaw | 0:e4a10ed6eb92 | 66 | writeNumber = args[0]; |
jbradshaw | 0:e4a10ed6eb92 | 67 | ProcessArgs(argStrs, args, writeNumber + 2); |
jbradshaw | 0:e4a10ed6eb92 | 68 | readNumber = args[writeNumber + 1]; |
jbradshaw | 0:e4a10ed6eb92 | 69 | FormatReply(reply, readNumber, replyStrs); |
jbradshaw | 0:e4a10ed6eb92 | 70 | return 0; |
jbradshaw | 0:e4a10ed6eb92 | 71 | } |
jbradshaw | 0:e4a10ed6eb92 | 72 | |
jbradshaw | 1:9490836294ea | 73 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 74 | int S25FS512_SpiWriteRead4Wire(char argStrs[32][32], char replyStrs[32][32]) { |
jbradshaw | 0:e4a10ed6eb92 | 75 | uint8_t args[16]; |
jbradshaw | 0:e4a10ed6eb92 | 76 | uint8_t reply[16]; |
jbradshaw | 0:e4a10ed6eb92 | 77 | uint8_t writeNumber; |
jbradshaw | 0:e4a10ed6eb92 | 78 | uint8_t readNumber; |
jbradshaw | 0:e4a10ed6eb92 | 79 | // get the number of bytes to write |
jbradshaw | 0:e4a10ed6eb92 | 80 | ProcessArgs(argStrs, args, 1); |
jbradshaw | 0:e4a10ed6eb92 | 81 | writeNumber = args[0]; |
jbradshaw | 0:e4a10ed6eb92 | 82 | ProcessArgs(argStrs, args, writeNumber + 2); |
jbradshaw | 0:e4a10ed6eb92 | 83 | readNumber = args[writeNumber + 1]; |
jbradshaw | 0:e4a10ed6eb92 | 84 | FormatReply(reply, readNumber, replyStrs); |
jbradshaw | 0:e4a10ed6eb92 | 85 | return 0; |
jbradshaw | 0:e4a10ed6eb92 | 86 | } |
jbradshaw | 0:e4a10ed6eb92 | 87 | |
jbradshaw | 1:9490836294ea | 88 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 89 | int S25FS512_ReadPage(char argStrs[32][32], char replyStrs[32][32]) { |
jbradshaw | 0:e4a10ed6eb92 | 90 | uint32_t args[2]; |
jbradshaw | 0:e4a10ed6eb92 | 91 | uint32_t reply[1]; |
jbradshaw | 0:e4a10ed6eb92 | 92 | ProcessArgs32(argStrs, args, sizeof(args) / sizeof(uint32_t)); |
jbradshaw | 0:e4a10ed6eb92 | 93 | reply[0] = 0x80; |
jbradshaw | 0:e4a10ed6eb92 | 94 | FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); |
jbradshaw | 0:e4a10ed6eb92 | 95 | return 0; |
jbradshaw | 0:e4a10ed6eb92 | 96 | } |
jbradshaw | 0:e4a10ed6eb92 | 97 | |
jbradshaw | 1:9490836294ea | 98 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 99 | int S25FS512_ReadPagesBinary(char argStrs[32][32], char replyStrs[32][32]) { |
jbradshaw | 0:e4a10ed6eb92 | 100 | uint32_t args[2]; |
jbradshaw | 1:9490836294ea | 101 | uint8_t pageData[258]; |
jbradshaw | 0:e4a10ed6eb92 | 102 | |
jbradshaw | 0:e4a10ed6eb92 | 103 | uint32_t startPage; |
jbradshaw | 0:e4a10ed6eb92 | 104 | uint32_t endPage; |
jbradshaw | 0:e4a10ed6eb92 | 105 | uint32_t page; |
jbradshaw | 0:e4a10ed6eb92 | 106 | |
jbradshaw | 3:8e9b9f5818aa | 107 | // indicate that we are doing a flash binary transfer |
jbradshaw | 3:8e9b9f5818aa | 108 | RPC_TransferingFlashPages(); |
jbradshaw | 3:8e9b9f5818aa | 109 | |
jbradshaw | 0:e4a10ed6eb92 | 110 | ProcessArgs32(argStrs, args, sizeof(args) / sizeof(uint32_t)); |
jbradshaw | 0:e4a10ed6eb92 | 111 | startPage = args[0]; |
jbradshaw | 0:e4a10ed6eb92 | 112 | endPage = args[1]; |
jbradshaw | 0:e4a10ed6eb92 | 113 | for (page = startPage; page <= endPage; page++) { |
jbradshaw | 0:e4a10ed6eb92 | 114 | Peripherals::s25FS512()->readPages_Helper(page, page, pageData, 0); |
jbradshaw | 1:9490836294ea | 115 | //putBytes256Block(pageData, 1); |
jbradshaw | 1:9490836294ea | 116 | pageData[sizeof(pageData) - 2] = 0x0D; |
jbradshaw | 1:9490836294ea | 117 | pageData[sizeof(pageData) - 1] = 0x0A; |
jbradshaw | 1:9490836294ea | 118 | putBytes(pageData, sizeof(pageData)); |
jbradshaw | 0:e4a10ed6eb92 | 119 | } |
jbradshaw | 1:9490836294ea | 120 | return RPC_SKIP_CRLF; |
jbradshaw | 0:e4a10ed6eb92 | 121 | } |
jbradshaw | 0:e4a10ed6eb92 | 122 | |
jbradshaw | 1:9490836294ea | 123 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 124 | int S25FS512_ReadId(char argStrs[32][32], char replyStrs[32][32]) { |
jbradshaw | 0:e4a10ed6eb92 | 125 | char str[32]; |
jbradshaw | 0:e4a10ed6eb92 | 126 | uint8_t data[128]; |
jbradshaw | 0:e4a10ed6eb92 | 127 | Peripherals::s25FS512()->readIdentification(data, sizeof(data)); |
jbradshaw | 0:e4a10ed6eb92 | 128 | Peripherals::s25FS512()->readIdentification(data, sizeof(data)); |
jbradshaw | 0:e4a10ed6eb92 | 129 | sprintf(str, "%02X%02X%02X%02X", data[0], data[1], data[2], data[3]); |
jbradshaw | 0:e4a10ed6eb92 | 130 | strcpy(replyStrs[0], str); |
jbradshaw | 0:e4a10ed6eb92 | 131 | return 0; |
jbradshaw | 0:e4a10ed6eb92 | 132 | } |