1 /* 2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef __APP_DEMO_SPI_H__ 17 #define __APP_DEMO_SPI_H__ 18 19 #include <hi_types_base.h> 20 #include <hi3861_platform.h> 21 #include <hi_task.h> 22 #include <hi_stdlib.h> 23 #include <hi_early_debug.h> 24 #include <hi_time.h> 25 #include <hi_watchdog.h> 26 #include <hi_io.h> 27 #include <hi_spi.h> 28 29 #define BUF_LENGTH 512 30 #define BUF_LENGTH_HALF (BUF_LENGTH >> 1) 31 #define TEST_LOOP_LENGTH 256 32 #define test_spi_printf(fmt...) \ 33 do { \ 34 printf("[SPI TEST]" fmt); \ 35 printf("\n"); \ 36 } while (0) 37 38 #ifndef min 39 #define min(a, b) ((a) < (b) ? (a) : (b)) 40 #endif 41 42 typedef struct { 43 hi_spi_cfg_basic_info cfg_info; 44 hi_spi_idx spi_id; 45 hi_u32 loop; 46 hi_u32 length; 47 hi_bool irq; 48 hi_bool slave; 49 hi_bool lb; 50 hi_bool dma_en; 51 } test_spi_para; 52 53 typedef enum { 54 TEST_CASE_ALL, 55 TEST_CASE_POL0_PHA0 = 1, 56 TEST_CASE_POL0_PHA1, 57 TEST_CASE_POL1_PHA0, 58 TEST_CASE_POL1_PHA1, 59 TEST_CASE_MOTOROLA, 60 TEST_CASE_TI, 61 TEST_CASE_BIT4, 62 TEST_CASE_BIT7, 63 TEST_CASE_BIT8, 64 TEST_CASE_BIT9 = 10, 65 TEST_CASE_BIT15, 66 TEST_CASE_BIT16, 67 TEST_CASE_CLK_MIN, 68 TEST_CASE_CLK_16, 69 TEST_CASE_CLK_50, 70 TEST_CASE_CLK_100, 71 TEST_CASE_CLK_200, 72 TEST_CASE_CLK_MAX, 73 TEST_CASE_PARAMETER_WRONG, 74 TEST_CASE_SLAVE = 20, 75 TEST_CASE_MASTER, 76 TEST_CASE_MAX, 77 } hi_spi_test_case; 78 79 hi_u32 app_demo_spi_para_test(hi_spi_cfg_basic_info *spi_para); 80 hi_u32 app_demo_spi_test_case(hi_u8 test_case); 81 hi_void app_demo_spi_test(hi_spi_idx spi_id, hi_u32 irq_en, hi_u32 test_case, hi_u32 loop); 82 hi_void app_demo_spi_cmd_host_read(hi_spi_idx spi_id, hi_u32 length, hi_u32 loop); 83 hi_void app_demo_spi_cmd_slave_write(hi_spi_idx spi_id, hi_u32 length, hi_u32 loop); 84 hi_void app_demo_spi_cmd_host_write(hi_spi_idx spi_id, hi_u32 length, hi_u32 loop); 85 hi_void app_demo_spi_cmd_slave_read(hi_spi_idx spi_id, hi_u32 length, hi_u32 loop); 86 #endif 87