Skip to content

Commit

Permalink
Update NRF_Peripheral_UARTE 06/16
Browse files Browse the repository at this point in the history
  • Loading branch information
Hom-Wang committed Jun 16, 2018
1 parent 30897f1 commit 8badca1
Show file tree
Hide file tree
Showing 22 changed files with 335 additions and 288 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* @file mathUnit.c
* @author KitSprout
* @date 22-Apr-2018
* @date 03-Jun-2018
* @brief
*
*/
Expand Down
30 changes: 15 additions & 15 deletions firmware/NRF_Peripheral_UARTE/Program/algorithms/mathUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* @file mathUnit.h
* @author KitSprout
* @date 22-Apr-2018
* @date 03-Jun-2018
* @brief
*
*/
Expand All @@ -31,20 +31,20 @@

/* Define ----------------------------------------------------------------------------------*/
/* Macro -----------------------------------------------------------------------------------*/
#define invSqrt( __iSq ) (1.0 / sqrt(__iSq))
#define invSqrtf( __iSq ) (1.0f / sqrtf(__iSq))
#define squa( __sq ) ((__sq) * (__sq))
#define squaf( __sq ) (((float32_t)(__sq)) * ((float32_t)(__sq)))
#define swap( __a, __b ) (__a) = (int32_t)(__a) ^ (int32_t)(__b); \
(__b) = (int32_t)(__a) ^ (int32_t)(__b); \
(__a) = (int32_t)(__a) ^ (int32_t)(__b)
#define swapf( __a, __b ) *(uint32_t*)(&(__a)) = *(uint32_t*)(&(__a)) ^ *(uint32_t*)(&(__b)); \
*(uint32_t*)(&(__b)) = *(uint32_t*)(&(__a)) ^ *(uint32_t*)(&(__b)); \
*(uint32_t*)(&(__a)) = *(uint32_t*)(&(__a)) ^ *(uint32_t*)(&(__b))
#define abs( __n ) (((__n) > 0) ? (__n) : -(__n))
#define toRad( __deg ) ((__deg) * 0.0174532925f)
#define toDeg( __rad ) ((__rad) * 57.2957795f)
#define arrayLens(__arr) (sizeof(__arr) / sizeof((__arr)[0]))
#define invSqrt( __iSq ) (1.0 / sqrt(__iSq))
#define invSqrtf( __iSq ) (1.0f / sqrtf(__iSq))
#define squa( __sq ) ((__sq) * (__sq))
#define squaf( __sq ) (((float32_t)(__sq)) * ((float32_t)(__sq)))
#define swap( __a, __b ) (__a) = (int32_t)(__a) ^ (int32_t)(__b); \
(__b) = (int32_t)(__a) ^ (int32_t)(__b); \
(__a) = (int32_t)(__a) ^ (int32_t)(__b)
#define swapf( __a, __b ) *(uint32_t*)(&(__a)) = *(uint32_t*)(&(__a)) ^ *(uint32_t*)(&(__b)); \
*(uint32_t*)(&(__b)) = *(uint32_t*)(&(__a)) ^ *(uint32_t*)(&(__b)); \
*(uint32_t*)(&(__a)) = *(uint32_t*)(&(__a)) ^ *(uint32_t*)(&(__b))
#define abs( __n ) (((__n) > 0) ? (__n) : -(__n))
#define toRad( __deg ) ((__deg) * 0.0174532925f)
#define toDeg( __rad ) ((__rad) * 57.2957795f)
#define arrayLens(__arr) (sizeof(__arr) / sizeof((__arr)[0]))

/* Typedef ---------------------------------------------------------------------------------*/
typedef enum {
Expand Down
82 changes: 41 additions & 41 deletions firmware/NRF_Peripheral_UARTE/Program/boardConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* @file boardConfig.h
* @author KitSprout
* @date 22-Apr-2018
* @date 16-Jun-2018
* @brief
*
*/
Expand All @@ -24,62 +24,62 @@
/* Includes --------------------------------------------------------------------------------*/
/* Define ----------------------------------------------------------------------------------*/

#define KS_HW_BOARD_NAME "SmartIMU"
#define KS_HW_MCU_NAME "NRF52810"
#define KS_HW_BOARD_NAME "SmartIMU"
#define KS_HW_MCU_NAME "NRF52810"

#define KS_HW_USE_CLOCK_SOUCE_INT (0U)
#define KS_HW_USE_CLOCK_SOUCE_EXT (1U)
#define KS_HW_HCLOCK_SOUCE KS_HW_USE_CLOCK_SOUCE_EXT
#define KS_HW_LCLOCK_SOUCE KS_HW_USE_CLOCK_SOUCE_INT
#define KS_HW_USE_CLOCK_SOUCE_INT (0U)
#define KS_HW_USE_CLOCK_SOUCE_EXT (1U)
#define KS_HW_HCLOCK_SOUCE KS_HW_USE_CLOCK_SOUCE_EXT
#define KS_HW_LCLOCK_SOUCE KS_HW_USE_CLOCK_SOUCE_INT

#define KS_SYSCLK SystemCoreClock
#define KS_SYSCLK SystemCoreClock


/* -------- LED and KEY */

#define LED_PIN 12
#define LED_PORT NRF_P0
#define LED_Set() __GPIO_SET(LED_PORT, LED_PIN)
#define LED_Reset() __GPIO_RST(LED_PORT, LED_PIN)
#define LED_Toggle() __GPIO_TOG(LED_PORT, LED_PIN)
#define LED_On() LED_Set()
#define LED_Off() LED_Reset()
#define LED_PIN 12
#define LED_PORT NRF_P0
#define LED_Set() __GPIO_SET(LED_PORT, LED_PIN)
#define LED_Reset() __GPIO_RST(LED_PORT, LED_PIN)
#define LED_Toggle() __GPIO_TOG(LED_PORT, LED_PIN)
#define LED_On() LED_Set()
#define LED_Off() LED_Reset()

#define KEY_PIN 25
#define KEY_PORT NRF_P0
#define KEY_Read() (__GPIO_READ(KEY_PORT, KEY_PIN) != SET)
#define KEY_PIN 9
#define KEY_PORT NRF_P0
#define KEY_Read() (__GPIO_READ(KEY_PORT, KEY_PIN) == RESET)


/* -------- Timer */

#define TIMERx NRF_TIMER0
#define TIMERx_IRQn TIMER0_IRQn
#define TIMERx_IRQn_PRIORITY 1
#define TIMERx_MODE NRF_TIMER_MODE_TIMER
#define TIMERx_PRESCALER NRF_TIMER_FREQ_1MHz
#define TIMERx_BIT_MODE NRF_TIMER_BIT_WIDTH_32
#define TIMERx NRF_TIMER0
#define TIMERx_IRQn TIMER0_IRQn
#define TIMERx_IRQn_PRIORITY 1
#define TIMERx_MODE NRF_TIMER_MODE_TIMER
#define TIMERx_PRESCALER NRF_TIMER_FREQ_1MHz
#define TIMERx_BIT_MODE NRF_TIMER_BIT_WIDTH_32

#define TIMERx_CHANNEL NRF_TIMER_CC_CHANNEL0
#define TIMERx_CHANNEL_PERIOD 1000
#define TIMERx_CHANNEL NRF_TIMER_CC_CHANNEL0
#define TIMERx_CHANNEL_PERIOD 1000


/* -------- Serial */

#define SERIAL_MAX_TXBUF 16
#define SERIAL_MAX_RXBUF 16

#define SERIAL_UARTEx NRF_UARTE0
#define SERIAL_UARTEx_IRQn UARTE0_IRQn
#define SERIAL_UARTEx_IRQn_PRIORITY 1

#define SERIAL_TXD_PIN 14
#define SERIAL_RXD_PIN 15
#define SERIAL_RTS_PIN 3
#define SERIAL_CTS_PIN 3
#define SERIAL_BAUDRATE NRF_UARTE_BAUDRATE_115200
#define SERIAL_PARITY NRF_UARTE_PARITY_EXCLUDED
#define SERIAL_HARDWARECTRL NRF_UARTE_HWFC_DISABLED
#define SERIAL_INTERRUPT_MODE NRF_UARTE_INT_RXSTARTED_MASK
#define SERIAL_MAX_TXBUF 32
#define SERIAL_MAX_RXBUF 32

#define SERIAL_UARTEx NRF_UARTE0
#define SERIAL_UARTEx_IRQn UARTE0_IRQn
#define SERIAL_UARTEx_IRQn_PRIORITY 1

#define SERIAL_TXD_PIN 30
#define SERIAL_RXD_PIN 25
#define SERIAL_RTS_PIN 2
#define SERIAL_CTS_PIN 2
#define SERIAL_BAUDRATE NRF_UARTE_BAUDRATE_115200
#define SERIAL_PARITY NRF_UARTE_PARITY_EXCLUDED
#define SERIAL_HARDWARECTRL NRF_UARTE_HWFC_DISABLED
#define SERIAL_INTERRUPT_MODE NRF_UARTE_INT_RXDRDY_MASK


/* Macro -----------------------------------------------------------------------------------*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* @file nrf5x_clock.c
* @author KitSprout
* @date 22-Apr-2018
* @date 21-Apr-2018
* @brief
*
*/
Expand Down
6 changes: 3 additions & 3 deletions firmware/NRF_Peripheral_UARTE/Program/drivers/nrf5x_clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* @file nrf5x_clock.h
* @author KitSprout
* @date 22-Apr-2018
* @date 16-Jun-2018
* @brief
*
*/
Expand Down Expand Up @@ -59,8 +59,8 @@ typedef struct {

/* Extern ----------------------------------------------------------------------------------*/
/* Functions -------------------------------------------------------------------------------*/
void CLOCK_Config( void );
void CLOCK_Init( CLOCK_InitTypeDef *hclock );
void CLOCK_Config( void );
void CLOCK_Init( CLOCK_InitTypeDef *hclock );

#ifdef __cplusplus
}
Expand Down
5 changes: 3 additions & 2 deletions firmware/NRF_Peripheral_UARTE/Program/drivers/nrf5x_delay.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* @file nrf5x_delay.c
* @author KitSprout
* @date 22-Apr-2018
* @date 16-Jun-2018
* @brief
*
*/
Expand Down Expand Up @@ -47,7 +47,8 @@ void delay_us( __IO uint32_t __us )

/**
* @brief delay_ms
*/void delay_ms( __IO uint32_t __ms )
*/
void delay_ms( __IO uint32_t __ms )
{
while (__ms != 0) {
__ms--;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* @file nrf5x_delay.h
* @author KitSprout
* @date 22-Apr-2018
* @date 11-Apr-2018
* @brief
*
*/
Expand Down
8 changes: 4 additions & 4 deletions firmware/NRF_Peripheral_UARTE/Program/drivers/nrf5x_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* @file nrf5x_timer.c
* @author KitSprout
* @date 22-Apr-2018
* @date 16-Jun-2018
* @brief
*
*/
Expand Down Expand Up @@ -52,11 +52,11 @@ void TIMER_ChannelInit( TIMER_BaseInitTypeDef *htimer, TIMER_ChannelInitTypeDef
void TIMER_Cmd( TIMER_BaseInitTypeDef *htimer, uint8_t state )
{
if (state != ENABLE) {
TIMER_TASKS_STOP(htimer->Instance);
TIMER_TASKS_STOP(htimer->Instance) = SET;
}
else {
TIMER_TASKS_CLEAR(htimer->Instance);
TIMER_TASKS_START(htimer->Instance);
TIMER_TASKS_CLEAR(htimer->Instance) = SET;
TIMER_TASKS_START(htimer->Instance) = SET;
}
}

Expand Down
16 changes: 8 additions & 8 deletions firmware/NRF_Peripheral_UARTE/Program/drivers/nrf5x_timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* @file nrf5x_timer.h
* @author KitSprout
* @date 22-Apr-2018
* @date 16-Jun-2018
* @brief
*
*/
Expand All @@ -26,14 +26,14 @@

/* Define ----------------------------------------------------------------------------------*/
/* Macro -----------------------------------------------------------------------------------*/
#define TIMER_TASKS_START(__INS) (__INS->TASKS_START = SET) // Start Timer
#define TIMER_TASKS_STOP(__INS) (__INS->TASKS_STOP = SET) // Stop Timer
#define TIMER_TASKS_COUNT(__INS) (__INS->TASKS_COUNT = SET) // Increment Timer (Counter mode only)
#define TIMER_TASKS_CLEAR(__INS) (__INS->TASKS_CLEAR = SET) // Clear time
#define TIMER_TASKS_SHUTDOWN(__INS) (__INS->TASKS_SHUTDOWN = SET) // Shut down timer
#define TIMER_TASKS_CAPTURE(__INS, __CH) (__INS->TASKS_CAPTURE[__CH] = SET) // Capture Timer value to CC[x] register
#define TIMER_TASKS_START(__INS) __INS->TASKS_START // Start Timer
#define TIMER_TASKS_STOP(__INS) __INS->TASKS_STOP // Stop Timer
#define TIMER_TASKS_COUNT(__INS) __INS->TASKS_COUNT // Increment Timer (Counter mode only)
#define TIMER_TASKS_CLEAR(__INS) __INS->TASKS_CLEAR // Clear time
#define TIMER_TASKS_SHUTDOWN(__INS) __INS->TASKS_SHUTDOWN // Shut down timer
#define TIMER_TASKS_CAPTURE(__INS, __CH) __INS->TASKS_CAPTURE[__CH] // Capture Timer value to CC[x] register

#define TIMER_EVENTS_COPPARE(__INS, __CH) __INS->EVENTS_COMPARE[__CH] // Compare event on CC[x] match
#define TIMER_EVENTS_COPPARE(__INS, __CH) __INS->EVENTS_COMPARE[__CH] // Compare event on CC[x] match

/* Typedef ---------------------------------------------------------------------------------*/

Expand Down
14 changes: 7 additions & 7 deletions firmware/NRF_Peripheral_UARTE/Program/drivers/nrf5x_uarte.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* @file nrf5x_uarte.c
* @author KitSprout
* @date 22-Apr-2018
* @date 16-Jun-2018
* @brief
*
*/
Expand Down Expand Up @@ -116,7 +116,7 @@ void UARTE_SendByte( UARTE_InitTypeDef *huarte, uint8_t *sendByte )
UARTE_EVENTS_TXSTOPPED(huarte->Instance) = RESET;
huarte->Instance->TXD.PTR = (uint32_t)sendByte;
huarte->Instance->TXD.MAXCNT = 1;
UARTE_TASKS_STARTTX(huarte->Instance);
UARTE_TASKS_STARTTX(huarte->Instance) = SET;
while ((UARTE_EVENTS_ENDTX(huarte->Instance) != SET) && (UARTE_EVENTS_TXSTOPPED(huarte->Instance) != SET));
}

Expand All @@ -129,7 +129,7 @@ void UARTE_RecvByte( UARTE_InitTypeDef *huarte, uint8_t *recvByte )
UARTE_EVENTS_RXTO(huarte->Instance) = RESET;
huarte->Instance->RXD.PTR = (uint32_t)recvByte;
huarte->Instance->RXD.MAXCNT = 1;
UARTE_TASKS_STARTRX(huarte->Instance);
UARTE_TASKS_STARTRX(huarte->Instance) = SET;
while ((UARTE_EVENTS_ENDRX(huarte->Instance) != SET) && (UARTE_EVENTS_RXTO(huarte->Instance) != SET) && (UARTE_EVENTS_ERROR(huarte->Instance) != SET));
}

Expand All @@ -148,7 +148,7 @@ uint32_t UARTE_SendData( UARTE_InitTypeDef *huarte, uint8_t *sendData, uint32_t
UARTE_EVENTS_TXSTOPPED(huarte->Instance) = RESET;
huarte->Instance->TXD.PTR = (uint32_t)sendData;
huarte->Instance->TXD.MAXCNT = lens;
UARTE_TASKS_STARTTX(huarte->Instance);
UARTE_TASKS_STARTTX(huarte->Instance) = SET;
do {
endtx = UARTE_EVENTS_ENDTX(huarte->Instance);
txstopped = UARTE_EVENTS_TXSTOPPED(huarte->Instance);
Expand Down Expand Up @@ -176,7 +176,7 @@ uint32_t UARTE_RecvData( UARTE_InitTypeDef *huarte, uint8_t *recvData, uint32_t
UARTE_EVENTS_RXTO(huarte->Instance) = RESET;
huarte->Instance->RXD.PTR = (uint32_t)recvData;
huarte->Instance->RXD.MAXCNT = lens;
UARTE_TASKS_STARTRX(huarte->Instance);
UARTE_TASKS_STARTRX(huarte->Instance) = SET;
do {
endrx = UARTE_EVENTS_ENDRX(huarte->Instance);
rxto = UARTE_EVENTS_RXTO(huarte->Instance);
Expand Down Expand Up @@ -208,7 +208,7 @@ uint32_t UARTE_SendDataWaitTimeout( UARTE_InitTypeDef *huarte, uint8_t *sendData
UARTE_EVENTS_TXSTOPPED(huarte->Instance) = RESET;
huarte->Instance->TXD.PTR = (uint32_t)sendData;
huarte->Instance->TXD.MAXCNT = lens;
UARTE_TASKS_STARTTX(huarte->Instance);
UARTE_TASKS_STARTTX(huarte->Instance) = SET;
do {
endtx = UARTE_EVENTS_ENDTX(huarte->Instance);
txstopped = UARTE_EVENTS_TXSTOPPED(huarte->Instance);
Expand Down Expand Up @@ -247,7 +247,7 @@ uint32_t UARTE_RecvDataWaitTimeout( UARTE_InitTypeDef *huarte, uint8_t *recvData
UARTE_EVENTS_RXTO(huarte->Instance) = RESET;
huarte->Instance->RXD.PTR = (uint32_t)recvData;
huarte->Instance->RXD.MAXCNT = lens;
UARTE_TASKS_STARTRX(huarte->Instance);
UARTE_TASKS_STARTRX(huarte->Instance) = SET;
do {
endrx = UARTE_EVENTS_ENDRX(huarte->Instance);
rxto = UARTE_EVENTS_RXTO(huarte->Instance);
Expand Down
34 changes: 17 additions & 17 deletions firmware/NRF_Peripheral_UARTE/Program/drivers/nrf5x_uarte.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* @file nrf5x_uarte.h
* @author KitSprout
* @date 22-Apr-2018
* @date 16-Jun-2018
* @brief
*
*/
Expand All @@ -26,23 +26,23 @@

/* Define ----------------------------------------------------------------------------------*/
/* Macro -----------------------------------------------------------------------------------*/
#define UARTE_TASKS_STARTRX(__INS) (__INS->TASKS_STARTRX = SET) // Start UART receiver
#define UARTE_TASKS_STOPRX(__INS) (__INS->TASKS_STOPRX = SET) // Stop UART receiver
#define UARTE_TASKS_STARTTX(__INS) (__INS->TASKS_STARTTX = SET) // Start UART transmitter
#define UARTE_TASKS_STOPTX(__INS) (__INS->TASKS_STOPTX = SET) // Stop UART transmitter
#define UARTE_TASKS_SUSPEND(__INS) (__INS->TASKS_FLUSHRX = SET) // Flush RX FIFO into RX buffer
#define UARTE_TASKS_STARTRX(__INS) __INS->TASKS_STARTRX // Start UART receiver
#define UARTE_TASKS_STOPRX(__INS) __INS->TASKS_STOPRX // Stop UART receiver
#define UARTE_TASKS_STARTTX(__INS) __INS->TASKS_STARTTX // Start UART transmitter
#define UARTE_TASKS_STOPTX(__INS) __INS->TASKS_STOPTX // Stop UART transmitter
#define UARTE_TASKS_SUSPEND(__INS) __INS->TASKS_FLUSHRX // Flush RX FIFO into RX buffer

#define UARTE_EVENTS_CTS(__INS) __INS->EVENTS_CTS // CTS is activated (set low). Clear To Send
#define UARTE_EVENTS_NCTS(__INS) __INS->EVENTS_NCTS // CTS is deactivated (set high). Not Clear To Send
#define UARTE_EVENTS_RXDRDY(__INS) __INS->EVENTS_RXDRDY // Data received in RXD.
#define UARTE_EVENTS_ENDRX(__INS) __INS->EVENTS_ENDRX // Receive buffer is filled up
#define UARTE_EVENTS_TXDRDY(__INS) __INS->EVENTS_TXDRDY // Data sent from TXD
#define UARTE_EVENTS_ENDTX(__INS) __INS->EVENTS_ENDTX // Last TX byte transmitted
#define UARTE_EVENTS_ERROR(__INS) __INS->EVENTS_ERROR // Error detected
#define UARTE_EVENTS_RXTO(__INS) __INS->EVENTS_RXTO // Receiver timeout
#define UARTE_EVENTS_RXSTARTED(__INS) __INS->EVENTS_RXSTARTED // UART receiver has started
#define UARTE_EVENTS_TXSTARTED(__INS) __INS->EVENTS_TXSTARTED // UART transmitter has started
#define UARTE_EVENTS_TXSTOPPED(__INS) __INS->EVENTS_TXSTOPPED // Transmitter stopped
#define UARTE_EVENTS_CTS(__INS) __INS->EVENTS_CTS // CTS is activated (set low). Clear To Send
#define UARTE_EVENTS_NCTS(__INS) __INS->EVENTS_NCTS // CTS is deactivated (set high). Not Clear To Send
#define UARTE_EVENTS_RXDRDY(__INS) __INS->EVENTS_RXDRDY // Data received in RXD.
#define UARTE_EVENTS_ENDRX(__INS) __INS->EVENTS_ENDRX // Receive buffer is filled up
#define UARTE_EVENTS_TXDRDY(__INS) __INS->EVENTS_TXDRDY // Data sent from TXD
#define UARTE_EVENTS_ENDTX(__INS) __INS->EVENTS_ENDTX // Last TX byte transmitted
#define UARTE_EVENTS_ERROR(__INS) __INS->EVENTS_ERROR // Error detected
#define UARTE_EVENTS_RXTO(__INS) __INS->EVENTS_RXTO // Receiver timeout
#define UARTE_EVENTS_RXSTARTED(__INS) __INS->EVENTS_RXSTARTED // UART receiver has started
#define UARTE_EVENTS_TXSTARTED(__INS) __INS->EVENTS_TXSTARTED // UART transmitter has started
#define UARTE_EVENTS_TXSTOPPED(__INS) __INS->EVENTS_TXSTOPPED // Transmitter stopped

/* Typedef ---------------------------------------------------------------------------------*/

Expand Down
Loading

0 comments on commit 8badca1

Please sign in to comment.