コード例 #1
0
ファイル: app.c プロジェクト: sakhnik/zelesta
void app_second(void)
{
    if (!app_running)
        return;
    clock_process();
    alarm_process();
}
コード例 #2
0
ファイル: loop.c プロジェクト: jsyk/Talking_Clock
/**
 * Main message (infinite) loop.
 */
void loop_loop(int8_t once)
{
    do {
        message_t lmsg;
        if (g_message_buffer.rdpos == g_message_buffer.wrpos) {
            /* no message in the buffer: Run NOP message */
            lmsg.cmd = Cmd_Nop;
            lmsg.arg1i = 0;
        } else {
            /* a message in the buffer: retrieve and process */
            lmsg = g_message_buffer.msg_buf[g_message_buffer.rdpos];
            g_message_buffer.rdpos = iwrap(g_message_buffer.rdpos + 1);

            if (lmsg.cmd != Cmd_ClockTick) {
                usart_sendstr_P(PSTR("[Msg:0x"));
                usart_sendhexb(lmsg.cmd);
                usart_sendstr_P(PSTR("]"));
            }
        }

        int8_t used = 0;
        used |= voice_process(&lmsg);
        used |= vfs_process(&lmsg);
        used |= sound_process(&lmsg);
        used |= ir_process(&lmsg);
        used |= debug_process(&lmsg);
        used |= btn_process(&lmsg);
        used |= clock_process(&lmsg);

        if (!used && (lmsg.cmd != Cmd_Nop)) {
            usart_sendstr_P(PSTR("[Msg not recognized!]\n"));
        }

        /* reset watchdog timer */
        wdt_reset();
    } while (!once);
}
コード例 #3
0
ファイル: main.c プロジェクト: GBert/EasyCAN
/**
 * Main function. Entry point for USBtin application.
 * Handles initialization and the the main processing loop.
 */
void main(void) {

    // initialize MCP2515 (reset and clock setup)
    mcp2515_init();   
   
    // switch (back) to external clock (if fail-safe-monitor switched to internal)
    OSCCON = 0x30;

    // disable all analog pin functions, set led pin to output
    ANSEL = 0;
    ANSELH = 0;
    TRISBbits.TRISB5 = 0;
    hardware_setLED(0);

    // initialize modules
    clock_init();
    usb_init();
    
    char line[LINE_MAXLEN];
    unsigned char linepos = 0;
    unsigned short lastclock = 0;

    while (1) {

        // do module processing
        usb_process();
        clock_process();

        // receive characters from UART and collect the data until end of line is indicated
        if (usb_chReceived()) {
            unsigned char ch = usb_getch();

            if (ch == CR) {
                line[linepos] = 0;
                parseLine(line);
                linepos = 0;
            } else if (ch != LR) {
                line[linepos] = ch;
                if (linepos < LINE_MAXLEN - 1) linepos++;
            }

        }
            
	// handles interrupt requests of MCP2515 controller: receive message and print it out.
        if ((state != STATE_CONFIG) && (hardware_getMCP2515Int())) {

            canmsg_t canmsg;
            mcp2515_receive_message(&canmsg);
            char type;
            unsigned char idlen;
            unsigned short timestamp = clock_getMS();

            if (canmsg.flags.rtr) type = 'r';
            else type = 't';

            if (canmsg.flags.extended) {
                type -= 'a' - 'A';
                idlen = 8;
            } else {
                idlen = 3;
            }

            usb_putch(type);
            sendHex(canmsg.id, idlen);

            sendHex(canmsg.length, 1);

            if (!canmsg.flags.rtr) {
                unsigned char i;
                for (i = 0; i < canmsg.length; i++) {
                   sendHex(canmsg.data[i], 2);
                }
            }

            if (timestamping) {
                sendHex(timestamp, 4);
            }

            usb_putch(CR);
        }        

        // led signaling
        hardware_setLED(state != STATE_CONFIG);

        // jump into bootloader, if jumper is closed
        if (hardware_getBLSwitch()) {
            UCON = 0;
            _delay(1000);
            RESET();
        }
    }
}
コード例 #4
0
ファイル: main.c プロジェクト: Elios007/alceosd
int main(void) {
    extern int __C30_UART; __C30_UART = 2;
    unsigned char i;
    unsigned char in_config = 0;
    char c;

    /* generic hw init */
    hw_init();
    
    /* real time clock init */
    clock_init();

    /* adc init */
    adc_init();

    /* init uart2 */
    uart_init2(UART_PORT_TELEMETRY);

    /* init video driver */
    init_video();

    /* try to load config from flash */
    load_config();

    /* video driver config */
    video_apply_config(&config.video);

    /* init widgets */
    widgets_init();

    /* enable all interrupts */
    SRbits.IPL = 0;
    CORCONbits.IPL3 = 1;

    /* TODO: rework config entry */
    /* check for config entry */
    for (i = 0; i < 8; i++) {
        while (uart_getc2(&c) == 0) {
            widgets_process();
            render_process();
            ClrWdt();
        }
        if (c != '!')
            break;
    }

    if (i == 8) {
        in_config = 1;
        while (in_config) {
            in_config = config_osd();
            widgets_process();
            render_process();
            ClrWdt();
        }
    }

    /* re-build tab list */
    build_tab_list();

    uart_set_baudrate2(config.baudrate);

    init_home_process();
    init_flight_stats_process();

    for (;;) {
        mavlink_process();
        widgets_process();
        render_process();
        clock_process();
        ClrWdt();
    }

    return 0;
}