Changed serial port address in ARM platform, chenged the spritnf call to snprintf call for safty reason. fixed other warnings.
Signed-off-by: gowtham.r <gowtham.r@adlinktech.com>
This commit is contained in:
@@ -36,9 +36,6 @@ static const char* spilink[] = { "/sys/class/spidev/spidev0.0",
|
|||||||
static const char* i2clink[] = {
|
static const char* i2clink[] = {
|
||||||
"/sys/class/i2c-dev/i2c-0", "/sys/class/i2c-dev/i2c-1" };
|
"/sys/class/i2c-dev/i2c-0", "/sys/class/i2c-dev/i2c-1" };
|
||||||
|
|
||||||
static const char* pwmlink[] = {
|
|
||||||
"/sys/class/pwm/pwmchip1", "/sys/class/pwm/pwmchip2" };
|
|
||||||
|
|
||||||
static unsigned char regIon[16] = {0x2A, 0x2D, 0x30, 0x33, 0x36, 0x3B, 0x40, 0x45, 0x4A, 0x4D, 0x50, 0x53, 0x56, 0x5B, 0x60, 0x65};
|
static unsigned char regIon[16] = {0x2A, 0x2D, 0x30, 0x33, 0x36, 0x3B, 0x40, 0x45, 0x4A, 0x4D, 0x50, 0x53, 0x56, 0x5B, 0x60, 0x65};
|
||||||
|
|
||||||
static unsigned int IonValue[16] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
static unsigned int IonValue[16] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
||||||
@@ -50,20 +47,6 @@ static int base2, _fd;
|
|||||||
|
|
||||||
static int sx150x_pwm_init(int);
|
static int sx150x_pwm_init(int);
|
||||||
|
|
||||||
static int
|
|
||||||
mraa_pwm_setup_duty_fp(mraa_pwm_context dev)
|
|
||||||
{
|
|
||||||
char bu[MAX_SIZE];
|
|
||||||
snprintf(bu, MAX_SIZE, "/sys/class/pwm/pwmchip%d/pwm%d/duty_cycle", dev->chipid, dev->pin);
|
|
||||||
|
|
||||||
dev->duty_fp = open(bu, O_RDWR);
|
|
||||||
if (dev->duty_fp == -1) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int _tperiod;
|
int _tperiod;
|
||||||
|
|
||||||
static mraa_result_t pwm_period_replace(mraa_pwm_context dev, int period)
|
static mraa_result_t pwm_period_replace(mraa_pwm_context dev, int period)
|
||||||
@@ -168,21 +151,21 @@ static mraa_result_t pwm_init_raw_replace(mraa_pwm_context dev, int pin)
|
|||||||
}
|
}
|
||||||
if((fd = open("/sys/class/gpio/unexport", O_WRONLY)) != -1)
|
if((fd = open("/sys/class/gpio/unexport", O_WRONLY)) != -1)
|
||||||
{
|
{
|
||||||
i = sprintf(buffer,"%d",base2 + pin);
|
i = snprintf(buffer, sizeof(buffer), "%d",base2 + pin);
|
||||||
write(fd, buffer, i);
|
write(fd, buffer, i);
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
if((fd = open("/sys/class/gpio/export", O_WRONLY)) != -1)
|
if((fd = open("/sys/class/gpio/export", O_WRONLY)) != -1)
|
||||||
{
|
{
|
||||||
i = sprintf(buffer,"%d",base2 + pin);
|
i = snprintf(buffer, sizeof(buffer), "%d",base2 + pin);
|
||||||
write(fd, buffer, i);
|
write(fd, buffer, i);
|
||||||
close(fd);
|
close(fd);
|
||||||
sprintf(buffer,"/sys/class/gpio/gpio%d/direction",base2 + pin);
|
snprintf(buffer, sizeof(buffer), "/sys/class/gpio/gpio%d/direction",base2 + pin);
|
||||||
if((fd = open(buffer, O_WRONLY)) != -1)
|
if((fd = open(buffer, O_WRONLY)) != -1)
|
||||||
{
|
{
|
||||||
write(fd, "out", 3);
|
write(fd, "out", 3);
|
||||||
close(fd);
|
close(fd);
|
||||||
sprintf(buffer,"/sys/class/gpio/gpio%d/value",base2 + pin);
|
snprintf(buffer, sizeof(buffer), "/sys/class/gpio/gpio%d/value",base2 + pin);
|
||||||
if((fd = open(buffer, O_WRONLY)) != -1)
|
if((fd = open(buffer, O_WRONLY)) != -1)
|
||||||
{
|
{
|
||||||
write(fd, "0", 1);
|
write(fd, "0", 1);
|
||||||
@@ -272,7 +255,7 @@ static mraa_result_t gpio_init_pre(int pin)
|
|||||||
{
|
{
|
||||||
if(read(_fd, &(rx_tx_buf[1]), 1) == 1)
|
if(read(_fd, &(rx_tx_buf[1]), 1) == 1)
|
||||||
{
|
{
|
||||||
rx_tx_buf[1] &= ~(1 < (pin % 8));
|
rx_tx_buf[1] &= ~(1 << (pin % 8));
|
||||||
write(_fd, &rx_tx_buf[0], 2);
|
write(_fd, &rx_tx_buf[0], 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -282,11 +265,11 @@ static mraa_result_t gpio_init_pre(int pin)
|
|||||||
{
|
{
|
||||||
if(read(_fd, &(rx_tx_buf[1]), 1) == 1)
|
if(read(_fd, &(rx_tx_buf[1]), 1) == 1)
|
||||||
{
|
{
|
||||||
rx_tx_buf[1] &= ~(1 < (pin % 8));
|
rx_tx_buf[1] &= ~(1 << (pin % 8));
|
||||||
write(_fd, &rx_tx_buf[0], 2);
|
write(_fd, &rx_tx_buf[0], 2);
|
||||||
if((fd = open("/sys/class/gpio/unexport", O_WRONLY)) != -1)
|
if((fd = open("/sys/class/gpio/unexport", O_WRONLY)) != -1)
|
||||||
{
|
{
|
||||||
i = sprintf(buffer,"%d",base2 + pin);
|
i = snprintf(buffer, sizeof(buffer), "%d",base2 + pin);
|
||||||
write(fd, buffer, i);
|
write(fd, buffer, i);
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
@@ -306,7 +289,7 @@ static int sx150x_init()
|
|||||||
|
|
||||||
for(i = 0; i < 999; i++)
|
for(i = 0; i < 999; i++)
|
||||||
{
|
{
|
||||||
sprintf(rx_tx_buf,"/sys/class/gpio/gpiochip%d/device/name",i);
|
snprintf(rx_tx_buf, sizeof(rx_tx_buf), "/sys/class/gpio/gpiochip%d/device/name",i);
|
||||||
if((fd = open(rx_tx_buf, O_RDONLY)) != -1)
|
if((fd = open(rx_tx_buf, O_RDONLY)) != -1)
|
||||||
{
|
{
|
||||||
int count = read(fd, rx_tx_buf, 7);
|
int count = read(fd, rx_tx_buf, 7);
|
||||||
@@ -324,7 +307,7 @@ static int sx150x_init()
|
|||||||
|
|
||||||
for(i = 0; i < 999;i++)
|
for(i = 0; i < 999;i++)
|
||||||
{
|
{
|
||||||
sprintf(rx_tx_buf,"/sys/bus/i2c/devices/%x-003e/name",i);
|
snprintf(rx_tx_buf, sizeof(rx_tx_buf), "/sys/bus/i2c/devices/%x-003e/name",i);
|
||||||
if((fd = open(rx_tx_buf, O_RDONLY)) != -1)
|
if((fd = open(rx_tx_buf, O_RDONLY)) != -1)
|
||||||
{
|
{
|
||||||
int count = read(fd, rx_tx_buf, 7);
|
int count = read(fd, rx_tx_buf, 7);
|
||||||
@@ -340,7 +323,7 @@ static int sx150x_init()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(rx_tx_buf, "/dev/i2c-%d",bus_num);
|
snprintf(rx_tx_buf, sizeof(rx_tx_buf), "/dev/i2c-%d",bus_num);
|
||||||
if((_fd = open(rx_tx_buf, O_RDWR)) < 0)
|
if((_fd = open(rx_tx_buf, O_RDWR)) < 0)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
@@ -401,8 +384,6 @@ mraa_adlink_ipi()
|
|||||||
int i2c1 = -1;
|
int i2c1 = -1;
|
||||||
int spi0 = -1;
|
int spi0 = -1;
|
||||||
int uart0 = -1;
|
int uart0 = -1;
|
||||||
int pwm0 = -1;
|
|
||||||
int pwm1 = -1;
|
|
||||||
|
|
||||||
//TODO: Handle different Adlink arm variants eg. IMX6, IMX8M
|
//TODO: Handle different Adlink arm variants eg. IMX6, IMX8M
|
||||||
b->platform_name = PLATFORM_NAME_ADLINK_IPI;
|
b->platform_name = PLATFORM_NAME_ADLINK_IPI;
|
||||||
@@ -417,7 +398,7 @@ mraa_adlink_ipi()
|
|||||||
*/
|
*/
|
||||||
int devnum;
|
int devnum;
|
||||||
for (devnum = 0; devnum < 2; devnum++) {
|
for (devnum = 0; devnum < 2; devnum++) {
|
||||||
if (mraa_link_targets(seriallink[devnum], "ff030000")) {
|
if (mraa_link_targets(seriallink[devnum], "ff160000")) {
|
||||||
uart0 = devnum;
|
uart0 = devnum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -437,15 +418,6 @@ mraa_adlink_ipi()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (devnum = 0; devnum < 2; devnum++) {
|
|
||||||
if (mraa_link_targets(pwmlink[devnum], "ff208020")) {
|
|
||||||
pwm0 = devnum;
|
|
||||||
}
|
|
||||||
if (mraa_link_targets(pwmlink[devnum], "ff208030")) {
|
|
||||||
pwm1 = devnum;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
b->adv_func = (mraa_adv_func_t*) calloc(1, sizeof(mraa_adv_func_t));
|
b->adv_func = (mraa_adv_func_t*) calloc(1, sizeof(mraa_adv_func_t));
|
||||||
if (b->adv_func == NULL) {
|
if (b->adv_func == NULL) {
|
||||||
free(b);
|
free(b);
|
||||||
|
|||||||
@@ -83,15 +83,15 @@ static mraa_result_t pwm_init_raw_replace(mraa_pwm_context dev, int pin)
|
|||||||
}
|
}
|
||||||
if((fd = open("/sys/class/gpio/export", O_WRONLY)) != -1)
|
if((fd = open("/sys/class/gpio/export", O_WRONLY)) != -1)
|
||||||
{
|
{
|
||||||
i = sprintf(buffer,"%d",base2 + pin);
|
i = snprintf(buffer, sizeof(buffer), "%d",base2 + pin);
|
||||||
write(fd, buffer, i);
|
write(fd, buffer, i);
|
||||||
close(fd);
|
close(fd);
|
||||||
sprintf(buffer,"/sys/class/gpio/gpio%d/direction",base2 + pin);
|
snprintf(buffer, sizeof(buffer), "/sys/class/gpio/gpio%d/direction",base2 + pin);
|
||||||
if((fd = open(buffer, O_WRONLY)) != -1)
|
if((fd = open(buffer, O_WRONLY)) != -1)
|
||||||
{
|
{
|
||||||
write(fd, "out", 3);
|
write(fd, "out", 3);
|
||||||
close(fd);
|
close(fd);
|
||||||
sprintf(buffer,"/sys/class/gpio/gpio%d/value",base2 + pin);
|
snprintf(buffer, sizeof(buffer), "/sys/class/gpio/gpio%d/value",base2 + pin);
|
||||||
if((fd = open(buffer, O_WRONLY)) != -1)
|
if((fd = open(buffer, O_WRONLY)) != -1)
|
||||||
{
|
{
|
||||||
write(fd, "0", 1);
|
write(fd, "0", 1);
|
||||||
@@ -361,7 +361,7 @@ static mraa_result_t intr_init()
|
|||||||
if((fd = open("/sys/class/gpio/export", O_WRONLY)) != -1)
|
if((fd = open("/sys/class/gpio/export", O_WRONLY)) != -1)
|
||||||
{
|
{
|
||||||
write(fd,"456",3);
|
write(fd,"456",3);
|
||||||
sprintf(bu,"%d",base1 + 12);
|
snprintf(bu, sizeof(bu), "%d",base1 + 12);
|
||||||
write(fd,bu,3);
|
write(fd,bu,3);
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
@@ -370,7 +370,7 @@ static mraa_result_t intr_init()
|
|||||||
return MRAA_ERROR_INVALID_RESOURCE;
|
return MRAA_ERROR_INVALID_RESOURCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(bu,"/sys/class/gpio/gpio%d/direction",456);
|
snprintf(bu, sizeof(bu), "/sys/class/gpio/gpio%d/direction",456);
|
||||||
if((fd = open(bu, O_WRONLY)) != -1)
|
if((fd = open(bu, O_WRONLY)) != -1)
|
||||||
{
|
{
|
||||||
write(fd, "in", 2);
|
write(fd, "in", 2);
|
||||||
@@ -381,7 +381,7 @@ static mraa_result_t intr_init()
|
|||||||
return MRAA_ERROR_INVALID_RESOURCE;
|
return MRAA_ERROR_INVALID_RESOURCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(bu,"/sys/class/gpio/gpio%d/direction",base1 + 12);
|
snprintf(bu, sizeof(bu), "/sys/class/gpio/gpio%d/direction",base1 + 12);
|
||||||
if((fd = open(bu, O_WRONLY)) != -1)
|
if((fd = open(bu, O_WRONLY)) != -1)
|
||||||
{
|
{
|
||||||
write(fd, "in", 2);
|
write(fd, "in", 2);
|
||||||
@@ -472,9 +472,9 @@ static mraa_result_t gpio_close_pre(mraa_gpio_context dev)
|
|||||||
mraa_gpio_isr_exit(gpio);
|
mraa_gpio_isr_exit(gpio);
|
||||||
if((fd = open("/sys/class/gpio/unexport", O_WRONLY)) != -1)
|
if((fd = open("/sys/class/gpio/unexport", O_WRONLY)) != -1)
|
||||||
{
|
{
|
||||||
length = sprintf(gpio_path,"%d",gpio->pin);
|
length = snprintf(gpio_path, sizeof(gpio_path), "%d",gpio->pin);
|
||||||
write(fd, gpio_path, length);
|
write(fd, gpio_path, length);
|
||||||
length = sprintf(gpio_path,"%d",base1 + 12);
|
length = snprintf(gpio_path, sizeof(gpio_path), "%d",base1 + 12);
|
||||||
write(fd, gpio_path, length);
|
write(fd, gpio_path, length);
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
@@ -645,7 +645,7 @@ static int sx150x_init(int bus_num)
|
|||||||
{
|
{
|
||||||
char rx_tx_buf[20] = {0};
|
char rx_tx_buf[20] = {0};
|
||||||
|
|
||||||
sprintf(rx_tx_buf, "/dev/i2c-%d",bus_num);
|
snprintf(rx_tx_buf, sizeof(rx_tx_buf), "/dev/i2c-%d",bus_num);
|
||||||
if((_fd = open(rx_tx_buf, O_RDWR)) < 0)
|
if((_fd = open(rx_tx_buf, O_RDWR)) < 0)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
@@ -761,7 +761,7 @@ static mraa_result_t gpio_init_pre(int pin)
|
|||||||
{
|
{
|
||||||
for(i = 0; i < 100; i++)
|
for(i = 0; i < 100; i++)
|
||||||
{
|
{
|
||||||
sprintf(buffer, "/sys/class/hwmon/hwmon%d/device/fan1_enable", i);
|
snprintf(buffer, sizeof(buffer), "/sys/class/hwmon/hwmon%d/device/fan1_enable", i);
|
||||||
|
|
||||||
if((fd = open(buffer, O_RDWR)) == -1)
|
if((fd = open(buffer, O_RDWR)) == -1)
|
||||||
{
|
{
|
||||||
@@ -801,7 +801,7 @@ static mraa_result_t gpio_init_pre(int pin)
|
|||||||
{
|
{
|
||||||
if(read(_fd, &(rx_tx_buf[1]), 1) == 1)
|
if(read(_fd, &(rx_tx_buf[1]), 1) == 1)
|
||||||
{
|
{
|
||||||
rx_tx_buf[1] &= ~(1 < (pin % 8));
|
rx_tx_buf[1] &= ~(1 << (pin % 8));
|
||||||
write(_fd, &rx_tx_buf[0], 2);
|
write(_fd, &rx_tx_buf[0], 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -811,11 +811,11 @@ static mraa_result_t gpio_init_pre(int pin)
|
|||||||
{
|
{
|
||||||
if(read(_fd, &(rx_tx_buf[1]), 1) == 1)
|
if(read(_fd, &(rx_tx_buf[1]), 1) == 1)
|
||||||
{
|
{
|
||||||
rx_tx_buf[1] &= ~(1 < (pin % 8));
|
rx_tx_buf[1] &= ~(1 << (pin % 8));
|
||||||
write(_fd, &rx_tx_buf[0], 2);
|
write(_fd, &rx_tx_buf[0], 2);
|
||||||
if((fd = open("/sys/class/gpio/unexport", O_WRONLY)) != -1)
|
if((fd = open("/sys/class/gpio/unexport", O_WRONLY)) != -1)
|
||||||
{
|
{
|
||||||
i = sprintf(buffer,"%d",base2 + pin);
|
i = snprintf(buffer, sizeof(buffer), "%d",base2 + pin);
|
||||||
write(fd, buffer, i);
|
write(fd, buffer, i);
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
@@ -885,7 +885,7 @@ mraa_board_t* mraa_lec_al_board()
|
|||||||
|
|
||||||
for(i = 0; i < 999; i++)
|
for(i = 0; i < 999; i++)
|
||||||
{
|
{
|
||||||
sprintf(buffer,"/sys/class/gpio/gpiochip%d/device/name",i);
|
snprintf(buffer, sizeof(buffer), "/sys/class/gpio/gpiochip%d/device/name",i);
|
||||||
if((fd = open(buffer, O_RDONLY)) != -1)
|
if((fd = open(buffer, O_RDONLY)) != -1)
|
||||||
{
|
{
|
||||||
int count = read(fd,buffer,7);
|
int count = read(fd,buffer,7);
|
||||||
|
|||||||
Reference in New Issue
Block a user