예제 #1
0
파일: uart.c 프로젝트: huanjiayang/SWoT
/****************************************************************************
 *
 * NAME: vUART_HandleUart0Interrupt
 *
 * DESCRIPTION:
 *
 * PARAMETERS:      Name            RW  Usage
 * None.
 *
 * RETURNS:
 * None.
 *
 * NOTES:
 * None.
 ****************************************************************************/
PRIVATE void UART_vInterrupt(uint32 u32Device, uint32 u32ItemBitmap)
{
	if (u32Device == E_AHI_DEVICE_UART0) u8Uart = E_AHI_UART_0;
	if (u32Device == E_AHI_DEVICE_UART1) u8Uart = E_AHI_UART_1;

        if ((u32ItemBitmap & 0x000000FF) == E_AHI_UART_INT_RXDATA)
        {
            vUART_RxCharISR(u8AHI_UartReadData(u8Uart));
        }
        else if (u32ItemBitmap == E_AHI_UART_INT_TX)
        {
            vUART_TxCharISR();
        }
    }
예제 #2
0
/****************************************************************************
 *
 * NAME:       vAppQApiPostHwInt
 *
 * DESCRIPTION:
 * Called by lower layer as a callback, this takes a buffer from the spare
 * buffers queue for hardware events, populates it, and places it on the used
 * buffers queue. If a callback to the application has been defined, this is
 * called as well.
 *
 * PARAMETERS:      Name            RW  Usage
 *                  u32Device       R   Device identifier of event originator
 *                  u32ItemBitmap   R   Bitmap of events generated by device
 *
 * RETURNS:
 * void
 *
 * NOTES:
 * Runs in interrupt context
 *
 ****************************************************************************/
PUBLIC void vAppQApiPostHwInt(uint32 u32Device, uint32 u32ItemBitmap)
{
    AppQApiHwInd_s *psBuffer;

    /* Need special case for UART RX interrupt, as this is only cleared when
       the data is removed from the RX FIFO */
    if ((u32Device == E_AHI_DEVICE_UART0) || (u32Device == E_AHI_DEVICE_UART1))
    {
        if ((u32ItemBitmap == E_AHI_UART_INT_RXDATA)
            || (u32ItemBitmap == E_AHI_UART_INT_TIMEOUT))
        {
            /* Read byte from UART and store it in the bitmap to be queued */
            uint8 u8ActiveUart;

            if (u32Device == E_AHI_DEVICE_UART0)
            {
                u8ActiveUart = E_AHI_UART_0;
            }
            else
            {
                u8ActiveUart = E_AHI_UART_1;
            }
            u32ItemBitmap |= (((uint32)u8AHI_UartReadData(u8ActiveUart)) << 8);
        }
    }

    /* Get buffer for upward data */
    psBuffer = (AppQApiHwInd_s *)pvFifoPull(&sHwIndBufferQueue);

    /* If buffer available, put item on queue */
    if (psBuffer != NULL)
    {
        psBuffer->u32DeviceId = u32Device;
        psBuffer->u32ItemBitmap = u32ItemBitmap;
        bFifoPush(&sHwIndQueue, (void *)psBuffer);
    }

    /* Call callback. If there was no queue space, callback with empty
       queue indicates a problem */
    if (prAppHwCallback != NULL)
    {
        prAppHwCallback();
    }
}
예제 #3
0
파일: sersniff.c 프로젝트: pscholl/serniff
void
AppColdStart(void)
{
    /* initialize unaligned access handler */
    UNALIGNED_ACCESS = UNALIGNED_ACCESS_HANDLER;

    /* initialize uart to 8N1 at 115200 baud, that gives a throughput og
     * ~14.4 kb/s, maxmimum packet rate on Ieee802.15.4 is 248 packets/sec at
     * 127 bytes payload + header, which allows to return about 50bytes on the
     * uart per packet. */
    vAHI_UartEnable(UART);
    vAHI_UartReset(UART, true, true);
    vAHI_UartReset(UART, false, false);
    vAHI_UartSetControl(UART, E_AHI_UART_EVEN_PARITY,
                        E_AHI_UART_PARITY_DISABLE,
                        E_AHI_UART_WORD_LEN_8,
                        E_AHI_UART_1_STOP_BIT,
                        E_AHI_UART_RTS_HIGH);
    vAHI_UartSetBaudrate(UART, BAUD);
    vAHI_UartSetRTSCTS(UART, false);
    vAHI_DioSetDirection(CTS, RTS);
    vAHI_DioSetOutput(0x00, RTS);

    /* run the main loop, wait for channel number, then start reception
     * and packet delivery. Ack by sending "okay\n". */
    while (1) {
        static int     started = MAC_ENUM_NO_DATA;
        static char    input[10];
        static uint8_t i=0;

        /* write one rxd packet to uart */
        if (started==MAC_ENUM_SUCCESS) {
            MAC_DcfmIndHdr_s *ind;

            if (rxq_peektype() == MCPS) {
                ind = rxq_peek();

                if (ind->u8Type == MAC_MCPS_IND_DATA) {
                    MAC_McpsDcfmInd_s *s = ind;
                    uart_write(UART, (char*) &s->uParam.sIndData, sizeof(s->uParam.sIndData));
                }
            }

            rxq_dequeue();
        }

        /* read from uart into buf */
        while (i<sizeof(input) && DATAREADY(UART)) {
            input[i] = u8AHI_UartReadData(UART);

            if ((i+1)==sizeof(input)) { /* buffer overrun, discard input */
                memset(input, '\0', i);
                i = 0;
            } else if (input[i]=='\n' || input[i]=='\r') {  /* read as channel number */
                int channel;

                input[9] = '\0';            /* terminate string */
                channel  = atoi(input);     /* convert string to num */
                started  = start_sniffer(channel);

                if (started != MAC_ENUM_SUCCESS)
                    printf("not started, error code: 0x%x, see MAC_Enum_e\r\n", started);
                else
                    printf("started on channel %d\r\n", channel);

                memset(input, '\0', i);
                i = 0;
            } else
                i++;
        }
    }
}
예제 #4
0
static void irq(unsigned int irqsrc, unsigned int map)
{
  while (u8AHI_UartReadLineStatus(E_AHI_UART_0)&E_AHI_UART_LS_DR)
    uart0_input(u8AHI_UartReadData(E_AHI_UART_0));
}