14 #include "nrf_assert.h"
34 #define ACK_PAYLOAD_LENGTH 1
35 #define DEBUG_PAYLOAD_LENGTH 32
36 #define DEBUG_LINE_LENGTH 80
39 #define DEAD_BEEF 0xDEADBEEF
49 uint8_t rts_pin_number,
50 uint8_t txd_pin_number,
51 uint8_t cts_pin_number,
52 uint8_t rxd_pin_number,
55 nrf_gpio_cfg_output(txd_pin_number);
56 nrf_gpio_cfg_input(rxd_pin_number, NRF_GPIO_PIN_NOPULL);
58 NRF_UART0->PSELTXD = txd_pin_number;
59 NRF_UART0->PSELRXD = rxd_pin_number;
62 nrf_gpio_cfg_output(rts_pin_number);
63 nrf_gpio_cfg_input(cts_pin_number, NRF_GPIO_PIN_NOPULL);
64 NRF_UART0->PSELCTS = cts_pin_number;
65 NRF_UART0->PSELRTS = rts_pin_number;
66 NRF_UART0->CONFIG = (UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos);
69 NRF_UART0->BAUDRATE = (baudrate << UART_BAUDRATE_BAUDRATE_Pos);
70 NRF_UART0->ENABLE = (UART_ENABLE_ENABLE_Enabled << UART_ENABLE_ENABLE_Pos);
71 NRF_UART0->TASKS_STARTTX = 1;
72 NRF_UART0->TASKS_STARTRX = 1;
73 NRF_UART0->EVENTS_RXDRDY = 0;
81 return (NRF_UART0->EVENTS_RXDRDY == 1);
110 return "PRU System Error";
112 return "Invalid state";
124 uint16_t tmp16_1, tmp16_2, tmp16_3, tmp16_4, tmp16_5;
139 tmp16_1 = (uint16_t)debug_data[2] << 8 | (uint16_t)debug_data[1];
140 tmp16_2 = (uint16_t)debug_data[4] << 8 | (uint16_t)debug_data[3];
141 tmp16_3 = (uint16_t)debug_data[6] << 8 | (uint16_t)debug_data[5];
142 tmp16_4 = (uint16_t)debug_data[8] << 8 | (uint16_t)debug_data[7];
143 temperature = (int16_t)((uint16_t)(debug_data[10]<<8 | (uint16_t)debug_data[9]));
144 print_string(
"Vrect\tIrect\tVout\tIout\tTemp\tCharged\tP_adj\r\n");
145 sprintf(temp_string,
"%u\t%u\t%u\t%u\t%u\t%u\t%u\r\n", tmp16_1, tmp16_2, tmp16_3, tmp16_4, temperature, debug_data[11], debug_data[24]);
152 tmp16_1 = (uint16_t)debug_data[13] << 8 | (uint16_t)debug_data[12];
153 tmp16_2 = (uint16_t)debug_data[15] << 8 | (uint16_t)debug_data[14];
154 tmp16_3 = (uint16_t)debug_data[17] << 8 | (uint16_t)debug_data[16];
155 tmp16_4 = (uint16_t)debug_data[20] << 8 | (uint16_t)debug_data[19];
156 tmp16_5 = (uint16_t)debug_data[22] << 8 | (uint16_t)debug_data[21];
157 print_string(
"Vrset\tVrmin\tVrmax\tTempmax\tVrmax\tPrmax\r\n");
158 sprintf(temp_string,
"%u\t%u\t%u\t%u\t%u\t%u\r\n", tmp16_1, tmp16_2, tmp16_3, debug_data[18], tmp16_4, tmp16_5);
166 print_string(
"En_out\tEn_Chin\tAdj_pow\tPerm\tTset\r\n");
167 sprintf(temp_string,
"%u\t%u\t%u\t%u\t%u\r\n", debug_data[25], debug_data[26], debug_data[27], debug_data[28], debug_data[29]);
170 if(debug_data[23] != 0)
210 res = nrf_gzll_init(NRF_GZLL_MODE_HOST);
212 res = nrf_gzll_set_base_address_0(NRF_GZLL_BASE_ADDRESS_0);
216 res = nrf_gzll_enable();
218 uart_config(UART_BAUDRATE_BAUDRATE_Baud460800, RTS_PIN_NUMBER, TX_PIN_NUMBER, CTS_PIN_NUMBER, RX_PIN_NUMBER, HWFC);
240 uint32_t data_payload_length = NRF_GZLL_CONST_MAX_PAYLOAD_LENGTH;
241 res = nrf_gzll_fetch_packet_from_rx_fifo(pipe,
data_payload, &data_payload_length);
static void debug_output_print(uint8_t *debug_data)
Print debug output.
uint8_t simple_uart_get(void)
Function for reading a character from UART. Execution is blocked until UART peripheral detects charac...
void nrf_gzll_host_rx_data_ready(uint32_t pipe, nrf_gzll_host_rx_info_t rx_info)
GZLL data packet received callback.
void nrf_gzll_disabled()
GZLL Disabled callback.
int main()
Application main function.
static bool m_uart_chars_available(void)
Checks if there are any characters available in the UART.
void nrf_gzll_device_tx_failed(uint32_t pipe, nrf_gzll_device_tx_info_t tx_info)
GZLL Transmission failed callback.
static void uart_config(uint32_t baudrate, uint8_t rts_pin_number, uint8_t txd_pin_number, uint8_t cts_pin_number, uint8_t rxd_pin_number, bool hwfc)
Local version of uart configure that take baud rate.
void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t *p_file_name)
Error handler function, which is called when an error has occurred.
static void line_print(void)
Print a dashed line to the UART.
#define DEBUG_PKT
Packed type used for packet with payload.
void nrf_gzll_device_tx_success(uint32_t pipe, nrf_gzll_device_tx_info_t tx_info)
GZLL ACK received callback.
static char * state_string_get(uint8_t state)
Convert state to string.
static bool pkt_received
True when a packet with first byte = DEBUG_POLL received.
static uint8_t data_payload[NRF_GZLL_CONST_MAX_PAYLOAD_LENGTH]
GZLL data payload.
static uint8_t ack_payload[ACK_PAYLOAD_LENGTH]
GZLL ack payload.
void print_string(char *char_array)
Decomposes char array and send chars through UART TX.
#define DEAD_BEEF
Error code for assert.
#define DEBUG_LINE_LENGTH
Debug string length.
static char temp_string[DEBUG_LINE_LENGTH]
#define ACK_PAYLOAD_LENGTH
We use 1 byte payload length when transmitting.
#define DEBUG_POLL
Packed type used for polling opnly.
void assert_nrf_callback(uint16_t line_num, const uint8_t *p_file_name)
Assert macro callback function.
#define NRF_GZLL_CHANNEL_TABLE_SIZE
#define DEBUG_STR
Packed type used for packet with string.