Files
kunlun/dtest/dtest3/kl3_sdcard/kl3_sdcard.c
2024-09-28 14:24:04 +08:00

286 lines
5.4 KiB
C

/****************************************************************************
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
be copied by any method or incorporated into another program without
the express written consent of Aerospace C.Power. This Information or any portion
thereof remains the property of Aerospace C.Power. The Information contained herein
is believed to be accurate and Aerospace C.Power assumes no responsibility or
liability for its use in any way and conveys no license or title under
any patent or copyright and makes no representation or warranty that this
Information is free from patent or copyright infringement.
****************************************************************************/
/* os shim includes */
#include "os_types.h"
#include "os_task.h"
#include "os_utils.h"
/* common includes */
#include "iot_io.h"
#include "iot_bitops.h"
#include "iot_pkt.h"
#include "iot_ipc.h"
#include "iot_dbglog_api.h"
#include "iot_config.h"
/* driver includes */
#include "iot_clock.h"
#include "iot_uart.h"
#include "uart.h"
#include "apb_dma.h"
#include "dma_hw.h"
/* cli includes */
#include "iot_cli.h"
#include "iot_uart_h.h"
/* debug includes*/
#include "dbg_io.h"
#include "spi.h"
#include "iot_gptmr.h"
#include "gp_timer.h"
#include "iot_gpio.h"
#include "dtest_printf.h"
#include "iot_share_task.h"
#include "uart.h"
#include "apb.h"
#include "irq.h"
#include "rtc.h"
#include "ahb.h"
#include "iot_mem.h"
#include "sd_card.h"
extern struct uart_ctrl uart_e_ctrl;
extern int platform_init();
os_task_h test_init_handle;
static const iot_pkt_config_t test_pkt_config =
{
{
{
256,
1,
PKT_OWNER_ALL,
},
{
600,
1,
PKT_OWNER_ALL,
},
{
1100,
1,
PKT_OWNER_ALL,
},
{
2200,
1,
PKT_OWNER_ALL,
},
{
0,
0,
PKT_OWNER_NONE,
},
{
0,
0,
PKT_OWNER_NONE,
},
{
0,
0,
PKT_OWNER_NONE,
},
{
0,
0,
PKT_OWNER_NONE,
},
}
};
void test_init()
{
/* init common modules */
iot_bitops_init();
/* init os related modules and utilities */
os_utils_init();
/* init dbglog module */
iot_dbglog_init();
/* init pkt module */
iot_pkt_init(&test_pkt_config);
/* init ipc module */
//iot_ipc_init();
/*init uart module*/
iot_uart_init(1);
/* gp timer init */
iot_gp_timer_init();
/* share task init */
iot_share_task_init();
/* gpio init */
iot_gpio_module_init();
//dma_test();
}
#define SPI_TEST_PORT DEVICE_SPI2_MASTER
void iot_task_2(void *arg)
{
iot_printf("task 2 entry....\n");
for(;;) {
// iot_printf("task 2 running....\n");
os_delay(1000);
}
}
//------------------------------------------------------------------------------------
void sdcard_task(void *arg)
{
int ret = 0;
sd_spi_info_t info;
uint8_t buf[512];
int sector = 0;
int i;
info.dev = SPI_TEST_PORT;
info.gpio_clk = 28;
info.gpio_cs = 29;
info.gpio_miso = 30;
info.gpio_mosi = 31;
ret = sd_init(&info);
if (ret == 0) {
iot_printf("init ok\r\n");
} else {
iot_printf("init err: ret = %d\r\n", ret);
}
while(1) {
for (i = 0; i < 512; i++) {
buf[i] = i % 0xff;
}
sd_write_disk(buf, sector, 1);
iot_memset(buf, 0, 512);
sd_read_disk(buf, sector, 1);
for (i = 0; i < 512; i++) {
if (buf[i] != (i % 0xff)) {
iot_printf("err @ %d - %d\r\n", sector, i);
break;
}
}
if (i == 512) {
iot_printf("test sector:%d ok\r\n", sector);
}
sector ++;
if (sector > 10000) {
sector = 0;
}
os_delay(10);
}
}
int32_t iot_task_init()
{
os_create_task(iot_task_2, NULL, 8);
/* start plc lib task */
test_init_handle = os_create_task(sdcard_task, NULL, 9);
//create the tasks;
if(test_init_handle != NULL) {
iot_printf("task 1 init successfully...\n");
}
return 0;
}
int32_t iot_task_start()
{
//start the tasks;
os_start_kernel();
return 0;
}
static void cache_init()
{
cache_enable(AHB_CACHE_D0);
cache_set_buffer_mode(AHB_CACHE_D0, 1);
cache_enable(AHB_CACHE_D1);
cache_set_buffer_mode(AHB_CACHE_D1, 1);
}
static int32_t iot_platform_init()
{
cache_init();
/*platform intialization*/
platform_init();
//resource initializations;
system_clock_init();
system_uart_init();
dbg_uart_init();
dbg_uart_stage1_init();
/* rtc init, idle used rtc lock */
iot_rtc_init();
return 0;
}
int32_t iot_module_init(void)
{
//platform intialization;
iot_platform_init();
//create all the tasks;
iot_task_init();
iot_printf("starting...\n");
return 0;
}
int32_t iot_module_start(void)
{
int32_t res = 0;
res = iot_task_start();
return res;
}
#include "apb_dma.h"
int main(void)
{
//module init;
iot_module_init();
iot_module_start();
return 0;
}