#include "buttons.h"
#include "gzll_mcu.h"
#include "gzll.h"
#include "hal_clk.h"
#include "lib_display.h"
#include "stdio.h"
#include "string.h"
#include "nordic_common.h"
#include "hal_delay.h"
Go to the source code of this file.
#define | MM_MODE_SELECT_HEADER "Operation:" |
#define | MM_MODE_SELECT_DEVICE "Device" |
#define | MM_MODE_SELECT_HOST "Host" |
#define | DEFAULT_DEVICE_MODE true |
#define | APP_SETUP_SIZE 4 |
#define | STATISTICS_SIZE 8 |
#define | MESSAGE_RUN_L0 " Running!" |
#define | MESSAGE_RUN_L1 " " |
#define | MESSAGE_STOP_L0 " Stopped!" |
#define | MESSAGE_STOP_L1 " " |
#define | MESSAGE_STATISTICS_CLR_L0 " Statistics" |
#define | MESSAGE_STATISTICS_CLR_L1 " cleared!" |
#define | BUFFER_SIZE 16 |
enum | main_menu_pages_t { MM_MODE_SELECT, MM_TEST_APP_SETUP, MM_STATISTICS, MM_GZLL_PARAMS, MM_CHANNEL_SETUP, MM_LAST_PAGE } |
enum | app_setup_t { TX_PACKET_INTERVAL, TX_PL_LENGTH, ACK_PL_LENGTH, TX_PIPE } |
enum | statistics_t { TX_PL_CNT, TX_TRY_CNT, AVG_TX_TRIES, MAX_TX_TRIES, TX_CH_SWITCHES, TX_BYTE_CNT, RX_PL_CNT, RX_BYTE_CNT } |
char | main_menu_header [][17] |
code const char | app_setup_menu_header [][17] |
xdata uint16_t | app_setup [4] |
code const uint16_t | app_setup_maximum [4] |
code const char | gzll_param_menu_header [][17] |
code const char | gzll_output_power [][17] |
code const char | statistics_menu_header [][17] |
xdata uint32_t | statistics [8] |
xdata _Bool | radio_run = (( _Bool )0) |
xdata _Bool | device_mode = (( _Bool )1) |
xdata volatile _Bool | gzll_timer_tick |
xdata uint16_t | cnt_1ms = 0 |
xdata uint8_t | button_db = 0 |
char | buffer_a [16] = {0} |
char | buffer_b [16] = {0} |
void | assert_handler (uint16_t line, char *file) |
void | app_init (void) |
uint8_t | buttons_read (void) |
_Bool | com_execute (void) |
void | app_execute (uint8_t buttons) |
uint16_t | inc_mod (uint16_t dat, uint16_t limit) |
uint16_t | dec_mod (uint16_t dat, uint16_t limit) |
void | lcd_update (char *l0, char *l1) |
void | t2_init (void) |
void | itoa (uint16_t i, char *a) |
void | strcpy_nrf (char *dest, char const code *src) |
void | mm_mode_select (char *lcd_l0, char *lcd_l1, uint8_t buttons) |
void | mm_test_app_setup (char *lcd_l0, char *lcd_l1, uint8_t buttons) |
void | mm_gzll_params (char *lcd_l0, char *lcd_l1, uint8_t buttons) |
void | mm_statistics (char *lcd_l0, char *lcd_l1, uint8_t buttons) |
void | mm_channel_setup (char *lcd_l0, char *lcd_l1, uint8_t buttons) |
void | main (void) |
T2_ISR () | |
TICK_ISR () |
Nordic Semiconductor Gazell Link Layer Configuration Tool.
Definition in file main.c.
enum main_menu_pages_t |
enum app_setup_t |
enum statistics_t |
void app_init | ( | void | ) |
uint8_t buttons_read | ( | void | ) |
Function for reading buttons and handle button debounce.
Definition at line 782 of file main.c.
{ static xdata uint8_t hold = 0; uint8_t temp; if(button_db == 0) { temp = BUTTONS; temp = ~temp; if(temp) { if(hold < BUTTON_HOLD_THRESHOLD) { ET2 = 0; hold++; button_db = BUTTONS_DEBOUNCE_SLOW; } else { button_db = BUTTONS_DEBOUNCE_FAST; } ET2 = 1; } else { hold = 0; } return temp; } else { return 0; } }
_Bool com_execute | ( | void | ) |
Function executing radio (gazell) related operations.
Definition at line 366 of file main.c.
{ bool retval = false; uint8_t user_data[32]; //lint -esym(645, user_data) "variable may not have been initialized" uint16_t temp; uint8_t t_length, t_pipe; gzll_states_t curr_gzll_state; static gzll_states_t prev_gzll_state = (gzll_states_t)0xff; // If Device operation if(device_mode) { // Get Gazell state curr_gzll_state = gzll_get_state(); if(curr_gzll_state == GZLL_IDLE) { // If state transition from TRANSMIT to IDLE if(prev_gzll_state == GZLL_DEVICE_ACTIVE) { retval = true; if(gzll_tx_success()) { statistics[TX_PL_CNT]++; statistics[TX_BYTE_CNT] += app_setup[TX_PL_LENGTH]; temp = gzll_get_tx_attempts(); statistics[TX_TRY_CNT] += temp; statistics[AVG_TX_TRIES] = (uint16_t)(((float)statistics[TX_TRY_CNT] * 100) / statistics[TX_PL_CNT] ); if(statistics[MAX_TX_TRIES] < temp) { statistics[MAX_TX_TRIES] = temp; } statistics[TX_CH_SWITCHES] += gzll_get_tx_channel_switches(); } if(gzll_rx_fifo_read(user_data, &t_length, &t_pipe)) { statistics[RX_PL_CNT]++; statistics[RX_BYTE_CNT] += t_length; } } if(radio_run) { EA = 0; if(cnt_1ms >= app_setup[TX_PACKET_INTERVAL] ) { gzll_timer_tick = false; cnt_1ms = 0; EA = 1; while(!gzll_timer_tick){} // Improves synchronization to start in synch with protocol timer gzll_tx_data(user_data, (uint8_t)app_setup[TX_PL_LENGTH], (uint8_t)app_setup[TX_PIPE]); curr_gzll_state = GZLL_DEVICE_ACTIVE; } EA = 1; } prev_gzll_state = curr_gzll_state; } } // Host operation else { if(gzll_rx_fifo_read(user_data, &t_length, &t_pipe)) { retval = true; statistics[RX_PL_CNT]++; statistics[RX_BYTE_CNT] += t_length; t_length = (uint8_t)app_setup[ACK_PL_LENGTH]; if(t_length != false) { if(gzll_ack_payload_write(user_data, t_length, t_pipe)) { statistics[TX_PL_CNT]++; statistics[TX_BYTE_CNT] += t_length; } } } } return retval; }
void app_execute | ( | uint8_t | buttons ) |
Function executing application tasks such as menu handling and LCD update.
Definition at line 451 of file main.c.
{ static xdata uint8_t main_menu = 0; uint8_t lcd_line0[17], lcd_line1[17], i; /*----------------------------------------------------------------------------- Evaluate menu independent buttons -----------------------------------------------------------------------------*/ if((buttons & (MAIN_MENU_INC | MAIN_MENU_DEC)) != false) { if((buttons & MAIN_MENU_INC) != false) { main_menu = (uint8_t)inc_mod(main_menu, (uint8_t)MM_LAST_PAGE - 1); } if((buttons & MAIN_MENU_DEC) != false) { main_menu = (uint8_t)dec_mod(main_menu, (uint8_t)MM_LAST_PAGE - 1); } lcd_update(main_menu_header[main_menu], " "); delay_ms(DELAY_SHORT_MESSAGE); } if((buttons & RUN_STOP) != false) { if(radio_run) { radio_run = false; gzll_goto_idle(); lcd_update(MESSAGE_STOP_L0, MESSAGE_STOP_L1); delay_ms(DELAY_SHORT_MESSAGE); } else { if(!device_mode) { gzll_rx_start(); } radio_run = true; lcd_update(MESSAGE_RUN_L0, MESSAGE_RUN_L1); delay_ms(DELAY_SHORT_MESSAGE); } } if((buttons & CLEAR_STATISTICS) != false) { lcd_update(MESSAGE_STATISTICS_CLR_L0, MESSAGE_STATISTICS_CLR_L1); delay_ms(DELAY_SHORT_MESSAGE); for(i = 0; i < STATISTICS_SIZE; i++) { statistics[i] = 0; } } /*----------------------------------------------------------------------------- Run submenu dependent operations -----------------------------------------------------------------------------*/ switch(main_menu) { case MM_MODE_SELECT: mm_mode_select((void*)lcd_line0, (void*)lcd_line1, buttons); break; case MM_TEST_APP_SETUP: mm_test_app_setup((void*)lcd_line0, (void*)lcd_line1, buttons); break; case MM_GZLL_PARAMS: mm_gzll_params((void*)lcd_line0, (void*)lcd_line1, buttons); break; case MM_STATISTICS: mm_statistics((void*)lcd_line0, (void*)lcd_line1, buttons); break; case MM_CHANNEL_SETUP: mm_channel_setup((void*)lcd_line0, (void*)lcd_line1, buttons); break; default: ; } lcd_update((void*)lcd_line0, (void*)lcd_line1); }
uint16_t inc_mod | ( | uint16_t | dat, |
uint16_t | limit | ||
) |
uint16_t dec_mod | ( | uint16_t | dat, |
uint16_t | limit | ||
) |
void lcd_update | ( | char * | l0, |
char * | l1 | ||
) |
Function updating line0 and line1 on LCD if content modified.
Definition at line 535 of file main.c.
{ uint8_t n0, n1; char temp_l0[17], temp_l1[17]; static char curr_l0[17] = {0}, curr_l1[17] = {0}; n0 = (uint8_t)strlen(l0); n1 = (uint8_t)strlen(l1); strcpy(temp_l0, l0); strcpy(temp_l1, l1); // Pad with white spaces at end of line for(; n0 < 16; n0++) { temp_l0[n0] = ' '; } temp_l0[16] = 0; for(; n1 < 16; n1++) { temp_l1[n1] = ' '; } temp_l1[16] = 0; if(strcmp(curr_l0, temp_l0) != 0) { strcpy(curr_l0, temp_l0); lcd_write_string(curr_l0, 0, 0); } if(strcmp(curr_l1, temp_l1) != 0) { strcpy(curr_l1, temp_l1); lcd_write_string(curr_l1, 1, 0); delay_ms(5); } }
void t2_init | ( | void | ) |
void itoa | ( | uint16_t | i, |
char * | a | ||
) |
Function converting a number to string
if value is 0
Definition at line 843 of file main.c.
{ uint16_t ord,temp; uint8_t n; bool flag = 0; n = 0; ord = 10000; // uint_16 digits have max 5 digits while(ord > 0) { temp = i/ord; if((i/ord) == 0 && !flag) a[n] = 0x20; else { flag = 1; a[n] = (uint8_t)(i/ord); a[n]|= 0x30; n++; } i -= (temp * ord); ord /= 10; } a[n] = '\0'; if(!flag) { a[0] = 0|0x30; a[1] = '\0'; } }
void strcpy_nrf | ( | char * | dest, |
char const code * | src | ||
) |
void mm_mode_select | ( | char * | lcd_l0, |
char * | lcd_l1, | ||
uint8_t | buttons | ||
) |
"Operation" menu.
Definition at line 576 of file main.c.
{ if((buttons & VALUE_INC) != false || (buttons & VALUE_DEC) != false) { device_mode = !device_mode; } strcpy(lcd_l0, MM_MODE_SELECT_HEADER); if(device_mode) { strcpy(lcd_l1, MM_MODE_SELECT_DEVICE); } else { strcpy(lcd_l1, MM_MODE_SELECT_HOST); } }
void mm_test_app_setup | ( | char * | lcd_l0, |
char * | lcd_l1, | ||
uint8_t | buttons | ||
) |
"Test setup" menu.
Definition at line 595 of file main.c.
{ static xdata uint8_t app_setup_page = 0; if((buttons & SUB_MENU_INC)) { app_setup_page = (uint8_t)inc_mod(app_setup_page, APP_SETUP_SIZE - 1); } if((buttons & SUB_MENU_DEC)) { app_setup_page = (uint8_t)dec_mod(app_setup_page, APP_SETUP_SIZE - 1); } if((buttons & VALUE_INC)) { app_setup[app_setup_page] = inc_mod(app_setup[app_setup_page], app_setup_maximum[app_setup_page]); } if((buttons & VALUE_DEC)) { app_setup[app_setup_page] = dec_mod(app_setup[app_setup_page], app_setup_maximum[app_setup_page]); } strcpy_nrf(lcd_l0, app_setup_menu_header[app_setup_page]); itoa(app_setup[app_setup_page],buffer_a); strcpy(lcd_l1, buffer_a); }
void mm_gzll_params | ( | char * | lcd_l0, |
char * | lcd_l1, | ||
uint8_t | buttons | ||
) |
"Gzll params" menu.
Definition at line 624 of file main.c.
{ static xdata uint8_t gzll_param_page = 0; if((buttons & SUB_MENU_INC)) { gzll_param_page = (uint8_t)inc_mod((uint8_t)gzll_param_page, GZLL_DYN_PARAM_SIZE - 1); } if((buttons & SUB_MENU_DEC)) { gzll_param_page = (uint8_t)dec_mod(gzll_param_page, GZLL_DYN_PARAM_SIZE - 1); } if((buttons & VALUE_INC)) { gzll_set_param((gzll_dyn_params_t)gzll_param_page, inc_mod(gzll_get_param((gzll_dyn_params_t)gzll_param_page), gzll_get_param_max((gzll_dyn_params_t)gzll_param_page))); } if((buttons & VALUE_DEC)) { gzll_set_param((gzll_dyn_params_t)gzll_param_page, dec_mod(gzll_get_param((gzll_dyn_params_t)gzll_param_page), gzll_get_param_max((gzll_dyn_params_t)gzll_param_page))); } strcpy_nrf(lcd_l0, gzll_param_menu_header[gzll_param_page]); if((gzll_dyn_params_t)gzll_param_page == GZLL_PARAM_OUTPUT_POWER) { strcpy_nrf(lcd_l1, gzll_output_power[gzll_get_param((gzll_dyn_params_t)gzll_param_page)]); } else { itoa(gzll_get_param((gzll_dyn_params_t)gzll_param_page), buffer_a); strcpy(lcd_l1, buffer_a); } }
void mm_statistics | ( | char * | lcd_l0, |
char * | lcd_l1, | ||
uint8_t | buttons | ||
) |
"Statistics" menu.
Definition at line 660 of file main.c.
{ static xdata uint8_t statistics_page = 0; if((buttons & SUB_MENU_INC)) { statistics_page = (uint8_t)inc_mod(statistics_page, STATISTICS_SIZE - 1); } if((buttons & SUB_MENU_DEC)) { statistics_page = (uint8_t)dec_mod(statistics_page, STATISTICS_SIZE - 1); } strcpy_nrf(lcd_l0, statistics_menu_header[statistics_page]); //Avg tx tries should be presented as a floating point number if(statistics_page == (uint8_t)AVG_TX_TRIES) { itoa(statistics[AVG_TX_TRIES],buffer_a); buffer_b[0] = buffer_a[0]; // Quick fix to avoid float buffer_b[1] = '.'; buffer_b[2] = buffer_a[1]; buffer_b[3] = buffer_a[2]; buffer_b[4] = '\0'; strcpy(lcd_l1, buffer_b); } else { itoa(statistics[statistics_page],buffer_a); strcpy(lcd_l1,buffer_a); } }
void mm_channel_setup | ( | char * | lcd_l0, |
char * | lcd_l1, | ||
uint8_t | buttons | ||
) |
"Channel conf" menu.
Definition at line 695 of file main.c.
{ static xdata uint8_t channel_tab_shadow[GZLL_MAX_CHANNEL_TAB_SIZE] = GZLL_DEFAULT_CHANNEL_TAB; static xdata uint16_t channel_tab_size = GZLL_DEFAULT_CHANNEL_TAB_SIZE; static xdata uint16_t channel_page = GZLL_DEFAULT_CHANNEL_TAB_SIZE; if((buttons & SUB_MENU_INC)) { channel_page = inc_mod(channel_page, channel_tab_size); } if((buttons & SUB_MENU_DEC)) { channel_page = dec_mod(channel_page, channel_tab_size); } if((buttons & VALUE_DEC)) { if(channel_page == channel_tab_size) { channel_tab_size = dec_mod(channel_tab_size, GZLL_MAX_CHANNEL_TAB_SIZE); channel_page = channel_tab_size; } else { channel_tab_shadow[channel_page] = (uint8_t)dec_mod(channel_tab_shadow[channel_page], 125); } gzll_set_channels(channel_tab_shadow, (uint8_t)channel_tab_size); } if((buttons & VALUE_INC) != false) { if(channel_page == channel_tab_size) { channel_tab_size = inc_mod(channel_tab_size, GZLL_MAX_CHANNEL_TAB_SIZE); channel_page = channel_tab_size; } else { channel_tab_shadow[channel_page] = (uint8_t)inc_mod(channel_tab_shadow[channel_page], 125); } gzll_set_channels(channel_tab_shadow, (uint8_t)channel_tab_size); } if(channel_page == channel_tab_size) { strcpy(lcd_l0, "No of channels:"); itoa(channel_tab_size,buffer_a); strcpy(lcd_l1,buffer_a); } else { strcpy(buffer_a,"RF channel: "); itoa(channel_page, buffer_b); strncat(buffer_a,buffer_b,BUFFER_SIZE - (strlen(buffer_b)-1)); strcpy(lcd_l0, buffer_a); itoa(channel_tab_shadow[channel_page],buffer_a); strcpy(lcd_l1, buffer_a); } }
void main | ( | void | ) |
Gazell Link Layer Configuration tool main application.
Definition at line 306 of file main.c.
{ bool radio_activity; uint8_t buttons; mcu_init(); gzll_init(); app_init(); lcd_init(); EA = 1; app_execute(0); /* char a[] = "hei"; int i; i = atoi(a); */ for(;;) { buttons = buttons_read(); radio_activity = com_execute(); if((buttons) || (radio_activity)) { app_execute(buttons); } } }
T2_ISR | ( | ) |
TICK_ISR | ( | ) |
Definition at line 776 of file main.c.
{ gzll_timer_tick = true; gzll_timer_isr_function(); }
char main_menu_header[][17] |
code const char app_setup_menu_header[][17] |
code const uint16_t app_setup_maximum[4] |
{ 0xffff, GZLL_MAX_FW_PAYLOAD_LENGTH, GZLL_MAX_ACK_PAYLOAD_LENGTH, 5 }
code const char gzll_param_menu_header[][17] |
{ "DEVICE_MODE:", "TX_TIMEOUT:", "TX_ATT..SNC_ON:", "TX_ATT..SNC_OFF:", "HOST_MODE:", "RX_PIPES:", "RX_TIMEOUT:", "TX_M1_CYCLE_PER:", "RX_PERIOD:", "RX_PERIOD_MOD:", "RX_CH_HOLD_PER:", "CRYPT_PIPES:", "OUTPUT_POWER:", "PDOWN_IDLE_EN:", "MAX_SYNC_PERIOD:", "COL_CH_SW_LIM:", }
code const char gzll_output_power[][17] |
code const char statistics_menu_header[][17] |
xdata uint32_t statistics[8] |
xdata _Bool device_mode = (( _Bool )1) |
xdata volatile _Bool gzll_timer_tick |