Example #1
0
PROCESS_THREAD(ieee_process, ev, data)
{
  static void (*ieee_mlmehandler)(MAC_MlmeDcfmInd_s*);
  static void (*ieee_mcpshandler)(MAC_McpsDcfmInd_s*);

  PROCESS_BEGIN();
  PUTS("ieee_process: starting\n");

  ieee_init();
  ieee_serial_init();

  PT_INIT(&ieee_mlme); ieee_mlmehandler = ieee_mlmept;
  PT_INIT(&ieee_mcps); ieee_mcpshandler = ieee_mcpspt;

  /* start the mlme thread by requesting a scan. */
  req_scan(MAC_MLME_SCAN_TYPE_ACTIVE,0);

  PUTS("ieee_process: started\n");

  /* run until this process is exiting */
  while(true)
  {
    size_t i;
    MAC_DcfmIndHdr_s *macev;

    for(i=0; i<RX_QUEUE_SIZE && (macev=rxq_peek())!=NULL; i++)
    {
      if(rxq_peektype()==MLME) {
        //ieee_serial_mlme((MAC_MlmeDcfmInd_s*) macev);
        ieee_mlmehandler((MAC_MlmeDcfmInd_s*) macev);
      }
      else if(rxq_peektype()==MCPS) {
        //ieee_serial_mcps((MAC_McpsDcfmInd_s*) macev);
        ieee_mcpshandler((MAC_McpsDcfmInd_s*) macev);
      }

      rxq_dequeue();
    }

    if (ev==ieee_event && data == IEEE_STARTED)
      ieee_started = true;

    PROCESS_YIELD();
  }

  PUTS("ieee_process: exiting\n");
  PROCESS_END();
}
Example #2
0
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++;
        }
    }
}