Skip to content

Commit

Permalink
Merge pull request #9 from nasa-itc/nos3#463-css-checkout
Browse files Browse the repository at this point in the history
[nasa/nos3#463] Generic CSS Checkout
  • Loading branch information
kevincbruce authored Jan 21, 2025
2 parents ba3a555 + 0b3523c commit e53bf02
Show file tree
Hide file tree
Showing 10 changed files with 229 additions and 254 deletions.
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#
# Metadata
#
.vagrant
.vscode

#
# Build Files
#
build
fprime/build
fsw/standalone/build
tmp
.cdskeyfile
.reservedkeyfile
.resetkeyfile
1 change: 1 addition & 0 deletions fsw/cfs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ include_directories(mission_inc)
include_directories(platform_inc)
include_directories(src)

include_directories(../shared)
include_directories(${hwlib_MISSION_DIR}/fsw/public_inc)

aux_source_directory(src APP_SRC_FILES)
Expand Down
118 changes: 59 additions & 59 deletions fsw/cfs/src/generic_css_device.c → fsw/shared/generic_css_device.c
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
/*******************************************************************************
** File: generic_css_device.c
**
** Purpose:
** This file contains the source code for the GENERIC_CSS device.
**
*******************************************************************************/

/*
** Include Files
*/
#include "generic_css_device.h"


/*
** Request data command
*/
int32_t GENERIC_CSS_RequestData(i2c_bus_info_t* device, GENERIC_CSS_Device_Data_tlm_t* data)
{
int32_t status = OS_SUCCESS;
uint8_t read_data[GENERIC_CSS_DEVICE_DATA_LNGTH] = {0};

status = i2c_master_transaction(device, GENERIC_CSS_I2C_ADDRESS, NULL, 0, read_data, GENERIC_CSS_DEVICE_DATA_LNGTH, GENERIC_CSS_CFG_MS_TIMEOUT);
if (status == OS_SUCCESS)
{
#ifdef GENERIC_CSS_CFG_DEBUG
OS_printf(" GENERIC_CSS_RequestData = 0x");
for (uint32_t i = 0; i < sizeof(read_data); i++)
{
OS_printf("%02x, ", read_data[i]);
}
OS_printf("\n");
#endif

data->Voltage[0] = (read_data[0] << 8) | read_data[1];
data->Voltage[1] = (read_data[2] << 8) | read_data[3];
data->Voltage[2] = (read_data[4] << 8) | read_data[5];
data->Voltage[3] = (read_data[6] << 8) | read_data[7];
data->Voltage[4] = (read_data[8] << 8) | read_data[9];
data->Voltage[5] = (read_data[10] << 8) | read_data[11];

#ifdef GENERIC_CSS_CFG_DEBUG
OS_printf(" Voltage ADC 1 = 0x%04x, %d \n", data->Voltage[0], data->Voltage[0]);
OS_printf(" Voltage ADC 2 = 0x%04x, %d \n", data->Voltage[1], data->Voltage[1]);
OS_printf(" Voltage ADC 3 = 0x%04x, %d \n", data->Voltage[2], data->Voltage[2]);
OS_printf(" Voltage ADC 4 = 0x%04x, %d \n", data->Voltage[3], data->Voltage[3]);
OS_printf(" Voltage ADC 5 = 0x%04x, %d \n", data->Voltage[4], data->Voltage[4]);
OS_printf(" Voltage ADC 6 = 0x%04x, %d \n", data->Voltage[5], data->Voltage[5]);
#endif
}
else
{
#ifdef GENERIC_CSS_CFG_DEBUG
OS_printf(" GENERIC_CSS_RequestData: Invalid data read! \n");
#endif
status = OS_ERROR;
}
return status;
}
/*******************************************************************************
** File: generic_css_device.c
**
** Purpose:
** This file contains the source code for the GENERIC_CSS device.
**
*******************************************************************************/

/*
** Include Files
*/
#include "generic_css_device.h"


/*
** Request data command
*/
int32_t GENERIC_CSS_RequestData(i2c_bus_info_t* device, GENERIC_CSS_Device_Data_tlm_t* data)
{
int32_t status = OS_SUCCESS;
uint8_t read_data[GENERIC_CSS_DEVICE_DATA_LNGTH] = {0};

status = i2c_master_transaction(device, GENERIC_CSS_I2C_ADDRESS, NULL, 0, read_data, GENERIC_CSS_DEVICE_DATA_LNGTH, GENERIC_CSS_CFG_MS_TIMEOUT);
if (status == OS_SUCCESS)
{
#ifdef GENERIC_CSS_CFG_DEBUG
OS_printf(" GENERIC_CSS_RequestData = 0x");
for (uint32_t i = 0; i < sizeof(read_data); i++)
{
OS_printf("%02x, ", read_data[i]);
}
OS_printf("\n");
#endif

data->Voltage[0] = (read_data[0] << 8) | read_data[1];
data->Voltage[1] = (read_data[2] << 8) | read_data[3];
data->Voltage[2] = (read_data[4] << 8) | read_data[5];
data->Voltage[3] = (read_data[6] << 8) | read_data[7];
data->Voltage[4] = (read_data[8] << 8) | read_data[9];
data->Voltage[5] = (read_data[10] << 8) | read_data[11];

#ifdef GENERIC_CSS_CFG_DEBUG
OS_printf(" Voltage ADC 1 = 0x%04x, %d \n", data->Voltage[0], data->Voltage[0]);
OS_printf(" Voltage ADC 2 = 0x%04x, %d \n", data->Voltage[1], data->Voltage[1]);
OS_printf(" Voltage ADC 3 = 0x%04x, %d \n", data->Voltage[2], data->Voltage[2]);
OS_printf(" Voltage ADC 4 = 0x%04x, %d \n", data->Voltage[3], data->Voltage[3]);
OS_printf(" Voltage ADC 5 = 0x%04x, %d \n", data->Voltage[4], data->Voltage[4]);
OS_printf(" Voltage ADC 6 = 0x%04x, %d \n", data->Voltage[5], data->Voltage[5]);
#endif
}
else
{
#ifdef GENERIC_CSS_CFG_DEBUG
OS_printf(" GENERIC_CSS_RequestData: Invalid data read! \n");
#endif
status = OS_ERROR;
}
return status;
}
82 changes: 41 additions & 41 deletions fsw/cfs/src/generic_css_device.h → fsw/shared/generic_css_device.h
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
/*******************************************************************************
** File: generic_css_device.h
**
** Purpose:
** This is the header file for the GENERIC_CSS device.
**
*******************************************************************************/
#ifndef _GENERIC_CSS_DEVICE_H_
#define _GENERIC_CSS_DEVICE_H_

/*
** Required header files.
*/
#include "device_cfg.h"
#include "hwlib.h"
#include "generic_css_platform_cfg.h"


/*
** Type definitions
*/
#define GENERIC_CSS_I2C_ADDRESS 0x40
#define GENERIC_CSS_NUM_CHANNELS 6


/*
** GENERIC_CSS device data telemetry definition
*/
typedef struct
{
uint16_t Voltage[GENERIC_CSS_NUM_CHANNELS];
} __attribute__((packed)) GENERIC_CSS_Device_Data_tlm_t;
#define GENERIC_CSS_DEVICE_DATA_LNGTH sizeof ( GENERIC_CSS_Device_Data_tlm_t )


/*
** Prototypes
*/
int32_t GENERIC_CSS_RequestData(i2c_bus_info_t* device, GENERIC_CSS_Device_Data_tlm_t* data);

#endif /* _GENERIC_CSS_DEVICE_H_ */
/*******************************************************************************
** File: generic_css_device.h
**
** Purpose:
** This is the header file for the GENERIC_CSS device.
**
*******************************************************************************/
#ifndef _GENERIC_CSS_DEVICE_H_
#define _GENERIC_CSS_DEVICE_H_

/*
** Required header files.
*/
#include "device_cfg.h"
#include "hwlib.h"
#include "generic_css_platform_cfg.h"


/*
** Type definitions
*/
#define GENERIC_CSS_I2C_ADDRESS 0x40
#define GENERIC_CSS_NUM_CHANNELS 6


/*
** GENERIC_CSS device data telemetry definition
*/
typedef struct
{
uint16_t Voltage[GENERIC_CSS_NUM_CHANNELS];
} __attribute__((packed)) GENERIC_CSS_Device_Data_tlm_t;
#define GENERIC_CSS_DEVICE_DATA_LNGTH sizeof ( GENERIC_CSS_Device_Data_tlm_t )


/*
** Prototypes
*/
int32_t GENERIC_CSS_RequestData(i2c_bus_info_t* device, GENERIC_CSS_Device_Data_tlm_t* data);

#endif /* _GENERIC_CSS_DEVICE_H_ */
65 changes: 65 additions & 0 deletions fsw/standalone/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
cmake_minimum_required(VERSION 2.6.4)

project (generic_css_checkout)

if (NOT DEFINED TGTNAME)
message(FATAL_ERROR "TGTNAME must be defined on the cmake command line (e.g. \"-DTGTNAME=cpu1\")")
endif()

include(../../../ComponentSettings.cmake)

if(${TGTNAME} STREQUAL cpu1)
find_path(_ITC_CMAKE_MODULES_
NAMES FindITC_Common.cmake
PATHS ${ITC_CMAKE_MODULES}
${ITC_DEV_ROOT}/cmake/modules
$ENV{ITC_DEV_ROOT}/cmake/modules
/usr/local/cmake/modules
/usr/cmake/modules)
if(NOT _ITC_CMAKE_MODULES_)
message(WARNING "Unable to find ITC CMake Modules")
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${_ITC_CMAKE_MODULES_})

find_package(NOSENGINE REQUIRED QUIET COMPONENTS common transport client uart can i2c spi)
endif()

include_directories("./")
include_directories("../cfs/platform_inc")
include_directories("../cfs/src")
include_directories("../shared")
include_directories("../../../../fsw/apps/hwlib/fsw/public_inc")

set(generic_css_checkout_src
generic_css_checkout.c
../shared/generic_css_device.c
)

if(${TGTNAME} STREQUAL cpu1)
include_directories("../../../../fsw/apps/hwlib/sim/inc")
set(generic_css_checkout_src
${generic_css_checkout_src}
../../../../fsw/apps/hwlib/sim/src/libuart.c
../../../../fsw/apps/hwlib/sim/src/libcan.c
../../../../fsw/apps/hwlib/sim/src/libi2c.c
../../../../fsw/apps/hwlib/sim/src/libspi.c
../../../../fsw/apps/hwlib/sim/src/nos_link.c
)
set(generic_css_checkout_libs
${ITC_Common_LIBRARIES}
${NOSENGINE_LIBRARIES}
)
endif()
if(${TGTNAME} STREQUAL cpu2)
set(generic_css_checkout_src
${generic_css_checkout_src}
../../../../fsw/apps/hwlib/fsw/linux/libuart.c
)
endif()

add_executable(generic_css_checkout ${generic_css_checkout_src})
target_link_libraries(generic_css_checkout ${generic_css_checkout_libs})

if(${TGTNAME} STREQUAL cpu1)
set_target_properties(generic_css_checkout PROPERTIES COMPILE_FLAGS "-g" LINK_FLAGS "-g")
endif()
14 changes: 14 additions & 0 deletions fsw/standalone/device_cfg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef _GENERIC_CSS_CHECKOUT_DEVICE_CFG_H_
#define _GENERIC_CSS_CHECKOUT_DEVICE_CFG_H_

/*
** GENERIC_CSS Checkout Configuration
*/
#define GENERIC_CSS_CFG
#define GENERIC_CSS_CFG_STRING "i2c_2"
#define GENERIC_CSS_CFG_HANDLE 2
#define GENERIC_CSS_CFG_BAUDRATE_HZ 1000
#define GENERIC_CSS_CFG_MS_TIMEOUT 250
#define GENERIC_CSS_CFG_DEBUG

#endif /* _GENERIC_CSS_CHECKOUT_DEVICE_CFG_H_ */
Loading

0 comments on commit e53bf02

Please sign in to comment.