/**************************************************************************** * * NAME: bAppQApiInit * * DESCRIPTION: * Initialised the Application Queue API, Application API and stack. Creates * the queues used for passing information up to the application and fills * the 'spare buffers' queues with the spare buffer entries. Also registers * the callback handlers with the Application API layer so all upward * information comes through this module. * * PARAMETERS: Name RW Usage * prMlmeCallback R Optional callback when MLME received * prMcpsCallback R Optional callback when MCPS received * prHwCallback R Optional callback when HW int received * * RETURNS: * TRUE if initialisation was successful * ****************************************************************************/ PUBLIC uint32 u32AppQApiInit(PR_QIND_CALLBACK prMlmeCallback, PR_QMCPS_CALLBACK prMcpsCallback, PR_HWQINT_CALLBACK prHwCallback) { int i; /* Initialise 'spare buffers' queues and fill with spare buffers */ vFifoInit(&sMlmeIndBufferQueue, apvMlmeIndBufferData, APP_MAX_MLME_IND); for (i = 0; i < APP_MAX_MLME_IND; i++) { bFifoPush(&sMlmeIndBufferQueue, (void *)&asMlmeIndBuffer[i]); } vFifoInit(&sMcpsIndBufferQueue, apvMcpsIndBufferData, APP_MAX_MCPS_IND); for (i = 0; i < APP_MAX_MCPS_IND; i++) { bFifoPush(&sMcpsIndBufferQueue, (void *)&asMcpsIndBuffer[i]); } vFifoInit(&sHwIndBufferQueue, apvHwIndBufferData, APP_MAX_HW_IND); for (i = 0; i < APP_MAX_HW_IND; i++) { bFifoPush(&sHwIndBufferQueue, (void *)&asHwIndBuffer[i]); } /* Initialise 'used buffers' queues */ vFifoInit(&sMlmeIndQueue, apvMlmeIndData, APP_MAX_MLME_IND); vFifoInit(&sMcpsIndQueue, apvMcpsIndData, APP_MAX_MCPS_IND); vFifoInit(&sHwIndQueue, apvHwIndData, APP_MAX_HW_IND); /* Store callbacks */ prAppMlmeCallback = prMlmeCallback; prAppMcpsCallback = prMcpsCallback; prAppHwCallback = prHwCallback; /* Register peripheral callbacks */ vAHI_SysCtrlRegisterCallback(vAppQApiPostHwInt); vAHI_APRegisterCallback(vAppQApiPostHwInt); #ifndef GDB vAHI_Uart0RegisterCallback(vAppQApiPostHwInt); #endif vAHI_Uart1RegisterCallback(vAppQApiPostHwInt); vAHI_TickTimerInit(vAppQApiPostHwInt); vAHI_SpiRegisterCallback(vAppQApiPostHwInt); vAHI_SiRegisterCallback(vAppQApiPostHwInt); vAHI_Timer0RegisterCallback(vAppQApiPostHwInt); vAHI_Timer1RegisterCallback(vAppQApiPostHwInt); /* Register this layer with AppApi layer */ return u32AppApiInit(psAppQApiGetMlmeBuffer, vAppQApiPostMlme, NULL, psAppQApiGetMcpsBuffer, vAppQApiPostMcps, NULL); }
void uart0_init(unsigned long br) { vAHI_UartSetRTSCTS(E_AHI_UART_0, false); vAHI_UartEnable(E_AHI_UART_0); vAHI_UartReset(E_AHI_UART_0, true, true); uart0_set_br(br); vAHI_UartSetRTSCTS(E_AHI_UART_0, false); vAHI_Uart0RegisterCallback(irq); vAHI_UartSetInterrupt(E_AHI_UART_0, false, /* modem status */ false, /* rx line error status */ false, /* tx fifo empty */ true, /* rx data there */ E_AHI_UART_FIFO_LEVEL_1); vAHI_UartSetRTSCTS(E_AHI_UART_0, false); vAHI_UartReset(E_AHI_UART_0, false, false); }
/**************************************************************************** * * NAME: vUART_Init * * DESCRIPTION: * * PARAMETERS: Name RW Usage * None. * * RETURNS: * None. * * NOTES: * None. ****************************************************************************/ PUBLIC bool_t vUART_Init(uint8 u8Uart, /**< Uart to open */ uint32 u32BaudRate, /**< Baud rate */ bool_t bEvenParity, /**< Even parity */ bool_t bEnableParity, /**< Enable parity */ uint8 u8WordLength, /**< Word length, one of:\n E_AHI_UART_WORD_LEN_5\n E_AHI_UART_WORD_LEN_6\n E_AHI_UART_WORD_LEN_7\n E_AHI_UART_WORD_LEN_8 */ bool_t bOneStopBit) /**< One stop bit */ { uint16 u16Divisor; /* Baud rate divisor */ uint32 u32Remainder; /* Baud rate remainder */ /* Valid uart ? */ if (u8Uart < 2) { /* Calculate divisor for baud rate = 16MHz / (16 x baud rate) */ u16Divisor = (uint16)(16000000UL / (16UL * u32BaudRate)); /* Correct for rounding errors */ u32Remainder = (uint32)(16000000UL % (16UL * u32BaudRate)); if (u32Remainder >= ((16UL * u32BaudRate) / 2)) u16Divisor += 1; /* Start with port unopened */ Uart_Opened[u8Uart]= FALSE; vAHI_UartSetRTSCTS(u8Uart, FALSE); /* Enable UART 0 */ vAHI_UartEnable(u8Uart); vAHI_UartReset(u8Uart, TRUE, TRUE); vAHI_UartReset(u8Uart, FALSE, FALSE); Uart_Opened[u8Uart]= TRUE; #if !UART_JENOS { /* Register function that will handle UART interrupts */ if (u8Uart == E_AHI_UART_0) vAHI_Uart0RegisterCallback(UART_vInterrupt); if (u8Uart == E_AHI_UART_1) vAHI_Uart1RegisterCallback(UART_vInterrupt); } #endif /* Set baud rate */ vAHI_UartSetBaudDivisor(u8Uart, u16Divisor); /* Set control */ vAHI_UartSetControl(u8Uart, bEvenParity, bEnableParity, u8WordLength, bOneStopBit, FALSE); /* Set UART interrupts */ vAHI_UartSetInterrupt(u8Uart, FALSE, /* ModemStatus */ FALSE, /* RxLineStatus */ TRUE, /* TxFifoEmpty */ TRUE, /* RxData */ E_AHI_UART_FIFO_LEVEL_1); return TRUE; } return FALSE; }