int serial_init (void) { /* and we have to set CLC register*/ CLEAR_BIT(pAsc->asc_clc, ASCCLC_DISS); SET_BITFIELD(pAsc->asc_clc, ASCCLC_RMCMASK, ASCCLC_RMCOFFSET, 0x0001); /* initialy we are in async mode */ pAsc->asc_con = ASCCON_M_8ASYNC; /* select input port */ pAsc->asc_pisel = (CONSOLE_TTY & 0x1); /* TXFIFO's filling level */ SET_BITFIELD(pAsc->asc_txfcon, ASCTXFCON_TXFITLMASK, ASCTXFCON_TXFITLOFF, DANUBEASC_TXFIFO_FL); /* enable TXFIFO */ SET_BIT(pAsc->asc_txfcon, ASCTXFCON_TXFEN); /* RXFIFO's filling level */ SET_BITFIELD(pAsc->asc_rxfcon, ASCRXFCON_RXFITLMASK, ASCRXFCON_RXFITLOFF, DANUBEASC_RXFIFO_FL); /* enable RXFIFO */ SET_BIT(pAsc->asc_rxfcon, ASCRXFCON_RXFEN); /* set baud rate */ serial_setbrg(); /* enable error signals & Receiver enable */ SET_BIT(pAsc->asc_whbstate, ASCWHBSTATE_SETREN); return 0; }
int serial_init (void) { #ifdef CONFIG_INCA_IP /* we have to set PMU.EN13 bit to enable an ASC device*/ INCAASC_PMU_ENABLE(13); #endif /* and we have to set CLC register*/ CLEAR_BIT(pAsc->asc_clc, ASCCLC_DISS); SET_BITFIELD(pAsc->asc_clc, ASCCLC_RMCMASK, ASCCLC_RMCOFFSET, 0x0001); /* initialy we are in async mode */ pAsc->asc_con = ASCCON_M_8ASYNC; /* select input port */ pAsc->asc_pisel = (CONSOLE_TTY & 0x1); #ifdef ASC_FIFO_PRESENT /* TXFIFO's filling level */ SET_BITFIELD(pAsc->asc_txfcon, ASCTXFCON_TXFITLMASK, ASCTXFCON_TXFITLOFF, INCAASC_TXFIFO_FL); /* enable TXFIFO */ SET_BIT(pAsc->asc_txfcon, ASCTXFCON_TXFEN); /* RXFIFO's filling level */ SET_BITFIELD(pAsc->asc_txfcon, ASCRXFCON_RXFITLMASK, ASCRXFCON_RXFITLOFF, INCAASC_RXFIFO_FL); /* enable RXFIFO */ SET_BIT(pAsc->asc_rxfcon, ASCRXFCON_RXFEN); #endif /* enable error signals */ SET_BIT(pAsc->asc_con, ASCCON_FEN); SET_BIT(pAsc->asc_con, ASCCON_OEN); #ifdef CONFIG_INCA_IP /* acknowledge ASC interrupts */ ASC_INTERRUPTS_CLEAR(INCAASC_IRQ_LINE_ALL); /* disable ASC interrupts */ ASC_INTERRUPTS_DISABLE(INCAASC_IRQ_LINE_ALL); #endif #ifdef ASC_FIFO_PRESENT /* set FIFOs into the transparent mode */ SET_BIT(pAsc->asc_txfcon, ASCTXFCON_TXTMEN); SET_BIT(pAsc->asc_rxfcon, ASCRXFCON_RXTMEN); #endif /* set baud rate */ serial_setbrg(); /* set the options */ serial_setopt(); return 0; }
static void output() { // nRF51 refman 13.1 p.56: "Pin direction can be configured both in // the DIR register as well as through the individual PIN_CNF[n] // registers. A change in one register will automatically be // reflected in the other register. port::ptr()->DIRSET = bit::value; // nRF51 refman 13.1 p.55: "The input buffer of a GPIO pin can be // disconnected from the pin to enable power savings when the pin is // not used as an input. Inputs must be connected in order to get a // valid input value in the IN register and for the sense mechanism // to get access to the pin. SET_BITFIELD(port::ptr()->PIN_CNF[bit::shift], FVAL(GPIO_PIN_CNF_INPUT, DISCONNECT)); }
/** * Start the threads in the specified Thread-group and assign them a task. * A task is specified by a function of the form 'void *func(void *arg)', * taking one void * argument and returning a void *. * * @param thr * Thread-group data * @param *start_routine * pointer to function, this is the task that is going to be executed * @param arg * the argument passed to the start_routine specified above, can be NULL * * @return * boolean indicating success. * On error, the following error codes are set: * - EAGAIN (insufficient resources, other than memory) * - EALREADY (Thread-group already running) * - ENOMEM (insufficient memory) */ bool rig_thread_start(RIG_THREAD thr, void *(*start_routine)(void *arg), void *arg) { NULLCHECK_EXIT(thr); NULLCHECK_EXIT(start_routine); if (TEST_BITFIELD(thr->flags, RIG_THREAD_STARTED)) { ERRET(EALREADY, false); } thr->start_routine = start_routine; thr->arg = arg; if (!thread_ops_start(thr)) { ERRET(errno, false); } SET_BITFIELD(thr->flags, RIG_THREAD_STARTED); return (true); }
/** * Detach the running threads in the specified Thread-group. * Once detached, threads cannot be made joinable again! * * @param thr * Thread-group data * * @return * boolean indicating success. * On error, the following error codes are set: * - EALREADY (Thread-group already detached) * - EINVAL (Thread-group not running or not joinable) */ bool rig_thread_detach(RIG_THREAD thr) { NULLCHECK_EXIT(thr); if (!TEST_BITFIELD(thr->flags, RIG_THREAD_STARTED)) { ERRET(EINVAL, false); } if (TEST_BITFIELD(thr->flags, RIG_THREAD_DETACHED)) { ERRET(EALREADY, false); } if (!thread_ops_detach(thr)) { VERIFY_ERRET(errno == EINVAL); ERRET(errno, false); } SET_BITFIELD(thr->flags, RIG_THREAD_DETACHED); return (true); }
static void pulldown() { volatile uint32_t *reg = &port::ptr()->PIN_CNF[bit::shift]; SET_BITFIELD(*reg, FVAL(GPIO_PIN_CNF_PULL, PULLDOWN)); }
static void pulloff() { volatile uint32_t *reg = &port::ptr()->PIN_CNF[bit::shift]; SET_BITFIELD(*reg, FVAL(GPIO_PIN_CNF_PULL, DISABLED)); }
static void input() { // See output() comments SET_BITFIELD(port::ptr()->PIN_CNF[bit::shift], FVAL(GPIO_PIN_CNF_INPUT, CONNECT)); port::ptr()->DIRCLR = bit::value; }