/*
 * Application entry point.
 */
int main(void) {
    unsigned i;

    /*
     * System initializations.
     * - HAL initialization, this also initializes the configured device drivers
     *   and performs the board-specific initializations.
     * - Kernel initialization, the main() function becomes a thread and the
     *   RTOS is active.
     */
    halInit();
    chSysInit();

    /*
     * SPI2 I/O pins setup.
     */
    palSetPadMode(GPIOB, 13, PAL_MODE_STM32_ALTERNATE_PUSHPULL);     /* New SCK.     */
    palSetPadMode(GPIOB, 14, PAL_MODE_STM32_ALTERNATE_PUSHPULL);     /* New MISO.    */
    palSetPadMode(GPIOB, 15, PAL_MODE_STM32_ALTERNATE_PUSHPULL);     /* New MOSI.    */
    palSetPadMode(GPIOB, 12, PAL_MODE_OUTPUT_PUSHPULL);              /* New CS.      */

    palSetPadMode(GPIOA, 9, PAL_MODE_STM32_ALTERNATE_PUSHPULL);      /* USART1 TX.       */
    palSetPadMode(GPIOA, 10, PAL_MODE_INPUT);

    sdStart(&SD1, NULL);

    spiAcquireBus(&SPID2);              /* Acquire ownership of the bus.    */
    spiStart(&SPID2, &ls_spicfg);       /* Setup transfer parameters.       */

//  nrf_init();
    nrf_configure_sb_tx();
    nrf_dump_regs(&nrf_reg_def);

// chThdCreateStatic(blinker_wa, sizeof(blinker_wa),
//                    NORMALPRIO-1, blinker, NULL);
    static nrf_payload   p;

    int s;

    // set payload size according to the payload size configured for the RX channel
    p.size = 1;
    p.data[0] = 0;

    while (TRUE) {
        chprintf((BaseSequentialStream *) &SD1, "Sending payload: %x ", p.data[0]);
        s = nrf_send_blocking(&p);
        chprintf((BaseSequentialStream *) &SD1, " - done; bytes send: %u\n\r", s);

        chThdSleepMilliseconds(100);

        p.data[0]++;
    }

    return 0;
}
Ejemplo n.º 2
0
int main(void)
{
	int i;

	clock_init();
	gpio_init();
	serial_init(9600);
	serirq_init();
	nrf_init();
	nrf_configure_sb();

	prx.size 	= PL_SIZE;
	ptx.size 	= PL_SIZE;

	while (1) {
        ptx.data[0] = 0;

        while(!serial_rb_empty(&srx) && ptx.data[0] < (PL_SIZE - 1)) {
			ptx.data[ptx.data[0] + 1] = serial_rb_read(&srx);
			ptx.data[0]++;
        }

        if(ptx.data[0] > 0) {
#ifdef MSP430
			P1OUT |= RXTX_LED;
#else
            gpio_set(GPIOC, TX_LED);
#endif
            // switch to PTX for sending out data ...
            nrf_set_mode_ptx();

            nrf_send_blocking(&ptx);

            nrf_set_mode_prx();
        }

        if(nrf_receive(&prx) != 0 && prx.data[0] > 0) {
            if(!serial_rb_full(&stx)) {
                for(i = 0; i < prx.data[0]; i++) serial_rb_write(&stx, prx.data[i + 1]);
#ifdef MSP430
				P1OUT |= RXTX_LED;
				IE2 |= UCA0TXIE;
#else
             	gpio_set(GPIOC, RX_LED);
               	USART_CR1(USART1) |= USART_CR1_TXEIE;
#endif
            }
    	}
	}

	return 0;
}