Skip to content

Adding structure for RF430CL331H #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ glaux:
cp src/boot/ksdk1.1.0/glaux.h build/ksdk1.1/work/boards/Glaux
cp src/boot/ksdk1.1.0/CMakeLists-Glaux.txt build/ksdk1.1/work/demos/Glaux/armgcc/Glaux/CMakeLists.txt
cp src/boot/ksdk1.1.0/devBME680.* build/ksdk1.1/work/demos/Glaux/src/
cp src/boot/ksdk1.1.0/devRF430CL331H.* build/ksdk1.1/work/demos/Glaux/src/
cp src/boot/ksdk1.1.0/devIS25xP.* build/ksdk1.1/work/demos/Glaux/src/
cp src/boot/ksdk1.1.0/devRV8803C7.* build/ksdk1.1/work/demos/Glaux/src/
cp src/boot/ksdk1.1.0/devBME680.* build/ksdk1.1/work/demos/Glaux/src/
Expand Down
4 changes: 1 addition & 3 deletions build/ksdk1.1/build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/bin/sh

# Uncomment this to set ARMGCC_DIR correctly: export ARMGCC_DIR=<full path to arm-gcc directory>

export ARMGCC_DIR=/Users/jamesmeech/Desktop/bare-metal-arm/gcc-arm-none-eabi-4_8-2014q1
mkdir -p work
mkdir -p work/boards/Warp
mkdir -p work/demos/Warp/src
Expand Down
3 changes: 2 additions & 1 deletion src/boot/ksdk1.1.0/CMakeLists-Glaux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ ADD_EXECUTABLE(Glaux
"${ProjDirPath}/../../src/errstrsEN.c"
"${ProjDirPath}/../../src/powermodes.c"
"${ProjDirPath}/../../src/devIS25xP.c"
"${ProjDirPath}/../../src/devBME680.c"
"${ProjDirPath}/../../src/devBME680.c"
"${ProjDirPath}/../../src/devRF430CL331H.c"
"${ProjDirPath}/../../src/devRV8803C7.c"
"${ProjDirPath}/../../src/SEGGER_RTT.c"
"${ProjDirPath}/../../src/SEGGER_RTT_printf.c"
Expand Down
86 changes: 54 additions & 32 deletions src/boot/ksdk1.1.0/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@
#include "SEGGER_RTT.h"



#define kWarpConstantStringI2cFailure "\rI2C failed, reg 0x%02x, code %d\n"
#define kWarpConstantStringErrorInvalidVoltage "\rInvalid supply voltage [%d] mV!"
#define kWarpConstantStringErrorSanity "\rSanity check failed!"


#if (WARP_BUILD_ENABLE_DEVADXL362)
#include "devADXL362.h"
volatile WarpSPIDeviceState deviceADXL362State;
Expand Down Expand Up @@ -136,6 +136,11 @@
volatile uint8_t deviceBME680CalibrationValues[kWarpSizesBME680CalibrationValuesCount];
#endif

#if (WARP_BUILD_ENABLE_DEVRF430CL331H)
#include "devRF430CL331H.h"
volatile WarpI2CDeviceState deviceRF430CL331HState;
#endif

#if (WARP_BUILD_ENABLE_DEVTCS34725)
#include "devTCS34725.h"
volatile WarpI2CDeviceState deviceTCS34725State;
Expand Down Expand Up @@ -1630,8 +1635,7 @@ main(void)
#endif

#if (WARP_BUILD_ENABLE_DEVBME680)
// initBME680( 0x77 /* i2cAddress */, &deviceBME680State, kWarpDefaultSupplyVoltageMillivoltsBME680 );
initBME680( 0x77 /* i2cAddress */, kWarpDefaultSupplyVoltageMillivoltsBME680 );
initBME680( 0x77 /* i2cAddress */, &deviceBME680State);
#endif

#if (WARP_BUILD_ENABLE_DEVTCS34725)
Expand Down Expand Up @@ -1887,7 +1891,7 @@ main(void)
}

warpScaleSupplyVoltage(3300);
printAllSensors(true /* printHeadersAndCalibration */, true /* hexModeFlag */, 0 /* menuDelayBetweenEachRun */, true /* loopForever */);
//printAllSensors(true /* printHeadersAndCalibration */, true /* hexModeFlag */, 0 /* menuDelayBetweenEachRun */, true /* loopForever */);
/*
* Notreached
*/
Expand Down Expand Up @@ -1987,34 +1991,52 @@ main(void)
warpDisableI2Cpins();

warpPrint("About to loop with printSensorDataBME680()...\n");
while (1)
{
blinkLED(kGlauxPinLED);
for (int i = 0; i < kGlauxSensorRepetitionsPerSleepIteration; i++)
{
printAllSensors(true /* printHeadersAndCalibration */, true /* hexModeFlag */, 0 /* menuDelayBetweenEachRun */, true /* loopForever */);
}

warpPrint("About to configureSensorBME680() for sleep...\n");
status = configureSensorBME680( 0b00000000, /* payloadCtrl_Hum: Sleep */
0b00000000, /* payloadCtrl_Meas: No temperature samples, no pressure samples, sleep */
0b00001000 /* payloadGas_0: Turn off heater */
);
if (status != kWarpStatusOK)
{
warpPrint("configureSensorBME680() failed...\n");
}
warpDisableI2Cpins();
blinkLED(kGlauxPinLED);

warpPrint("About to go into VLLS0 for 30 (was 60*60) seconds (will reset afterwords)...\n");
status = warpSetLowPowerMode(kWarpPowerModeVLLS0, kGlauxSleepSecondsBetweenSensorRepetitions /* sleep seconds */);
if (status != kWarpStatusOK)
{
warpPrint("warpSetLowPowerMode(kWarpPowerModeVLLS0, 10)() failed...\n");
}
warpPrint("Should not get here...");
}

WarpStatus i2cReadStatus;
initRF430CL331H(0b00011111);
while(1){

//i2cReadStatus = readSensorRegisterRF430CL331H(0xFF,0xFC, 2);
//uint8_t readSensorRegisterValueMSB = deviceRF430CL331HState.i2cBuffer[0];
//uint8_t readSensorRegisterValueLSB = deviceRF430CL331HState.i2cBuffer[1];
//uint16_t readSensorRegisterValueCombined = ((readSensorRegisterValueMSB & 0xFF) << 8) | (readSensorRegisterValueLSB & 0xFF);
//warpPrint("\r\n\t[0x%02x].\n", readSensorRegisterValueCombined);
i2cReadStatus = writeSensorRegisterRF430CL331H(0xFF, 0xE0, 0x004E);
warpPrint("\nDelay\n");
i2cReadStatus = readSensorRegisterRF430CL331H(0xFF, 0xE0, 2);
uint8_t readSensorRegisterValueMSB = deviceRF430CL331HState.i2cBuffer[0];
uint8_t readSensorRegisterValueLSB = deviceRF430CL331HState.i2cBuffer[1];
uint16_t readSensorRegisterValueCombined = ((readSensorRegisterValueMSB & 0xFF) << 8) | (readSensorRegisterValueLSB & 0xFF);
warpPrint("\r\n\t[0x%04x].\n", readSensorRegisterValueCombined);
}
//while (1)
//{
//blinkLED(kGlauxPinLED);
//for (int i = 0; i < kGlauxSensorRepetitionsPerSleepIteration; i++)
//{
//printAllSensors(true /* printHeadersAndCalibration */, true /* hexModeFlag */, 0 /* menuDelayBetweenEachRun */, true /* loopForever */);
//}

//warpPrint("About to configureSensorBME680() for sleep...\n");
//status = configureSensorBME680( 0b00000000, /* payloadCtrl_Hum: Sleep */
//0b00000000, /* payloadCtrl_Meas: No temperature samples, no pressure samples, sleep */
//0b00001000 /* payloadGas_0: Turn off heater */
//);
//if (status != kWarpStatusOK)
//{
//warpPrint("configureSensorBME680() failed...\n");
//}
//warpDisableI2Cpins();
//blinkLED(kGlauxPinLED);

//warpPrint("About to go into VLLS0 for 30 (was 60*60) seconds (will reset afterwards)...\n");
//status = warpSetLowPowerMode(kWarpPowerModeVLLS0, kGlauxSleepSecondsBetweenSensorRepetitions /* sleep seconds */);
//if (status != kWarpStatusOK)
//{
//warpPrint("warpSetLowPowerMode(kWarpPowerModeVLLS0, 10)() failed...\n");
//}
//warpPrint("Should not get here...");
//}
#endif

while (1)
Expand Down
5 changes: 3 additions & 2 deletions src/boot/ksdk1.1.0/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
#define WARP_BUILD_ENABLE_DEVAS7263 0
#define WARP_BUILD_ENABLE_DEVBGX 0
#define WARP_BUILD_ENABLE_DEVBME680 1
#define WARP_BUILD_ENABLE_DEVRF430CL331H 1
#define WARP_BUILD_ENABLE_DEVBMX055 0
#define WARP_BUILD_ENABLE_DEVCCS811 0
#define WARP_BUILD_ENABLE_DEVHDC1000 0
Expand All @@ -85,7 +86,7 @@
#define WARP_BUILD_ENABLE_DEVAS7262 0
#define WARP_BUILD_ENABLE_DEVAS7263 0
#define WARP_BUILD_ENABLE_DEVBGX 0
#define WARP_BUILD_ENABLE_DEVBME680 0
#define WARP_BUILD_ENABLE_DEVBME680 1
#define WARP_BUILD_ENABLE_DEVBMX055 0
#define WARP_BUILD_ENABLE_DEVCCS811 0
#define WARP_BUILD_ENABLE_DEVHDC1000 0
Expand All @@ -110,7 +111,7 @@
#define WARP_BUILD_ENABLE_DEVAS7262 0
#define WARP_BUILD_ENABLE_DEVAS7263 0
#define WARP_BUILD_ENABLE_DEVBGX 1
#define WARP_BUILD_ENABLE_DEVBME680 0
#define WARP_BUILD_ENABLE_DEVBME680 1
#define WARP_BUILD_ENABLE_DEVBMX055 0
#define WARP_BUILD_ENABLE_DEVCCS811 0
#define WARP_BUILD_ENABLE_DEVHDC1000 0
Expand Down
138 changes: 138 additions & 0 deletions src/boot/ksdk1.1.0/devRF430CL331H.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
Authored 2022. James T. Meech.

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

* Redistributions of source code must retain the above
copyright notice, this list of conditions and the following
disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.

* Neither the name of the author nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior written
permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdlib.h>

/*
* config.h needs to come first
*/
#include "config.h"

#include "fsl_misc_utilities.h"
#include "fsl_device_registers.h"
#include "fsl_i2c_master_driver.h"
#include "fsl_spi_master_driver.h"
#include "fsl_rtc_driver.h"
#include "fsl_clock_manager.h"
#include "fsl_power_manager.h"
#include "fsl_mcglite_hal.h"
#include "fsl_port_hal.h"

#include "gpio_pins.h"
#include "SEGGER_RTT.h"
#include "warp.h"


extern volatile uint32_t gWarpI2cBaudRateKbps;
extern volatile uint32_t gWarpI2cTimeoutMilliseconds;
extern volatile uint32_t gWarpSupplySettlingDelayMilliseconds;
extern volatile WarpI2CDeviceState deviceRF430CL331HState;

void
initRF430CL331H(const uint8_t i2cAddress)
{
deviceRF430CL331HState.i2cAddress = i2cAddress;
return;
}

WarpStatus
readSensorRegisterRF430CL331H(uint8_t deviceRegisterMSB, uint8_t deviceRegisterLSB, int numberOfBytes)
{
uint8_t cmdBuf[2] = {0xFF, 0xFF};
i2c_status_t status;

i2c_device_t slave =
{
.address = deviceRF430CL331HState.i2cAddress,
.baudRate_kbps = kWarpDefaultI2cBaudRateKbps};

cmdBuf[0] = deviceRegisterMSB;
cmdBuf[1] = deviceRegisterLSB;

warpEnableI2Cpins();
status = I2C_DRV_MasterReceiveDataBlocking(
0 /* I2C peripheral instance */,
&slave,
cmdBuf,
2,
(uint8_t *)deviceRF430CL331HState.i2cBuffer,
numberOfBytes,
kWarpDefaultI2cTimeoutMilliseconds);

if (status != kStatus_I2C_Success)
{
warpPrint("Communication failed: %d\n", status);
return kWarpStatusDeviceCommunicationFailed;
}

return kWarpStatusOK;
}

WarpStatus
writeSensorRegisterRF430CL331H(uint8_t deviceRegisterMSB, uint8_t deviceRegisterLSB, uint16_t payload)
{
uint8_t payloadByte[2], commandByte[2];
i2c_status_t returnValue;

i2c_device_t slave =
{
.address = deviceRF430CL331HState.i2cAddress,
.baudRate_kbps = gWarpI2cBaudRateKbps
};

warpEnableI2Cpins();

commandByte[0] = deviceRegisterMSB;
commandByte[1] = deviceRegisterLSB;
payloadByte[0] = (payload>>8) & 0xFF; /* MSB first */
payloadByte[1] = payload & 0xFF; /* LSB */

returnValue = I2C_DRV_MasterSendDataBlocking(
0 /* I2C instance */,
&slave,
commandByte,
2,
payloadByte,
2,
1000);
if (returnValue != kStatus_I2C_Success)
{
return kWarpStatusDeviceCommunicationFailed;
}

return kWarpStatusOK;
}

43 changes: 43 additions & 0 deletions src/boot/ksdk1.1.0/devRF430CL331H.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
Authored 2022. James T. Meech.

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

* Redistributions of source code must retain the above
copyright notice, this list of conditions and the following
disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.

* Neither the name of the author nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior written
permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/

void
initRF430CL331H(const uint8_t i2cAddress);
WarpStatus
readSensorRegisterRF430CL331H(uint8_t deviceRegisterMSB, uint8_t deviceRegisterLSB, int numberOfBytes);
WarpStatus
writeSensorRegisterRF430CL331H(uint8_t deviceRegisterMSB, uint8_t deviceRegisterLSB, uint16_t payload);
Loading