Skip to content

Commit

Permalink
[nasa/nos3#176] Updates to resolve build issues with linux version an…
Browse files Browse the repository at this point in the history
…d added pragma for unit tests in hwlib.h;
  • Loading branch information
jlucas9 committed Jul 1, 2024
1 parent cf82b54 commit f3143f2
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 63 deletions.
2 changes: 1 addition & 1 deletion fsw/linux/libcan.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ int32_t can_close_device(can_info_t* device)
int32_t can_master_transaction(can_info_t* device)
{
int32_t status;
uint8_t i;

status = can_write(device);
if (status != CAN_SUCCESS)
Expand All @@ -233,6 +232,7 @@ int32_t can_master_transaction(can_info_t* device)
}

#ifdef LIBCAN_VERBOSE
uint8_t i;
OS_printf("can_master_transaction: \n");
OS_printf(" can_id = 0x%08x \t tx: 0x", device->tx_frame.can_id);
for (i = 0; i < device->tx_frame.can_dlc; i++)
Expand Down
6 changes: 3 additions & 3 deletions fsw/linux/libgpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ int32_t gpio_read(gpio_info_t* device, uint8_t* value)
{
int32_t status = GPIO_SUCCESS;
char buffer[128];
char readValue;
char readValue[3];
int fd;

if(device->isOpen != GPIO_OPEN)
Expand All @@ -95,8 +95,8 @@ int32_t gpio_read(gpio_info_t* device, uint8_t* value)
}

//convert from ASCII to decimal
if(readValue == '0') *value = 0;
else if(readValue == '1') *value = 1;
if(readValue[0] == '0') *value = 0;
else if(readValue[0] == '1') *value = 1;
else {
*value = 0;
}
Expand Down
48 changes: 24 additions & 24 deletions fsw/linux/libi2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,118 +33,118 @@ int32_t i2c_master_init(i2c_bus_info_t* device)
device->handle = open(devname, O_RDWR);
if (device->handle < 0)
{
OS_printf("i2c bus open failed for handle = %d, %s\n", device->handle, strerror(errno));
printf("i2c bus open failed for handle = %d, %s\n", device->handle, strerror(errno));
status = I2C_ERROR;
device->isOpen = I2C_CLOSED;
}
else
{
device->isOpen = I2C_OPEN;
OS_printf("i2c bus open passed for handle = %d\n", device->handle);
printf("i2c bus open passed for handle = %d\n", device->handle);
}
return status;
}

int32_t i2c_master_transaction(int32_t handle, uint8_t addr, void * txbuf, uint8_t txlen, void * rxbuf, uint8_t rxlen, uint16_t timeout)
int32_t i2c_master_transaction(i2c_bus_info_t* device, uint8_t addr, void * txbuf, uint8_t txlen, void * rxbuf, uint8_t rxlen, uint16_t timeout)
{
int32_t status = I2C_SUCCESS;
int32_t resp;

/* Set I2C slave address */
if (ioctl(handle, I2C_SLAVE, addr) < 0)
if (ioctl(device->handle, I2C_SLAVE, addr) < 0)
{
OS_printf("i2c-%d setting slave address = 0x%X FAILED, %s\n", handle, addr, strerror(errno));
printf("i2c-%d setting slave address = 0x%X FAILED, %s\n", device->handle, addr, strerror(errno));
status = I2C_ERROR;
return status;
}

/* Perform write if needed */
if (txlen > 0 )
{
resp = write(handle, txbuf, txlen);
resp = write(device->handle, txbuf, txlen);
if (resp != txlen)
{
OS_printf("i2c-%d write to address 0x%X FAILED, [%u] %s\n", handle, addr, errno, strerror(errno));
printf("i2c-%d write to address 0x%X FAILED, [%u] %s\n", device->handle, addr, errno, strerror(errno));
status = I2C_ERROR;
}
}
/* Perform read if needed */
if (rxlen > 0 )
{
resp = read(handle, rxbuf, rxlen);
resp = read(device->handle, rxbuf, rxlen);
if (resp != rxlen)
{
OS_printf("i2c-%d read from address 0x%X FAILED, %s\n", handle, addr, strerror(errno));
printf("i2c-%d read from address 0x%X FAILED, %s\n", device->handle, addr, strerror(errno));
status = I2C_ERROR;
}
}

return status;
}

int32_t i2c_read_transaction(int32_t handle, uint8_t addr, void * rxbuf, uint8_t rxlen, uint8_t timeout)
int32_t i2c_read_transaction(i2c_bus_info_t* device, uint8_t addr, void * rxbuf, uint8_t rxlen, uint8_t timeout)
{
int32_t resp;
int32_t status = I2C_SUCCESS;

/* Set I2C slave address */
if (ioctl(handle, I2C_SLAVE, addr) < 0)
if (ioctl(device->handle, I2C_SLAVE, addr) < 0)
{
OS_printf("i2c-%d setting slave address = 0x%X FAILED, %s\n", handle, addr, strerror(errno));
printf("i2c-%d setting slave address = 0x%X FAILED, %s\n", device->handle, addr, strerror(errno));
status = I2C_ERROR;
return status;
}

resp = read(handle, rxbuf, rxlen); //<-- ACK would need to go in here
resp = read(device->handle, rxbuf, rxlen); //<-- ACK would need to go in here
if (resp != rxlen)
{
OS_printf("i2c-%d read from address 0x%X FAILED, %s\n", handle, addr, strerror(errno));
printf("i2c-%d read from address 0x%X FAILED, %s\n", device->handle, addr, strerror(errno));
status = I2C_ERROR;
}

return status;
}

int32_t i2c_write_transaction(int32_t handle, uint8_t addr, void * txbuf, uint8_t txlen, uint8_t timeout)
int32_t i2c_write_transaction(i2c_bus_info_t* device, uint8_t addr, void * txbuf, uint8_t txlen, uint8_t timeout)
{
int32_t resp;
int32_t status = I2C_SUCCESS;

/* Set I2C slave address */
if (ioctl(handle, I2C_SLAVE, addr) < 0)
if (ioctl(device->handle, I2C_SLAVE, addr) < 0)
{
OS_printf("i2c-%d setting slave address = 0x%X FAILED, %s\n", handle, addr, strerror(errno));
printf("i2c-%d setting slave address = 0x%X FAILED, %s\n", device->handle, addr, strerror(errno));
status = I2C_ERROR;
return status;
}

resp = write(handle, txbuf, txlen);
resp = write(device->handle, txbuf, txlen);
if (resp != txlen)
{
OS_printf("i2c-%d write from address 0x%X FAILED, %s\n", handle, addr, strerror(errno));
printf("i2c-%d write from address 0x%X FAILED, %s\n", device->handle, addr, strerror(errno));
status = I2C_ERROR;
}

return status;
}

int32_t i2c_multiple_transaction(int32_t handle, uint8_t addr, struct i2c_rdwr_ioctl_data* rdwr_data, uint16_t timeout)
int32_t i2c_multiple_transaction(i2c_bus_info_t* device, uint8_t addr, struct i2c_rdwr_ioctl_data* rdwr_data, uint16_t timeout)
{
/* Do combined read/write transaction without stop (simply restarts) in between. */
int32_t status = I2C_SUCCESS;

/* Set I2C slave address */
if (ioctl(handle, I2C_SLAVE, addr) < 0)
if (ioctl(device->handle, I2C_SLAVE, addr) < 0)
{
OS_printf("i2c-%d setting slave address = 0x%X FAILED, %s\n", handle, addr, strerror(errno));
printf("i2c-%d setting slave address = 0x%X FAILED, %s\n", device->handle, addr, strerror(errno));
status = I2C_ERROR;
return status;
}

/* Make the ICOTL call */
if (ioctl(handle, I2C_RDWR, rdwr_data) < 0)
if (ioctl(device->handle, I2C_RDWR, rdwr_data) < 0)
{
OS_printf("i2c-%d multple transaction error = 0x%X FAILED, %s\n", handle, addr, strerror(errno));
printf("i2c-%d multple transaction error = 0x%X FAILED, %s\n", device->handle, addr, strerror(errno));
status = I2C_ERROR;
return status;
}
Expand Down
4 changes: 0 additions & 4 deletions fsw/linux/libsocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ int32_t socket_accept(socket_info_t* socket_info)
int ret;
struct sockaddr_in client;
int32_t status;
int ip_str_len;

status = SOCKET_SUCCESS;

Expand Down Expand Up @@ -290,9 +289,7 @@ int32_t socket_send(socket_info_t* socket_info, uint8_t* buffer, size_t buflen,
{
int ret;
int32_t status;
int address_family;
struct sockaddr_in remote_sockaddr;
unsigned int i;
status = SOCKET_SUCCESS;

switch(socket_info->type)
Expand Down Expand Up @@ -354,7 +351,6 @@ int32_t socket_recv(socket_info_t* socket_info, uint8_t* buffer, size_t buflen,
{
int c;
int ret;
int ip_str_len;
int32_t status;
struct sockaddr_in remote_sockaddr;

Expand Down
1 change: 0 additions & 1 deletion fsw/linux/libspi.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ NASA IV&V
[email protected]
*/

#include "osapi.h"
#include "libspi.h"

spi_mutex_t spi_bus_mutex[MAX_SPI_BUSES];
Expand Down
27 changes: 12 additions & 15 deletions fsw/linux/libtrq.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,21 @@ int32_t trq_set_time_high(trq_info_t* device, uint32_t new_time)
{
if(!device->enabled)
{
OS_printf("trq_set_time_high: Error setting trq %d timer period because it's disabled! \n", device->trq_num);
printf("trq_set_time_high: Error setting trq %d timer period because it's disabled! \n", device->trq_num);
return TRQ_ERROR;
}

// Make sure the time high isn't greater than the period
if(new_time > device->timer_period_ns)
{
OS_printf("trq_set_time_high: Error setting trq %d time high, must not exceed the period! \n", device->trq_num);
printf("trq_set_time_high: Error setting trq %d time high, must not exceed the period! \n", device->trq_num);
return TRQ_TIME_HIGH_VAL_ERR;
}

ioctl(device->timerfd, TMRCTR_PWM_DISABLE);
if(ioctl(device->timerfd, TMRCTR_PWM_SET_HIGH_TIME, new_time) < 0)
{
OS_printf("trq_set_time_high: Error setting trq %d high time! \n", device->trq_num);
printf("trq_set_time_high: Error setting trq %d high time! \n", device->trq_num);
return TRQ_ERROR;
}
device->timer_high_ns = new_time;
Expand All @@ -61,7 +61,7 @@ int32_t trq_set_time_high(trq_info_t* device, uint32_t new_time)
ioctl(device->timerfd, TMRCTR_PWM_ENABLE);
}

//OS_printf("trq_set_time_high: timer_period_ns = %d, timer_high_ns = %d\n", device->timer_period_ns, device->timer_high_ns);
//printf("trq_set_time_high: timer_period_ns = %d, timer_high_ns = %d\n", device->timer_period_ns, device->timer_high_ns);
return TRQ_SUCCESS;
}

Expand All @@ -79,7 +79,7 @@ int32_t trq_set_period(trq_info_t* device)
{
if(!device->enabled)
{
OS_printf("trq_set_period: Error setting trq %d timer period because it's disabled! \n", device->trq_num);
printf("trq_set_period: Error setting trq %d timer period because it's disabled! \n", device->trq_num);
return TRQ_ERROR;
}

Expand All @@ -88,7 +88,7 @@ int32_t trq_set_period(trq_info_t* device)

if(ioctl(device->timerfd, TMRCTR_PWM_SET_PERIOD, device->timer_period_ns) < 0)
{
OS_printf("trq_set_period: Error setting trq %d timer period! \n", device->trq_num);
printf("trq_set_period: Error setting trq %d timer period! \n", device->trq_num);
return TRQ_ERROR;
}

Expand Down Expand Up @@ -125,7 +125,7 @@ int32_t trq_set_direction(trq_info_t* device, bool direction)

if (write(device->direction_pin_fd, &charVal, 1) != 1)
{
OS_printf("trq_set_direction: Error setting trq %d direction! \n", device->trq_num);
printf("trq_set_direction: Error setting trq %d direction! \n", device->trq_num);
return TRQ_ERROR;
}
device->positive_direction = direction;
Expand All @@ -148,15 +148,14 @@ int32_t trq_init(trq_info_t* device)
{
int32_t status = TRQ_SUCCESS;
char devname[TRQ_FNAME_SIZE];
char pinname[TRQ_FNAME_SIZE];

if(!device->enabled)
{
// Open axi timer
snprintf(devname, TRQ_FNAME_SIZE, "/dev/tmrctr%d", device->trq_num);
if((device->timerfd = open(devname, O_RDWR, 0)) < 0)
{
OS_printf("trq_init: Error opening axi timer device %s \n", devname);
printf("trq_init: Error opening axi timer device %s \n", devname);
return TRQ_INIT_ERR;
}
//printf("trq_init: Initialized AXI Timer Device: %s for device->trq_num %d \n", devname, device->trq_num);
Expand All @@ -165,7 +164,7 @@ int32_t trq_init(trq_info_t* device)
snprintf(devname, TRQ_FNAME_SIZE, "/dev/hb%d", device->trq_num);
if((device->direction_pin_fd = open(devname, O_RDWR, 0)) < 0)
{
OS_printf("trq_init: Error opening axi timer device %s \n", devname);
printf("trq_init: Error opening axi timer device %s \n", devname);
return TRQ_INIT_ERR;
}

Expand All @@ -175,7 +174,6 @@ int32_t trq_init(trq_info_t* device)
{
return TRQ_INIT_ERR;
}
//OS_printf("trq_init: Initialized direction pin: %s for device->trq_num %d\n", pinname, device->trq_num);

device->enabled = true;
}
Expand Down Expand Up @@ -214,7 +212,6 @@ int32_t trq_command(trq_info_t *device, uint8_t percent_high, bool pos_dir)
{
int32_t status = TRQ_SUCCESS;
uint32_t time_high_ns;
char charVal;

if(!device->enabled)
{
Expand All @@ -225,7 +222,7 @@ int32_t trq_command(trq_info_t *device, uint8_t percent_high, bool pos_dir)
// Calculate time high
if (percent_high > 100)
{
OS_printf("trq_command: Error setting percent high greater than 100! \n");
printf("trq_command: Error setting percent high greater than 100! \n");
return TRQ_ERROR;
}
time_high_ns = device->timer_period_ns * (percent_high / 100.00);
Expand All @@ -249,7 +246,7 @@ int32_t trq_command(trq_info_t *device, uint8_t percent_high, bool pos_dir)
status = trq_set_direction(device, pos_dir);
if(status != TRQ_SUCCESS)
{
OS_printf("trq_command: Error setting trq %d direction! \n", device->trq_num);
printf("trq_command: Error setting trq %d direction! \n", device->trq_num);
status = TRQ_INIT_ERR;
return status;
}
Expand All @@ -269,7 +266,7 @@ void trq_close(trq_info_t* device)
{
if(!device->enabled)
{
OS_printf("trq_close: Error closing trq %d, already disabled! \n", device->trq_num);
printf("trq_close: Error closing trq %d, already disabled! \n", device->trq_num);
return;
}

Expand Down
Loading

0 comments on commit f3143f2

Please sign in to comment.