Exemplo n.º 1
0
SYS_MODULE_OBJ STIMULUS_USART_DRV_Initialize(const SYS_MODULE_INDEX index,
                                       const SYS_MODULE_INIT * const init )
{
    /* Get the USART COnfig Data */
    configData = (DRV_USART_CONFIG_INIT *)init;
    /* Initialize USART */
    PLIB_USART_BaudRateSet(configData->usartId, SYS_CLK_PeripheralFrequencyGet(CLK_BUS_PERIPHERAL_1), configData->baudRate);
    PLIB_USART_HandshakeModeSelect(configData->usartId, USART_HANDSHAKE_MODE_FLOW_CONTROL);
    PLIB_USART_OperationModeSelect(configData->usartId, USART_ENABLE_TX_RX_USED);
    PLIB_USART_LineControlModeSelect(configData->usartId, configData->lineControl);
    PLIB_USART_TransmitterEnable(configData->usartId);
    PLIB_USART_TransmitterInterruptModeSelect(configData->usartId, USART_TRANSMIT_FIFO_NOT_FULL);
    PLIB_USART_ReceiverEnable(configData->usartId);
    PLIB_USART_ReceiverInterruptModeSelect(configData->usartId, configData->rxIntMode);
    /* Initialize interrupts */
    /* Note: TX interrupt must be enabled when data is ready to be transmitted */
    /* The following code can be used to enable TX Interrupt */
    /* PLIB_INT_SourceEnable(INT_ID_0, INT_SOURCE_USART_1_TRANSMIT); */
    PLIB_INT_SourceEnable(INT_ID_0, INT_SOURCE_USART_1_RECEIVE);
    PLIB_INT_SourceEnable(INT_ID_0, INT_SOURCE_USART_1_ERROR);
    PLIB_INT_VectorPrioritySet(INT_ID_0, INT_VECTOR_UART1, INT_PRIORITY_LEVEL1);
    PLIB_INT_VectorSubPrioritySet(INT_ID_0, INT_VECTOR_UART1, INT_SUBPRIORITY_LEVEL0);
    
    PLIB_USART_Enable(configData->usartId);
}
Exemplo n.º 2
0
void DRV_USART0_Initialize(void)
{
    /* Initialize USART */
    PLIB_USART_BaudRateSet(USART_ID_1, SYS_CLK_PeripheralFrequencyGet(CLK_BUS_PERIPHERAL_2), 9600);
    PLIB_USART_HandshakeModeSelect(USART_ID_1, USART_HANDSHAKE_MODE_FLOW_CONTROL);
    PLIB_USART_OperationModeSelect(USART_ID_1, USART_ENABLE_TX_RX_USED);
    PLIB_USART_LineControlModeSelect(USART_ID_1, USART_8N1);
    PLIB_USART_TransmitterEnable(USART_ID_1);
    PLIB_USART_TransmitterInterruptModeSelect(USART_ID_1, USART_TRANSMIT_FIFO_NOT_FULL);
    PLIB_USART_ReceiverEnable(USART_ID_1);
    PLIB_USART_ReceiverInterruptModeSelect(USART_ID_1, USART_RECEIVE_FIFO_ONE_CHAR);

    /* Initialize TX interrupt */
    PLIB_INT_SourceEnable(INT_ID_0, INT_SOURCE_USART_1_TRANSMIT);
    PLIB_INT_VectorPrioritySet(INT_ID_0, INT_VECTOR_UART1_TX, INT_PRIORITY_LEVEL1);
    PLIB_INT_VectorSubPrioritySet(INT_ID_0, INT_VECTOR_UART1_TX, INT_SUBPRIORITY_LEVEL0);

    /* Initialize RX interrupt */
    PLIB_INT_SourceEnable(INT_ID_0, INT_SOURCE_USART_1_RECEIVE);
    PLIB_INT_VectorPrioritySet(INT_ID_0, INT_VECTOR_UART1_RX, INT_PRIORITY_LEVEL1);
    PLIB_INT_VectorSubPrioritySet(INT_ID_0, INT_VECTOR_UART1_RX, INT_SUBPRIORITY_LEVEL0);

    /* Initialize Fault interrupt */
    PLIB_INT_SourceEnable(INT_ID_0, INT_SOURCE_USART_1_ERROR);
    PLIB_INT_VectorPrioritySet(INT_ID_0, INT_VECTOR_UART1_FAULT, INT_PRIORITY_LEVEL1);
    PLIB_INT_VectorSubPrioritySet(INT_ID_0, INT_VECTOR_UART1_FAULT, INT_SUBPRIORITY_LEVEL0);

    PLIB_USART_Enable(USART_ID_1);
}
Exemplo n.º 3
0
void DRV_USART0_Initialize(void)
{
    /* Initialize USART */
    PLIB_USART_BaudRateSet(USART_ID_1, SYS_CLK_PeripheralFrequencyGet(CLK_BUS_PERIPHERAL_1), 115200);
    PLIB_USART_HandshakeModeSelect(USART_ID_1, USART_HANDSHAKE_MODE_SIMPLEX);
    PLIB_USART_OperationModeSelect(USART_ID_1, USART_ENABLE_TX_RX_USED);
    PLIB_USART_LineControlModeSelect(USART_ID_1, USART_8N1);
    PLIB_USART_TransmitterEnable(USART_ID_1);
    PLIB_USART_TransmitterInterruptModeSelect(USART_ID_1, USART_TRANSMIT_FIFO_EMPTY);

    PLIB_USART_Enable(USART_ID_1);
}
Exemplo n.º 4
0
/**********************************************************
 * Application tasks routine. This function implements the
 * application state machine.
 ***********************************************************/
void APP_Tasks ( void )
{
    /* check the application state*/
    switch ( appData.state )
    {
        case USART_ENABLE:
           
            /* Enable the UART module*/
            PLIB_USART_Enable(USART_ID_2);

            appData.stringPointer = txPowerValuesBuff_1;
;

            appData.state =  USART_TRANSMIT_FIRST_STRING;

            break;

        case USART_TRANSMIT_FIRST_STRING:
            if(true == WriteString())
            {
                appData.state = USART_TRANSMIT_SECOND_STRING;
                appData.stringPointer = string2;
            }

            break;

        case USART_TRANSMIT_SECOND_STRING:
            if(true == WriteString())
            {
                appData.state = USART_RECEIVE_DONE;
            }
            break;

        case USART_RECEIVE_DONE:
              if (appData.InterruptFlag)
              {
                  if(true == PutCharacter(appData.data))
                  {
                    BSP_LEDOn(BSP_LED_3);
                    appData.InterruptFlag = false;        
                  }
              }
            break;

        default:
            SYS_DEBUG (SYS_ERROR_FATAL,"ERROR! Invalid state\r\n");
            while (1);

    }

} 
Exemplo n.º 5
0
void APP_Debug_Initialize(){

    // PPS Output Mapping:
    PLIB_PORTS_RemapOutput(PORTS_ID_0, OUTPUT_FUNC_U1TX, OUTPUT_PIN_RPD3 );

    /* Initialize USART */
    PLIB_USART_BaudRateSet(APP_DEBUG_USART_ID, SYS_CLK_PeripheralFrequencyGet(CLK_BUS_PERIPHERAL_1), APP_DEBUG_USART_BAUD);
    PLIB_USART_HandshakeModeSelect(APP_DEBUG_USART_ID, USART_HANDSHAKE_MODE_FLOW_CONTROL);
    PLIB_USART_OperationModeSelect(APP_DEBUG_USART_ID, USART_ENABLE_TX_RX_USED);
    PLIB_USART_LineControlModeSelect(APP_DEBUG_USART_ID, USART_8N1);
    PLIB_USART_TransmitterEnable(APP_DEBUG_USART_ID);

    PLIB_USART_Enable(APP_DEBUG_USART_ID);
}
Exemplo n.º 6
0
void hal_uart_dma_init(void){

    bytes_to_write = 0;
    bytes_to_read = 0;

    /* PPS Input Remapping */
    PLIB_PORTS_RemapInput(PORTS_ID_0, INPUT_FUNC_U2RX, INPUT_PIN_RPF4 );
    PLIB_PORTS_RemapInput(PORTS_ID_0, INPUT_FUNC_U2CTS, INPUT_PIN_RPB2 );

    /* PPS Output Remapping */
    PLIB_PORTS_RemapOutput(PORTS_ID_0, OUTPUT_FUNC_U2RTS, OUTPUT_PIN_RPG9 );
    PLIB_PORTS_RemapOutput(PORTS_ID_0, OUTPUT_FUNC_U2TX, OUTPUT_PIN_RPF5 );

    /* Initialize USART */
    PLIB_USART_BaudRateSet(BT_USART_ID, SYS_CLK_PeripheralFrequencyGet(CLK_BUS_PERIPHERAL_1), BT_USART_BAUD);
    PLIB_USART_HandshakeModeSelect(BT_USART_ID, USART_HANDSHAKE_MODE_FLOW_CONTROL);
    PLIB_USART_OperationModeSelect(BT_USART_ID, USART_ENABLE_TX_RX_CTS_RTS_USED);
    PLIB_USART_LineControlModeSelect(BT_USART_ID, USART_8N1);
    PLIB_USART_TransmitterEnable(BT_USART_ID);
//    PLIB_USART_TransmitterInterruptModeSelect(bluetooth_uart_id, USART_TRANSMIT_FIFO_IDLE);
    PLIB_USART_ReceiverEnable(BT_USART_ID);
//    PLIB_USART_ReceiverInterruptModeSelect(bluetooth_uart_id, USART_RECEIVE_FIFO_ONE_CHAR);

    PLIB_USART_Enable(BT_USART_ID);

    // enable _RESET
    SYS_PORTS_PinDirectionSelect(PORTS_ID_0, SYS_PORTS_DIRECTION_OUTPUT, BT_RESET_PORT, BT_RESET_BIT);

    bluetooth_power_cycle();

    // After reset, CTS is high and we need to wait until CTS is low again

    // HACK: CTS doesn't seem to work right now
    msleep(250);

    // HACK: CSR seems to do an auto-baud on the uart, which makes the first HCI RESET fail
    // 2 options: a) check for CTS going high within 10 ms, b) just send HCI RESET twice

//    const uint8_t hci_reset_cmd[] = {0x01, 0x03, 0x0c, 0x00};
//    int pos = 0;
//    while(pos < sizeof(hci_reset_cmd)){
//        if (PLIB_USART_TransmitterIsEmpty(BT_USART_ID)){
//            PLIB_USART_TransmitterByteSend(BT_USART_ID, hci_reset_cmd[pos]);
//            pos++;
//        }
//    }
//    msleep(250);

}
Exemplo n.º 7
0
void DRV_USART0_Initialize(void)
{
    /* Initialize USART */
    PLIB_USART_BaudRateSet(USART_ID_2, SYS_CLK_PeripheralFrequencyGet(CLK_BUS_PERIPHERAL_1), 230400);
    PLIB_USART_HandshakeModeSelect(USART_ID_2, USART_HANDSHAKE_MODE_SIMPLEX);
    PLIB_USART_OperationModeSelect(USART_ID_2, USART_ENABLE_TX_RX_USED);
    PLIB_USART_LineControlModeSelect(USART_ID_2, USART_8N1);
    PLIB_USART_TransmitterEnable(USART_ID_2);
    PLIB_USART_TransmitterInterruptModeSelect(USART_ID_2, USART_TRANSMIT_FIFO_NOT_FULL);
    /* Initialize interrupts */
    /* Note: TX interrupt must be enabled when data is ready to be transmitted */
    /* The following code can be used to enable TX Interrupt */
    /* PLIB_INT_SourceEnable(INT_ID_0, INT_SOURCE_USART_2_TRANSMIT); */
    PLIB_INT_SourceEnable(INT_ID_0, INT_SOURCE_USART_2_ERROR);
    PLIB_INT_VectorPrioritySet(INT_ID_0, INT_VECTOR_UART2, INT_PRIORITY_LEVEL1);
    PLIB_INT_VectorSubPrioritySet(INT_ID_0, INT_VECTOR_UART2, INT_SUBPRIORITY_LEVEL0);

    PLIB_USART_Enable(USART_ID_2);
}
Exemplo n.º 8
0
int  hal_uart_dma_set_baud(uint32_t baud){
    PLIB_USART_Disable(BT_USART_ID);
    PLIB_USART_BaudRateSet(BT_USART_ID, SYS_CLK_PeripheralFrequencyGet(CLK_BUS_PERIPHERAL_1), baud);
    PLIB_USART_Enable(BT_USART_ID);
    return 0;
}
Exemplo n.º 9
0
SYS_MODULE_OBJ DRV_USART_Initialize
(
    const SYS_MODULE_INDEX drvIndex,
    const SYS_MODULE_INIT * const init
)
{
    DRV_USART_OBJ *dObj = (DRV_USART_OBJ*)NULL;
    DRV_USART_INIT *usartInit = NULL ;

    /* Check if the specified driver index is in valid range */
    if(drvIndex >= DRV_USART_INSTANCES_NUMBER)
    {
        SYS_DEBUG(0, "Invalid driver index");
        return SYS_MODULE_OBJ_INVALID;
    }

    /* Check if this hardware instance was already initialized */
    if(gDrvUSARTObj[drvIndex].inUse != false)
    {
        SYS_DEBUG(0, "Instance already in use");
        return SYS_MODULE_OBJ_INVALID;
    }

    /* Assign to the local pointer the init data passed */
    usartInit = ( DRV_USART_INIT * ) init ;

    /* Disable the USART module */
    PLIB_USART_Disable (usartInit->usartID) ;

    /* Allocate the driver object and set the operation flag to be in use */
    dObj = &gDrvUSARTObj[drvIndex];
    dObj->inUse = true;

    /* Update the USART PLIB Id and other parameters. */

    dObj->nClients              = 0;
    dObj->moduleId              = usartInit->usartID;
    dObj->brgClock              = usartInit->brgClock;
    dObj->isExclusive           = false;
    dObj->queueSizeRead         = usartInit->queueSizeReceive;
    dObj->queueSizeWrite        = usartInit->queueSizeTransmit;
    dObj->dmaChannelRead        = usartInit->dmaReceive;
    dObj->dmaChannelWrite       = usartInit->dmaTransmit;
    dObj->txInterruptSource     = usartInit->interruptTransmit;
    dObj->rxInterruptSource     = usartInit->interruptReceive;
    dObj->errorInterruptSource  = usartInit->interruptError;
    dObj->dmaInterruptTransmit  = usartInit->dmaInterruptTransmit;
    dObj->dmaInterruptReceive   = usartInit->dmaInterruptReceive;
    dObj->interruptNestingCount = 0;
    dObj->queueSizeCurrentRead  = 0; 
    dObj->queueSizeCurrentWrite = 0;

    /* Setup the Hardware */
    _DRV_USART_HardwareSetup(usartInit->usartID, usartInit ) ;

    /* Clear the interrupts */
    SYS_INT_SourceStatusClear(dObj->txInterruptSource);
    SYS_INT_SourceStatusClear(dObj->rxInterruptSource);
    SYS_INT_SourceStatusClear(dObj->errorInterruptSource);

    /* Enable the interrupt source in case of interrupt mode */
    _DRV_USART_InterruptSourceEnable(dObj->errorInterruptSource);

    /* TODO: Enable DMA interrupts if the DMA channel is selected */

    /* Create the hardware instance mutex. */
     OSAL_ASSERT((OSAL_MUTEX_Create(&(dObj->mutexDriverInstance)) == OSAL_RESULT_TRUE),
                 "Unable to create hardware instance mutex");


    /* Check if the global mutexes have been created. If not
       then create these. */

     if(!gDrvUSARTCommonDataObj.membersAreInitialized)
     {
         /* This means that mutexes where not created. Create them. */
         OSAL_ASSERT((OSAL_MUTEX_Create(&(gDrvUSARTCommonDataObj.mutexClientObjects)) == OSAL_RESULT_TRUE),
                     "Unable to create client instance mutex");
         OSAL_ASSERT((OSAL_MUTEX_Create(&(gDrvUSARTCommonDataObj.mutexBufferQueueObjects)) == OSAL_RESULT_TRUE),
                     "Unable to create buffer queue objects mutex");

         /* Set this flag so that global mutexes get allocated only once */
         gDrvUSARTCommonDataObj.membersAreInitialized = true;
     }

    /* Enable the USART module */
    PLIB_USART_Enable(usartInit->usartID) ;

    /* Update the status */
    dObj->status = SYS_STATUS_READY;

    /* Return the object structure */
    return ( (SYS_MODULE_OBJ)drvIndex );
}