forked from xuos/xiuos
				
			add edu-riscv64 lora example and fix name problem
This commit is contained in:
		
							parent
							
								
									00b39cdd55
								
							
						
					
					
						commit
						e746639f8a
					
				|  | @ -31,7 +31,7 @@ menu "test app" | |||
|                 default n | ||||
|                 if USER_TEST_FS | ||||
|                     if ADD_XIZI_FETURES | ||||
|                         config SD_FPATH | ||||
|                         config FPATH | ||||
|                             string "Set test file path" | ||||
|                             default "/test_file" | ||||
|                     endif | ||||
|  | @ -53,6 +53,37 @@ menu "test app" | |||
|                     endif | ||||
|                 endif | ||||
| 
 | ||||
|             menuconfig USER_TEST_LORA | ||||
|                 select BSP_USING_UART | ||||
|                 select BSP_USING_GPIO | ||||
|                 select RESOURCES_PIN | ||||
|                 select BSP_USING_UART2 | ||||
|                 select BSP_USING_LORA | ||||
|                 bool "Config test uart" | ||||
|                 default n | ||||
|                 if USER_TEST_LORA | ||||
|                     if ADD_XIZI_FETURES | ||||
|                         config LORA_UART_DEV_DRIVER | ||||
|                             string "Set uart dev path" | ||||
|                             default "/dev/uart2_dev2" | ||||
|                         config LORA_PIN_DEV_DRIVER | ||||
|                             string "Set pin dev path" | ||||
|                             default "/dev/pin_dev" | ||||
|                     endif | ||||
|                 endif | ||||
| 
 | ||||
|             menuconfig USER_TEST_RTC | ||||
|                 select BSP_USING_RTC | ||||
|                 bool "Config test rtc" | ||||
|                 default n | ||||
|                 if USER_TEST_RTC | ||||
|                     if ADD_XIZI_FETURES | ||||
|                         config RTC_DEV_DRIVER | ||||
|                             string "Set rtc dev path" | ||||
|                             default "/dev/rtc_dev" | ||||
|                     endif | ||||
|                 endif | ||||
| 
 | ||||
|             menuconfig USER_TEST_I2C | ||||
|                 select BSP_USING_I2C | ||||
|                 bool "Config test i2c" | ||||
|  |  | |||
|  | @ -45,5 +45,13 @@ ifeq ($(CONFIG_ADD_XIZI_FETURES),y) | |||
|         SRC_FILES += test_gpio.c | ||||
|     endif | ||||
| 
 | ||||
|     ifeq ($(CONFIG_USER_TEST_LORA),y) | ||||
|         SRC_FILES += test_loraE220.c | ||||
|     endif | ||||
| 
 | ||||
|     ifeq ($(CONFIG_USER_TEST_RTC),y) | ||||
|         SRC_FILES += test_rtc.c | ||||
|     endif | ||||
| 
 | ||||
|     include $(KERNEL_ROOT)/compiler.mk | ||||
| endif | ||||
|  |  | |||
|  | @ -8,7 +8,7 @@ | |||
| void TestFs(void) | ||||
| { | ||||
|     //open the file in sdcard
 | ||||
|     int fd = open(SD_FPATH,O_RDWR|O_CREAT); | ||||
|     int fd = open(FPATH,O_RDWR|O_CREAT); | ||||
|     if(fd<0){ | ||||
|         printf("fs fd open error:%d\n",fd); | ||||
|         return; | ||||
|  | @ -38,7 +38,7 @@ void TestFs(void) | |||
|     } | ||||
| 
 | ||||
|     //re-open the file and re-read the file
 | ||||
|     fd = open(SD_FPATH,O_RDWR); | ||||
|     fd = open(FPATH,O_RDWR); | ||||
|      if(fd<0){ | ||||
|         printf("fs fd open error:%d\n",fd); | ||||
|         return; | ||||
|  |  | |||
|  | @ -31,13 +31,9 @@ void  TestGpio(void) | |||
|     } | ||||
| 
 | ||||
|     //config key pin in board
 | ||||
|      parameter.cmd = GPIO_CONFIG_MODE; | ||||
|      parameter.pin = BSP_KEY_PIN; | ||||
|      parameter.mode = GPIO_CFG_INPUT; | ||||
| 
 | ||||
|     ioctl_cfg.ioctl_driver_type = PIN_TYPE; | ||||
|     ioctl_cfg.args =  (void *)¶meter; | ||||
| 
 | ||||
|     if (0 != PrivIoctl(pin_fd, OPE_CFG, &ioctl_cfg)) { | ||||
|         printf("ioctl pin fd error %d\n", pin_fd); | ||||
|         PrivClose(pin_fd); | ||||
|  | @ -61,19 +57,15 @@ void  TestGpio(void) | |||
|         //led on if key pressed,or led off
 | ||||
|         if(pin_key.val){ | ||||
|             pin_led.val = GPIO_HIGH; | ||||
|             if(0>PrivWrite(pin_fd,&pin_led,NULL_PARAMETER)){ | ||||
|                 printf("write pin fd error %d\n", pin_fd); | ||||
|                 PrivClose(pin_fd); | ||||
|                 return; | ||||
|             } | ||||
|         }else{ | ||||
|             pin_led.val = GPIO_LOW; | ||||
|             if(0>PrivWrite(pin_fd,&pin_led,NULL_PARAMETER)){ | ||||
|         }             | ||||
|          | ||||
|         if(0>PrivWrite(pin_fd,&pin_led,NULL_PARAMETER)){ | ||||
|                 printf("write pin fd error %d\n", pin_fd); | ||||
|                 PrivClose(pin_fd); | ||||
|                 return; | ||||
|             }            | ||||
|         } | ||||
|          }            | ||||
| 
 | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -0,0 +1,155 @@ | |||
| #include <stdio.h> | ||||
| #include <string.h> | ||||
| #include <transform.h> | ||||
| 
 | ||||
| #define NULL_PARAMETER 0 | ||||
| #define E220_CFG_LENGTH | ||||
| #define GPIOSET(fd, buf, bit)                        \ | ||||
|     {                                                \ | ||||
|         buf.val = bit;                               \ | ||||
|         if (0 > PrivWrite(fd, &buf, NULL_PARAMETER)) \ | ||||
|         {                                            \ | ||||
|             printf("write pin fd error %d\n", fd);   \ | ||||
|             PrivClose(fd);                           \ | ||||
|             return;                                  \ | ||||
|         }                                            \ | ||||
|     } | ||||
| #define BSP_E220_M0_PIN 32 | ||||
| #define BSP_E220_M1_PIN 33 | ||||
| 
 | ||||
| void TestLora(int argc, char *agrv[]) | ||||
| { | ||||
|     char uart_recvbuff[100]; | ||||
|     memset(uart_recvbuff, 0, sizeof(uart_recvbuff)); | ||||
| 
 | ||||
|     int pin_fd = PrivOpen(LORA_PIN_DEV_DRIVER, O_RDWR); | ||||
|     if (pin_fd < 0) | ||||
|     { | ||||
|         printf("open pin fd error:%d\n", pin_fd); | ||||
|         return; | ||||
|     } | ||||
| 
 | ||||
|     int uart_fd = PrivOpen(LORA_UART_DEV_DRIVER, O_RDWR); | ||||
|     if (uart_fd < 0) | ||||
|     { | ||||
|         printf("open pin fd error:%d\n", uart_fd); | ||||
|         return; | ||||
|     } | ||||
|     printf("uart and pin fopen success\n"); | ||||
| 
 | ||||
|     struct PinStat pin_m0; | ||||
|     struct PinStat pin_m1; | ||||
|     struct PinStat pin_key; | ||||
|     pin_m0.pin = BSP_E220_M0_PIN; | ||||
|     pin_m1.pin = BSP_E220_M1_PIN; | ||||
| 
 | ||||
|     // config led pin in board
 | ||||
|     struct PrivIoctlCfg ioctl_cfg; | ||||
|     struct PinParam pin_param; | ||||
|     pin_param.cmd = GPIO_CONFIG_MODE; | ||||
|     pin_param.mode = GPIO_CFG_INPUT; | ||||
| 
 | ||||
|     ioctl_cfg.ioctl_driver_type = PIN_TYPE; | ||||
|     ioctl_cfg.args = (void *)&pin_param; | ||||
|     if (0 != PrivIoctl(pin_fd, OPE_CFG, &ioctl_cfg)) | ||||
|     { | ||||
|         printf("ioctl pin fd error %d\n", pin_fd); | ||||
|         PrivClose(pin_fd); | ||||
|         return; | ||||
|     } | ||||
| 
 | ||||
|     pin_param.mode = GPIO_CFG_OUTPUT; | ||||
|     pin_param.pin = BSP_E220_M0_PIN; | ||||
|     if (0 != PrivIoctl(pin_fd, OPE_CFG, &ioctl_cfg)) | ||||
|     { | ||||
|         printf("ioctl pin fd error %d\n", pin_fd); | ||||
|         PrivClose(pin_fd); | ||||
|         return; | ||||
|     } | ||||
| 
 | ||||
|     pin_param.pin = BSP_E220_M1_PIN; | ||||
|     if (0 != PrivIoctl(pin_fd, OPE_CFG, &ioctl_cfg)) | ||||
|     { | ||||
|         printf("ioctl pin fd error %d\n", pin_fd); | ||||
|         PrivClose(pin_fd); | ||||
|         return; | ||||
|     } | ||||
| 
 | ||||
|     printf("pin configure success\n"); | ||||
|     struct SerialDataCfg uart_cfg; | ||||
|     memset(&uart_cfg, 0, sizeof(struct SerialDataCfg)); | ||||
| 
 | ||||
|     // loraE220 support only 9600bps with 8N1 during initializing
 | ||||
|     uart_cfg.serial_baud_rate = BAUD_RATE_9600; | ||||
|     uart_cfg.serial_data_bits = DATA_BITS_8; | ||||
|     uart_cfg.serial_stop_bits = STOP_BITS_1; | ||||
|     uart_cfg.serial_parity_mode = PARITY_NONE; | ||||
|     uart_cfg.serial_bit_order = BIT_ORDER_LSB; | ||||
|     uart_cfg.serial_invert_mode = NRZ_NORMAL; | ||||
|     uart_cfg.serial_buffer_size = SERIAL_RB_BUFSZ; | ||||
|     uart_cfg.serial_timeout = 1000; | ||||
|     uart_cfg.is_ext_uart = 0; | ||||
| 
 | ||||
|     ioctl_cfg.ioctl_driver_type = SERIAL_TYPE; | ||||
|     ioctl_cfg.args = (void *)&uart_cfg; | ||||
| 
 | ||||
|     if (0 != PrivIoctl(uart_fd, OPE_INT, &ioctl_cfg)) | ||||
|     { | ||||
|         printf("ioctl uart fd error %d\n", uart_fd); | ||||
|         PrivClose(uart_fd); | ||||
|         return; | ||||
|     } | ||||
|     printf("uart configure success\n"); | ||||
| 
 | ||||
|     GPIOSET(pin_fd, pin_m0, GPIO_HIGH); | ||||
|     GPIOSET(pin_fd, pin_m1, GPIO_HIGH); | ||||
|     printf("lora configure into sleep(configure) mode\n"); | ||||
| 
 | ||||
|     // send configure data, and receive the same length of data
 | ||||
|     char sendbuff[] = {0xC0, 0x00, 0x05, 0x19, 0x49, 0xE6, 0x00, 0x17}; // config as address 1949 CH17 2.4kps
 | ||||
| 
 | ||||
|     PrivTaskDelay(2000); | ||||
| 
 | ||||
|     printf("Sending lora configure information(SIZE:%d)\n", sizeof(sendbuff)); | ||||
|     PrivWrite(uart_fd, sendbuff, sizeof(sendbuff)); | ||||
|     printf("lora configure information send\n"); | ||||
| 
 | ||||
|     PrivTaskDelay(2000); | ||||
| 
 | ||||
|     PrivRead(uart_fd, uart_recvbuff, sizeof(sendbuff)); | ||||
|     printf("%x %x %x %x", uart_recvbuff[0], uart_recvbuff[1], uart_recvbuff[2], uart_recvbuff[3]); | ||||
|     printf("lora configure success\n"); | ||||
| 
 | ||||
|     // error when all bytes are 0xff
 | ||||
|     if (0xFF == (uart_recvbuff[0] & uart_recvbuff[1] & uart_recvbuff[2])) | ||||
|     { | ||||
|         printf("from lora receive error:%d\n", 0xff); | ||||
|         return; | ||||
|     } | ||||
| 
 | ||||
|     uart_cfg.serial_baud_rate = BAUD_RATE_115200; | ||||
|     if (0 != PrivIoctl(uart_fd, OPE_INT, &ioctl_cfg)) | ||||
|     { | ||||
|         printf("ioctl uart fd error %d\n", uart_fd); | ||||
|         PrivClose(uart_fd); | ||||
|         return; | ||||
|     } | ||||
| 
 | ||||
|     // into transparent transmission mode
 | ||||
|     GPIOSET(pin_fd, pin_m0, GPIO_LOW); | ||||
|     GPIOSET(pin_fd, pin_m1, GPIO_LOW); | ||||
|     // receive and send "Hello World"
 | ||||
|     while (1) | ||||
|     { | ||||
|         PrivTaskDelay(500); | ||||
|         PrivWrite(uart_fd, "Hello_World!", sizeof("Hello_World!")); | ||||
|         printf("Data Send:\n%s\n", "Hello_World!"); | ||||
| 
 | ||||
|         PrivTaskDelay(500); | ||||
|         memset(uart_recvbuff, 0, sizeof(uart_recvbuff)); | ||||
|         PrivRead(uart_fd, uart_recvbuff, sizeof(uart_recvbuff)); | ||||
|         printf("Receive Data is :\n%s\n", uart_recvbuff); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| PRIV_SHELL_CMD_FUNCTION(TestLora, a lora test sample, PRIV_SHELL_CMD_MAIN_ATTR); | ||||
|  | @ -32,16 +32,16 @@ CONFIG_BSP_USING_UART_HS=y | |||
| # | ||||
| # General Purpose UARTs | ||||
| # | ||||
| CONFIG_BSP_USING_UART1=y | ||||
| CONFIG_BSP_UART1_TXD_PIN=20 | ||||
| CONFIG_BSP_UART1_RXD_PIN=21 | ||||
| CONFIG_BSP_USING_UART2=y | ||||
| CONFIG_BSP_UART2_TXD_PIN=28 | ||||
| CONFIG_BSP_UART2_RXD_PIN=27 | ||||
| CONFIG_BSP_USING_UART3=y | ||||
| CONFIG_BSP_UART3_TXD_PIN=22 | ||||
| CONFIG_BSP_UART3_RXD_PIN=23 | ||||
| CONFIG___STACKSIZE__=4096 | ||||
| # CONFIG_BSP_USING_UART1=y | ||||
| # CONFIG_BSP_UART1_TXD_PIN=20 | ||||
| # CONFIG_BSP_UART1_RXD_PIN=21 | ||||
| # CONFIG_BSP_USING_UART2=y | ||||
| # CONFIG_BSP_UART2_TXD_PIN=28 | ||||
| # CONFIG_BSP_UART2_RXD_PIN=27 | ||||
| # CONFIG_BSP_USING_UART3=y | ||||
| # CONFIG_BSP_UART3_TXD_PIN=22 | ||||
| # CONFIG_BSP_UART3_RXD_PIN=23 | ||||
| # CONFIG___STACKSIZE__=4096 | ||||
| 
 | ||||
| # | ||||
| # Hardware feature | ||||
|  |  | |||
|  | @ -184,6 +184,12 @@ struct InitSequenceDesc _board_init[] = | |||
| #ifdef BSP_USING_I2C | ||||
|     { "hw_i2c", HwI2cInit }, | ||||
| #endif | ||||
| #ifdef BSP_USING_RTC | ||||
|     { "hw_uart", HwRTC }, | ||||
| #endif | ||||
| #ifdef BSP_USING_UART | ||||
|     { "hw_uart", HwUartInit }, | ||||
| #endif | ||||
| #ifdef BSP_USING_SPI | ||||
| 	{ "hw_spi", HwSpiInit }, | ||||
| #endif | ||||
|  |  | |||
|  | @ -78,7 +78,6 @@ enum HS_GPIO_CONFIG | |||
| #define BSP_CH438_INT_PIN   35 | ||||
| #endif | ||||
| 
 | ||||
| #define BSP_USING_SOFT_SPI | ||||
| #ifdef BSP_USING_SOFT_SPI | ||||
| #define FPIOA_SOFT_SPI_SCK  26 | ||||
| #define FPIOA_SOFT_SPI_MIOS   25 | ||||
|  | @ -90,10 +89,20 @@ enum HS_GPIO_CONFIG | |||
| #define BSP_SOFT_SPI_MSOI_PIN 27 | ||||
| #define BSP_SOFT_SPI_NCS_PIN 28 | ||||
| 
 | ||||
| #endif | ||||
| 
 | ||||
| #ifdef BSP_USING_LED | ||||
| #define BSP_LED_PIN 29 | ||||
| #endif | ||||
| 
 | ||||
| #ifdef BSP_USING_KEY | ||||
| #define BSP_KEY_PIN 31 | ||||
| #endif | ||||
| 
 | ||||
| #ifdef BSP_USING_LORA | ||||
| #define BSP_E220_M0_PIN 32 | ||||
| #define BSP_E220_M1_PIN 33 | ||||
| #endif | ||||
| extern int IoConfigInit(void); | ||||
| 
 | ||||
| #endif | ||||
|  |  | |||
|  | @ -12,22 +12,20 @@ | |||
| #include <dev_spi.h> | ||||
| #include <bus_spi.h> | ||||
| 
 | ||||
| 
 | ||||
| static x_err_t softSPIinit(struct SpiDriver *spi_drv, struct BusConfigureInfo *cfg) | ||||
| { | ||||
|     NULL_PARAM_CHECK(spi_drv ); | ||||
|     NULL_PARAM_CHECK(cfg ); | ||||
|     NULL_PARAM_CHECK(spi_drv); | ||||
|     NULL_PARAM_CHECK(cfg); | ||||
| 
 | ||||
| 	//mode  CPOL = 0  CPHA = 0 
 | ||||
|     gpiohs_set_drive_mode(SOFT_SPI_CS0_PIN,GPIO_DM_OUTPUT); | ||||
|     gpiohs_set_pin(SOFT_SPI_CS0_PIN, GPIO_PV_HIGH);//set the cs gpio high
 | ||||
|     // mode  CPOL = 0  CPHA = 0
 | ||||
|     gpiohs_set_drive_mode(SOFT_SPI_CS0_PIN, GPIO_DM_OUTPUT); | ||||
|     gpiohs_set_pin(SOFT_SPI_CS0_PIN, GPIO_PV_HIGH); // set the cs gpio high
 | ||||
|     gpiohs_set_drive_mode(SOFT_SPI_SCK, GPIO_DM_OUTPUT); | ||||
|     gpiohs_set_drive_mode(SOFT_SPI_MOSI, GPIO_DM_OUTPUT); | ||||
|     gpiohs_set_drive_mode(SOFT_SPI_MISO, GPIO_DM_INPUT); | ||||
|     gpiohs_set_pin(SOFT_SPI_SCK,GPIO_PV_LOW); | ||||
|     KPrintf("%s init done\n",SOFT_SPI_BUS_NAME); | ||||
|     gpiohs_set_pin(SOFT_SPI_SCK, GPIO_PV_LOW); | ||||
|     KPrintf("%s init done\n", SOFT_SPI_BUS_NAME); | ||||
| 
 | ||||
|      | ||||
|     return EOK; | ||||
| } | ||||
| 
 | ||||
|  | @ -43,118 +41,118 @@ static uint32 softSpiDrvConfigure(void *drv, struct BusConfigureInfo *configure_ | |||
|     switch (configure_info->configure_cmd) | ||||
|     { | ||||
|     case OPE_INT: | ||||
|         softSPIinit(spi_drv,configure_info); | ||||
|         softSPIinit(spi_drv, configure_info); | ||||
|         break; | ||||
| 
 | ||||
|     case OPE_CFG: | ||||
|         break;     | ||||
|         break; | ||||
|     default: | ||||
| 
 | ||||
|         break; | ||||
|     } | ||||
|      | ||||
| 
 | ||||
|     return ret;         | ||||
|     return ret; | ||||
| } | ||||
| 
 | ||||
| static void soft_spi_writebyte(struct SpiHardwareDevice *spi_dev, uint8_t data) | ||||
| { | ||||
|     int8_t i = 0; | ||||
|     uint8_t temp = 0; | ||||
|     for(i=0; i<8; i++)  | ||||
|     for (i = 0; i < 8; i++) | ||||
|     { | ||||
|         temp = ((data&0x80)==0x80)? 1:0; | ||||
|         data = data<<1; | ||||
|         gpiohs_set_pin(SOFT_SPI_SCK,GPIO_PV_LOW); | ||||
|         usleep(SOFT_SPI_CLK_DELAY);  | ||||
|         if(0 == temp ) | ||||
|         temp = ((data & 0x80) == 0x80) ? 1 : 0; | ||||
|         data = data << 1; | ||||
|         gpiohs_set_pin(SOFT_SPI_SCK, GPIO_PV_LOW); | ||||
|         usleep(SOFT_SPI_CLK_DELAY); | ||||
|         if (0 == temp) | ||||
|         { | ||||
|             gpiohs_set_pin(SOFT_SPI_MOSI,GPIO_PV_LOW); | ||||
|             gpiohs_set_pin(SOFT_SPI_MOSI, GPIO_PV_LOW); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             gpiohs_set_pin(SOFT_SPI_MOSI,GPIO_PV_HIGH); | ||||
|             gpiohs_set_pin(SOFT_SPI_MOSI, GPIO_PV_HIGH); | ||||
|         } | ||||
|         gpiohs_set_pin(SOFT_SPI_SCK,GPIO_PV_HIGH); | ||||
|         usleep(SOFT_SPI_CLK_DELAY);  | ||||
|         gpiohs_set_pin(SOFT_SPI_SCK, GPIO_PV_HIGH); | ||||
|         usleep(SOFT_SPI_CLK_DELAY); | ||||
|     } | ||||
|     gpiohs_set_pin(SOFT_SPI_SCK,GPIO_PV_LOW); | ||||
|     gpiohs_set_pin(SOFT_SPI_SCK, GPIO_PV_LOW); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| /* 读一个字节 */ | ||||
| static uint8_t soft_spi_readbyte(struct SpiHardwareDevice *spi_dev) | ||||
| { | ||||
|     uint8_t i = 0; | ||||
|     uint8_t read_data = 0xFF; | ||||
|     for(i=0; i<8; i++)  | ||||
|     {    | ||||
|     for (i = 0; i < 8; i++) | ||||
|     { | ||||
|         read_data = read_data << 1; | ||||
|         gpiohs_set_pin(SOFT_SPI_SCK,GPIO_PV_LOW); | ||||
|         gpiohs_set_pin(SOFT_SPI_SCK, GPIO_PV_LOW); | ||||
|         usleep(SOFT_SPI_CLK_DELAY); | ||||
|         gpiohs_set_pin(SOFT_SPI_SCK,GPIO_PV_HIGH); | ||||
|         gpiohs_set_pin(SOFT_SPI_SCK, GPIO_PV_HIGH); | ||||
|         usleep(SOFT_SPI_CLK_DELAY); | ||||
|         if(1==gpiohs_get_pin(SOFT_SPI_MISO))  | ||||
|         if (1 == gpiohs_get_pin(SOFT_SPI_MISO)) | ||||
|         { | ||||
|             read_data = read_data | 0x01;  | ||||
|         }  | ||||
|             read_data = read_data | 0x01; | ||||
|         } | ||||
|     } | ||||
|     return read_data; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| /* 读写一个字节 */ | ||||
| //this funcition is unverify until now!
 | ||||
| // this funcition is unverify until now!
 | ||||
| static uint8_t soft_spi_readwritebyte(struct SpiHardwareDevice *spi_dev, uint8_t data) | ||||
| { | ||||
|     uint8_t i = 0; | ||||
|     uint8_t temp = 0; | ||||
|     uint8_t read_data = 0xFF; | ||||
|     for(i=0;i<8;i++)  | ||||
|     for (i = 0; i < 8; i++) | ||||
|     { | ||||
|         temp = ((data&0x80)==0x80)? 1:0; | ||||
|         data = data<<1; | ||||
|         read_data = read_data<<1; | ||||
|         if(temp == 0) | ||||
|         temp = ((data & 0x80) == 0x80) ? 1 : 0; | ||||
|         data = data << 1; | ||||
|         read_data = read_data << 1; | ||||
|         if (temp == 0) | ||||
|         { | ||||
|             gpiohs_set_pin(SOFT_SPI_MOSI,GPIO_PV_LOW); | ||||
|             gpiohs_set_pin(SOFT_SPI_MOSI, GPIO_PV_LOW); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             gpiohs_set_pin(SOFT_SPI_MOSI,GPIO_PV_HIGH); | ||||
|             gpiohs_set_pin(SOFT_SPI_MOSI, GPIO_PV_HIGH); | ||||
|         } | ||||
|         usleep(SOFT_SPI_CLK_DELAY); | ||||
|         gpiohs_set_pin(SOFT_SPI_SCK,GPIO_PV_HIGH); | ||||
|         gpiohs_set_pin(SOFT_SPI_SCK, GPIO_PV_HIGH); | ||||
|         usleep(SOFT_SPI_CLK_DELAY); | ||||
|         if(gpiohs_get_pin(SOFT_SPI_MISO)==1)  | ||||
|         if (gpiohs_get_pin(SOFT_SPI_MISO) == 1) | ||||
|         { | ||||
|             read_data = read_data + 1;  | ||||
|         }  | ||||
|             read_data = read_data + 1; | ||||
|         } | ||||
|         return read_data; | ||||
|     } | ||||
|     return read_data; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| static uint32 softSpiWriteData(struct SpiHardwareDevice *spi_dev, struct SpiDataStandard *spi_datacfg) | ||||
| { | ||||
|    SpiDeviceParam *dev_param = (SpiDeviceParam *)(spi_dev->haldev.private_data); | ||||
|     SpiDeviceParam *dev_param = (SpiDeviceParam *)(spi_dev->haldev.private_data); | ||||
| 
 | ||||
|     uint8 cs_gpio_pin = dev_param->spi_slave_param->spi_cs_gpio_pin; | ||||
|     const uint8_t *data_buff = spi_datacfg->tx_buff; | ||||
|     int data_length =  spi_datacfg->length; | ||||
|      if(NONE == spi_datacfg->tx_buff){ | ||||
|     int data_length = spi_datacfg->length; | ||||
|     if (NONE == spi_datacfg->tx_buff) | ||||
|     { | ||||
|         data_length = 0; | ||||
|      } | ||||
|       | ||||
|     if (spi_datacfg->spi_chip_select) { | ||||
|         gpiohs_set_pin(cs_gpio_pin, GPIO_PV_LOW); | ||||
|     }  | ||||
| 
 | ||||
|     for(size_t i=0;i<data_length;i++){ | ||||
|         soft_spi_writebyte(spi_dev,data_buff[i] ); | ||||
|     } | ||||
| 
 | ||||
|     if (spi_datacfg->spi_cs_release) { | ||||
|     if (spi_datacfg->spi_chip_select) | ||||
|     { | ||||
|         gpiohs_set_pin(cs_gpio_pin, GPIO_PV_LOW); | ||||
|     } | ||||
| 
 | ||||
|     for (size_t i = 0; i < data_length; i++) | ||||
|     { | ||||
|         soft_spi_writebyte(spi_dev, data_buff[i]); | ||||
|     } | ||||
| 
 | ||||
|     if (spi_datacfg->spi_cs_release) | ||||
|     { | ||||
|         gpiohs_set_pin(cs_gpio_pin, GPIO_PV_HIGH); | ||||
|     } | ||||
|     spi_datacfg = spi_datacfg->next; | ||||
|  | @ -164,40 +162,41 @@ static uint32 softSpiWriteData(struct SpiHardwareDevice *spi_dev, struct SpiData | |||
| 
 | ||||
| static uint32 softSpiReadData(struct SpiHardwareDevice *spi_dev, struct SpiDataStandard *spi_datacfg) | ||||
| { | ||||
|    SpiDeviceParam *dev_param = (SpiDeviceParam *)(spi_dev->haldev.private_data); | ||||
|     SpiDeviceParam *dev_param = (SpiDeviceParam *)(spi_dev->haldev.private_data); | ||||
|     uint8 cs_gpio_pin = dev_param->spi_slave_param->spi_cs_gpio_pin; | ||||
|     uint8_t *recv_buff = spi_datacfg->rx_buff; | ||||
|     int recv_length = spi_datacfg->length; | ||||
| 
 | ||||
|      if(NONE == spi_datacfg->rx_buff){ | ||||
|     if (NONE == spi_datacfg->rx_buff) | ||||
|     { | ||||
|         recv_length = 0; | ||||
|      } | ||||
|     } | ||||
| 
 | ||||
|     if (spi_datacfg->spi_chip_select) { | ||||
|     if (spi_datacfg->spi_chip_select) | ||||
|     { | ||||
|         gpiohs_set_pin(cs_gpio_pin, GPIO_PV_LOW); | ||||
|     }     | ||||
|     } | ||||
| 
 | ||||
|     for(size_t i=0;i<recv_length;i++){ | ||||
|     for (size_t i = 0; i < recv_length; i++) | ||||
|     { | ||||
|         recv_buff[i] = soft_spi_readbyte(spi_dev); | ||||
|     } | ||||
| 
 | ||||
|     if (spi_datacfg->spi_cs_release) { | ||||
|     if (spi_datacfg->spi_cs_release) | ||||
|     { | ||||
|         gpiohs_set_pin(cs_gpio_pin, GPIO_PV_HIGH); | ||||
|     } | ||||
| 
 | ||||
|     spi_datacfg = spi_datacfg->next; | ||||
| 
 | ||||
|     return  spi_datacfg->length; | ||||
|     return spi_datacfg->length; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| const struct SpiDevDone soft_spi_dev_done={ | ||||
| const struct SpiDevDone soft_spi_dev_done = { | ||||
|     .dev_close = NONE, | ||||
|     .dev_open = NONE, | ||||
|     .dev_read   = softSpiReadData, | ||||
|    .dev_write  = softSpiWriteData | ||||
| }; | ||||
| 
 | ||||
|     .dev_read = softSpiReadData, | ||||
|     .dev_write = softSpiWriteData}; | ||||
| 
 | ||||
| static int BoardSoftSpiBusInit(struct SpiBus *spi_bus, struct SpiDriver *spi_driver) | ||||
| { | ||||
|  | @ -205,24 +204,27 @@ static int BoardSoftSpiBusInit(struct SpiBus *spi_bus, struct SpiDriver *spi_dri | |||
| 
 | ||||
|     /*Init the spi bus */ | ||||
|     ret = SpiBusInit(spi_bus, SOFT_SPI_BUS_NAME); | ||||
|     if (EOK != ret) { | ||||
|     if (EOK != ret) | ||||
|     { | ||||
|         KPrintf("Board_Spi_init SpiBusInit error %d\n", ret); | ||||
|         return ERROR; | ||||
|     } | ||||
| 
 | ||||
|     /*Init the spi driver*/ | ||||
|     ret = SpiDriverInit(spi_driver, SOFT_SPI_DRV_NAME); | ||||
|     if (EOK != ret) { | ||||
|     if (EOK != ret) | ||||
|     { | ||||
|         KPrintf("Board_Spi_init SpiDriverInit error %d\n", ret); | ||||
|         return ERROR; | ||||
|     } | ||||
| 
 | ||||
|     /*Attach the spi driver to the spi bus*/ | ||||
|     ret = SpiDriverAttachToBus(SOFT_SPI_DRV_NAME, SOFT_SPI_BUS_NAME); | ||||
|     if (EOK != ret) { | ||||
|     if (EOK != ret) | ||||
|     { | ||||
|         KPrintf("Board_Spi_init SpiDriverAttachToBus error %d\n", ret); | ||||
|         return ERROR; | ||||
|     }  | ||||
|     } | ||||
| 
 | ||||
|     return ret; | ||||
| } | ||||
|  | @ -247,21 +249,24 @@ static int BoardSoftSpiDevBend(void) | |||
|     spi_device0.spi_dev_done = &(soft_spi_dev_done); | ||||
| 
 | ||||
|     ret = SpiDeviceRegister(&spi_device0, (void *)(&spi_device0.spi_param), SOFT_SPI_DEVICE_NAME); | ||||
|     if (EOK != ret) { | ||||
|     if (EOK != ret) | ||||
|     { | ||||
|         KPrintf("Board_Spi_init SpiDeviceInit device %s error %d\n", SOFT_SPI_DEVICE_NAME, ret); | ||||
|         return ERROR; | ||||
|     }   | ||||
|     } | ||||
| 
 | ||||
|     ret = SpiDeviceAttachToBus(SOFT_SPI_DEVICE_NAME, SOFT_SPI_BUS_NAME); | ||||
|     if (EOK != ret) { | ||||
|     if (EOK != ret) | ||||
|     { | ||||
|         KPrintf("Board_Spi_init SpiDeviceAttachToBus device %s error %d\n", SOFT_SPI_DEVICE_NAME, ret); | ||||
|         return ERROR; | ||||
|     } | ||||
| 
 | ||||
|      return  ret;   | ||||
|     return ret; | ||||
| } | ||||
| 
 | ||||
| int HwSoftSPIInit(void){ | ||||
| int HwSoftSPIInit(void) | ||||
| { | ||||
|     x_err_t ret = EOK; | ||||
| 
 | ||||
|     static struct SpiBus spi_bus; | ||||
|  | @ -270,23 +275,21 @@ int HwSoftSPIInit(void){ | |||
|     static struct SpiDriver spi_driver; | ||||
|     memset(&spi_driver, 0, sizeof(struct SpiDriver)); | ||||
| 
 | ||||
| 
 | ||||
|     spi_driver.configure = &(softSpiDrvConfigure); | ||||
| 
 | ||||
| 
 | ||||
|     ret = BoardSoftSpiBusInit(&spi_bus, &spi_driver); | ||||
|     if (EOK != ret) { | ||||
|     if (EOK != ret) | ||||
|     { | ||||
|         KPrintf("Board_Spi_Init error ret %u\n", ret); | ||||
|         return ERROR; | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|     ret = BoardSoftSpiDevBend(); | ||||
|     if (EOK != ret) { | ||||
|     if (EOK != ret) | ||||
|     { | ||||
|         KPrintf("Board_Spi_Init error ret %u\n", ret); | ||||
|         return ERROR; | ||||
|     }     | ||||
|     } | ||||
| 
 | ||||
|     return ret; | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue