Beispiel #1
0
/* Encrypt at most 16 bytes of data. */
static void
cipher16(uint8_t *data, int len)
{
  uint8_t status;

  len = MIN(len, MAX_DATALEN);

  CC2420_WRITE_RAM(data, CC2420RAM_SABUF, len);
  CC2420_STROBE(CC2420_SAES);
  /* Wait for the encryption to finish */
  do {
    CC2420_GET_STATUS(status);
  } while(status & BV(CC2420_ENC_BUSY));
  CC2420_READ_RAM(data, CC2420RAM_SABUF, len);
}
Beispiel #2
0
/*
 * \brief Read contents of PHY register.
 *
 * \param reg PHY register number.
 *
 * \return Contents of the specified register.
 */
static uint16_t phy_hw_read(uint8_t phy_addr, reg8_t reg)
{
	// PHY read command.
	EMAC_MAN = EMAC_SOF | EMAC_RW_READ
		| ((phy_addr << EMAC_PHYA_SHIFT) & EMAC_PHYA)
		| ((reg  << EMAC_REGA_SHIFT) & EMAC_REGA)
		| EMAC_CODE;

	// Wait until PHY logic completed.
	while (!(EMAC_NSR & BV(EMAC_IDLE)))
		cpu_relax();

	// Get data from PHY maintenance register.
	return (uint16_t)(EMAC_MAN & EMAC_DATA);
}
Beispiel #3
0
/*
 * Initialize SPI bus.
 */
void
spi_init(void)
{
  static unsigned char spi_inited = 0;

  if (spi_inited)
    return;

  /* Initalize ports for communication with SPI units. */
  /* CSN=SS and must be output when master! */
  DDRB  |= BV(MOSI) | BV(SCK) | BV(CSN);
  PORTB |= BV(MOSI) | BV(SCK);

  /* Enables SPI, selects "master", clock rate FCK / 2, and SPI mode 0 */
  SPCR = BV(SPE) | BV(MSTR);
  SPSR = BV(SPI2X);
}
Beispiel #4
0
/**************************************************************************************************
 *
 * @fn      timer_start_timerEx
 *
 * @brief   Modeled after OSAL_start_timerEx.
 * 			To stop timer call with same threadId, and event, and
 * 			set timeout to 0.
 *
 * @param   threadId - Id of the thread to call at the event.
 * @param	event - event bitmask
 * @param	timeout - number of milliseconds to count down
 *
 * @return  void
 */
uint8 timer_start_timerEx(uint8 threadId, uint32 event, uint32 timeout)
{
	uint8 i;
	if (event == 0)
	{
		// No event requested, just return
		return -1;
	}
	for (i = 0; i < 32; i++)
	{
		if (event & BV(i))
			break;
	}

	LOG_DEBUG_TIMER("[TIMER] timer_start_timerEx(%d, 0x%.8X, %d)... \n", threadId, event, timeout);
	fflush(LOG_DESTINATION_FP);
	// To avoid race conditions we cannot update timerThreadTbl without mutex lock
	pthread_mutex_lock(&timerMutex);
	LOG_DEBUG_TIMER("lock (line: %d)\n", __LINE__);

	// Value is stored in us for better precision
	timerThreadTbl[threadId].timeoutValue[i] = timeout * 1000;
	// Use a 0 value of timeout to disable timer
	if (timeout)
	{
		// Enable event
		timerThreadTbl[threadId].timerEnabled |= event;
		// We also need to make sure the timer update does not decrement now.
		timerThreadTbl[threadId].justKicked |= event;
	}
	else
	{
		timerThreadTbl[threadId].timerEnabled &= ~event;
		// Clear event in case it just fired.
		timer_clear_event(threadId, event);
	}

	LOG_DEBUG_TIMER("[TIMER] Timer started for %dus, for event 0x%.8X and thread %d\n",
			(int)timerThreadTbl[threadId].timeoutValue[i], event, threadId);

	// Unlock mutex before notifying timer thread
	pthread_mutex_unlock(&timerMutex);

	// Notify timer thread that timer has been set
	pthread_cond_signal(&timerSetCond);

	return 1;
}
Beispiel #5
0
void NRF24L01_Initialize(uint8_t baseConfig)
{
    standbyConfig = BV(NRF24L01_00_CONFIG_PWR_UP) | baseConfig;
    NRF24_CE_LO();
    // nRF24L01+ needs 100 milliseconds settling time from PowerOnReset to PowerDown mode
    static const uint32_t settlingTimeUs = 100000;
    const uint32_t currentTimeUs = micros();
    if (currentTimeUs < settlingTimeUs) {
        delayMicroseconds(settlingTimeUs - currentTimeUs);
    }
    // now in PowerDown mode
    NRF24L01_WriteReg(NRF24L01_00_CONFIG, standbyConfig); // set PWR_UP to enter Standby mode
    // nRF24L01+ needs 4500 microseconds from PowerDown mode to Standby mode, for crystal oscillator startup
    delayMicroseconds(4500);
    // now in Standby mode
}
Beispiel #6
0
void
cc2420_off(void)
{
  u8_t spiStatusByte;

  if (receive_on == 0)
    return;
  receive_on = 0;
  /* Wait for transmission to end before turning radio off. */
  do {
    spiStatusByte = cc2420_status();
  } while (spiStatusByte & BV(CC2420_TX_ACTIVE));

  cc2420_strobe(CC2420_SRFOFF);
  DISABLE_FIFOP_INT();
}
Beispiel #7
0
static void
on(void)
{
  if(completely_off) {
    completely_off = 0;
    powerup();
    configure();
  }
  CC2420_ENABLE_FIFOP_INT();
  strobe(CC2420_SRXON);

  BUSYWAIT_UNTIL(status() & (BV(CC2420_XOSC16M_STABLE)), RTIMER_SECOND / 100);

  ENERGEST_ON(ENERGEST_TYPE_LISTEN);
  receive_on = 1;
}
Beispiel #8
0
int
compile_preamble(int *instructions, struct local *s)
{
    int *instp;
    int len;
    int extra_regs, i, j, t, disp;

    extra_regs = s->maxreg - INITIAL_NSCRATCHREGS;
    if (extra_regs > 0) {
	len = extra_regs * 2 + 4;
	/* stw rp | (n-1) * stw | bl | stw | ldw rp | (n-1) * ldw | bv | ldw */
    } else
	return 0;
    if (instructions == NULL)
	return len;
    instp = instructions;
    /* Generate a wrapper function to save the callee-saves registers
       before invoking the filter code we have generated.  It would be
       marginally better to have the filter branch directly to the
       postamble code on return, but the difference is trivial and it
       is easier to have it always branch to (rp).  */
#define FRAME_SIZE 128	/* This is plenty without being excessive. */
    *instp++ = STW_NEG(REG_RTN, 20, REG_SP);		/* stw rp,-20(sp) */
    i = INITIAL_NSCRATCHREGS;
    t = STWM(scratchregs[i], FRAME_SIZE, REG_SP);	/* stwm r3,128(sp) */
    j = FRAME_SIZE;
    while (++i < s->maxreg) {
	*instp++ = t;
	j -= sizeof (int);
	t = STW_NEG(scratchregs[i], j, REG_SP);		/* stw r4,-124(sp) &c */
    }
    disp = extra_regs + 2;	/* n * ldw | bv | ldw rp */
    *instp++ = BL(disp, REG_RTN);			/* bl filter,rp */
    *instp++ = t;					/* stw in delay slot */
    *instp++ = LDW_NEG(FRAME_SIZE + 20, REG_SP, REG_RTN);
							/* ldw -148(sp),rp */
    while (--i > INITIAL_NSCRATCHREGS) {
	*instp++ = LDW_NEG(j, REG_SP, scratchregs[i]);	/* ldw -124(sp),r4 &c */
	j += sizeof (int);
    }
    *instp++ = BV(0, REG_RTN);				/* bv (rp) */
    *instp++ = LDWM_NEG(FRAME_SIZE, REG_SP, scratchregs[i]);
							/* ldwm -128(sp),r3
							   in delay slot */
    assert(instp - instructions == len);
    return len;
}
Beispiel #9
0
void adc_init (void)
{
	adc_ch = 0;
	adc_ports[0] = ADC_VOLT;

	ADCSRA = BV(ADEN); /* enable ADC conversion */
	ADCSRA |= (BV(ADPS2) | BV(ADPS1) | BV(ADPS0)); /* div by 128 presc. */
	ADCSRA |= BV(ADIE); /* interrupt enable */
	ADMUX = adc_ports[adc_ch]; /* Voltage reference is AREF) */
	ADCSRA |= BV(ADSC); /* request ADC conversion */
}
Beispiel #10
0
void delegateSetCellStatus(uint8_t xCol){
	// Col -> set only one port as output low and all others as input full up
	DDRCOLUMNS  = BV(xCol);	// 해당 col을 출력으로 설정, 나머지 입력
	PORTCOLUMNS = ~BV(xCol);	// 해당 col output low, 나머지 컬럼을 풀업 저항

	/*
	DDR을 1로 설정하면 출력, 0이면 입력
	입력중, PORT가 1이면 풀업(풀업 상태는  high 상태);

	출력 상태의 PORT가 0이면 output low(0v);

	스위치를 on하면 0, off하면 1이 PIN에 저장;
	row는 내부 풀업 저항 상태 이기 때문에 1값이 기본값
	*/
				
	_delay_us(5);
}
Beispiel #11
0
//*****************************************************************************
// File Name    : user_code.c
// 
// Author  : Markus Joos ([email protected])
//
//*****************************************************************************

// This file is the source file for user code. Users of the MMC S/W should only have to modify this file as well as user_code.h

check that the addresses sent to i2cswSend are not shifted << 1


// Header file
#include "user_code.h"


// Globals
// For the LEDs
extern leds led[NUM_OF_LED];

// For the sensors
extern u08 run_type;
u08 SDR0[] =  { 0x00, 0x00, 0x51, 0x12, 0x14, 0x00, 0x00, 0x00, // Device Locator Record
                0x29, 0x00, 0x00, 0x00, 0xc1, 0x00, 0x00, 0xcb, 'A', 'M', 'C', '-', 'T', 'E', 'S', 'T', 'E', 'R', '.' };

//Temperature 1 - Full Sensor
u08 SDR1[] =
{
    //sensor record header
    //Byte 1
    0x02,                //record number, LSB
    0x00,                //record number,MSB
    0x51,                //IPMI protocol version
    0x01,                //record type: full sensor
    0x33,                //record length: remaining bytes -> SDR_Init

    //record key bytes
    0x00,                //i2c address, -> SDR_Init
    0x00,                //sensor owner LUN
    //Byte 8
    TEMPERATURE_SENSOR1, //sensor number

    //record body bytes
    0xc1,                //entity id: AMC Module
    0x00,                //entity instance -> SDR_Init
    0x03,                //init: event generation + scanning enabled
    0x48,                //capabilities: auto re-arm, Threshold is readable and setable
    0x01,                //sensor type: Temperature
    0x01,                //sensor reading: Threshold
    0x80,                //LSB assert event mask: 3 bit value
    //Byte 16
    0x0a,                //MSB assert event mask
    0xa8,                //LSB deassert event mask: 3 bit value
    0x7a,                //MSB deassert event mask
    0x38,                //LSB: readable Threshold mask: all thresholds are readable
    0x38,                //MSB: setable Threshold mask: all thresholds are setable
    0x80,                //sensor units 1 : 2's complement
    0x01,                //sensor units 2 : Temperature
    0x00,                //sensor units 3 : Modifier
    // Byte 24
    0x00,                //Linearisation
    0x01,                //M
    0x01,                //M - Tolerance
    0x00,                //B
    0x25,                //B - Accuracy
    0x88,                //Sensor direction
    0x00,                //R-Exp , B-Exp
    0x07,                //Analogue characteristics flags
    //Byte 32
    30,                  //Nominal reading
    50,                  //Normal maximum
    25,                  //Normal minimum
    0xFF,                //Sensor Maximum reading
    0x00,                //Sensor Minimum reading
    85,                  //Upper non-recoverable Threshold
    50,                  //Upper critical Threshold
    75,                  //Upper non critical Threshold
    //Byte 40
    -20,                 //Lower non-recoverable Threshold
    -10,                 //Lower critical Threshold
    0,                   //Lower non-critical Threshold
    0x02,                //positive going Threshold hysteresis value
    0x02,                //negative going Threshold hysteresis value
    0x00,                //reserved
    0x00,                //reserved
    0x00,                //OEM reserved
    //Byte 48
    0xD0,                //8 bit ASCII, number of bytes
    'T', 'e', 'm', 'p', '_', 'F', 'P', 'G', 'A', '_', 'M', 'A', 'S', 'T', 'E', 'R'   //sensor string
};

//Temperature 2 - Full Sensor
u08 SDR2[] =
{
    //sensor record header
    //Byte 1
    0x03,                //record number, LSB  - filled by SDR_Init()
    0x00,                //record number, MSB  - filled by SDR_Init()
    0x51,                //IPMI protocol version
    0x01,                //record type: full sensor
    0x33,                //record length: remaining bytes -> SDR_Init

    //record key bytes
    0x00,                //i2c address, -> SDR_Init
    0x00,                //sensor owner LUN
    //Byte 8
    TEMPERATURE_SENSOR2, //sensor number

    //record body bytes
    0xc1,                //entity id: AMC Module
    0x00,                //entity instance -> SDR_Init
    0x03,                //init: event generation + scanning enabled
    0x48,                //capabilities: auto re-arm, Threshold is readable and setable
    0x01,                //sensor type: Temperature
    0x01,                //sensor reading: Threshold
    0x80,                //LSB assert event mask: 3 bit value
    //Byte 16
    0x0a,                //MSB assert event mask
    0xa8,                //LSB deassert event mask: 3 bit value
    0x7a,                //MSB deassert event mask
    0x38,                //LSB: readable Threshold mask: all thresholds are readable
    0x38,                //MSB: setable Threshold mask: all thresholds are setable
    0x80,                //***** Modified by P.Vichoudis - it was: 0x00, //sensor units 1 : 2's complement
    0x01,                //sensor units 2 : Temperature
    0x00,                //sensor units 3 : Modifier
    //Byte 24
    0x00,                //Linearisation
    0x01,                //M
    0x01,                //M - Tolerance
    0x00,                //B
    0x25,                //B - Accuracy
    0x88,                //Sensor direction
    0x00,                //R-Exp , B-Exp
    0x07,                //Analogue characteristics flags
    //Byte 32
    30,                  //Nominal reading
    50,                  //Normal maximum
    25,                  //Normal minimum
    0xff,                //Sensor Maximum reading
    0x00,                //Sensor Minimum reading
    110,                 //Upper non-recoverable Threshold
    80,                  //Upper critical Threshold
    75,                  //Upper non critical Threshold
    //Byte 40
    -20,                 //Lower non-recoverable Threshold
    -10,                 //Lower critical Threshold
    0,                   //Lower non-critical Threshold
    0x02,                //positive going Threshold hysteresis value
    0x02,                //negative going Threshold hysteresis value
    0x00,                //reserved
    0x00,                //reserved
    0x00,                //OEM reserved
    //Byte 48
    0xc8,                //8 bit ASCII, number of bytes
    'T', 'e', 'm', 'p', ' ', 'I', '/', 'O' //sensor string
};

u08 SDR3[] =
{
    //sensor record header
    //Byte 1
    0x03,            //record number, LSB  - filled by SDR_Init()
    0x00,            //record number, MSB  - filled by SDR_Init()
    0x51,            //IPMI protocol version
    0x01,            //record type: full sensor
    0x37,            //record length: remaining bytes -> SDR_Init

    //record key bytes
    0x00,            //i2c address, -> SDR_Init
    0x00,            //sensor owner LUN
    //Byte 8
    HOT_SWAP_SENSOR, //sensor number

    //record body bytes
    0xc1,            //entity id: AMC Module
    0x00,            //entity instance -> SDR_Init
    0x03,            //init: event generation + scanning enabled
    0xc1,            //capabilities: auto re-arm,
    HOT_SWAP,        //sensor type: HOT SWAP
    0x6f,            //sensor reading
    0x07,            //LSB assert event mask: 3 bit value
    //Byte 16
    0x00,            //MSB assert event mask
    0x07,            //LSB deassert event mask: 3 bit value
    0x00,            //MSB deassert event mask
    0x00,            //LSB: readable Threshold mask: all thresholds are readable
    0x00,            //MSB: setable Threshold mask: all thresholds are setable
    0xc0,            //sensor units 1
    0x00,            //sensor units 2
    0x00,            //sensor units 3
    //Byte 24
    0x00,            //Linearization
    0x00,            //M
    0x00,            //M - Tolerance
    0x00,            //B
    0x00,            //B - Accuracy
    0x00,            //Sensor direction
    0x00,            //R-Exp , B-Exp
    0x00,            //Analogue characteristics flags
    //Byte 32
    0x00,            //Nominal reading
    0x00,            //Normal maximum
    0x00,            //Normal minimum
    0x00,            //Sensor Maximum reading
    0x00,            //Sensor Minimum reading
    0x00,            //Upper non-recoverable Threshold
    0x00,            //Upper critical Threshold
    0x00,            //Upper non critical Threshold
    //Byte 40
    0x00,            //Lower non-recoverable Threshold
    0x00,            //Lower critical Threshold
    0x00,            //Lower non-critical Threshold
    0x00,            //positive going Threshold hysteresis value
    0x00,            //negative going Threshold hysteresis value
    0x00,            //reserved
    0x00,            //reserved
    0x00,            //OEM reserved
    //Byte 48
    0xcc,            //8 bit ASCII, number of bytes
    'F', 'R', 'U', ' ', 'H', 'O', 'T', '_', 'S', 'W', 'A', 'P' //sensor string
};

u08 SDR4[] =
{
    //sensor record header
    0x04,              //record number, LSB  - filled by SDR_Init()
    0x00,              //record number, MSB  - filled by SDR_Init()
    0x51,              //IPMI protocol version
    0x02,              //record type: compact sensor
    0x23,              //record length: remaining bytes, SDR_Init

    //record key bytes
    0x00,              //i2c address, filled by SDR_Init
    0x00,              //sensor owner LUN
    VOLTAGE_OK_SENSOR, //sensor number

    //record body bytes
    //Byte 8
    0xc1,              //entity id: MCH
    0x00,              //entity instance, SDR_Init
    0x03,              //init: events + scanning enabled
    0xc2,              //capabilities: auto re-arm, global disable
    0x08,              //type: Power Supply(DC-to-DC converter)
    0x6f,              //sensor specific event/read
    0x01,              //LSB assert event mask: 1 bit value
    0x00,              //MSB assert event mask
    0x01,              //LSB deassert event mask: 1 bit value
    0x00,              //MSB deassert event mask
    0x01,              //LSB read event mask: 1 bit value
    0x00,              //MSB read event mask
    0xc0,              //sensor units 1
    0x00,              //sensor units 2
    0x00,              //sensor units 3
    0x01,              //sharing: 1 sensor
    0x00,              //no entity instance string
    0x00,              //no positive threshold hysteresis
    0x00,              //no negative threshold hysteresis
    0x00,              //reserved
    0x00,              //reserved
    0x00,              //reserved
    0x00,              //OEM reserved
    0xc8,              //8 bit ASCII, number of bytes
    'P', 'O', 'W', 'E', 'R', '_', 'O', 'K' //sensor string
};

u08 SDR5[] =
{
    //sensor record header
    0x05,        //record number, LSB  - filled by SDR_Init()
    0x00,        //record number, MSB  - filled by SDR_Init()
    0x51,        //IPMI protocol version
    0x02,        //record type: compact sensor
    0x23,        //record length: remaining bytes, SDR_Init

    //record key bytes
    0x00,        //i2c address, filled by SDR_Init
    0x00,        //sensor owner LUN
    FPGA_MASTER, //sensor number

    //record body bytes
    //Byte 8
    0xc1,        //entity id: MCH
    0x00,        //entity instance, SDR_Init
    0x03,        //init: events + scanning enabled
    0xc2,        //capabilities: auto re-arm, global disable
    0x07,        //type: Power Supply(DC-to-DC converter)
    0x0a,        //sensor discrete event/read
    0x01,        //LSB assert event mask: 1 bit value
    0x00,        //MSB assert event mask
    0x01,        //LSB deassert event mask: 1 bit value
    0x00,        //MSB deassert event mask
    0x01,        //LSB read event mask: 1 bit value
    0x00,        //MSB read event mask
    0xc0,        //sensor units 1
    0x00,        //sensor units 2
    0x00,        //sensor units 3
    0x01,        //sharing: 1 sensor
    0x00,        //no entity instance string
    0x00,        //no positive threshold hysteresis
    0x00,        //no negative threshold hysteresis
    0x00,        //reserved
    0x00,        //reserved
    0x00,        //reserved
    0x00,        //OEM reserved
    0xcb,        //8 bit ASCII, number of bytes
    'F', 'P', 'G', 'A', '_', 'M', 'A', 'S', 'T', 'E', 'R' //sensor string
};

//12V Payload power sensor
u08 SDR6[] =
{
    //sensor record header
    //Byte 1
    0x06,    //record number, LSB  - filled by SDR_Init()
    0x00,    //record number, MSB  - filled by SDR_Init()
    0x51,    //IPMI protocol version
    0x01,    //record type: full sensor
    0x2e,    //record length: remaining bytes -> SDR_Init

    //record key bytes
    0x00,    //i2c address, -> SDR_Init
    0x00,    //sensor owner LUN
    //Byte 8
    VOLT_12, //sensor number

    //record body bytes
    0xc1,    //entity id: AMC Module
    0x00,    //entity instance -> SDR_Init
    0x03,    //init: event generation + scanning enabled
    0x48,    //capabilities: auto re-arm, Threshold is readable and setable
    VOLTAGE, //sensor type: Voltage
    0x01,    //sensor reading: Threshold
    0x80,    //LSB assert event mask: 3 bit value
    //Byte 16
    0x0a,    //MSB assert event mask
    0xa8,    //LSB deassert event mask: 3 bit value
    0x7a,    //MSB deassert event mask
    0x38,    //LSB: readable Threshold mask: all thresholds are readable
    0x38,    //MSB: setable Threshold mask: all thresholds are setable
    0x00,    //sensor units 1 : 2's complement
    0x04,    //sensor units 2 : Temperature
    0x00,    //sensor units 3 : Modifier
    //Byte 24
    0x00,    //Linearization
    0x4e,    //M
    0x02,    //M - Tolerance
    0x00,    //B
    0x04,    //B - Accuracy
    0x0c,    //Sensor direction
    0xd0,    //R-Exp , B-Exp
    0x07,    //Analogue characteristics flags
    //Byte 32
    0x7f,    //Nominal reading
    0xef,    //Normal maximum
    0xab,    //Normal minimum
    0xff,    //Sensor Maximum reading
    0x00,    //Sensor Minimum reading
    0xf7,    //Upper non-recoverable Threshold
    0xf2,    //Upper critical Threshold
    0xe9,    //Upper non critical Threshold
    //Byte 40
    0xa2,    //Lower non-recoverable Threshold
    0xa7,    //Lower critical Threshold
    0xab,    //Lower non-critical Threshold
    0x02,    //positive going Threshold hysteresis value
    0x02,    //negative going Threshold hysteresis value
    0x00,    //reserved
    0x00,    //reserved
    0x00,    //OEM reserved
    //Byte 48
    0xc3,    //8 bit ASCII, number of bytes
    '1', '2', 'V' //sensor string
};

u08 SDR7[] =
{
    //sensor record header
    0x05,       //record number, LSB  - filled by SDR_Init()
    0x00,       //record number, MSB  - filled by SDR_Init()
    0x51,       //IPMI protocol version
    0x02,       //record type: compact sensor
    0x23,       //record length: remaining bytes, SDR_Init

    //record key bytes
    0x00,       //i2c address, filled by SDR_Init
    0x00,       //sensor owner LUN
    FPGA_SLAVE, //sensor number

    //record body bytes
    //Byte 8
    0xc1,       //entity id: MCH
    0x00,       //entity instance, SDR_Init
    0x03,       //init: events + scanning enabled
    0xc2,       //capabilities: auto re-arm, global disable
    0x07,       //type: Power Supply(DC-to-DC converter)
    0x0a,       //sensor discrete event/read
    0x01,       //LSB assert event mask: 1 bit value
    0x00,       //MSB assert event mask
    0x01,       //LSB deassert event mask: 1 bit value
    0x00,       //MSB deassert event mask
    0x01,       //LSB read event mask: 1 bit value
    0x00,       //MSB read event mask
    0xc0,       //sensor units 1
    0x00,       //sensor units 2
    0x00,       //sensor units 3
    0x01,       //sharing: 1 sensor
    0x00,       //no entity instance string
    0x00,       //no positive threshold hysteresis
    0x00,       //no negative threshold hysteresis
    0x00,       //reserved
    0x00,       //reserved
    0x00,       //reserved
    0x00,       //OEM reserved
    0xca,       //8 bit ASCII, number of bytes
    'F', 'P', 'G', 'A', '_', 'S', 'L', 'A', 'V', 'E' //sensor string
};

u08 *sdrPtr[NUM_SDR] = {SDR0, SDR1, SDR2, SDR3, SDR4, SDR5, SDR6, SDR7};
u08 sdrLen[NUM_SDR] =  {sizeof(SDR0), sizeof(SDR1), sizeof(SDR2), sizeof(SDR3), sizeof(SDR4), sizeof(SDR5), sizeof(SDR6), sizeof(SDR7)};

sensor_t sens[NUM_SENSOR];

//******************/
void leds_init_user()    //Called from leds_init in led.c
//******************/
{
    led[USER_LED].local_cntr_fnc   = LED_OFF;
    led[USER_LED].fnc_off          = LED_OFF;
    led[USER_LED].on_duration      = 0;
    led[USER_LED].color            = RED;
    led[USER_LED].control_state    = LOCAL_CONTROL_STATE;
    local_led_control_user(USER_LED, LED_OFF);
}


//**************************/
u08 state_led_user(u08 led_n)   //Called from state_led in led.c
//**************************/
{
    if (led[led_n].control_state == OVERRIDE_STATE)
        return (0); //MJ: 0 = LED_OFF. Is this what we want in mmc_main.c? What is OVERRIDE_STATE used for?

    switch (led_n)
    {
    case USER_LED:
        if (inb(LED_USER_IN) & BV(LED_USER_PIN))    return LED_OFF;
        else                                        return LED_ON;
        break;
    default:
        break;
    }
    return (0xff); //MJ: mmc_main.c does not process this error. How could it react?
}
Beispiel #12
0
void spi_set_speed(spi_speed_t speed) {
  /* Wait until TX fifo is empty */
  while (!BITBAND(SSP_REGS->SR, 0)) ;

  /* Disable SSP (FIXME: Is this required?) */
  SSP_REGS->CR1 = 0;

  /* Change clock divisor */
  if (speed == SPI_SPEED_FAST) {
    SSP_REGS->CPSR = SSP_CLK_DIVISOR_FAST;
  } else {
    SSP_REGS->CPSR = SSP_CLK_DIVISOR_SLOW;
  }

  /* Enable SSP */
  SSP_REGS->CR1 = BV(1);
}
Beispiel #13
0
/*************************************************************
 * @fn        I2c_Read_Byte
 *
 * @brief     This func for read byte
 *            Make i2c data wire to be input
 * 
 * @param     none
 *
 * @return    uint8 
 */
uint8 I2c_Read_Byte( void )
{
  uint8 Num, Recv = 0;
  I2C_DAT = 1;
  P0DIR &= ~BV(0);    // Make i2c data wire to be input
  for(Num = 0; Num < 8; Num++)
  {
    I2C_CLK = 0; 
    delay_us(2);
    I2C_CLK = 1;
    Recv = (Recv << 1) | I2C_DAT;// delay_us(2);
   // I2C_CLK = 1; 
    delay_us(2);
  }
  P0DIR |= BV(0);     // Restore i2c data wire direction
  return Recv;
}
 void HalSPIWrite(uint32 addr, uint8 *pBuf, uint16 len)
{
  uint8 cnt;
  uint8 shdw = P1DIR;
  P1DIR |= BV(3);
  while (len)
  {
    XNV_SPI_BEGIN();
    do {
      xnvSPIWrite(XNV_STAT_CMD);
    } while (XNV_SPI_RX() & XNV_STAT_WIP);
    XNV_SPI_END();
    asm("NOP"); asm("NOP");

    XNV_SPI_BEGIN();
    xnvSPIWrite(XNV_WREN_CMD);
    XNV_SPI_END();
    asm("NOP"); asm("NOP");

    XNV_SPI_BEGIN();
    xnvSPIWrite(XNV_WRPG_CMD);
    xnvSPIWrite(addr >> 16);
    xnvSPIWrite(addr >> 8);
    xnvSPIWrite(addr);

    // Can only write within any one page boundary, so prepare for next page write if bytes remain.
    cnt = 0 - (uint8)addr;
    if (cnt)
    {
      addr += cnt;
    }
    else
    {
      addr += 256;
    }

    do
    {
      xnvSPIWrite(*pBuf++);
      cnt--;
      len--;
    } while (len && cnt);
    XNV_SPI_END();
  }
  P1DIR = shdw;
}
Beispiel #15
0
static void
off(void)
{
  /*  PRINTF("off\n");*/
  receive_on = 0;

  /* Wait for transmission to end before turning radio off. */
  BUSYWAIT_UNTIL(!(status() & BV(CC2520_TX_ACTIVE)), RTIMER_SECOND / 10);

  ENERGEST_OFF(ENERGEST_TYPE_LISTEN);
  strobe(CC2520_INS_SRFOFF);
  CC2520_DISABLE_FIFOP_INT();

  if(!CC2520_FIFOP_IS_1) {
    flushrx();
  }
}
Beispiel #16
0
void xUartEnable(u08 nUart)
{
	if (nUart == 0) {
		UCSR0B |= BV(RXCIE0)| BV(RXEN0)| BV(TXEN0);
		return;
	}

	if (nUart == 1) {
		UCSR1B |= BV(RXCIE1)| BV(RXEN1)| BV(TXEN1);
		return;
	}
}
void HalLcdInit(void)
{
#if (HAL_LCD == TRUE)
    /*config the I/O---------------by Zimuge*/
    P1SEL &= ~(BV(3) + BV(5) + BV(6) + BV(7));
    P1DIR |= (BV(3) + BV(5) + BV(6) + BV(7));
    P2SEL &= ~BV(0);
    P2DIR |= BV(0);
    LEDD = 0; //open the backlight
    HalLcd_HW_WriteCommand(0xE2);// software rest
    HalLcd_HW_WaitUs(2);

    HalLcd_HW_WriteCommand(0x2C);// open the boost circuit
    HalLcd_HW_WaitUs(2);
    HalLcd_HW_WriteCommand(0x2E);// open the voltage management circuit
    HalLcd_HW_WaitUs(2);
    HalLcd_HW_WriteCommand(0x2F);// open the voltage follower
    HalLcd_HW_WaitUs(2);

    HalLcd_HW_WriteCommand(0x24);// select the contrast roughly
    HalLcd_HW_WriteCommand(0x81);// select the contrast smoothly
    HalLcd_HW_WriteCommand(0x12);
    HalLcd_HW_WriteCommand(0xA2);// select the bias voltage radio 1/9

    HalLcd_HW_WriteCommand(0xC8);// scan the LCD from top to bottom

    HalLcd_HW_WriteCommand(0xA0);// the address will automatically increase one by one

    HalLcd_HW_WriteCommand(0x40);// select the begining of the column to display the char

    HalLcd_HW_WriteCommand(0xAF);// open the lcd

    // HalLcd_HW_WriteCommand(0xA5);
    HalLcd_HW_Clear();
    LoadBackground();

#endif
}
Beispiel #18
0
void
__cc2420_arch_init(void)
{
  SFIOR |= BV(PUD);		/* Beware, disable all pull-ups. */

  spi_init();

  DDRB  |= BV(RESET_N) | BV(VREG_EN) | BV(CSN);
  PORTB |= BV(RESET_N) | BV(CSN);

  SPI_DISABLE();                /* Unselect radio. */
}
Beispiel #19
0
void tlc5940_gspwm(void)
{
 	uint8_t first_cycle = 0;
	uint8_t data_count = 0;
	uint16_t gsclk_count = 0;
	uint16_t tmp;

	if(CHECKBIT(VPRG_PORT, VPRG))
	{
		CLEARBIT(VPRG_PORT, VPRG);
		first_cycle = 1;
	}

	CLEARBIT(BLANK_PORT, BLANK);
	while(1)
	{
	 	 if(gsclk_count > GSCLK_VAL)
		 {
		  	SETBIT(BLANK_PORT, BLANK);
			PULSE(XLAT_PORT, XLAT);
			if(first_cycle)
			{
				PULSE(SCLK_PORT, SCLK);
				first_cycle = 0;
			}
			break;
		 }else{
		 	if(data_count < 192*2)
			{
				tmp = pwm[data_count/12];
				tmp &= BV(11 - (data_count%12));
			 	if(tmp)
				//if(gsdata[data_count])
					SETBIT(SIN_PORT, SIN);
				else
					CLEARBIT(SIN_PORT, SIN);

				PULSE(SCLK_PORT, SCLK);
				data_count++;
			}
		}
		PULSE(GSCLK_PORT, GSCLK);
		gsclk_count++;
	}
}
Beispiel #20
0
uint8_t i2cMasterSendNI(uint8_t deviceAddr, uint8_t length, uint8_t const *data)
{
    uint8_t retval = I2C_OK;

    // disable TWI interrupt
    cbi(TWCR, TWIE);

    // send start condition
    i2cSendStart();
    i2cWaitForComplete();

    // send device address with write
    i2cSendByte(deviceAddr & 0xFE);
    i2cWaitForComplete();

    // check if device is present and live
    if (inb(TWSR) == TW_MT_SLA_ACK)
    {
        // send data
        while (length)
        {
            i2cSendByte(*data++);
            i2cWaitForComplete();
            length--;
        }
    }
    else
    {
        // device did not ACK it's address,
        // data will not be transferred
        // return error
        retval = I2C_ERROR_NODEV;
    }

    // transmit stop condition
    // leave with TWEA on for slave receiving
    i2cSendStop();
    while (!(inb(TWCR) & BV(TWSTO)))
        ;

    // enable TWI interrupt
    sbi(TWCR, TWIE);

    return retval;
}
Beispiel #21
0
void fpga_rompgm() {
  int MAXRETRIES = 10;
  int retries = MAXRETRIES;
  uint8_t data;
  int i;
  tick_t timeout;
  do {
    i=0;
    timeout = getticks() + 100;
    fpga_set_prog_b(0);
    uart_putc('P');
    fpga_set_prog_b(1);
    while(!fpga_get_initb()){
      if(getticks() > timeout) {
        printf("no response from FPGA trying to initiate configuration!\n");
        led_panic();
      }
    };
    if(fpga_get_done()) {
      printf("DONE is stuck high!\n");
      led_panic();
    }
    LPC_GPIO2->FIOMASK1 = ~(BV(0));
    uart_putc('p');

    /* open configware file */
    rle_mem_init(cfgware, sizeof(cfgware));
    printf("sizeof(cfgware) = %d\n", sizeof(cfgware));
    for (;;) {
      data = rle_mem_getc();
      if(rle_state) break;
      i++;
      FPGA_SEND_BYTE_SERIAL(data);
    }
    uart_putc('c');
    printf("fpga_pgm: %d bytes programmed\n", i);
    delay_ms(1);
  } while (!fpga_get_done() && retries--);
  if(!fpga_get_done()) {
    printf("FPGA failed to configure after %d tries.\n", MAXRETRIES);
    led_panic();
  }
  printf("FPGA configured\n");
  fpga_postinit();
}
Beispiel #22
0
/*---------------------------------------------------------------------------*/
void
cc2420_arch_sfd_init(void)
{
  /* Need to select the special function! */
  P4SEL = BV(CC2420_SFD_PIN);
  
  /* start timer B - 32768 ticks per second */
  TBCTL = TBSSEL_1 | TBCLR;
  
  /* CM_3 = capture mode - capture on both edges */
  TBCCTL1 = CM_3 | CAP | SCS;
  TBCCTL1 |= CCIE;
  
  /* Start Timer_B in continuous mode. */
  TBCTL |= MC1;

  TBR = RTIMER_NOW();
}
Beispiel #23
0
static DECLARE_ISR(irq_dac)
{
	if (DACC_ISR & BV(DACC_ENDTX))
	{
		if (remaing_size > 0)
		{
			DACC_TNPR = (uint32_t)&sample_buff[next_idx];
			DACC_TNCR = chunk_size;

			remaing_size -= chunk_size;
			next_idx += chunk_size;
		}
		else
			/* Clear the pending irq when the dma ends the conversion */
			DACC_TCR = 1;
	}
	event_do(&buff_emtpy);
}
Beispiel #24
0
/*---------------------------------------------------------------------------*/
void
cc2420_set_pan_addr(unsigned pan,
			   unsigned addr,
			   const uint8_t *ieee_addr)
{
  uint16_t f = 0;
  /*
   * Writing RAM requires crystal oscillator to be stable.
   */
  while(!(status() & (BV(CC2420_XOSC16M_STABLE))));

  pan_id = pan;
  FASTSPI_WRITE_RAM_LE(&pan, CC2420RAM_PANID, 2, f);
  FASTSPI_WRITE_RAM_LE(&addr, CC2420RAM_SHORTADDR, 2, f);
  if(ieee_addr != NULL) {
    FASTSPI_WRITE_RAM_LE(ieee_addr, CC2420RAM_IEEEADDR, 8, f);
  }
}
static int check_rx(void)
{

    union {
        u16 value;
        struct {
            u8 lsb;
            u8 msb;
        } bytes;
    } chanval;

    if (NRF24L01_ReadReg(NRF24L01_07_STATUS) & BV(NRF24L01_07_RX_DR)) {
        // data received from aircraft
        XN297_ReadPayload(packet, PACKET_SIZE);

        NRF24L01_WriteReg(NRF24L01_07_STATUS, 255);

        NRF24L01_FlushRx();
        // decode data , check sum is ok as well, since there is no crc
        if (packet[0] == 0x85 && packet[14] == checksum()) {
            // uncompensated battery volts*100
            chanval.bytes.msb = packet[3] & 0x7;
            u8 flags = packet[3] >> 3;
            chanval.bytes.lsb = packet[4] & 0xff;
            Telemetry.value[TELEM_DSM_FLOG_VOLT1] = chanval.value;
            TELEMETRY_SetUpdated(TELEM_DSM_FLOG_VOLT1);

            // compensated battery volts*100
            chanval.bytes.msb = packet[5] & 0x7;
            chanval.bytes.lsb = packet[6] & 0xff;
            Telemetry.value[TELEM_DSM_FLOG_VOLT2] = chanval.value;
            TELEMETRY_SetUpdated(TELEM_DSM_FLOG_VOLT2);

            // reception in packets / sec , multiplied by 2
            Telemetry.value[TELEM_DSM_FLOG_HOLDS] = packet[7] * 2;
            TELEMETRY_SetUpdated(TELEM_DSM_FLOG_HOLDS);

            // battery low flag
            Telemetry.value[TELEM_DSM_FLOG_FADESL] = (flags & 1) ? 100 : 0;
            TELEMETRY_SetUpdated(TELEM_DSM_FLOG_FADESL);

            telemetry_count++;
            return 1;
        }                       // end tel received
Beispiel #26
0
/***********************************************************************************
* @fn      halDigioConfig
*
* @brief   Configure the pin as specified by p.
*
* @param   digioConfig* p - pointer to configuration structure for IO pin
*
* @return  uint8 - HAL_DIGIO_ERROR or HAL_DIGIO_OK
*/
uint8 halDigioConfig(const digioConfig* p)
{
    register volatile uint8* dir;
    register volatile uint8* out;
    register const uint8 bitmask = p->pin_bm;

    // Sanity check
    if ((bitmask == 0) || (bitmask != (uint8)BV(p->pin)))
    {
        return(HAL_DIGIO_ERROR);
    }

    switch(p->port)
    {
    case 1: P1SEL &= ~bitmask; out = &P1OUT; dir = &P1DIR; break;
    case 2: P2SEL &= ~bitmask; out = &P2OUT; dir = &P2DIR; break;
    case 3: P3SEL &= ~bitmask; out = &P3OUT; dir = &P3DIR; break;
    case 4: P4SEL &= ~bitmask; out = &P4OUT; dir = &P4DIR; break;
    case 5: P5SEL &= ~bitmask; out = &P5OUT; dir = &P5DIR; break;
    case 6: P6SEL &= ~bitmask; out = &P6OUT; dir = &P6DIR; break;
    case 7: P7SEL &= ~bitmask; out = &P7OUT; dir = &P7DIR; break;
    case 8: P8SEL &= ~bitmask; out = &P8OUT; dir = &P8DIR; break;
    default: return(HAL_DIGIO_ERROR);
    }

    if (p->dir == HAL_DIGIO_OUTPUT)
    {
        if (p->initval == 1)
        {
            *out |= bitmask;
        }
        else
        {
            *out &= ~bitmask;
        }
        *dir |= bitmask;
    }
    else // input
    {
        *out &= ~bitmask;
        *dir &= ~bitmask;
    }
    return(HAL_DIGIO_OK);
}
Beispiel #27
0
void spi_dma_init(SpiDmaAt91 *spi)
{
	/* Disable PIO on SPI pins */
	PIOA_PDR = BV(SPI0_SPCK) | BV(SPI0_MOSI) | BV(SPI0_MISO);

	/* Reset device */
	SPI0_CR = BV(SPI_SWRST);

	/*
	 * Set SPI to master mode, fixed peripheral select, chip select directly connected to a peripheral device,
	 * SPI clock set to MCK, mode fault detection disabled, loopback disable, NPCS0 active, Delay between CS = 0
	 */
	SPI0_MR = BV(SPI_MSTR) | BV(SPI_MODFDIS);

	/*
	 * Set SPI mode.
	 * At reset clock division factor is set to 0, that is
	 * *forbidden*. Set SPI clock to minimum to keep it valid.
	 */
	SPI0_CSR0 = BV(SPI_NCPHA) | (255 << SPI_SCBR_SHIFT);

	/* Disable all irqs */
	SPI0_IDR = 0xFFFFFFFF;
	/* Enable SPI clock. */
	PMC_PCER = BV(SPI0_ID);

	/* Enable SPI */
	SPI0_CR = BV(SPI_SPIEN);

	DB(spi->fd._type = KFT_SPIDMAAT91);
	spi->fd.write = spi_dma_write;
	spi->fd.read = spi_dma_read;
	spi->fd.flush = spi_dma_flush;

	SPI_DMA_STROBE_INIT();
}
Beispiel #28
0
void uart_recv_intr_thread(void *arg)
{
	recv_isr_ctx = current_context;
	
	/*
	 * Release the interrupt to the processor.
	 */
	out8(UCR, in8(UCR) | BV(RXCIE));
	
	isr_disable();
	debug_set_lights(0x02);
	isr_spinlock_lock(&recv_isr_lock);
	
	while (1) {
		while (recv_tail == recv_head) {
			isr_context_wait(&recv_isr_lock);
		}

		while (recv_tail != recv_head) {
			u8_t ch;

			ch = recv_fifo[recv_tail++];
			recv_tail &= (UART_RX_FIFO_DEPTH - 1);
		
			isr_spinlock_unlock(&recv_isr_lock);
			isr_enable();
			
			spinlock_lock(&uart_lock);
			if (client) {
				uart_client_ref(client);
				spinlock_unlock(&uart_lock);
				client->uc_recv(client, ch);
				spinlock_lock(&uart_lock);
				uart_client_deref(client);
			}
			spinlock_unlock(&uart_lock);
			
			isr_disable();
			debug_set_lights(0x02);
			isr_spinlock_lock(&recv_isr_lock);
		}
	}
}
Beispiel #29
0
static void
configure(void)
{
  uint16_t reg;
  BUSYWAIT_UNTIL(status() & (BV(CC2420_XOSC16M_STABLE)), RTIMER_SECOND / 100);

  /* Turn on/off automatic packet acknowledgment and address decoding. */
  reg = getreg(CC2420_MDMCTRL0);

#if CC2420_CONF_AUTOACK
  reg |= AUTOACK | ADR_DECODE;
#else
  reg &= ~(AUTOACK | ADR_DECODE);
#endif /* CC2420_CONF_AUTOACK */
  setreg(CC2420_MDMCTRL0, reg);

  /* Set transmission turnaround time to the lower setting (8 symbols
     = 0.128 ms) instead of the default (12 symbols = 0.192 ms). */
  /*  reg = getreg(CC2420_TXCTRL);
  reg &= ~(1 << 13);
  setreg(CC2420_TXCTRL, reg);*/

  /* Change default values as recomended in the data sheet, */
  /* correlation threshold = 20, RX bandpass filter = 1.3uA. */
  setreg(CC2420_MDMCTRL1, CORR_THR(20));
  reg = getreg(CC2420_RXCTRL1);
  reg |= RXBPF_LOCUR;
  setreg(CC2420_RXCTRL1, reg);

  /* Set the FIFOP threshold to maximum. */
  setreg(CC2420_IOCFG0, FIFOP_THR(127));

  /* Turn off "Security enable" (page 32). */
  reg = getreg(CC2420_SECCTRL0);
  reg &= ~RXFIFO_PROTECTION;
  setreg(CC2420_SECCTRL0, reg);

  cc2420_set_pan_addr(pan, addr, NULL);
  cc2420_set_channel(channel);

  flushrx();

}
Beispiel #30
0
/* Late initialisation, increase CPU clock */
void system_init_late(void) {
  /* Set flash accelerator to 5 CPU cycle access time */
  LPC_SC->FLASHCFG = (LPC_SC->FLASHCFG & 0xffff0fff) | (4 << 12);

  /* Enable main oscillator, range 1-20MHz */
  BITBAND(LPC_SC->SCS, 5) = 1;

  /* Wait until stable */
  while (!BITBAND(LPC_SC->SCS, 6)) ;

  /* Use main oscillator as system clock source */
  LPC_SC->CLKSRCSEL = 1;

  /* Set up PLL0 multiplier and pre-divisor */
  LPC_SC->PLL0CFG  = ((PLL_PREDIV-1) << 16) | (PLL_MULTIPLIER-1);
  LPC_SC->PLL0FEED = 0xaa;
  LPC_SC->PLL0FEED = 0x55;

  /* Enable PLL0 */
  LPC_SC->PLL0CON  = 1;
  LPC_SC->PLL0FEED = 0xaa;
  LPC_SC->PLL0FEED = 0x55;

  /* Increase CPU clock divider */
  LPC_SC->CCLKCFG = PLL_DIVISOR-1;

  /* Wait until PLL locks */
  while (!(LPC_SC->PLL0STAT & BV(26))) ;

  /* Connect PLL0 */
  LPC_SC->PLL0CON  = 3;
  LPC_SC->PLL0FEED = 0xaa;
  LPC_SC->PLL0FEED = 0x55;

  /* Enable GPIO interrupt */
  NVIC_EnableIRQ(EINT3_IRQn);

  // FIXME: Debugging
  //LPC_GPIO0->FIODIR |= BV(11) | BV(10);
  //LPC_GPIO2->FIODIR |= BV(0) | BV(1);
  //set_debugstate(0);
}