| 254 | // char strings[stringssize] |
| 255 | |
| 256 | bool SerialFlashChip::create(const char *filename, uint32_t length, uint32_t align) |
| 257 | { |
| 258 | uint32_t maxfiles, stringsize; |
| 259 | uint32_t index, buf[3]; |
| 260 | uint32_t address, straddr, len; |
| 261 | SerialFlashFile file; |
| 262 | |
| 263 | // check if the file already exists |
| 264 | if (exists(filename)) return false; |
| 265 | |
| 266 | // first, get the filesystem parameters |
| 267 | maxfiles = check_signature(); |
| 268 | if (!maxfiles) return false; |
| 269 | stringsize = (maxfiles & 0xFFFF0000) >> 14; |
| 270 | maxfiles &= 0xFFFF; |
| 271 | |
| 272 | // find the first unused slot for this file |
| 273 | index = find_first_unallocated_file_index(maxfiles); |
| 274 | if (index >= maxfiles) return false; |
| 275 | //Serial.printf("index = %u\n", index); |
| 276 | // compute where to store the filename and actual data |
| 277 | straddr = 8 + maxfiles * 12; |
| 278 | if (index == 0) { |
| 279 | address = straddr + stringsize; |
| 280 | } else { |
| 281 | buf[2] = 0; |
| 282 | SerialFlash.read(8 + maxfiles * 2 + (index-1) * 10, buf, 10); |
| 283 | address = buf[0] + buf[1]; |
| 284 | straddr += buf[2] * 4; |
| 285 | straddr += string_length(straddr); |
| 286 | straddr = (straddr + 3) & 0x0003FFFC; |
| 287 | } |
| 288 | //Serial.printf("straddr = %u\n", straddr); |
| 289 | //Serial.printf("address = %u\n", address); |
| 290 | //Serial.printf("length = %u\n", length); |
| 291 | if (align > 0) { |
| 292 | // for files aligned to sectors, adjust addr & len |
| 293 | address += align - 1; |
| 294 | address /= align; |
| 295 | address *= align; |
| 296 | //Serial.printf("align address = %u\n", address); |
| 297 | length += align - 1; |
| 298 | length /= align; |
| 299 | length *= align; |
| 300 | //Serial.printf("align length = %u\n", length); |
| 301 | } else { |
| 302 | // always align every file to a page boundary |
| 303 | // for predictable write latency and to guarantee |
| 304 | // write suspend for reading another file can't |
| 305 | // conflict on the same page (2 files never share |
| 306 | // a write page). |
| 307 | address = (address + 255) & 0xFFFFFF00; |
| 308 | } |
| 309 | //Serial.printf("address = %u\n", address); |
| 310 | // last check, if enough space exists... |
| 311 | len = strlen(filename); |
| 312 | // TODO: check for enough string space for filename |
| 313 | uint8_t id[5]; |
nothing calls this directly
no test coverage detected