Esempio n. 1
0
// initialization of the ADXL345 component
u8 ADXL_init(void)
{
	u8 tx_buf[2];
	u8 rx_buf[2];

	// setup the SPI according to ADXL specs
	SPI_init(SPI_MASTER, SPI_THREE, SPI_MSB, SPI_DIV_2);

	// read the device ID
	tx_buf[0] = ADXL_READ | DEVID;
	SPI_master(tx_buf, 1, rx_buf, 2);
	while ( ! SPI_is_fini() )
		;

	// check if device is the ADXL345
	if ( rx_buf[1] != DEVID_VALUE ) {
		return KO;
	}

	// set the measure bit in power control to start acquisitions
	tx_buf[0] = ADXL_WRITE | POWER_CTL;
	tx_buf[1] = (1 << 3);
	SPI_master(tx_buf, 2, rx_buf, 0);
	while ( ! SPI_is_fini() )
		;

	return OK;
}
Esempio n. 2
0
void init()
{
    WDTCTL = WDTPW + WDTHOLD; // disable WDT
    BCSCTL1 = CALBC1_1MHZ; // 1MHz clock
    DCOCTL = CALDCO_1MHZ;

    P1OUT = 0;
    P2OUT = 0;
    P1DIR = 0;
    P2DIR = 0;

    WDTCTL = WDT_ADLY_1000;                   // WDT 1s interval timer
    IE1 = WDTIE;                             // Enable WDT interrupt

    P1DIR |= LCD5110_SCE_PIN + LCD5110_DC_PIN + BACKLIGHT;
    P1OUT |= LCD5110_SCE_PIN + LCD5110_DC_PIN;

    SPI_init();
    __delay_cycles(50000);
    initLCD();
    clearLCD();

    defaultRX = 0;
    NRF_init(86);
    NRF_down();

    initKeyboard();
    // end init
};
Esempio n. 3
0
void init(void) {
	// configure pins
	DDRB |= (1 << DSKY_DISPLAY_PIN_CLR); 		// output
	DDRD |= (1 << DSKY_DISPLAY_PIN_PWRCLR); // output
	DDRD &= ~(1 << DSKY_DISPLAY_PIN_PWRCLR);
	
	// configure pins for SPI master
	SPI_init();	
	// initialize UART
  uart_init( UART_BAUD_SELECT(UART_BAUD_RATE,F_CPU) ); 
	// intialize KSP plugin
  kspio_init();
	
	clearRegisters(); // resets the shift registers and the decade counter
	
  // initialize bargraph PWM pins as outputs
  DSKY_BARGRAPH_CTRL_PORT |= (1 << DSKY_BARGRAPH_PIN_B1);
  DSKY_BARGRAPH_CTRL_PORT |= (1 << DSKY_BARGRAPH_PIN_B2);
  DSKY_BARGRAPH_CTRL_PORT |= (1 << DSKY_BARGRAPH_PIN_B3);
  
  // configure PWMs for bargraph displays
  TCCR0A |= (1 << COM0A1);								// set non-inverting mode for OC0A
  TCCR0A |= (1 << COM0B1);								// set non-inverting mode for OC0B
  TCCR0A |= (1 << WGM01) | (1 << WGM00);	// set fast PWM mode
  TCCR0B |= (1 << CS02) | (1 << CS00);		// set prescaler to 1024 and start PWM

  TCCR2A |= (1 << COM2B1);								// set non-inverting mode for OC2B
  //TCCR2A |= (1 << WGM21) | (1 << WGM20);				// set fast PWM mode - done in millis.c
  //TCCR2B |= (1 << CS22) | (1 << CS21) | (1 << CS20); 	// set prescaler to 1024 and start PWM - done in millis.c

	// multiplexing the displays
	TCCR1A |= (1 << WGM10);  												// timer/counter control register 1 A: fast PWM
	TCCR1B |= (1<<WGM12) | (1<<CS11) | (1<<CS10);  	// timer/counter control register 1 B: clock select 64th frequency
	TIMSK1 |= (1<<TOIE1);														// timer/counter interrupt mask register: timer/counter 1 overflow interrupt enable
}
Esempio n. 4
0
File: main.c Progetto: ADTL/ARMWork
int main (void) {
  
  SystemCoreClockUpdate();

  USART_init(&usart, PIO0_18, PIO0_19);
  USART_begin(&usart, 9600);
  USART_puts(&usart, "Hello.\n");

  VCOM_Init();                              // VCOM Initialization

  USB_Init();                               // USB Initialization
  USB_Connect(TRUE);                        // USB Connect

  while (!USB_Configuration) ;              // wait until USB is configured

  while (1) {                               // Loop forever
    VCOM_Serial2Usb();                      // read serial port and initiate USB event
    VCOM_CheckSerialState();
	VCOM_Usb2Serial();
  } // end while											   
  
  SPI_init(&SPI0, PIO0_1, PIO0_1, PIO0_1, PIO0_2);			
	
  while ( 1 );
}
Esempio n. 5
0
/**
 *		\brief Funkcja inicjalizująca piny GPIO, interfejs SPI oraz moduł RC522.
 *
 *		\warning Musi zostać wywołana przed pętlą nieskończoną w funkcji main()
 */
void RFID_init(void)
{
	uint8_t temp=0;
	// właczenie zegara do portów 
	SIM->SCGC5 |= SIM_SCGC5_PORTA_MASK
			|  SIM_SCGC5_PORTB_MASK
			|  SIM_SCGC5_PORTC_MASK
			|  SIM_SCGC5_PORTD_MASK
			|  SIM_SCGC5_PORTE_MASK;
	SPI_init();		// inicjalizacja SPI

	/* USTAWIENIE PORTU ODPOWIEDZIALNEGO ZA RESET SPRZĘTOWY UKŁADU MFRC522 */
	RESET_PORTx->PCR[RESET_NUMBER] |= PORT_PCR_MUX(1);
	RESET_PTx->PDDR |= (1<<RESET_NUMBER);
	RESET_PTx->PSOR |= (1<<RESET_NUMBER);		

	RC522_write(CommandReg,SoftReset_CMD);		// reset programowy, przywraca domyślne wartości wszystkim rejestrom

	RC522_write(TModeReg, 0x8D);					// TModeReg -> konfiguruje zewnętrzny timer => timer startuje od razu po zakończeniu transmisji, 0xD00 -> tak ustawione są 4 starsze bity preskalera
	RC522_write(TPrescalerReg, 0x3E);			// definiuje ustawienie 8 młodszych bitów preskalera 0x03E
	RC522_write(TReloadReg_1, 30);				// wartość rejestru przeładowania starszy bajt
	RC522_write(TReloadReg_2, 0);					// wartość rejstru przeładowania młodszy bajt
	RC522_write(TxASKReg, 0x40);					// rejestr kontroluje ustawienia modulacji transmisji => 100% używamy modulacji ASK niezależnie od ustawień rejestru ModGsPReg
	RC522_write(ModeReg, 0x3D);	          // rejestr od generalnych ustawień transmisji => tramiter stratuje tylko jest pole elektryczne,MFIN jest aktywny w stanie wysokim,usatwienie wartości startowej dla CRC


	// sprawdzenie włączenia anteny jeśli jest wyłączona to ją właczamy
	temp = RC522_read(TxControlReg);
	if(!(temp&0x03))
	{
		RC522_write(TxControlReg,temp|0x03);
	}
}
Esempio n. 6
0
void inline apa102_setleds(struct cRGB *ledarray, uint16_t leds)
{
  uint16_t i;
  uint8_t *rawarray=(uint8_t*)ledarray;
  SPI_init();
  
  SPI_write(0x00);  // Start Frame
  SPI_write(0x00);
  SPI_write(0x00);
  SPI_write(0x00);
 
  for (i=0; i<(leds+leds+leds); i+=3)
  {
    SPI_write(0xff);  // Maximum global brightness
    SPI_write(rawarray[i+0]);
    SPI_write(rawarray[i+1]);
    SPI_write(rawarray[i+2]);
  }
  
  // End frame: 8+8*(leds >> 4) clock cycles    
  for (i=0; i<leds; i+=16)
  {
    SPI_write(0xff);  // 8 more clock cycles
  }
}
Esempio n. 7
0
int main() {
  char ret;

  USART_init(51);

  USART_printstr("\r\n");
  USART_println("Initializing");
  USART_printstr(" SPI...");
  SPI_init();
  USART_println("done");

  USART_printstr(" SD...");
  if ((ret = SD_init())) {
    USART_printstr("error: ");
    USART_printhex(ret);
    USART_printstr("\r\n");
    return -1;
  }
  USART_println("done");

  USART_printstr(" FAT16...");
  if ((ret = FAT16_init())) {
    USART_printstr("error: ");
    USART_printhex(ret);
    USART_printstr("\r\n");
    return -1;
  }
  USART_println("done");

  return 0;
}
Esempio n. 8
0
void mrf24j40_setup_io() {

        #ifndef __PIC32MX__	
	        make_input(mrf24j40_int_port, mrf24j40_int_pin);
	        set_pin(mrf24j40_cs_port, mrf24j40_cs_pin);	// keep high
	        make_output(mrf24j40_cs_port, mrf24j40_cs_pin);
        #endif	
        #ifdef __PIC32MX__
        	SPI_init();			// init SPI default (2 on PIC32-PINGUINO)
        						// only called here for test
        						// will be called later in main32.c
        	#ifndef PIC32_PINGUINO_220
				//pinmode(13,OUTPUT); // CLK
				//pinmode(11,OUTPUT); // SDO
				//pinmode(12,INPUT);	// SDI				
				ZIGRESETOUT;		// macro for RESET
				ZIGCSOUT;			// macro for CS
				ZIGINTIN;			// interrupt (not yet implemented)
        	#else
				ZIGRESETOUT;		// macro for RESET
				ZIGCSOUT;			// macro for CS
			#endif
        	ZIGRESET=0;
        	ZIGCS=1;
        	ZIGRESET=1;
        	Delayms(100);
		#endif        	
}
Esempio n. 9
0
/*
 *  ======== EK_TM4C123GXL_initWiFi ========
 */
void EK_TM4C123GXL_initWiFi(void)
{
	/* Configure SSI2 */
	SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI2);
	GPIOPinConfigure(GPIO_PB4_SSI2CLK);
	GPIOPinConfigure(GPIO_PB6_SSI2RX);
	GPIOPinConfigure(GPIO_PB7_SSI2TX);
	GPIOPinTypeSSI(GPIO_PORTB_BASE, GPIO_PIN_4 | GPIO_PIN_6 | GPIO_PIN_7);

	/* Configure IRQ pin */
	GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_2);
	GPIOIntTypeSet(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_FALLING_EDGE);

	/* Configure EN pin */
	GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_5);
	GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5, 0);

	/* Configure CS pin */
	GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_0);
	GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_0, 0);

	/* Call necessary SPI init functions */
	SPI_init();
	EK_TM4C123GXL_initDMA();

	/* Initialize WiFi driver */
	WiFi_init();
}
Esempio n. 10
0
/*
 *  ======== EK_TM4C123GXL_initWiFi ========
 */
void EK_TM4C123GXL_initWiFi(void)
{
	/* Configure EN & CS pins to disable CC3100 */
	GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_4);
	GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_0, GPIO_PIN_0);
	GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_4, 0);

	/* Configure SSI2 for CC3100 */
	SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI2);
	GPIOPinConfigure(GPIO_PB4_SSI2CLK);
	GPIOPinConfigure(GPIO_PB6_SSI2RX);
	GPIOPinConfigure(GPIO_PB7_SSI2TX);
	GPIOPinTypeSSI(GPIO_PORTB_BASE, GPIO_PIN_4 | GPIO_PIN_6 | GPIO_PIN_7);

	/* Configure IRQ pin */
	GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_2);
	GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_STRENGTH_2MA,
			GPIO_PIN_TYPE_STD_WPD);
	GPIOIntTypeSet(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_RISING_EDGE);

	SPI_init();
	EK_TM4C123GXL_initDMA();

	WiFi_init();
}
/*
 *  ======== MSP_EXP430F5529LP_initWiFi ========
 */
void MSP_EXP430F5529LP_initWiFi(void)
{
    /* Configure EN & CS pins to disable CC3100 */
    GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN2);
    GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN6);
    GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN2);
    GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN6);

    /* Configure SPI */
    /* SPI CLK */
    GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P3, GPIO_PIN2);
    /* MOSI/SIMO */
    GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P3, GPIO_PIN0);
    /* MISO/SOMI */
    GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P3, GPIO_PIN1);

    /* Configure IRQ pin */
    GPIO_setAsInputPinWithPullDownResistor(GPIO_PORT_P2, GPIO_PIN0);
    GPIO_selectInterruptEdge(GPIO_PORT_P2, GPIO_PIN0,
                             GPIO_LOW_TO_HIGH_TRANSITION);

    /* Initialize SPI and WiFi drivers */
    SPI_init();
    WiFi_init();
}
Esempio n. 12
0
void init (void) {
	/* Enable the change of clock prescaler */
	CLKPR = (1 << CLKPCE);
	/* Within 4 clock cycles change the prescaler */
	CLKPR = (0 << CLKPS0 |
		 0 << CLKPS1 |
		 0 << CLKPS2 |
		 0 << CLKPS3);

	uart_init();
	/* Set stdout and stdin so that printf works */
	stdout = &uart_output;
	stdin  = &uart_input;

	/* Set the CE and CSN to output */
	DDRB |= (1 << CE);
	DDRB |= (1 << CSN);

	SPI_init();

	/* Default states */
	CSN_hi;
	CE_lo;

}
Esempio n. 13
0
int main(){

#ifndef TESTING

#include "uart.h"
#include "mmc.h"

	// Initializam modulele hardware

	uart_init();
	SPI_init();
	MMC_init();
	BTN_init();
	LCD_init();
#endif
	/* Gaseste prima partitie FAT32 de pe card*/
	init_partition(buffer);

	/**
	  * Gaseste datele despre sistemul de fisiere :
	  * nr de tabele FAT, cluster-ul directorului Root, etc.
	  */
	initFAT32(buffer);
	print_volid(buffer);

	LCD_str( "  ", 0);
	LCD_str( "  ", 0);
	LCD_str( "  Welcome to", 0);
	LCD_str( " MMC Explorer", 0);
	_delay_ms(2500);
	LCD_clear();
	printdirs(openroot());
	return EXIT_SUCCESS;
}
Esempio n. 14
0
/*
 *  ======== EK_TM4C123GXL_initSPI ========
 */
void EK_TM4C123GXL_initSPI(void)
{
  //INEEDMD_ADC_SPI
  //
  MAP_SysCtlPeripheralEnable(INEEDMD_ADC_SYSCTL_PRIPH_SSI);

  // Enable pin SSI CLK
  //
  MAP_GPIOPinConfigure(INEEDMD_ADC_GPIO_SSICLK);

  // Enable pin SSI TX
  //
  MAP_GPIOPinConfigure(INEEDMD_ADC_GPIO_SSITX);

  // Enable pin SSI RX
  //
  MAP_GPIOPinConfigure(INEEDMD_ADC_GPIO_SSIRX);

//  MAP_GPIOPinConfigure(GPIO_PA3_SSI0FSS);

  //Set the pins to type SSI
  //
  MAP_GPIOPinTypeSSI(INEEDMD_ADC_GPIO_PORT, (INEEDMD_ADC_SSICLK_PIN | INEEDMD_ADC_SSITX_PIN | INEEDMD_ADC_SSIRX_PIN ));//| GPIO_PIN_3));

  EK_TM4C123GXL_initDMA();
  SPI_init();
}
Esempio n. 15
0
bool LIS3DH_Initialize(void)
{
    SPI_Params spiParams;
    SPI_init();
    // Init SPI and specify non-default parameters
    SPI_Params_init(&spiParams);

    spiParams.mode                     = SPI_MASTER;
    spiParams.transferMode             = SPI_MODE_BLOCKING; //SPI_MODE_CALLBACK; //SPI_MODE_CALLBACK; // SPI_MODE_BLOCKING
    spiParams.transferCallbackFxn      = sbp_spiCallback;
    spiParams.bitRate                  = 800000;
    spiParams.frameFormat              = SPI_POL1_PHA1;// Clock to be normally high, write on the falling edge and capture data on the rising edge //SPI_POL1_PHA1; (clock is normally high) //SPI_POL0_PHA0; (clock is normally low)
//    spiParams.dataSize				   = 16;
    spiHandle = SPI_open(MOTIONSNS_SPI, &spiParams);
/*    params.bitRate     = 1000000;
    params.frameFormat = SPI_POL1_PHA1;
    params.mode        = SPI_MASTER;
*/
    // Open the SPI and perform the transfer
//    handle = SPI_open(MOTIONSNS_SPI, &params);

	PINCC26XX_setOutputEnable(SPI_CS, 1);
	PINCC26XX_setOutputValue(SPI_CS, 1);

	PINCC26XX_setOutputEnable(SPI_MISO, 0);

    return LIS3DH_VerifyCommunication();

}
Esempio n. 16
0
static void OLED_initSPI(void)
{
   /*
   IE2 &= ~(UTXIE1 | URXIE1);  // interrupt disable

   P5DIR |=  0x0a; // P5.3 (UCLK1) and P5.1 (SIMO1) - outputs
   P5SEL |=  0x0a; // They peripherial I/O pins
   
   U1CTL |= SWRST;  
   U1CTL |= CHAR | SYNC | MM;  // 8-bit char, spi-mode, USART as master
   U1CTL &= ~(0x20); 
   U1TCTL = STC ;     // 3-pin
//   U1TCTL |= CKPL | SSEL_1;    //
   U1TCTL |= CKPH | CKPL | SSEL_2;    // half-cycle delayed UCLK 
   U1BR0 = 0x02;   // as fast as possible
   U1BR1 = 0x00;
   U1MCTL = 0;
   ME2 &= ~(UTXE1 | URXE1); //USART UART module disable
   ME2 |= USPIE1;  // USART SPI module enable
   U1CTL &= ~SWRST;
   */
   
   SPI_init();
                     
}
Esempio n. 17
0
//*****************************************************************************
//
// 板级开发包初始化
//
//*****************************************************************************
void BSP_init(void)
{
    // Set the clocking to run directly from the crystal.
    SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_8MHZ);

    // Enable processor interrupts.
    IntMasterEnable();

    // Configure SysTick for a periodic interrupt.
    SysTickPeriodSet(SysCtlClockGet() / SYSTICKHZ);
    SysTickEnable();
    SysTickIntEnable();

    // Initialize the DEBUG UART.           (UART0)
    DEBUG_UART_init();

    // Initialize the IO Hardware.          (LED/SOL/I2C_HOTSWAP)
    IO_init();

    // Initialize the UART Hardware.        (ICMB/SOL)
    UART_init();

    // Initialize the SPI Hardware.         (SSIF)
    SPI_init();

    // Initialize the I2C Hardware.         (IPMB/PMB)
    I2C_init();

    // Initialize the Ethernet Hardware.    (LAN)
    ETH_init();
}
Esempio n. 18
0
static void *doAtSpiScreenOpen(void *arg) {
  AccessibleEventListener *evListener;
  sem_t *SPI_init_sem = (sem_t *)arg;
  int res;
  static const char *events[] = {
    "object:text-changed",
    "object:text-caret-moved",
    "object:state-changed:focused",
    "focus:",
  };
  const char **event;
  if ((res=SPI_init())) {
    logMessage(LOG_ERR,"SPI_init returned %d",res);
    return 0;
  }
  if (!(evListener = SPI_createAccessibleEventListener(evListenerCB,NULL)))
    logMessage(LOG_ERR,"SPI_createAccessibleEventListener failed");
  else for (event=events; event<&events[sizeof(events)/sizeof(*events)]; event++)
    if (!(SPI_registerGlobalEventListener(evListener,*event)))
      logMessage(LOG_ERR,"SPI_registerGlobalEventListener(%s) failed",*event);
  sem_post(SPI_init_sem);
  SPI_event_main();
  if (!(SPI_deregisterGlobalEventListenerAll(evListener)))
    logMessage(LOG_ERR,"SPI_deregisterGlobalEventListenerAll failed");
  AccessibleEventListener_unref(evListener);
  if (curFocus)
    finiTerm();
  if ((res=SPI_exit()))
    logMessage(LOG_ERR,"SPI_exit returned %d",res);
  return NULL;
}
Esempio n. 19
0
void SDCard_init(PinName mosi, PinName miso, PinName sclk, PinName cs)
{
  SPI_init(mosi, miso, sclk);
  GPIO_init(cs);
  GPIO_output(cs);
  GPIO_set(cs);
  _cs = cs;
}
/*
 *  ======== SENSORTAG_CC2650_initSPI ========
 */
Void SENSORTAG_CC2650_initSPI(Void)
{
    /* Initialize driver */
    SPI_init();
    
    /* Initialize IOs */
    SPICC26XX_ioInit(SPI_config);
}
Esempio n. 21
0
int main(int argc,char *argv[])
{
	CPU_Init();
	TRCINIT();
	SPI_init();
	start(INITIALIZE);
	return 0;
}
Esempio n. 22
0
void ADNS3080_Init(void)
{
  ADNS_3080_GPIO_Configuration();
  SPI_init(256);  //改变速度(2到256分频)
  ADNS3080_reset(); //复位
  GPIO_SetBits(GPIOA,GPIO_Pin_10);  //拉高NPD,免睡眠
  delay_ms(10);
  Write_srom();
  ADNS_Configuration();
 //printf("%d\n",read_register(0x1f));	 //查看是否下载成功
}
Esempio n. 23
0
dacI::dacI(list_t* exp_list, const std::string& name, unsigned spi_device_id) :
	info_interface(exp_list, name),
	spi_device_id(spi_device_id),
	calibrationWord("Cal. word", &params, "value=0 min=0 max=65535"),
	doCalibration("Calibrate", &params, "value=0"),
	Debug("Debug", &params, "value=0 min=0 max=65535")
{
	SPI_init(&spi, spi_device_id, true),
	calibrationWord.setFlag(RP_FLAG_UPDATE_IMMEDIATE);
	doCalibration.setFlag(RP_FLAG_UPDATE_IMMEDIATE);
}
Esempio n. 24
0
//////////////////////////////////////////////////////////////////////////////////
// LED-Strip Writer
//////////////////////////////////////////////////////////////////////////////////
void lw_setup() {
	// start by writting zeros to wake-up latch(s)
	lw_state = LW_S_WAIT_TO_WRITE_ZEROS;
	lw_pixelIndex = 0;
	lw_zeroCounter = ZEROS_NEEDED;

	SPI_init();
	/* 10mhz - faster is not working */
	SPI_clock(GetSystemClock() / SPI_PBCLOCK_DIV8);
	SPI_mode(SPI_MASTER);
	BUFFER = 0x00; // Trigger STATRX
}
Esempio n. 25
0
File: basic.c Progetto: nnayo/scalp
// basic module initialization
void BSC_init(void)
{
	frame_t fr;

	// fifoes init
	FIFO_init(&BSC.in_fifo, &BSC.in_buf, NB_IN_FRAMES, sizeof(frame_t));
	FIFO_init(&BSC.out_fifo, &BSC.out_buf, NB_OUT_FRAMES, sizeof(frame_t));

	// thread init
	PT_INIT(&BSC.in_pt);
	PT_INIT(&BSC.out_pt);

	// reset time-out
	BSC.time_out = 0;
	BSC.is_running = FALSE;

	// register own call-back for specific commands
	BSC.interf.channel = 0;
	BSC.interf.cmde_mask = _CM(FR_NO_CMDE)
				| _CM(FR_RAM_READ)
				| _CM(FR_RAM_WRITE)
				| _CM(FR_EEP_READ)
				| _CM(FR_EEP_WRITE)
				| _CM(FR_FLH_READ)
				| _CM(FR_FLH_WRITE)
				| _CM(FR_SPI_READ)
				| _CM(FR_SPI_WRITE)
				| _CM(FR_WAIT)
				| _CM(FR_CONTAINER);
	BSC.interf.queue = &BSC.in_fifo;
	DPT_register(&BSC.interf);

	// drivers init
	SLP_init();
	EEP_init();
	SPI_init(SPI_MASTER, SPI_THREE, SPI_MSB, SPI_DIV_16);

	// read reset frame
	EEP_read(0x00, (u8*)&fr, sizeof(frame_t));
	while ( ! EEP_is_fini() )
		;

	// check if the frame is valid
	if ( fr.dest == 0xff || fr.orig == 0xff || fr.cmde == 0xff || fr.status == 0xff ) {
		return;
	}

	// enqueue the reset frame
	FIFO_put(&BSC.out_fifo, &fr);

	// lock the dispatcher to be able to treat the frame
	DPT_lock(&BSC.interf);
}
Esempio n. 26
0
int main (void) {
	SystemInit();
  SystemCoreClockUpdate();                      /* Get Core Clock Frequency */
  SysTick_Config(SystemCoreClock/1000);         /* Generate interrupt each 1 ms    */     

	SPI_init();
 
  while(1) {
		uint8_t data[2] = { 0x01, 0xFC };
		SPI_write(data, 2, 0x00);
  }
 }
Esempio n. 27
0
/* Echo program - for testing purposes */
int echo(void)
{
	/* USART initialization */
	USART_init();

	/* SPI initialization */
	SPI_init();

	/* AD9833 initialization as off */
	AD9833_init();

	/* Send word sequence to AD9833 via SPI */
	main_send_word_sequence_ad9833_uart( ad9833_words, AD9833_WORD_SEQUENCE );

	/* Infinite loop */
	for(;;)
	{
		uint32_t counter = 0;
		uint32_t delay   = 0;

		/* If all bytes were received */
		if ( data_ready != SIG_DATA_VALID ) continue;

		USART_sendbyte(reception_delay[0]);
		USART_sendbyte(reception_delay[1]);

		delay = main_get_delay( reception_delay, DELAY_BYTES );

		/* For each frequency */
		for ( ; counter < ( received_bytes - DELAY_BYTES ) / FREQUENCY_BYTES; counter++ )
		{
			double frequency;

			/* Reset word sequence */
			main_reset_word_sequence( ad9833_words, AD9833_WORD_SEQUENCE );

			/* Get received frequency */
			frequency = main_get_frequency( frequency_buffer[counter], FREQUENCY_BYTES );

			/* Create word sequence for AD9833 */
			main_create_word_sequence_ad9833( ad9833_words, AD9833_WORD_SEQUENCE, frequency );

			/* Send word sequence to AD9833 */
			main_send_word_sequence_ad9833_uart( ad9833_words, AD9833_WORD_SEQUENCE );

			/* Delay - the same for each frequency */
			delay_ms( delay );
		}
	}

	return 0;
}
Esempio n. 28
0
void main()
{
    //initialize button pins
    ADCON1=0x07;
    TRISB=0xFC;
    TRISC=0x7F;
    SPI_init();               //initialize MSSP for SPI comm
    while(1)
    {
        button_press();
        SPI_transmit(tx_data);
    }
}
Esempio n. 29
0
int MCP_init(){ 
  //Start SPI driver
  SPI_init();
  
  //Reset MPC to enter configuration mode
  MCP_reset();
  
  // Self-test
  uint8_t value = MCP_read(MCP_CANSTAT);
  if ((value & MODE_MASK) != MODE_CONFIG) {
    return 1;
  }
  return 0;
}
Esempio n. 30
0
int
main (int argc, char **argv)
{
  AccessibleKeySet switch_set;
  
  if ((argc > 1) && (!strncmp (argv[1], "-h", 2)))
    {
      printf ("Usage: keysynth-demo\n");
      exit (1);
    }

  gtk_init (&argc, &argv); /* must call, because this program uses GTK+ */

  SPI_init ();

  key_listener = SPI_createAccessibleKeystrokeListener (is_command_key, NULL);
  /* will listen only to Alt-key combinations */
  SPI_registerAccessibleKeystrokeListener (key_listener,
					   (AccessibleKeySet *) SPI_KEYSET_ALL_KEYS,
					   SPI_KEYMASK_ALT | SPI_KEYMASK_CONTROL,
					   (unsigned long) ( KeyPress | KeyRelease),
					   SPI_KEYLISTENER_CANCONSUME | SPI_KEYLISTENER_ALL_WINDOWS);
  create_vkbd ();  

  /*
   * Register a listener on an 'unused' key, to serve as a 'single switch'.
   * On most Intel boxes there is at least one 'special' system key that does not
   * have a non-zero keycode assigned in the Xserver, so we will intercept any keycode
   * that is 'zero'.  Often these the are the "windows" or the "menu" keys.
   */
  switch_set.keysyms = g_new0 (unsigned long, 1);
  switch_set.keycodes = g_new0 (unsigned short, 1);
  switch_set.keystrings = g_new0 (char *, 1);
  switch_set.len = 1;
  switch_set.keysyms[0] = (unsigned long) 0;
  switch_set.keycodes[0] = (unsigned short) 0;
  switch_set.keystrings[0] = "";
  switch_listener = SPI_createAccessibleKeystrokeListener (switch_callback, NULL);
  SPI_registerAccessibleKeystrokeListener (switch_listener,
					   &switch_set,
					   SPI_KEYMASK_UNMODIFIED,
					   (unsigned long) ( SPI_KEY_PRESSED | SPI_KEY_RELEASED ),
					   SPI_KEYLISTENER_NOSYNC);
  
  SPI_event_main ();

  return SPI_exit ();
}