Amb8420InitCode_e amb8420Reset(void) { bool ok; Handle_t h; Amb8420InitCode_e result = AMB8420_INIT_HARD_FAIL; RPRINTF("amb8420Reset\n"); if (serial[AMB8420_UART_ID].function != SERIAL_FUNCTION_RADIO) { amb8420InitSerial(); } AMB8420ModeContext_t ctx; // the chip cannot be configured while in sleep mode AMB8420_ENTER_ACTIVE_MODE(ctx); RPRINTF("active mode ok\n"); pinClear(AMB8420_RESET_PORT, AMB8420_RESET_PIN); ledsSet(0xff); mdelay(200); ledsSet(0); pinSet(AMB8420_RESET_PORT, AMB8420_RESET_PIN); mdelay(500); // wait for initialization to complete AMB8420_WAIT_FOR_RTS_READY(ok); if (!ok) goto end; RPRINTF(" init completed\n"); ATOMIC_START(h); udelay(100); // Switch to command mode (generate falling front) pinClear(AMB8420_CONFIG_PORT, AMB8420_CONFIG_PIN); mdelay(1); pinSet(AMB8420_CONFIG_PORT, AMB8420_CONFIG_PIN); ATOMIC_END(h); // Wait for device to become ready AMB8420_WAIT_FOR_RTS_READY(ok); if (ok) { RPRINTF(" device ready\n"); result = AMB8420_INIT_SUCCESS; } else { RPRINTF(" device NOT ready\n"); } end: // restore sleep mode AMB8420_RESTORE_MODE(ctx); return result; }
void amb8420On(void) { // check and re-initialize serial if required if (serial[AMB8420_UART_ID].function != SERIAL_FUNCTION_RADIO) { amb8420InitSerial(); } if (!isOn) { // RPRINTF("amb842On\n"); isOn = true; pinClear(AMB8420_TRX_DISABLE_PORT, AMB8420_TRX_DISABLE_PIN); pinClear(AMB8420_SLEEP_PORT, AMB8420_SLEEP_PIN); // if the waiting fails, will retry next time when "on" is called AMB8420_WAIT_FOR_RTS_READY(isOn); } }
static void serialInitPins1(void) { // serial 1 pinAsOutput(UTXD1_PORT, UTXD1_PIN); pinAsInput(URXD1_PORT, URXD1_PIN); pinClear(UTXD1_PORT, UTXD1_PIN); pinAsFunction(UTXD1_PORT, UTXD1_PIN); pinAsFunction(URXD1_PORT, URXD1_PIN); }
void DrvDmLd4812::shiftClock() const { pinSet(_pin_sh); pinClear(_pin_sh); }
void DrvDmLd4812::shiftLatch() const { pinSet(_pin_st); pinClear(_pin_st); }
//------------------------------------------- // Entry point for the application //------------------------------------------- void appMain(void) { #if 0 // no effect UCTL0 = SWRST; ME1 &= ~(URXE0 | UTXE0 | USPIE0); UCTL0 &= ~SWRST; UCTL1 = SWRST; ME2 &= ~(URXE1 | UTXE1 | USPIE1); UCTL1 &= ~SWRST; #endif #if 1 ADC12IE = 0; ADC12IFG = 0; ADC12CTL0 &= ~ENC; ADC12CTL0 &= ~REFON; ADC12CTL0 &= ~ADC12ON; DMA0CTL = 0; DMA1CTL = 0; #endif #if 0 pinAsData(1, 0); pinAsData(1, 1); pinAsData(1, 2); pinAsData(1, 3); pinAsData(1, 4); pinAsData(1, 5); pinAsData(1, 6); pinAsData(1, 7); // radio data indicate pinAsData(2, 0); // ADS interrupts (unused) pinAsData(2, 1); pinAsData(2, 2); pinAsData(2, 3); // SHT SDA + I2C soft SDA pinAsData(2, 4); // SHT SCL + I2C soft SCL pinAsData(2, 5); // sensors enable pinAsData(2, 6); pinAsData(2, 7); // uart0 rx pinAsData(3, 0); // SD card CS pinAsData(3, 1); pinAsData(3, 2); pinAsData(3, 3); pinAsData(3, 4); // uart0 hw tx pinAsData(3, 5); // uart0 hw rx pinAsData(3, 6); // uart1 hw tx pinAsData(3, 7); // uart1 hw tx pinAsData(4, 0); // radio data request pinAsData(4, 1); // radio rts pinAsData(4, 2); // radio config pinAsData(4, 3); // radio trx disable pinAsData(4, 4); // radio reset pinAsData(4, 5); // radio sleep // pinAsData(4, 6); // uart0 tx // pinAsData(4, 7); pinAsData(5, 0); pinAsData(5, 1); pinAsData(5, 2); pinAsData(5, 3); pinAsData(5, 4); // red LED pinAsData(5, 5); // green LED pinAsData(5, 6); // blue LED pinAsData(5, 7); pinAsData(6, 0); pinAsData(6, 1); pinAsData(6, 2); pinAsData(6, 3); pinAsData(6, 4); pinAsData(6, 5); pinAsData(6, 6); pinAsData(6, 7); #endif pinAsInput(1, 0); pinAsInput(1, 1); pinAsInput(1, 2); pinAsInput(1, 3); pinAsInput(1, 4); pinAsInput(1, 5); pinAsInput(1, 6); pinAsInput(1, 7); // radio data indicate pinAsInput(2, 0); // ADS interrupts (unused) pinAsInput(2, 1); pinAsInput(2, 2); pinAsInput(2, 3); // SHT SDA + I2C soft SDA // pinAsInput(2, 4); // SHT SCL + I2C soft SCL // pinAsInput(2, 5); // sensors enable pinAsInput(2, 6); pinAsInput(2, 7); // uart0 rx pinAsInput(3, 0); // SD card CS pinAsInput(3, 1); pinAsInput(3, 2); pinAsInput(3, 3); pinAsInput(3, 4); // uart0 hw tx pinAsInput(3, 5); // uart0 hw rx pinAsInput(3, 6); // uart1 hw tx pinAsInput(3, 7); // uart1 hw tx pinAsInput(4, 0); // radio data request pinAsInput(4, 1); // radio rts pinAsInput(4, 2); // radio config // pinAsInput(4, 3); // radio trx disable pinAsInput(4, 4); // radio reset // pinAsInput(4, 5); // radio sleep pinAsInput(4, 6); // uart0 tx pinAsInput(4, 7); pinAsInput(5, 0); pinAsInput(5, 1); pinAsInput(5, 2); pinAsInput(5, 3); // pinAsInput(5, 4); // red LED pinAsInput(5, 5); // green LED pinAsInput(5, 6); // blue LED pinAsInput(5, 7); pinAsInput(6, 0); pinAsInput(6, 1); pinAsInput(6, 2); pinAsInput(6, 3); pinAsInput(6, 4); pinAsInput(6, 5); pinAsInput(6, 6); pinAsInput(6, 7); // -- required for better efficiency // make sure I2C clock is high I2C_SCL_HI(); // make sure sensors are disabled pinClear(SM3_SENSORS_ENABLE_PORT, SM3_SENSORS_ENABLE_PIN); // -- while (1) { msleep(PAUSE); // sleep PAUSE seconds // PRINTF("%lu: hello world\n", (uint32_t) getJiffies()); ledToggle(); } }
void serialSendByte(uint8_t id, uint8_t data) { if (!serialTxEnabled[id]) return; uint16_t txd = data | 0x300; // transmitter "shift register" // Start transmitter. This has to be done with interrupts disabled Handle_t h; ATOMIC_START(h); TBCCTL1 = 0; // transmit start bit if (id == 0) { pinClear(UART0_TX_PORT, UART0_TX_PIN); // pinClear(UART0_HW_TX_PORT, UART0_HW_TX_PIN); } else { pinClear(UART1_TX_PORT, UART1_TX_PIN); } TBCCR1 = TBR + UART_BITTIME; // set time till the first data bit //XXX: the stability is MUCH worse if ints are enabled at this point // ATOMIC_END(h); // wait until the end of start bit while (0 == (TBCCTL1 & CCIFG)); TBCCR1 += UART_BITTIME; while (txd) { if (txd & 1) { // transmit "Mark" (1) using OUTMOD=1 (Set) TBCCTL1 = OUTMOD_1; if (id == 0) { pinSet(UART0_TX_PORT, UART0_TX_PIN); // pinSet(UART0_HW_TX_PORT, UART0_HW_TX_PIN); } else { pinSet(UART1_TX_PORT, UART1_TX_PIN); } } else { // transmit "Space" (0) using OUTMOD=5 (Reset) TBCCTL1 = OUTMOD_5; if (id == 0) { pinClear(UART0_TX_PORT, UART0_TX_PIN); // pinClear(UART0_HW_TX_PORT, UART0_HW_TX_PIN); } else { pinClear(UART1_TX_PORT, UART1_TX_PIN); } } // wait for TA compare event while (0 == (TBCCTL1 & CCIFG)); // set next bit time TBCCR1 += UART_BITTIME; txd >>= 1; } // all bits sent out; set TxD idle to "Mark" TBCCTL1 = OUT; if (id == 0) { pinSet(UART0_TX_PORT, UART0_TX_PIN); // pinSet(UART0_HW_TX_PORT, UART0_HW_TX_PIN); } else { pinSet(UART1_TX_PORT, UART1_TX_PIN); } ATOMIC_END(h); }