コード例 #1
0
/**
 * Initializes the minimal system including CPU Clock, UART, and Flash accelerator
 * Be careful of the order of operations!!!
 */
void low_level_init(void)
{
    rtc_init();
    m_rtc_boot_time = rtc_gettime();

    /**
     * Configure System Clock based on desired clock rate @ sys_config.h
     * Setup default interrupt priorities that will work with FreeRTOS
     */
    sys_clock_configure();
    configure_flash_acceleration(sys_get_cpu_clock());
    configure_interrupt_priorities();
    __enable_irq();

    // Setup UART with minimum I/O functions
    uart0_init(UART0_DEFAULT_RATE_BPS);
    sys_set_outchar_func(uart0_putchar);
    sys_set_inchar_func(uart0_getchar);

    /**
     *  If buffers are set to 0, so printf/scanf will behave correctly!
     *  If not set, then printf/scanf will have weird buffering/flushing effects
     */
    setvbuf(stdout, 0, _IONBF, 0);
    setvbuf(stdin,  0, _IONBF, 0);

    /**
     * Set the semaphore for the malloc lock.
     * Initialize newlib fopen() fread() calls support
     */
    syscalls_init();

    /**
     * Enable watchdog to allow us to recover in case of:
     *  - We attempt to run an application and it's not there
     *  - Application we ran crashes
     */
    sys_watchdog_enable();
    print_boot_info();
}
コード例 #2
0
/**
 * Initializes the minimal system including CPU Clock, UART, and Flash accelerator
 * Be careful of the order of the operations!!!
 */
void low_level_init(void)
{
    rtc_init();
    g_rtc_boot_time = rtc_gettime();

    /* Configure System Clock based on desired clock rate @ sys_config.h */
    sys_clock_configure();
    configure_flash_acceleration(sys_get_cpu_clock());

    /* Setup default interrupt priorities that will work with FreeRTOS */
    configure_interrupt_priorities();

    /* These methods shouldn't be needed but doing it anyway to be safe */
    NVIC_SetPriorityGrouping(0);
    __set_BASEPRI(0);
    __enable_fault_irq();
    __enable_irq();

    /* Setup UART with minimal I/O functions */
    uart0_init(SYS_CFG_UART0_BPS);
    sys_set_outchar_func(uart0_putchar);
    sys_set_inchar_func(uart0_getchar);

    /**
     * Turn off I/O buffering otherwise sometimes printf/scanf doesn't behave
     * correctly due to strange buffering and/or flushing effects.
     */
    setvbuf(stdout, 0, _IONBF, 0);
    setvbuf(stdin,  0, _IONBF, 0);

    /* Initialize newlib fopen() fread() calls support */
    syscalls_init();

    /* Enable the watchdog to allow us to recover in an event of system crash */
    sys_watchdog_enable();

    /* Uart and printf() are initialized, so print our boot-up message */
    print_boot_info();
}
コード例 #3
0
/**
 * Initializes the minimal system including CPU Clock, UART, and Flash accelerator
 * Be careful of the order of operations!!!
 */
void low_level_init(void)
{
    rtc_init();
    g_rtc_boot_time = rtc_gettime();

    /**
     * Configure System Clock based on desired clock rate @ sys_config.h
     * Setup default interrupt priorities that will work with FreeRTOS
     */
    sys_clock_configure();
    configure_flash_acceleration(sys_get_cpu_clock());
    configure_interrupt_priorities();
    __enable_irq();

    // Setup UART with minimum I/O functions
    uart0_init(UART0_DEFAULT_RATE_BPS);
    sys_set_outchar_func(uart0_putchar);
    sys_set_inchar_func(uart0_getchar);

    /**
     * Turn off I/O buffering otherwise sometimes printf/scanf doesn't behave
     * correctly due to strange buffering and/or flushing effects.
     */
    setvbuf(stdout, 0, _IONBF, 0);
    setvbuf(stdin,  0, _IONBF, 0);

    // Initialize newlib fopen() fread() calls support
    syscalls_init();

    /**
     * Enable watchdog to allow us to recover in case of:
     *  - We attempt to run an application and it's not there
     *  - Application we ran crashes
     */
    sys_watchdog_enable();
    print_boot_info();
}
コード例 #4
0
bool terminalTask::taskEntry()
{
    /* remoteTask() creates shared object in its init(), so we can get it now */
    CommandProcessor &cp = mCmdProc;

    // System information handlers
    cp.addHandler(taskListHandler, "info",    "Task/CPU Info.  Use 'info 200' to get CPU during 200ms");
    cp.addHandler(memInfoHandler,  "meminfo", "See memory info");
    cp.addHandler(healthHandler,   "health",  "Output system health");
    cp.addHandler(timeHandler,     "time",    "'time' to view time.  'time set MM DD YYYY HH MM SS Wday' to set time");

    // File I/O handlers:
    cp.addHandler(catHandler,    "cat",   "Read a file.  Ex: 'cat 0:file.txt' or "
                                          "'cat 0:file.txt -noprint' to test if file can be read");
    cp.addHandler(cpHandler,     "cp",    "Copy files from/to Flash/SD Card.  Ex: 'cp 0:file.txt 1:file.txt'");
    cp.addHandler(dcpHandler,    "dcp",   "Copy all files of a directory to another directory.  Ex: 'dcp 0:src 1:dst'");
    cp.addHandler(lsHandler,     "ls",    "Use 'ls 0:' for Flash, or 'ls 1:' for SD Card");
    cp.addHandler(mkdirHandler,  "mkdir", "Create a directory. Ex: 'mkdir test'");
    cp.addHandler(mvHandler,     "mv",    "Rename a file. Ex: 'rm 0:file.txt 0:new.txt'");
    cp.addHandler(newFileHandler,"nf",    "Write a new file. Ex: 'nf <file.txt>");
    cp.addHandler(rmHandler,     "rm",    "Remove a file. Ex: 'rm 0:file.txt'");

    // Misc. handlers
    cp.addHandler(i2cIoHandler,   "i2c",   "'i2c read 0x01 0x02 <count>' : Reads  device 0x01, and register 0x02\n"
                                           "'i2c write 0x01 0x02 0x03'   : Writes device 0x01, reg 0x02, data 0x03\n"
                                           "'i2c discover' : Discover I2C devices");
#if TERMINAL_USE_CAN_BUS_HANDLER
    CMD_HANDLER_FUNC(canBusHandler);
    cp.addHandler(canBusHandler,  "canbus", "'canbus init' : initialize CAN-1\n"
                                            "'canbus filter <id>' : Add 29-bit ID fitler\n"
                                            "'canbus tx <msg id> <len> <byte0> <byte1> ...' : Send CAN Message\n"
                                            "'canbus rx <timeout in ms>' : Receive a CAN message\n"
                                            "'canbus registers' : See some of CAN BUS registers");
#endif

    cp.addHandler(storageHandler,  "storage",  "Parameters: 'format sd', 'format flash', 'mount sd', 'mount flash'");
    cp.addHandler(rebootHandler,   "reboot",   "Reboots the system");
    cp.addHandler(logHandler,      "log",      "'log <hello>': log an info message\n"
                                               "'log flush'  : flush the logs\n"
                                               "' log status': get status of the logger\n"
                                               "'log enableprint debug/info/warn/error' : Enables logger calls to printf\n"
                                               "'log disableprint debug/info/warn/error': Disables logger calls to printf\n"
                                               );
    cp.addHandler(learnIrHandler,  "learn",    "Begin to learn IR codes for numbers 0-9");
    cp.addHandler(wirelessHandler, "wireless", "Use 'wireless' to see the nested commands");

    /* Firmware upgrade handlers
     * Please read "netload_readme.txt" at ref_and_datasheets directory.
     */
    CMD_HANDLER_FUNC(getFileHandler);
    CMD_HANDLER_FUNC(flashProgHandler);
    cp.addHandler(getFileHandler,   "file",  "Get a file using netload.exe or by using the following protocol:\n"
                                             "Write buffer: buffer <offset> <num bytes> ...\n"
                                             "Write buffer to file: commit <filename> <file offset> <num bytes from buffer>");
    cp.addHandler(flashProgHandler, "flash", "'flash <filename>' Will flash CPU with this new binary file");

    #if (SYS_CFG_ENABLE_TLM)
    cp.addHandler(telemetryHandler, "telemetry", "Outputs registered telemetry: "
                                                 "'telemetry save' : Saves disk tel\n"
                                                 "'telemetry ascii' : Prints all telemetry in human readable format\n"
                                                 "'telemetry <comp. name> <name> <value>' to set a telemetry variable\n"
                                                 "'telemetry get <comp. name> <name>' to get variable value\n");
    #endif

    // Initialize Interrupt driven version of getchar & putchar
    Uart0& uart0 = Uart0::getInstance();
    bool success = uart0.init(SYS_CFG_UART0_BPS, 32, SYS_CFG_UART0_TXQ_SIZE);
    uart0.setReady(true);
    sys_set_inchar_func(uart0.getcharIntrDriven);
    sys_set_outchar_func(uart0.putcharIntrDriven);

    /* Add UART0 to command input/output */
    addCommandChannel(&uart0, true);

    #if TERMINAL_USE_NRF_WIRELESS
    do {
        NordicStream& nrf = NordicStream::getInstance();
        nrf.setReady(true);
        addCommandChannel(&nrf, false);
    } while(0);
    #endif

    #if SYS_CFG_ENABLE_TLM
    /* Telemetry should be registered at this point, so initialize the binary
     * telemetry space that we periodically check to save data to disk
     */
    tlm_component *disk = tlm_component_get_by_name(SYS_CFG_DISK_TLM_NAME);
    mDiskTlmSize = tlm_binary_get_size_one(disk);
    mpBinaryDiskTlm = new char[mDiskTlmSize];
    if (success) {
        success = (NULL != mpBinaryDiskTlm);
    }

    /* Now update our copy of disk telemetry */
    tlm_binary_get_one(disk, mpBinaryDiskTlm);
    #endif

    /* Display "help" command on UART0 */
    STR_ON_STACK(help, 8);
    help = "help";
    mCmdProc.handleCommand(help, uart0);

    return success;
}
コード例 #5
0
ファイル: startup.cpp プロジェクト: amin901/cmpe
/**
 * HardFaultHandler_C:
 * This is called from the HardFault_HandlerAsm with a pointer the Fault stack
 * as the parameter. We can then read the values from the stack and place them
 * into local variables for ease of reading.
 * We then read the various Fault Status and Address Registers to help decode
 * cause of the fault.
 * The function ends with a BKPT instruction to force control back into the debugger
 */
void HardFault_HandlerC(unsigned long *hardfault_args){
        volatile unsigned int stacked_r0 ;
        volatile unsigned int stacked_r1 ;
        volatile unsigned int stacked_r2 ;
        volatile unsigned int stacked_r3 ;
        volatile unsigned int stacked_r12 ;
        volatile unsigned int stacked_lr ;
        volatile unsigned int stacked_pc ;
        volatile unsigned int stacked_psr ;

        stacked_r0 = ((unsigned long)hardfault_args[0]) ;
        stacked_r1 = ((unsigned long)hardfault_args[1]) ;
        stacked_r2 = ((unsigned long)hardfault_args[2]) ;
        stacked_r3 = ((unsigned long)hardfault_args[3]) ;
        stacked_r12 = ((unsigned long)hardfault_args[4]) ;
        stacked_lr = ((unsigned long)hardfault_args[5]) ;
        stacked_pc = ((unsigned long)hardfault_args[6]) ;
        stacked_psr = ((unsigned long)hardfault_args[7]) ;

        sys_set_outchar_func(uart0_putchar);
        puts("\nSystem Crash!");
        printf("Registers: 0x%08X, 0x%08X, 0x%08X, 0x%08X, 0x%08X\n",
                stacked_r0, stacked_r1, stacked_r2, stacked_r3, stacked_r12);
        printf("LR: 0x%08X, PC: 0x%08X, PSR: 0x%08X\n", stacked_lr, stacked_pc, stacked_psr);
        FAULT_EXISTS = 0xDEADBEEF;
        FAULT_PC = stacked_pc;
        FAULT_LR = stacked_lr;
        FAULT_PSR = stacked_psr;

        delay_us(10 * 1000 * 1000);
        sys_reboot();

        #if (1 == USE_EXPERIMENTAL_UNWIND)
            int depth=0;
            printf("Instructions: ");
            _Unwind_Backtrace(&trace_fcn, &depth);
        #endif

#if 0
        // Configurable Fault Status Register
        // Consists of MMSR, BFSR and UFSR
        volatile unsigned int _CFSR = (*((volatile unsigned long *)(0xE000ED28))) ;

        // Hard Fault Status Register
        volatile unsigned int _HFSR = (*((volatile unsigned long *)(0xE000ED2C))) ;

        // Debug Fault Status Register
        volatile unsigned int _DFSR = (*((volatile unsigned long *)(0xE000ED30))) ;

        // Auxiliary Fault Status Register
        volatile unsigned int _AFSR = (*((volatile unsigned long *)(0xE000ED3C))) ;

        // Read the Fault Address Registers. These may not contain valid values.
        // Check BFARVALID/MMARVALID to see if they are valid values
        // MemManage Fault Address Register
        volatile unsigned int _MMAR = (*((volatile unsigned long *)(0xE000ED34))) ;
        // Bus Fault Address Register
        volatile unsigned int _BFAR = (*((volatile unsigned long *)(0xE000ED38))) ;

        __asm("BKPT #0\n") ; // Break into the debugger
#endif
        while(1);
}