| 144 | } |
| 145 | |
| 146 | void xs_flash_write(xsMachine *the) |
| 147 | { |
| 148 | modFlash flash; |
| 149 | SpiFlashOpResult result; |
| 150 | int offset = xsmcToInteger(xsArg(0)); |
| 151 | int byteLength = xsmcToInteger(xsArg(1)); |
| 152 | void *buffer; |
| 153 | xsUnsignedValue bufferLength; |
| 154 | |
| 155 | flash = xsmcGetHostChunk(xsThis); |
| 156 | if ((offset < 0) || (offset >= flash->partitionByteLength)) |
| 157 | xsUnknownError("invalid offset"); |
| 158 | |
| 159 | if ((byteLength <= 0) || ((offset + byteLength) > flash->partitionByteLength)) |
| 160 | xsUnknownError("invalid length"); |
| 161 | |
| 162 | xsmcGetBufferReadable(xsArg(2), &buffer, &bufferLength); |
| 163 | if (bufferLength < (xsUnsignedValue)byteLength) |
| 164 | xsUnknownError("invalid"); |
| 165 | |
| 166 | flash = xsmcGetHostChunk(xsThis); |
| 167 | if (0 == modSPIWrite(offset + flash->partitionStart, byteLength, buffer)) |
| 168 | xsUnknownError("write fail"); |
| 169 | } |
| 170 | |
| 171 | void xs_flash_map(xsMachine *the) |
| 172 | { |
nothing calls this directly
no test coverage detected