Exemplo n.º 1
0
extern void timerCallback(timer_id const id) 
{
    uint8 hacksplack = 0;    
    uint8 minimap =  (g_eeg_serv_data.channel_map & 0x00FF);

    if ((minimap & 0x01) == 1)
        hacksplack += 1;
    if ((minimap & 0x02) == 2)
        hacksplack += 2;
    if ((minimap & 0x04) == 4)
        hacksplack += 4;
    if ((minimap & 0x08) == 8)
        hacksplack += 8;
    if ((minimap & 0x10) == 16)
        hacksplack += 16;
    if ((minimap & 0x20) == 32)
        hacksplack += 32;
    if ((minimap & 0x40) == 64)
        hacksplack += 64;
    if ((minimap & 0x80) == 128)
        hacksplack += 128;
    
    if (hacksplack == 0)
        hacksplack = 1;
    readChannels((hacksplack) , &meas_report[0]);
    
#ifdef DEBUG
   /* writeASCIICodedNumber(minimap);
    DebugWriteString("\r\n");
    writeASCIICodedNumber(hacksplack);
    DebugWriteString("\r\n");
    writeASCIICodedNumber(meas_report[0]);
    DebugWriteString(" ");
    writeASCIICodedNumber(meas_report[1]);
    DebugWriteString("\r\n");
    writeASCIICodedNumber(meas_report[2]);
    DebugWriteString(" ");
    writeASCIICodedNumber(meas_report[3]);
    DebugWriteString("\r\n");
    writeASCIICodedNumber(meas_report[4]);
    DebugWriteString(" ");
    writeASCIICodedNumber(meas_report[5]);
    DebugWriteString("\r\n"); */
#endif
    
    if ((g_eeg_serv_data.acquisition_rate < 1) || (g_eeg_serv_data.acquisition_rate > 900))
        g_eeg_serv_data.acquisition_rate = 10000;

    
    TimerCreate((TIME) (((uint32) g_eeg_serv_data.acquisition_rate) * 100UL), TRUE, timerCallback);
 #ifdef DEBUG   
   
    writeASCIICodedNumber(g_eeg_serv_data.acquisition_rate * 100UL);

    #endif
}
Exemplo n.º 2
0
/*----------------------------------------------------------------------------*
 *  NAME
 *      processRxCmd
 *
 *  DESCRIPTION
 *      Read and process the next command from the byte queue.
 *
 * PARAMETERS
 *      None
 *
 * RETURNS
 *      Nothing
 *----------------------------------------------------------------------------*/
static void processRxCmd(void)
{
    /* Loop until the byte queue is empty */
    while (BQGetDataSize() > 0)
    {
        uint8 byte = '\0';

        /* Read in the next byte */
        if (BQPopBytes(&byte, 1) > 0)
        {
            CMD_T cmd_type;

            /* Convert byte into a command */
            switch (byte)
            {
            case 's':
            case 'S':
                cmd_type = cmd_set;
                break;
            case 'g':
            case 'G':
                cmd_type = cmd_get;
                break;
            case 'c':
            case 'C':
                cmd_type = cmd_clear;
                break;
            case 'd':
            case 'D':
                cmd_type = cmd_digital;
                break;
            case 'h':
            case 'H':
                showHelp();
                continue;
            default:
                /* Discard the byte (we don't know what to do with it) and
                 * jump back to the top of the loop.
                 */
                continue;
            }

            /* At this point a valid command has been found */
            uint32 value;

            /* Read in the port number (in ASCII) from the byte queue */
            if (readASCIICodedNumber(&value))
            {
                const aio_select port = (aio_select)value;

                /* Validate the port number */
                if ((port == value) && (port < NUMBER_OF_AIOS))
                {
                    switch (cmd_type)
                    {
                    /* Read the voltage level of an analogue port */
                    case cmd_get:
                    {
                        /* Read the analogue voltage... */
                        const uint16 mvs = AioRead(port);

                        /* ...and send it to the UART */
                        DebugWriteString("\r\nAnalog voltage measured on AIO ");
                        writeASCIICodedNumber(port);
                        DebugWriteString(" is ");
                        writeASCIICodedNumber(mvs);
                        DebugWriteString("mV\r\n");
                        break;
                    }

                    /* Clear the voltage set on an analogue port */
                    case cmd_clear:
                    {
                        /* Turn off the specified analogue port... */
                        AioOff(port);

                        /* ...and print confirmation to the UART */
                        DebugWriteString("\r\nAnalog voltage set on AIO ");
                        writeASCIICodedNumber(port);
                        DebugWriteString(" is now cleared\r\n");
                        break;
                    }

                    /* Set the requested voltage in mV on an analogue port */
                    case cmd_set:
                    {
                        uint32 vol;

                        /* Read in the requested voltage from the byte queue */
                        if (readASCIICodedNumber(&vol))
                        {
                            /* Validate the requested voltage */
                            if ((uint16)vol == vol)
                            {
                                /* Set the analogue port to the requested voltage... */
                                AioDrive(port, (uint16)vol);

                                /* ...and print confirmation to the UART */
                                DebugWriteString("\r\nAIO ");
                                writeASCIICodedNumber(port);
                                DebugWriteString(" is attempting to drive ");
                                writeASCIICodedNumber((uint16)vol);
                                DebugWriteString( "mV output\r\n");
                            }
                        }
                        break;
                    }

                    /* Set the requested digital output on an analogue port */
                    case cmd_digital:
                    {
                        uint32 vol;

                        /* Read in the requested value from the byte queue */
                        if (readASCIICodedNumber(&vol))
                        {
                            /* Validate the requested value */
                            if ((uint16)vol == vol)
                            {
                                /* Set the analogue port to the requested output... */
                                AioSetDig(port, vol);

                                /* ...and print confirmation to the UART */
                                DebugWriteString("\r\nAIO ");
                                writeASCIICodedNumber(port);
                                DebugWriteString(" is attempting to drive ");
                                DebugWriteString(vol ? "HIGH\r\n" : "LOW\r\n");
                            }
                        }
                        break;
                    }

                    default:
                        /* This case should never be called */
                        DebugWriteString("\r\nCommand not recognised\r\n");
                        break;
                    }
                }
            }
        }
    }
}