Skip to content
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

develop_FW-871 Standalone SPI project for openmote-B #505

Open
wants to merge 52 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
2a5ed88
develop_FW-871
dalilox Mar 27, 2020
fa96403
testing modification
dalilox Mar 27, 2020
672a874
New modification concerning the GPIOs that will be used as SSI1. Thes…
dalilox Apr 2, 2020
93c5856
New modified comments
dalilox Apr 8, 2020
4f52a5d
New modified code wit new comments
dalilox Apr 8, 2020
7a66998
New modified code with new comments
dalilox Apr 9, 2020
641f981
New modified code with new comments
dalilox Apr 14, 2020
a4ee275
New modified code with new comments
dalilox Apr 14, 2020
9b00664
Calling spi_txrx function
dalilox Apr 15, 2020
fb9e8f8
Modifying
dalilox Apr 15, 2020
d7eda8a
Modifying spi_txrx function
dalilox Apr 15, 2020
2ff37d8
Changing location of the folder
dalilox Apr 16, 2020
2b09bc6
Including the IAR project
dalilox Apr 21, 2020
4f499b6
Including IAR files
dalilox Apr 21, 2020
c845bd2
modification new commit
dalilox Apr 21, 2020
5a153b0
new commit
dalilox Apr 21, 2020
36bbcaf
new commit
dalilox Apr 21, 2020
e2ddc59
IAR project update
dalilox Apr 21, 2020
53dbbc1
New commit to push the code
dalilox Apr 28, 2020
07ad22f
FW-871 merging with develop branch
dalilox Apr 28, 2020
2bceeba
Final CODE communicating with LoRa shield
dalilox May 12, 2020
9911a15
Final code communicating with LoRa shield
dalilox May 12, 2020
09c1ac8
Merge branch 'develop_FW-871' of https://github.com/daloul44/openwsn-…
dalilox May 12, 2020
fabf6b8
SPI LoRa transmission part
dalilox May 20, 2020
64a6c39
Lora DRIVER implementation
dalilox May 29, 2020
fd2e46d
LoRa driver cleaning files
dalilox Jun 2, 2020
1ed04f2
Changing Lora modes
dalilox Jun 10, 2020
1a5fb6f
sx1276 header and source files
dalilox Jun 10, 2020
5a3b078
Adding files of defined functions
dalilox Jun 10, 2020
361949f
Customizing all radio mode functions
dalilox Jun 12, 2020
ec49df6
Multiple mode Radio functions
dalilox Jun 16, 2020
535234b
Functions and interruptions
dalilox Jun 24, 2020
8f6d497
New modified version
dalilox Jul 2, 2020
b05e812
Active Loop section
dalilox Jul 2, 2020
2b25561
Adding interrupts TX RX CRC
dalilox Jul 6, 2020
266e15e
fixing FiFo exercice
dalilox Jul 10, 2020
eba8589
Fix exercise
dalilox Jul 10, 2020
65a5359
fix Fifo exercise
dalilox Jul 10, 2020
6501779
fix FIFO exercise
dalilox Jul 10, 2020
ed5d2a1
Sending multiple bytes
dalilox Jul 15, 2020
f3b1c9c
Wrinting and reading multiple bytes
dalilox Jul 15, 2020
41e86a9
Code cleaned adding different functions
dalilox Jul 16, 2020
04614bd
Modification of functions
dalilox Jul 31, 2020
3e652ed
Modified version Reading multiple bytes
dalilox Aug 24, 2020
a0784ed
Modified version
dalilox Aug 24, 2020
357c168
Multiple bytes
dalilox Aug 25, 2020
a254336
Testing LoRa transmission
dalilox Aug 26, 2020
1673da6
Modified transmission version
dalilox Aug 26, 2020
23f538d
Reset the flags to 0
dalilox Aug 27, 2020
2139b88
Sending LoRa buffer
dalilox Aug 27, 2020
cc7560b
Testing receive part
dalilox Aug 28, 2020
760cdf8
TESTING reception
dalilox Aug 28, 2020
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
2 changes: 1 addition & 1 deletion bsp/boards/openmote-b/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void board_init(void) {
uart_init();
radio_init();
i2c_init();
sensors_init();
//sensors_init();
cryptoengine_init();
}

Expand Down
18 changes: 9 additions & 9 deletions bsp/boards/openmote-b/sensors.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "board.h"
#include "sensors.h"

#include "si70x.h"
//#include "si70x.h"

//=========================== defines =========================================

Expand All @@ -25,7 +25,7 @@ sensors_vars_t sensors_vars;
/**
\brief Initialize sensors on the board
*/
void sensors_init(void) {
/*void sensors_init(void) {

memset(&sensors_vars,0,sizeof(sensors_vars_t));

Expand All @@ -38,23 +38,23 @@ void sensors_init(void) {
adc_sensor_init();
sensors_vars.sensorsTypes[SENSOR_ADCTEMPERATURE] = 1;

}
}*/

/**
\brief Returns a bool value indicating if a given sensor is present
\param[in] sensorType sensor type polled.
\param[out] returnVal presence of the sensor.
*/
bool sensors_is_present(uint8_t sensorType) {
/*bool sensors_is_present(uint8_t sensorType) {
return sensors_vars.sensorsTypes[sensorType];
}
}*/

/**
\brief Returns the callback for reading data from a given sensor
\param[in] sensorType sensor type used to associate the callback.
\param[out] callback for reading data.
*/
callbackRead_cbt sensors_getCallbackRead(uint8_t sensorType) {
/*callbackRead_cbt sensors_getCallbackRead(uint8_t sensorType) {

switch (sensorType) {
case SENSOR_TEMPERATURE:
Expand All @@ -67,14 +67,14 @@ callbackRead_cbt sensors_getCallbackRead(uint8_t sensorType) {
return NULL;
}

}
}*/

/**
\brief Returns the callback for converting data from a given sensor
\param[in] sensorType sensor type used to associate the callback.
\param[out] callback for converting data.
*/
callbackConvert_cbt sensors_getCallbackConvert(uint8_t sensorType) {
/*callbackConvert_cbt sensors_getCallbackConvert(uint8_t sensorType) {

switch (sensorType) {
case SENSOR_TEMPERATURE:
Expand All @@ -87,6 +87,6 @@ callbackConvert_cbt sensors_getCallbackConvert(uint8_t sensorType) {
return NULL;
}

}
}*/

//=========================== private =========================================
2 changes: 1 addition & 1 deletion bsp/boards/openmote-b/startup_iar.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ lockPageCCA_t;

__root const lockPageCCA_t __cca @ ".flashcca" =
{
BOOTLOADER_BACKDOOR_ENABLE, // Bootloader backdoor disabled
BOOTLOADER_BACKDOOR_DISABLE, // Bootloader backdoor disabled
0, // Image valid bytes
FLASH_START_ADDR // Vector table located at flash start address
};
Expand Down
264 changes: 264 additions & 0 deletions bsp/chips/sx1276/def_spitxrx.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
/**
\brief definition of the "spi" bsp module.
\author Xavier Vilajosana <[email protected]>, September 2017.
*/
#include "board.h"
#include "board_info.h"
#include "ssi.h"
#include "spi.h"
#include "gpio.h"
#include "ioc.h"
#include "sys_ctrl.h"

#include <headers/hw_ints.h>
#include <headers/hw_ioc.h>
#include <headers/hw_memmap.h>
#include <headers/hw_ssi.h>
#include <headers/hw_sys_ctrl.h>
#include <headers/hw_types.h>

#include <math.h>
#include <string.h>
#include "radio_sx1276.h"
#include "sx1276Regs-LoRa.h"


//=========================== variables =======================================

typedef struct {
// information about the current transaction
uint8_t* pNextTxByte;
uint16_t numTxedBytes;
uint16_t txBytesLeft;
spi_return_t returnType;
uint8_t* pNextRxByte;
uint16_t maxRxBytes;
spi_first_t isFirst;
spi_last_t isLast;
// state of the module
uint8_t busy;
#ifdef SPI_IN_INTERRUPT_MODE
// callback when module done
spi_cbt callback;
#endif
} spi_vars_t;

spi_vars_t spi_vars;


//=========================== defines =========================================
#define SPI_PIN_SSI_CLK GPIO_PIN_0 // CLK
#define SPI_PIN_SSI_FSS GPIO_PIN_1 // CSn
#define SPI_PIN_SSI_RX GPIO_PIN_2 // MISO
#define SPI_PIN_SSI_TX GPIO_PIN_3 // MOSI
#define SPI_GPIO_SSI_BASE GPIO_B_BASE

//=========================== public ==========================================

//uint8_t spi_tx_buffer[2];
//uint8_t spi_rx_buffer[2];

void spi_init(){

// clear variables
memset(&spi_vars,0,sizeof(spi_vars_t));

//Set the CLK , MOSI(TX) and MISO(RX) pins as Hardware-controlled (Configures GPIO_AFSEL-->1)
GPIOPinTypeSSI(SPI_GPIO_SSI_BASE, SPI_PIN_SSI_CLK );
GPIOPinTypeSSI(SPI_GPIO_SSI_BASE, SPI_PIN_SSI_RX );
GPIOPinTypeSSI(SPI_GPIO_SSI_BASE, SPI_PIN_SSI_TX );

//Set the SS pin as Software-controlled outputs (configures GPIO_AFSEL-->0 (software) and GPIO_DIR-->1 (Output) )
//Only FSS can be used as SOFTWARE controlled OUTPUT
GPIOPinTypeGPIOOutput(SPI_GPIO_SSI_BASE, SPI_PIN_SSI_FSS);

//Set SS to High (writes into GPIO_DATA register)
GPIOPinWrite(SPI_GPIO_SSI_BASE, SPI_PIN_SSI_FSS, SPI_PIN_SSI_FSS);

//Configuration of SSI1 peripheral
SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_SSI1);
SysCtrlPeripheralSleepEnable(SYS_CTRL_PERIPH_SSI1);
SysCtrlPeripheralDeepSleepDisable(SYS_CTRL_PERIPH_SSI1);

//Disabling SSI (writes into SSI_CR1 --> 0)
SSIDisable(SSI1_BASE);

//Set clock source (The baud clock source for the SSI to select.)
SSIClockSourceSet(SSI1_BASE, SSI_CLOCK_PIOSC); //The precision internal oscillator

//Configure output signal to IOC_Pxx_SEL register
//Each signal is identified with its address table 9.1 in T.I datasheet
IOCPinConfigPeriphOutput(SPI_GPIO_SSI_BASE, SPI_PIN_SSI_CLK, IOC_MUX_OUT_SEL_SSI1_CLKOUT);
IOCPinConfigPeriphOutput(SPI_GPIO_SSI_BASE, SPI_PIN_SSI_TX, IOC_MUX_OUT_SEL_SSI1_TXD);
IOCPinConfigPeriphOutput(SPI_GPIO_SSI_BASE, SPI_PIN_SSI_FSS, IOC_MUX_OUT_SEL_SSI1_FSSOUT);
//Configures hardware peripheral input selection (i.e. IOC_SSIRXD_SSI1)
IOCPinConfigPeriphInput(SPI_GPIO_SSI_BASE, SPI_PIN_SSI_RX, IOC_SSIRXD_SSI1);


//Sets SSI_CR0 (SPI MODE and Data Size), SSI_CR1(Protocol -- Master/Slave), SSI_CPSR(Clock prescaler divisor)
//According to the LoRaSX1276 datasheet, the corresponding mode is CPOL=0 , CPHA=0 which is FRF mode 0
SSIConfigSetExpClk(SSI1_BASE, SysCtrlIOClockGet(), SSI_FRF_MOTO_MODE_0, SSI_MODE_MASTER, SysCtrlIOClockGet()/200 /*16000000*/, 8);

//Enable the SSI1 module(writes into CR1)
SSIEnable(SSI1_BASE);

//spi_tx_buffer[0] = 0x42;
//spi_tx_buffer[1] = 0xFF;

//spi_tx_buffer[0] = 0x81;
//spi_tx_buffer[1] = 0x80;

//spi_tx_buffer[0] = REG_LR_OPMODE | (1 << 7);
//spi_tx_buffer[1] = 0x81;

// =========== Call the spi_txrx function =============

//spi_txrx(spi_tx_buffer, sizeof(spi_tx_buffer),SPI_FIRSTBYTE,spi_rx_buffer,sizeof(spi_rx_buffer),SPI_FIRST,SPI_LAST);

//sx1276_spiWriteReg( REG_LR_OPMODE, 0x80);

/*SX1276SetSleep();
SX1276SetStby();
SX1276SetFstx();
SX1276SetTx();
SX1276SetFsrx();
SX1276SetRxContinuous();
SX1276SetRxSingle();*/

//SX1276SetSleep();
//SX1276SetStby();
//exercice();
//=========== Calling LoRa process transmission function ================
while(1) sx1276Receive();
//sx1276Send();
/*GPIOPinTypeGPIOOutput(GPIO_A_BASE, GPIO_PIN_7);
GPIOPinWrite(GPIO_A_BASE, GPIO_PIN_7, 0);


GPIOPinWrite(GPIO_A_BASE, GPIO_PIN_7, 1);*/

//====================== End LoRa process ================================
}

//======================= SPI TX_RX definition ===========================

void spi_txrx(uint8_t* bufTx,
uint16_t lenbufTx,
spi_return_t returnType,
uint8_t* bufRx,
uint16_t maxLenBufRx,
spi_first_t isFirst,
spi_last_t isLast) {

uint32_t data,i;
GPIOPinWrite(GPIO_C_BASE, GPIO_PIN_3, GPIO_PIN_3);
// register spi frame to send
spi_vars.pNextTxByte = bufTx;
spi_vars.numTxedBytes = 0;
spi_vars.txBytesLeft = lenbufTx;
spi_vars.returnType = returnType;
spi_vars.pNextRxByte = bufRx;
spi_vars.maxRxBytes = maxLenBufRx;
spi_vars.isFirst = isFirst;
spi_vars.isLast = isLast;

// SPI is now busy
spi_vars.busy = 1;

// lower CS signal to have slave listening (FSS is managed through software, not hardware)
if (spi_vars.isFirst==SPI_FIRST) {
GPIOPinWrite(SPI_GPIO_SSI_BASE, SPI_PIN_SSI_FSS, 0);
}

for ( i = 0; i < lenbufTx; i++)
{
// Push a byte
SSIDataPut(SSI1_BASE, spi_vars.pNextTxByte[i]);

// Wait until it is complete
while(SSIBusy(SSI1_BASE));

// Read a byte
SSIDataGet(SSI1_BASE, &data);

// Store the result
spi_vars.pNextRxByte[i] = (uint8_t)(data & 0xFF);
// one byte less to go
}

if (spi_vars.isLast==SPI_LAST) {
GPIOPinWrite(SPI_GPIO_SSI_BASE, SPI_PIN_SSI_FSS, SPI_PIN_SSI_FSS);
}

// SPI is not busy anymore
spi_vars.busy = 0;
GPIOPinWrite(GPIO_C_BASE, GPIO_PIN_3, 0);
}

#ifdef SPI_IN_INTERRUPT_MODE
void spi_setCb(spi_cbt cb) {
spi_vars.spi_cb = cb;
}
#endif

//=========================== private =========================================

port_INLINE void enableInterrupts(void)
{
// Enable the SPI interrupt
SSIIntEnable(SSI1_BASE, (SSI_TXFF | SSI_RXFF | SSI_RXTO | SSI_RXOR));

// Enable the SPI interrupt
IntEnable(INT_SSI1);
}

port_INLINE void disableInterrupts(void)
{
// Disable the SPI interrupt
SSIIntDisable(SSI1_BASE, (SSI_TXFF | SSI_RXFF | SSI_RXTO | SSI_RXOR));

// Disable the SPI interrupt
IntDisable(INT_SSI1);
}

//=========================== interrupt handlers ==============================

kick_scheduler_t spi_isr() {
#ifdef SPI_IN_INTERRUPT_MODE
uint32_t data;
// save the byte just received in the RX buffer
status = SSIIntStatus(SSI1_BASE, true);

// Clear SPI interrupt in the NVIC
IntPendClear(INT_SSI1);

SSIDataGet(SSI1_BASE, &data);

// Store the result
spi_vars.pNextRxByte = (uint8_t)(data & 0xFF);

// one byte less to go
spi_vars.pNextTxByte++;
spi_vars.pNextRxByte++;
spi_vars.txBytesLeft--;

if (spi_vars.txBytesLeft>0) {
// write next byte to TX buffer
SSIDataPut(SSI1_BASE, *spi_vars.pNextTxByte);

} else {
// SPI is not busy anymore
spi_vars.busy = 0;

// SPI is done!
if (spi_vars.callback!=NULL) {
// call the callback
spi_vars.spi_cb();
// kick the OS
return KICK_SCHEDULER;
}
}

#endif
return DO_NOT_KICK_SCHEDULER;
}
24 changes: 24 additions & 0 deletions bsp/chips/sx1276/def_spitxrx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <math.h>
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
#include "spi.h"


//=========================== prototypes ======================================
static void disableInterrupts(void);
static void enableInterrupts(void);


void spi_init();

void spi_txrx(uint8_t* bufTx,
uint16_t lenbufTx,
spi_return_t returnType,
uint8_t* bufRx,
uint16_t maxLenBufRx,
spi_first_t isFirst,
spi_last_t isLast);



Loading