/*
 * norflash-test.c
 *
 * created: 2026-04-04
 *  author: 
 */

#include "bsp.h"

#include <stdio.h>
#include <string.h>
#include <inttypes.h>

#include "ls2k_spi_bus.h"
#include "spi/norflash.h"

#include "osal.h"

/*
 * ¶Á NORFLASH
 */

#define RD_BUF_LEN  512

static char rd_buf[RD_BUF_LEN];

void norflash_read_test(void)
{
    int rt;
    unsigned int id, jdecid, flashAddr;
    unsigned long uniqueid;

    rt = ls2k_spi_ioctl(busSPI0, IOCTL_FLASH_FAST_READ_DISABLE, NULL);
    if (rt == 0)
    {
        rt = ls2k_norflash_ioctl(busSPI0, IOCTL_NORFLASH_READ_ID, (void *)&id);
        if (rt == 0)
            printk("ID = 0x%08x\r\n", id);

        rt = ls2k_norflash_ioctl(busSPI0, IOCTL_NORFLASH_READ_JDECID, (void *)&jdecid);
        if (rt == 0)
            printk("JDECID = 0x%08x\r\n", jdecid);

        rt = ls2k_norflash_ioctl(busSPI0, IOCTL_NORFLASH_READ_UNIQUEID, (void *)&uniqueid);
        if (rt == 0)
            printk("UniqueID = 0x%" PRIx64 "\r\n", uniqueid);
        
        ls2k_spi_ioctl(busSPI0, IOCTL_FLASH_FAST_READ_ENABLE, NULL);
    }

    flashAddr = 0;
    rt = ls2k_norflash_read(busSPI0, rd_buf, RD_BUF_LEN, &flashAddr);
    if (rt == RD_BUF_LEN)
        print_hex(rd_buf, rt);

}


