Loading...
Searching...
No Matches
mem.c
1/***********************************************************************************
2 * @file launch.c *
3 * @author Matt Ricci *
4 * @addtogroup Shell *
5 * *
6 * @{ *
7 ***********************************************************************************/
8
9#include "mem.h"
10
11#include "devicelist.h"
12#include "w25q128.h"
13#include "shell.h"
14#include "uart.h"
15
16static void Flash_exec(Shell *, uint8_t *);
17
18DEFINE_PROGRAM_HANDLE("flash", Flash_exec)
19
20/* =============================================================================== */
31static void Flash_exec(Shell *shell, uint8_t *flags) {
32 W25Q128_t *flash = DeviceList_getDeviceHandle(DEVICE_FLASH).device;
33 UART_t *usb = DeviceList_getDeviceHandle(DEVICE_UART_USB).device;
34 // flash erase
35 if (!strcmp(flags, CMD_FLASH_ERASE)) {
36 usb->print(usb, "Clearing flash... ");
37 flash->erase(flash);
38 usb->print(usb, "Done.\n\r");
39 }
40 // flash read all
41 else if (!strcmp(flags, CMD_FLASH_READ_ALL)) {
42 vTaskSuspendAll();
43 volatile uint8_t pageData[256];
44 for (long i = 0; i < flash->pageCount; i++) {
45 flash->readPage(flash, i * 0x100, pageData);
46 for (int j = 0; j < flash->pageSize; j++)
47 usb->send(usb, pageData[j]);
48 }
49 xTaskResumeAll();
50 }
51}
52
DeviceHandle_t DeviceList_getDeviceHandle(DeviceKey)
Retrieve device handle from list by key.
Definition devicelist.c:36
Struct definition for shell interface.
Definition shell.h:48
void(* print)(struct UART *, char *)
UART print string method.
Definition uart.h:61
void(* send)(struct UART *, uint8_t)
UART send method.
Definition uart.h:59
Struct definition for UART interface.
Definition uart.h:52
void(* readPage)(struct W25Q128 *, uint32_t, volatile uint8_t *)
Read page method.
Definition w25q128.h:37
int pageSize
Number of bytes per page.
Definition w25q128.h:34
void(* erase)(struct W25Q128 *)
Chip erase method.
Definition w25q128.h:36
long pageCount
Total number of pages.
Definition w25q128.h:35