Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
Signed-off-by: pettershao-ragilenetworks <pettershao@ragilenetworks.com>
  • Loading branch information
pettershao-ragilenetworks committed Mar 19, 2023
1 parent c587cc0 commit 7412242
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

/* TCK clock MAX 16MHz */
#define TCK_DELAY (current_fmw_cpld->tck_delay)
#define mem_clear(data, size) memset((data), 0, (size))
#if 0
static firmware_cpld_t default_fmw_cpld;
#endif
Expand Down Expand Up @@ -154,7 +153,7 @@ int fmw_cpld_set_gpio_info(firmware_upg_gpio_info_t *info)
dev_debug(firmware_debug(), "g_set_gpio_info_func is null.\n");
return -1;
}

return g_set_gpio_info_func(info);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#include <linux/platform_device.h>

#include <asm/ioctl.h>
#include <linux/string.h>

#define mem_clear(data, size) memset((data), 0, (size))
#define dev_debug(debug, fmt, arg...) \
if (debug == 1) { do{printk(KERN_ERR fmt,##arg);} while(0); }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,24 @@
#include <ctype.h>
#include <debug_ispvme.h>

#define mem_clear(data, size) memset((data), 0, (size))
/**
/**
* firmware_upgrade_debug:handle debug switch
*
*
* analyse file /tmp/firmware_upgrade_debug,return the information correspoding to debug
*
* return:return DEBUG_OFF when debug off,return DEBUG_ON when debug on,return DEBUG_IGNORE in other cases
*
* return:return DEBUG_OFF when debug off,return DEBUG_ON when debug on,return DEBUG_IGNORE in other cases
*/
int firmware_upgrade_debug(void)
{
int size;
FILE *fp;
char debug_info[DEBUG_INFO_LEN];
char debug_info[DEBUG_INFO_LEN] = {0};

fp = fopen(DEBUG_FILE, "r");
if (fp == NULL) {
return DEBUG_IGNORE;
}

mem_clear(debug_info, DEBUG_INFO_LEN);

size = fread(debug_info, DEBUG_INFO_LEN - 1, 1, fp);
if (size < 0) {
fclose(fp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
/*
* dfd_debug.c
*
*
* Function:Device framework driver debugging interface
*
* History
Expand All @@ -14,7 +14,7 @@
#include <string.h>

#include <errno.h>
#include <stdlib.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <string.h>
Expand All @@ -23,7 +23,6 @@

#undef ARRAY_SIZE
#define ARRAY_SIZE(a) (sizeof(a) /sizeof((a)[0]))
#define mem_clear(data, size) memset((data), 0, (size))
/* Debug switch storage of dfd module */
int g_dfd_fpga_debug = 0x0;

Expand All @@ -36,7 +35,7 @@ int g_dfd_fpga_debug = 0x0;
*/
static int dfd_fpga_pkt_debug_set(int type, int enable)
{

if (type >= DFD_DBG_CNT || type < 0) {
DFD_ERROR("unknow dfd debug type=%d\n", type);
return -1;
Expand Down Expand Up @@ -74,16 +73,15 @@ void dfd_fpga_open_debug(int val)
(void)dfd_fpga_pkt_debug_set(DFD_FLOCK_DBG_VBOSE, 0);
(void)dfd_fpga_pkt_debug_set(DFD_DBG_DBG, 0);
}

return;
}

void dfd_fpga_debug_init(void)
{
FILE *fp;
char buf[10];
char buf[10] = {0};

mem_clear(buf, sizeof(buf));
fp = fopen(DFD_DEBUG_FILE, "r");
if (fp != NULL) {
if (fgets(buf, sizeof(buf), fp) != NULL) {
Expand Down Expand Up @@ -114,7 +112,7 @@ void dfd_fpga_debug_init(void)
(void)dfd_fpga_pkt_debug_set(DFD_FLOCK_DBG_VBOSE, 1);
}
}

fclose(fp);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

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

#define DFD_DEBUG_FILE "/sbin/.dfd_debug_flag"

Expand All @@ -12,6 +13,7 @@
#define DFD_DEBUG_SET_ALL "0xf"
#define DFD_DEBUG_SET_DBG "0xd"
#define DFD_DEBUG_SET_FLOCK "0xe"
#define mem_clear(data, size) memset((data), 0, (size))

#define DFD_DEBUG_CHECK(type) (g_dfd_fpga_debug & (1U << (type)))

Expand Down Expand Up @@ -41,7 +43,7 @@
printf("[%s-%s]:<File:%s, Func:%s, Line:%d>\n" fmt, "DFD", "flock_vbose", \
__FILE__, __FUNCTION__, __LINE__, ##args); \
} \
} while (0)
} while (0)

#define DFD_DBG(fmt, args...) do { \
if (DFD_DEBUG_CHECK(DFD_DBG_DBG)) { \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,15 @@
#include "dfd_fpga_pkt.h"
#include "dfd_fpga_debug.h"

#define DFD_FPGA_FAC_MODE_CONFIG_FILE "/tmp/.factory_disabale_cli_tty"
#define mem_clear(data, size) memset((data), 0, (size))
#define DFD_FPGA_FAC_MODE_CONFIG_FILE "/tmp/.factory_disabale_cli_tty"
#if 1
#define DFD_FPGA_PKT_SEND_PKT_TO_FRAME
#endif

void dfd_fpga_pkt_print(uint8_t *buf, int buf_len)
{
int i;

for (i = 0; i < buf_len; i++) {
if ((i % 16) == 0) {
DFD_DBG("\n");
Expand All @@ -60,7 +59,7 @@ static unsigned int littel_endian_byte_to_word32(uint8_t *byte_buf, int len)
unsigned int word;

word = 0;

mem_clear(tmp_buf, 4);
memcpy(tmp_buf, byte_buf, len < 4 ? len : 4);

Expand All @@ -84,7 +83,7 @@ static int littel_endian_word32_to_byte(uint8_t *byte_buf, int len, unsigned int
tmp_buf[1] = (word >> 8) & 0xff;
tmp_buf[2] = (word >> 16) & 0xff;
tmp_buf[3] = (word >> 24) & 0xff;

memcpy(byte_buf, tmp_buf, 4);

return 0;
Expand Down Expand Up @@ -130,7 +129,7 @@ int dfd_fpga_pci_read(dfd_pci_dev_priv_t *pci_priv, int offset, uint8_t *buf, in
struct stat sb;
int i;
int len, align;

if ((pci_priv == NULL) || (buf == NULL)) {
DFD_ERROR("pci_prive or read buf is null.\n");
return -1;
Expand Down Expand Up @@ -163,13 +162,13 @@ int dfd_fpga_pci_read(dfd_pci_dev_priv_t *pci_priv, int offset, uint8_t *buf, in
close(fd);
return -1;
}

align = pci_priv->align;
len = rd_len;
ret = 0;
i = 0;
ptr_data = ptr + offset;

while((i < len) && (ret == 0)){
if (align == 4) {
data = *((volatile unsigned int *)(ptr_data + i));
Expand All @@ -183,7 +182,7 @@ int dfd_fpga_pci_read(dfd_pci_dev_priv_t *pci_priv, int offset, uint8_t *buf, in
munmap(ptr, sb.st_size);
close(fd);
return ret;

}

/**
Expand Down Expand Up @@ -242,7 +241,7 @@ int dfd_fpga_pci_write(dfd_pci_dev_priv_t *pci_priv, int offset, uint8_t *buf, i
ret = 0;
i = 0;
ptr_data = ptr + offset;

while((i < len) && (ret == 0)){
if (align == 4) {
data = littel_endian_byte_to_word32(buf + i,len - i);
Expand All @@ -256,13 +255,13 @@ int dfd_fpga_pci_write(dfd_pci_dev_priv_t *pci_priv, int offset, uint8_t *buf, i
munmap(ptr, sb.st_size);
close(fd);
return ret;

}

/**
* dfd_fpga_read_word -provide FPGA read register interface (address must be four-byte aligned)
* @addr: address (four-byte alignment)
* @val: the returned number of reading
* @val: the returned number of reading
* return: return 0 if success,else return failure
*/
int dfd_fpga_read_word(dfd_pci_dev_priv_t *pci_priv, int addr, int *val)
Expand Down Expand Up @@ -309,8 +308,8 @@ int dfd_fpga_write_word(dfd_pci_dev_priv_t *pci_priv, int addr, int val)
littel_endian_word32_to_byte(tmp, DFD_FPGA_PKT_WORD_LEN, val);
for (i = 0; i < DFD_FPGA_PKT_WORD_LEN; i++) {
DFD_VERBOS("tmp[%d]: 0x%x.\n", i, tmp[i]);
}
}

ret = dfd_fpga_pci_write(pci_priv, addr, tmp, DFD_FPGA_PKT_WORD_LEN);
if (ret) {
DFD_ERROR("dfd_fpga_pci_write addr 0x%x failed ret %d.\n", addr, ret);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "dfd_fpga_pkt.h"
#include "dfd_fpga_debug.h"

#define mem_clear(data, size) memset((data), 0, (size))
typedef struct dfd_fpga_upg_node_s {
int sslot; /* Expansion card slot number */
int extype; /* Expansion card type */
Expand Down Expand Up @@ -529,7 +528,7 @@ int dfd_fpga_upg_set_erase_p4e(dfd_pci_dev_priv_t *pci_priv, int spi_addr)
return -1;
}

/* write erase address */
/* write erase address */
val = spi_addr;
addr = pci_priv->fpga_upg_base + FPGA_UPG_ADDR_REG;
ret = dfd_fpga_upg_write_word(pci_priv, addr, val);
Expand Down
Loading

0 comments on commit 7412242

Please sign in to comment.