/*********************************************************************************** * @fn appSelectRole * * @brief Select application role. Device 1, device 2 or loopback. * * @param none * * @return none */ static void appSelectRole(void) { #ifdef DEVICE_LOOPBACK_FORCE appRole= DEVICE_LOOPBACK; #else #ifdef LCD_NOT_SUPPORTED appRole= DEVICE_2; #else halLcdWriteLine(1, "Device Role: "); appRole= utilMenuSelect(&pRoleMenu); #endif // LCD_NOT_SUPPORTED #endif // DEVICE_LOOPBACK_FORCE halLcdClear(); // Set distinct addresses if(appRole == DEVICE_1) { halLcdWriteLine(HAL_LCD_LINE_2, "Device 1 ready"); appLocalAddr = DEVICE_1_ADDR; appRemoteAddr= DEVICE_2_ADDR; } else if (appRole == DEVICE_2) { halLcdWriteLine(HAL_LCD_LINE_2, "Device 2 ready"); appLocalAddr = DEVICE_2_ADDR; appRemoteAddr= DEVICE_1_ADDR; } else if (appRole == DEVICE_LOOPBACK) { halLcdWriteLine(HAL_LCD_LINE_2, "Loopback ready"); } }
/*********************************************************************************** * @fn main * * @brief This is the main entry of the RF Modem application. It sets * distinct short addresses for the nodes, initalises and runs * receiver and sender tasks sequentially in an endless loop. * * @return none */ void main(void) { char *szTitle= "MRFI RF modem"; appUartRxIdle = FALSE; // Initialise board peripherals halBoardInit(); halUartInit(HAL_UART_BAUDRATE_38400, 0); // 100 ms RX idle timeout appConfigTimer(1000/UART_RX_IDLE_TIME); // Indicate that the application has been initialised halLcdClear(); halLcdWriteLine(HAL_LCD_LINE_1, szTitle); halLedSet(1); // Select application role (Device 1, Device 2 or Loopback) appSelectRole(); if (appRole != DEVICE_LOOPBACK) { // Initialize the MRFI RF link layer mrfiLinkInit(appLocalAddr,appRemoteAddr,MRFI_CHANNEL); } // Indicate that the modem is operating halLcdWriteLine(HAL_LCD_LINE_1, szTitle); // Initialise error counters nTxErr= nRxErr= 0; // Enable RX idle timeout interrupt halTimer32kIntEnable(); // Main processing loop while(TRUE) { // On-board device processing (UART etc.) HAL_PROCESS(); if (appRole == DEVICE_LOOPBACK) { // Loopback processing appLoopbackTask(); } else { // RF transmitter processing appRfSenderTask(); // RF receiver processing appRfReceiverTask(); } } }
/*********************************************************************************** * @fn halLcdInit * * @brief Initalise LCD * * @param none * * @return none */ void halLcdInit(void) { // Initialize I/O LCD_CTRL_INIT_PORTS(); // Perform the initialization sequence FUNCTION_SET(CGRAM | COM_FORWARD | THREE_LINE); halLcdSetContrast(15); SET_POWER_SAVE_MODE(OSC_OFF | POWER_SAVE_ON); SET_POWER_CTRL(VOLTAGE_DIVIDER_ON | CONVERTER_AND_REG_ON); SET_BIAS_CTRL(BIAS_1_5); halMcuWaitMs(21); // 21 ms // Clear the display halLcdClear(); halLcdClearAllSpecChars(); SET_DISPLAY_CTRL(DISPLAY_CTRL_ON | DISPLAY_CTRL_BLINK_OFF | DISPLAY_CTRL_CURSOR_OFF); }