河北水利局项目

This commit is contained in:
2025-12-15 16:07:49 +08:00
commit f11a7c2b95
1146 changed files with 452892 additions and 0 deletions

885
APP/hal_radio.c Normal file
View File

@@ -0,0 +1,885 @@
/**
******************************************************************************
* @file hal_radio.c
* @author William Liang
* @version V1.0.0
* @date 09/10/2013
* @brief This file contains the initialization and handle of the radio frequency.
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include <string.h>
#include <stdlib.h>
#include "hal_radio.h"
#include "uart.h"
#include "Rtc.h"
#include "sx1276-LoRa.h"
#include "sx1276-Fsk.h"
#include "apl.h"
/*****************************************************************************
Prototype : spiReadWriteByte
Description : spi basic function
Input : u8 data
Output : None
Return Value :
Date : 2014/3/15
Author : Barry
*****************************************************************************/
u8 spiReadWriteByte(u8 data)
{
while(SPI_I2S_GetFlagStatus(sRF_SPI,SPI_I2S_FLAG_TXE)==RESET);
SPI_I2S_SendData(sRF_SPI, data);
while(SPI_I2S_GetFlagStatus(sRF_SPI,SPI_I2S_FLAG_RXNE)==RESET);
return (u8)(SPI_I2S_ReceiveData(sRF_SPI));
}
/*****************************************************************************
Prototype : SX1276WriteBuffer
Description : spi write buffer
Input : uint8_t addr
uint8_t *buffer
uint8_t size
Output : None
Return Value :
Date : 2014/3/15
Author : Barry
*****************************************************************************/
void SX1276WriteBuffer( uint8_t addr, uint8_t *buffer, uint8_t size )
{
sRF_CS_LOW();
spiReadWriteByte(addr|0x80);
for(u8 i = 0;i < size; i++)
{
spiReadWriteByte(buffer[i]);
}
sRF_CS_HIGH();
}
/*****************************************************************************
Prototype : SX1276ReadBuffer
Description : none
Input : uint8_t addr
uint8_t *buffer
uint8_t size
Output : None
Return Value :
Date : 2014/3/15
Author : Barry
*****************************************************************************/
void SX1276ReadBuffer( uint8_t addr, uint8_t *buffer, uint8_t size )
{
sRF_CS_LOW();
spiReadWriteByte(addr);
for(u8 i = 0;i < size; i++)
{
buffer[i] = spiReadWriteByte(0xFF);
}
sRF_CS_HIGH();
}
/*****************************************************************************
Prototype : SX1276Write
Description : 1276 write Reg
Input : uint8_t addr
uint8_t data
Output : None
Return Value :
Date : 2014/3/15
Author : Barry
*****************************************************************************/
void SX1276Write( uint8_t addr, uint8_t data )
{
SX1276WriteBuffer( addr, &data, 1 );
}
/*****************************************************************************
Prototype : SX1276Read
Description : 1276 read Reg
Input : uint8_t addr
uint8_t *data
Output : None
Return Value :
Date : 2014/3/15
Author : Barry
*****************************************************************************/
void SX1276Read( uint8_t addr, uint8_t *data )
{
SX1276ReadBuffer( addr, data, 1 );
}
/*****************************************************************************
Prototype : SX1276WriteFifo
Description : none
Input : uint8_t *buffer
uint8_t size
Output : None
Return Value :
Date : 2014/3/15
Author : Barry
*****************************************************************************/
void SX1276WriteFifo( uint8_t *buffer, uint8_t size )
{
SX1276WriteBuffer( sRF_FIFO_ARRD, buffer, size );
}
/*****************************************************************************
Prototype : SX1276ReadFifo
Description : none
Input : uint8_t *buffer
uint8_t size
Output : None
Return Value :
Date : 2014/3/15
Author : Barry
*****************************************************************************/
void SX1276ReadFifo( uint8_t *buffer, uint8_t size )
{
SX1276ReadBuffer( sRF_FIFO_ARRD, buffer, size );
}
/*****************************************************************************
* Function : SX1276Reset
* Description : none
* Input : void
* Output : None
* Return :
* Others :
* Record
* 1.Date : 20170307
* Author : barry
* Modification: Created function
*****************************************************************************/
#define get_sys_time() xTaskGetTickCount()*portTICK_RATE_MS
void SX1276Reset(void)
{
u32 startTick;
GPIO_InitTypeDef GPIO_InitStructure;
hal_DIOx_ITConfig(all, DISABLE);
RCC_APB2PeriphClockCmd(sRF_RESET_SCK, ENABLE);
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = sRF_RESET_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init( sRF_RESET_PORT, &GPIO_InitStructure );
GPIO_ResetBits( sRF_RESET_PORT, sRF_RESET_PIN);
startTick = get_sys_time( );
while( get_sys_time( ) < ( startTick + 2 ));
GPIO_SetBits( sRF_RESET_PORT, sRF_RESET_PIN );
startTick = get_sys_time( );
while( get_sys_time( ) < ( startTick + 6 ));
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = sRF_RESET_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init( sRF_RESET_PORT, &GPIO_InitStructure );
hal_sRF_ClearAllRF_IT();
}
/*****************************************************************************
Prototype : hal_sRF_ITConfig
Description : none
Input : en_GDOx_IrqLine irqLine
FunctionalState NewState
Output : None
Return Value :
Date : 2014/3/15
Author : Barry
*****************************************************************************/
void hal_sRF_ITConfig(uint32_t irqLine, FunctionalState NewState)
{
EXTI_InitTypeDef EXTI_InitStructure;
EXTI_InitStructure.EXTI_Line = irqLine;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = NewState;
EXTI_Init(&EXTI_InitStructure);
}
/*****************************************************************************
* Function : hal_sRF_FSK_ITConfig
* Description : none
* Input : uint32_t irqLine
FunctionalState NewState
* Output : None
* Return :
* Others :
* Record
* 1.Date : 20170418
* Author : barry
* Modification: Created function
*****************************************************************************/
void hal_sRF_FSK_ITConfig( uint32_t irqLine, FunctionalState NewState)
{
EXTI_InitTypeDef EXTI_InitStructure;
if (NewState == ENABLE)
{
EXTI_ClearITPendingBit(irqLine);
}
EXTI_InitStructure.EXTI_Line = irqLine;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = NewState;
EXTI_Init(&EXTI_InitStructure);
if (NewState == DISABLE)
{
EXTI_ClearITPendingBit(irqLine);
}
}
/*****************************************************************************
* Function : hal_sRF_ClearAllRF_IT
* Description : none
* Input : void
* Output : None
* Return :
* Others :
* Record
* 1.Date : 20170418
* Author : barry
* Modification: Created function
*****************************************************************************/
void hal_sRF_ClearAllRF_IT(void)
{
EXTI_ClearITPendingBit(DIO0_IRQ);
EXTI_ClearITPendingBit(DIO1_IRQ);
EXTI_ClearITPendingBit(DIO2_IRQ);
EXTI_ClearITPendingBit(DIO3_IRQ);
}
/*****************************************************************************
Prototype : hal_Init_RF_pins
Description : none
Input : void
Output : None
Return Value :
Date : 2014/3/15
Author : Barry
*****************************************************************************/
void hal_Init_RF_pins(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(sRF_CS_GPIO_CLK | sRF_SPI_MOSI_GPIO_CLK | sRF_SPI_MISO_GPIO_CLK |
sRF_SPI_SCK_GPIO_CLK | sRF_DIOx_SCK | sRF_RESET_SCK | sRF_DIO4_SCK, ENABLE);
hal_DIOx_ITConfig(all,DISABLE);
hal_sRF_ClearAllRF_IT();
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = sRF_RESET_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init( sRF_RESET_PORT, &GPIO_InitStructure );
/*!< Configure sRF_SPI pins: SCK */
GPIO_InitStructure.GPIO_Pin = sRF_SPI_SCK_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(sRF_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
/*!< Configure sRF_SPI pins: MOSI */
GPIO_InitStructure.GPIO_Pin = sRF_SPI_MOSI_PIN;
GPIO_Init(sRF_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
/*!< Configure sRF_SPI pins: MISO */
GPIO_InitStructure.GPIO_Pin = sRF_SPI_MISO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(sRF_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
/*!< Configure sRF_CS_PIN pin: sRF CS pin */
GPIO_InitStructure.GPIO_Pin = sRF_CS_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(sRF_CS_GPIO_PORT, &GPIO_InitStructure);
/*!< Configure sRF_IRQ_PINs pin: DDO0~GDO5 */
GPIO_InitStructure.GPIO_Pin = sRF_DIO0_PIN | sRF_DIO1_PIN | sRF_DIO3_PIN;// | sRF_DIO2_PIN ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(sRF_DIOx_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = sRF_DIO4_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
GPIO_Init(sRF_DIO4_PORT, &GPIO_InitStructure);
/*TX LED pin*/
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = sRF_TX_CTRL_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init( sRF_TX_CTRL_PORT, &GPIO_InitStructure );
}
void hal_Init_RF_int(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Disable sRF_IRQ_EXTI clock */
RCC_APB2PeriphResetCmd(RCC_APB2Periph_AFIO, DISABLE);
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
GPIO_EXTILineConfig(sRF_DIOx_PORT_SOURCE, sRF_DIO0_PIN_SOURCE);
GPIO_EXTILineConfig(sRF_DIOx_PORT_SOURCE, sRF_DIO1_PIN_SOURCE);
//GPIO_EXTILineConfig(sRF_DIOx_PORT_SOURCE, sRF_DIO2_PIN_SOURCE);
GPIO_EXTILineConfig(sRF_DIOx_PORT_SOURCE, sRF_DIO3_PIN_SOURCE);
GPIO_EXTILineConfig(sRF_DIO4_PORT_SOURCE, sRF_DIO4_PIN_SOURCE);
/* Enable AFIO clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
}
/*****************************************************************************
Prototype : hal_sRF_SPI_Config
Description : none
Input : void
Output : None
Return Value :
Date : 2014/3/15
Author : Barry
*****************************************************************************/
void hal_Init_RF_SPI(void)
{
SPI_InitTypeDef SPI_InitStructure;
if (sRF_SPI == SPI1)
{
RCC_APB2PeriphClockCmd(sRF_SPI_CLK, ENABLE);
}
else
{
RCC_APB1PeriphClockCmd(sRF_SPI_CLK, ENABLE);
}
/* Enable sRF SPI DMA clock */
RCC_AHBPeriphClockCmd(sRF_SPI_DMA_CLK, ENABLE);
/*!< Deselect the RF: Chip Select high */
sRF_CS_HIGH();
/* Disable sRF_SPI */
SPI_Cmd(sRF_SPI, DISABLE);
/*!< SPI configuration */
SPI_I2S_DeInit(sRF_SPI);
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(sRF_SPI, &SPI_InitStructure);
/*!< Enable the sRF_SPI */
SPI_Cmd(sRF_SPI, ENABLE);
}
/*****************************************************************************
Prototype : hal_sRF_InitSPI
Description : none
Input : void
Output : None
Return Value :
Date : 2014/3/15
Author : Barry
*****************************************************************************/
void hal_sRF_InitSPI(void)
{
hal_Init_RF_pins();
hal_Init_RF_int();
hal_Init_RF_SPI();
#ifdef SPI_DMA_FIFO
init_SPI_DMA();
#endif
}
/*****************************************************************************
* Function : SX1276_lora_init
* Description : none
* Input : bool lora
* Output : None
* Return :
* Others :
* Record
* 1.Date : 20170320
* Author : barry
* Modification: Created function
*****************************************************************************/
void SX1276_init(bool lora)
{
SX1276Reset();
if (lora)
{
SX1276LoRaInit();
}
else
{
#ifndef USE_LORA_MODE
SX1276FskInit();
#endif
}
}
/*****************************************************************************
Prototype : hal_InitRF
Description : none
Input : void
Output : None
Return Value :
Date : 2014/3/15
Author : Barry
*****************************************************************************/
void hal_InitRF(void)
{
hal_sRF_InitSPI();
#ifdef USE_LORA_MODE
SX1276_init(true);
#else
SX1276_init(false);
#endif
}
#if 0
/*****************************************************************************
Prototype : init_SPI_DMA
Description : none
Input : void
Output : None
Return Value :
Date : 2014/3/15
Author : Barry
*****************************************************************************/
void init_SPI_DMA(void)
{
DMA_InitTypeDef DMA_InitStructure;
/* Enable SPI Rx and Tx request */
SPI_I2S_DMACmd(sRF_SPI, SPI_I2S_DMAReq_Rx | SPI_I2S_DMAReq_Tx, ENABLE);
/* sRF_SPI_DMA_RX_Channel configuration ---------------------------------------------*/
DMA_DeInit(sRF_SPI_DMA_RX_Channel);
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)sRF_SPI_DR_Base;
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)0;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = 0;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(sRF_SPI_DMA_RX_Channel, &DMA_InitStructure);
/* sRF_SPI_DMA_TX_Channel configuration ---------------------------------------------*/
DMA_DeInit(sRF_SPI_DMA_TX_Channel);
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)sRF_SPI_DR_Base;
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)0;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
DMA_InitStructure.DMA_BufferSize = 0;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(sRF_SPI_DMA_TX_Channel, &DMA_InitStructure);
}
/*****************************************************************************
Prototype : hal_sRF_ReadRegister
Description : none
Input : u8 reg
Output : None
Return Value :
Date : 2014/3/15
Author : Barry
*****************************************************************************/
u8 hal_sRF_ReadRegister(u8 reg)
{
if (reg > TOTAL_REGISTER_NUMBER)
{
printf("regsiter input error\r\n");
return 0;
}
/*!< Deselect the Radio: Chip Select high */
sRF_CS_HIGH();
/*!< Select the radio by pulling low the nSEL pin */
sRF_CS_LOW();
/*!< Loop while DR register in not emplty */
while (SPI_I2S_GetFlagStatus(sRF_SPI, SPI_I2S_FLAG_TXE) == RESET);
/*!< Send byte through the SPI1 peripheral */
SPI_I2S_SendData(sRF_SPI, reg);
/*!< Wait to receive a byte */
while (SPI_I2S_GetFlagStatus(sRF_SPI, SPI_I2S_FLAG_RXNE) == RESET);
/* read from the SPI bus */
SPI_I2S_ReceiveData(sRF_SPI);
/*!< Loop while DR register in not emplty */
while (SPI_I2S_GetFlagStatus(sRF_SPI, SPI_I2S_FLAG_TXE) == RESET);
/*!< Send byte through the SPI1 peripheral */
SPI_I2S_SendData(sRF_SPI, sRF_DUMMY_BYTE);
/*!< Wait to receive a byte */
while (SPI_I2S_GetFlagStatus(sRF_SPI, SPI_I2S_FLAG_RXNE) == RESET);
/*!< Return the byte read from the SPI bus */
reg = SPI_I2S_ReceiveData(sRF_SPI);
/*!< Deselect the radio by pulling high the nSEL pin */
sRF_CS_HIGH();
return reg;
}
/*****************************************************************************
Prototype : hal_sRF_WriteRegister
Description : none
Input : u8 reg
u8 val
Output : None
Return Value :
Date : 2014/3/15
Author : Barry
*****************************************************************************/
void hal_sRF_WriteRegister(u8 reg, u8 val)
{
reg |= 0x80;
/*!< Deselect the Radio: Chip Select high */
sRF_CS_HIGH();
/*!< Select the radio by pulling low the nSEL pin */
sRF_CS_LOW();
/*!< Loop while DR register in not emplty */
while (SPI_I2S_GetFlagStatus(sRF_SPI, SPI_I2S_FLAG_TXE) == RESET);
/*!< Send byte through the SPI1 peripheral */
SPI_I2S_SendData(sRF_SPI, reg);
/*!< Wait to receive a byte */
while (SPI_I2S_GetFlagStatus(sRF_SPI, SPI_I2S_FLAG_RXNE) == RESET);
/* read from the SPI bus */
SPI_I2S_ReceiveData(sRF_SPI);
/*!< Loop while DR register in not emplty */
while (SPI_I2S_GetFlagStatus(sRF_SPI, SPI_I2S_FLAG_TXE) == RESET);
/*!< Send byte through the SPI1 peripheral */
SPI_I2S_SendData(sRF_SPI, val);
/*!< Wait to receive a byte */
while (SPI_I2S_GetFlagStatus(sRF_SPI, SPI_I2S_FLAG_RXNE) == RESET);
/* read from the SPI bus */
SPI_I2S_ReceiveData(sRF_SPI);
/*!< Deselect the radio by pulling high the nSEL pin */
sRF_CS_HIGH();
}
/*****************************************************************************
Prototype : hal_sRF_DMA_Read
Description : none
Input : u8 startReg
u8 *pBuffer
u8 length
Output : None
Return Value :
Date : 2014/3/15
Author : Barry
*****************************************************************************/
void hal_sRF_DMA_Read(u8 startReg, u8 *pBuffer, u8 length)
{
/* Allocate storage for CPU status register */
#if OS_CRITICAL_METHOD == 3u
OS_CPU_SR cpu_sr = 0u;
#endif
if (startReg > TOTAL_REGISTER_NUMBER)
{
return;
}
if (length > 0)
{
/*!< Deselect the Radio: Chip Select high */
sRF_CS_HIGH();
/*!< Select the radio by pulling low the nSEL pin */
sRF_CS_LOW();
/*!< Loop while DR register in not emplty */
while (SPI_I2S_GetFlagStatus(sRF_SPI, SPI_I2S_FLAG_TXE) == RESET);
/*!< Send byte through the SPI1 peripheral */
SPI_I2S_SendData(sRF_SPI, startReg);
/*!< Wait to receive a byte */
while (SPI_I2S_GetFlagStatus(sRF_SPI, SPI_I2S_FLAG_RXNE) == RESET);
/* read from the SPI bus */
SPI_I2S_ReceiveData(sRF_SPI);
OS_ENTER_CRITICAL();
sRF_SPI->CR1 |= SPI_Direction_2Lines_RxOnly;
/* sRF_SPI_DMA_RX_Channel configuration ---------------------------------------------*/
sRF_SPI_DMA_RX_Channel->CMAR = (u32)pBuffer;
sRF_SPI_DMA_RX_Channel->CNDTR = (u32)length;
/* Enable sRF_SPI_DMA_RX_Channel and TC interrupt*/
sRF_SPI_DMA_RX_Channel->CCR |= DMA_CCR1_EN | DMA_CCR1_TCIE;
OS_EXIT_CRITICAL();
}
}
/*****************************************************************************
Prototype : hal_sRF_DMA_Write
Description : none
Input : u8 *pBuffer
u8 length
Output : None
Return Value :
Date : 2014/3/15
Author : Barry
*****************************************************************************/
void hal_sRF_DMA_Write(u8 *pBuffer, u8 length)
{
if (length > 0)
{
/*!< Deselect the Radio: Chip Select high */
sRF_CS_HIGH();
/*!< Select the radio by pulling low the nSEL pin */
sRF_CS_LOW();
/* sRF_SPI_DMA_TX_Channel configuration ---------------------------------------------*/
sRF_SPI_DMA_TX_Channel->CMAR = (u32)pBuffer;
sRF_SPI_DMA_TX_Channel->CNDTR = (u32)length;
/* Enable sRF_SPI_DMA_TX_Channel */
sRF_SPI_DMA_TX_Channel->CCR |= DMA_CCR1_EN | DMA_CCR1_TCIE;
}
else
{
printf("length input error\r\n");
}
}
/*****************************************************************************
Prototype : hal_sRF_Config
Description : none
Input : u8 startReg
u8 *pBuffer
u8 length
Output : None
Return Value :
Date : 2014/3/15
Author : Barry
*****************************************************************************/
void hal_sRF_Config(u8 startReg, u8 *pBuffer, u8 length)
{
if (startReg >= TOTAL_REGISTER_NUMBER)
{
printf("startReg input error\r\n");
return;
}
if (length > 0)
{
hal_sRF_InitSPI();
*pBuffer = startReg | 0x80;
hal_sRF_DMA_Write(pBuffer, length + 1);
}
}
/*****************************************************************************
Prototype : hal_sRF_Read
Description : DMA read FIFO
Input : u8 startReg
u8 *pBuffer
u8 length
Output : None
Return Value :
Date : 2014/3/15
Author : Barry
*****************************************************************************/
void hal_sRF_Read(u8 startReg, u8 *pBuffer, u8 length)
{
if (length > 0)
{
hal_sRF_InitSPI();
hal_sRF_DMA_Read(startReg,pBuffer,length);
}
}
/*****************************************************************************
Prototype : hal_sRF_readFIFO_DMA
Description : none
Input : u8 * pBuffer指向接收数组数组的第一个字节为长度字节
u8 length
Output : None
Return Value :
Date : 2014/3/21
Author : Barry
*****************************************************************************/
void hal_sRF_readFIFO_DMA(u8 * pBuffer, u8 length)
{
hal_sRF_DMA_Read(0,pBuffer+1,length);
}
/*****************************************************************************
Prototype : hal_sRF_writeFIFO_DMA
Description : none
Input : u8 * pBuffer 指向开始发送的数组数组的第一个字节为FIFO地址
u8 length 实际发送的字节数
Output : None
Return Value :
Date : 2014/3/21
Author : Barry
*****************************************************************************/
void hal_sRF_writeFIFO_DMA(u8 * pBuffer, u8 length)
{
hal_sRF_Config(0,pBuffer,length);
}
/******************************************************************************/
/* STM32F10x Peripherals Interrupt Handlers */
/******************************************************************************/
/*****************************************************************************
Prototype : DMA1_Channel2_IRQHandler
Description : This function handles SPI1 Rx Transfer Complete interrupt
and Transfer Error interrupt.
Input : void
Output : None
Return Value :
Date : 2014/3/15
Author : Barry
*****************************************************************************/
void DMA1_Channel2_IRQHandler(void)
{
if (DMA_GetITStatus(DMA1_IT_TC2) != RESET)
{
/* hal_sRF_InitSPI();初始化放在主循环中去 */
RxEndProcess(TRUE);
}
/*!< Deselect the RADIO: Chip Select high */
//sRF_CS_HIGH();
/* Disable the selected SPI peripheral */
//sRF_SPI->CR1 &= 0xFFBF;
/* Clear the DMA1 interrupt pending bits */
DMA1->IFCR = DMA1_IT_TC2 | DMA1_IT_HT2 | DMA1_IT_TE2;
/* Disable the selected DMA1_Channel2 */
DMA1_Channel2->CCR &= (u16)(~DMA_CCR1_EN);
}
/*****************************************************************************
Prototype : DMA1_Channel3_IRQHandler
Description : This function handles SPI1 Tx Transfer Complete interrupt
and Transfer Error interrupt.
Input : void
Output : None
Return Value :
Date : 2014/3/15
Author : Barry
*****************************************************************************/
void DMA1_Channel3_IRQHandler(void)
{
if (DMA_GetITStatus(DMA1_IT_TC3) != RESET)
{
SX1276LoRaStartTransmit();
}
/* Clear the DMA1 interrupt pending bits */
DMA1->IFCR = DMA1_IT_TC3 | DMA1_IT_HT3 | DMA1_IT_TE3;
/* Disable the selected DMA1_Channel3 */
DMA1_Channel3->CCR &= (u16)(~DMA_CCR1_EN);
}
/*****************************************************************************
Prototype : hal_sRF_Transmit
Description : PHY send
Input : u8 *pBuffer
u8 length
u8 channel
Output : None
Return Value :
Calls :
Called By :
History :
1.Date : 2014/10/29
Author : liwei
Modification : Created function
*****************************************************************************/
void hal_sRF_Transmit(u8 *pBuffer, u8 length, u8 channel)
{
SX1276LoRa_NormalTx(pBuffer,length);
}
#endif
/******************* (C) COPYRIGHT 2013 Robulink Technology Ltd.*****END OF FILE****/