コード例 #1
0
ファイル: board.c プロジェクト: LucasMahieu/neon
void boardInit(void)
{
    SIM_SCGC5 |= 0x00000400; //enable Port B clock
    SIM_SCGC5 |= 0x00000200; //enable Port A clock
    SIM_SCGC5 |= 0x00001000; //enable Port D clock

    PORTB_PCR19 |= (uint32_t)0x00000100; //Configure portB19 as GPIO (GREEN)
    GPIOB_PDDR |= (uint32_t)0x00080000; //Configure portB19 as output

    PORTA_PCR12 |= (uint32_t)0x000A0102; //Configure portA12 as GPIO with falling edge interrupt and pullup enabled.
    GPIOA_PDDR &= ~(uint32_t)(1<<12); //Configure portA12 as input.

    PORTB_PCR18 |= (uint32_t)0x00000100; //Configure portB18 as GPIO (RED)
    GPIOB_PSOR |= (uint32_t)0x00040000;
    GPIOB_PDDR |= (uint32_t)0x00040000; //Configure portB18 as output

    PORTD_PCR1 |= (uint32_t)0x00000100; //Configure portD1 as GPIO (BLUE)
    FGPIOD_PSOR |= (uint32_t)0x00000002;
    FGPIOD_PDDR |= (uint32_t)0x00000002; //Configure portD1 as output

    //SIM_SCGC6 |= (uint8_t) 0x00800000; // Enable PIT clock

    SIM_SOPT2 |= 0x01000000; // Set TPM to use the MCGFLLCLK as a clock source
    // MCGFLLCLK is either 24MHz or 23 986 176Hz
    SIM_SCGC6 |= 0x01000000; // Enable TPM0 clock

    uart0Config();
    uart0Enable();

    llwuConfigure();
    vllsEnable();
    vllsConfigure(1);

    PMC_REGSC = 0x08;

    systickConfigure();

    interruptSetPriority(30,0); //Port A ISR
    interruptEnable(30);

    interruptSetPriority(7,0); // Configure LLWU interrupt as highest priority.
    interruptEnable(7); //Enable LLWU interrupt.

    systickEnable();

    rtcInit();
    rtcStart();

    interruptSetPriority(21,0); // Configure RTC Seconds interrupt as highest priority.
    interruptEnable(21); //Enable RTC Seconds interrupt.

    i2cInit();
    interruptSetPriority(9,3); // Configure I2C interrupt as Lowest priority.
    interruptEnable(9); //Enable I2C interrupt.

    interruptSetPriority(22,3); // Configure PIT interrupt as Lowest priority.
    interruptEnable(9); //Enable PIT interrupt.
}
コード例 #2
0
extern int threadCreate(thFuncPtr funcPtr, void *argPtr) {
    interruptDisable();

    // Create a thread structure for the user function
    thread_t *t = (thread_t *) malloc(sizeof(thread_t));
    getcontext(&t->context);
    // Make a stack for it
    t->context.uc_stack.ss_sp = malloc(STACK_SIZE);
    t->context.uc_stack.ss_size = STACK_SIZE;
    t->context.uc_stack.ss_flags = 0;
    t->context.uc_link = &start->t->context;
    // Add other details
    t->func = funcPtr;
    t->arg = argPtr;
    t->done = 0;
    t->id = ++thread_count;
    makecontext(&t->context, (void (*)(void)) runThread, 1, t);

    // Create the node structure
    node_t *newnode = (node_t *) malloc(sizeof(node_t));
    newnode->t = t;
    // Add it to the list
    append_node(newnode);
    // Run it (or something else)
    threadYieldInternal();

    interruptEnable();
    return newnode->t->id;
}
コード例 #3
0
void runThread(thread_t *t) {
    // Wrapper function for running the user function
    interruptEnable();
    t->result = t->func(t->arg);
    t->done = 1;
    interruptDisable();
}
コード例 #4
0
extern void threadExit(void *result) {
    interruptDisable();
    // Store the result and mark thread as complete
    current->t->result = result;
    current->t->done = 1;
    // Remove it from the list
    remove_node(current);
    // Move on to other threads
    threadYieldInternal();
    interruptEnable();
}
コード例 #5
0
ファイル: eeprom.c プロジェクト: cmp1084/f3g
void eepromWrite(char addr, char byte)
{
	//Sleep until the EEPROM is ready to be read (this might be 3.4 ms, maximum)
	while(EECR & (1 << EEPE)) { pmSleep(); }
	EEARL = addr;							//Set the EEPROM address
	EEDR = byte;							//Set the data to write into EEPROM addr
	interruptDisable();
	EECR = (0 << EEPM1) | (0 << EEPM0) |	//Atomic write operation
			(0 << EERIE) |					//Writing a single byte, so there is no need to interrupt
			(1 << EEMPE)
	//Within four clocks
	EECR |= (1 << EEPE);
	interruptEnable();
}
コード例 #6
0
ファイル: sdmmc.c プロジェクト: stxent/halm
/*----------------------------------------------------------------------------*/
static void interruptHandler(void *object)
{
  static const uint32_t hostErrors = INT_FRUN | INT_HLE;
  static const uint32_t integrityErrors = INT_RE | INT_RCRC | INT_DCRC
      | INT_SBE | INT_EBE;
  static const uint32_t timeoutErrors = INT_RTO | INT_DRTO | INT_HTO;

  struct Sdmmc * const interface = object;
  LPC_SDMMC_Type * const reg = interface->base.reg;
  const uint32_t status = reg->MINTSTS;

  interruptDisable(interface->finalizer);

  irqDisable(interface->base.irq);
  reg->INTMASK = 0;
  reg->RINTSTS = INT_MASK;

  if (status & hostErrors)
  {
    interface->status = E_ERROR;
  }
  else if (status & integrityErrors)
  {
    interface->status = E_INTERFACE;
  }
  else if (status & timeoutErrors)
  {
    interface->status = E_TIMEOUT;
  }
  else if (!(reg->STATUS & STATUS_DATA_BUSY))
  {
    interface->status = E_OK;
  }
  else
  {
    interruptEnable(interface->finalizer);

    if (!(reg->STATUS & STATUS_DATA_BUSY))
    {
      interface->status = E_OK;
      interruptDisable(interface->finalizer);
    }
    else
      interface->status = E_BUSY;
  }

  if (interface->status != E_BUSY && interface->callback)
    interface->callback(interface->callbackArgument);
}
コード例 #7
0
/* Function to initialize the LIS302DL. */
void acc_init(void) {
	LIS302DL_InitTypeDef LIS302DL_conf;
	LIS302DL_InterruptConfigTypeDef LIS302DL_InterruptStruct;

	
	LIS302DL_conf.Power_Mode = LIS302DL_LOWPOWERMODE_ACTIVE;
	LIS302DL_conf.Output_DataRate = LIS302DL_DATARATE_100;
	LIS302DL_conf.Axes_Enable = LIS302DL_XYZ_ENABLE;
	LIS302DL_conf.Full_Scale = LIS302DL_FULLSCALE_2_3;
	LIS302DL_conf.Self_Test = LIS302DL_SELFTEST_NORMAL;
	LIS302DL_Init(&LIS302DL_conf);

	LIS302DL_InterruptStruct.Latch_Request = LIS302DL_INTERRUPTREQUEST_LATCHED;
	LIS302DL_InterruptStruct.SingleClick_Axes=LIS302DL_CLICKINTERRUPT_Z_ENABLE;
	LIS302DL_InterruptStruct.DoubleClick_Axes=LIS302DL_DOUBLECLICKINTERRUPT_XYZ_DISABLE;
	LIS302DL_InterruptConfig(&LIS302DL_InterruptStruct);
	
	interruptEnable();
}
コード例 #8
0
extern void threadJoin(int thread_id, void **result) {
    interruptDisable();

    // Find the thread
    node_t *tmp = start;
    while (tmp->t->id != thread_id) {
        tmp = tmp->next;
    }

    // Switch threads until it's done
    while (!tmp->t->done) {
        threadYieldInternal();
    }

    // Store the result
    if (result)
        *result = tmp->t->result;

    interruptEnable();
}
コード例 #9
0
void DeviceCAN_AT90CAN::implInit(unsigned char mode)
  {
    OSDeviceDebug::putString_P(PSTR("DeviceCAN_AT90CAN::implInit()"));
    OSDeviceDebug::putNewLine();

    transceiverInit();

    Can_reset();

    interruptInit(); // must be after reset()

    /* CAN_KING setting */
    /* 125K, 75%, Tq=0.5uS, Tbit=16*Tq=8uS */
    /* Tprs=7*Tq, Tph1=4*Tq, Tph2=4*Tq, Tsjw=1*Tq */
    CANBT1 = 0x0E; /* 125K@16MHz */
    CANBT2 = 0x0C;
    CANBT3 = 0x37;

    can_clear_all_mob();

    // enable reception on the reception mob
    Can_set_mob(NB_MOB_RX);
    Can_config_rx();

    // enable both RX and TX mobs
    CANEN2 = _BV(NB_MOB_RX) | _BV(NB_MOB_TX);

    // enable interrupts for both RX and TX mobs
    CANIE2 = _BV(NB_MOB_RX) | _BV(NB_MOB_TX);

    mode = mode; // set to given mode
    Can_enable();

    transceiverHighSpeed();

    //OSDebugLed2::init();

    interruptEnable();

    m_isConnected = true;
  }
コード例 #10
0
ファイル: pm.c プロジェクト: cmp1084/f3g
 /** \todo Correct ADC prescale and timer0 prescale to not affect these peripherals by
  * a faster system clk.
  * \todo Use a MHz frequency value as parameter instead.
  * Let the function find the closest prescale to give that CPU freq
  * and return the actual frequency set.
  *
  * \param prescale
  * legal values [0..8]
  * Prescale	Clock division factor
  * 	0				1
  * 	1				2
  * 	2				4
  * 	3				8
  * 	4				16
  * 	5				32
  * 	6				64
  * 	7				128
  * 	8				256
  */
void pmClkPrescale(unsigned char prescale)
{
	int interruptWasEnabled = 0;

	//Dont do anything if we are fed with faulty prescaler
	if(prescale > 8) return;
	//{
	//	prescale = 8;															//TODO: Consider setting prescale to 8 and continue
	//}

	//Turn interrupt off
	//Look at the I bit (nr. 7) in SREG to determine if global interrupt was enabled
	if(SREG & (1 << 7)) {
		interruptWasEnabled = 1;
	}
	interruptDisable();
	//This write sequency must be completed in four cycles
	CLKPR = (1 << CLKPCE);
	CLKPR = (0 << CLKPCE) | (prescale); //(0 << CLKPS3);
	if(interruptWasEnabled) {
		interruptEnable();
	}
}
コード例 #11
0
extern void threadWait(int lockNum, int conditionNum) {
    interruptDisable();

    // Prevent erroroneous calls
    if (!locks[lockNum]) {
        printf("threadWait called with unlocked mutex\n");
        exit(1);
    }

    threadUnlock(lockNum);
    // Take the current thread out of the rotation
    node_t *old = current;
    remove_node(current);
    // Wait for a condition variable signal
    while (!conditions[lockNum][conditionNum]) {
        threadYield();
    }
    // Put the thread back into the rotation
    append_node(old);
    threadLockInternal(lockNum);

    interruptEnable();
}
コード例 #12
0
extern void threadYield() {
    interruptDisable();
    threadYieldInternal();
    interruptEnable();
}
コード例 #13
0
extern void threadSignal(int lockNum, int conditionNum) {
    interruptDisable();
    // Signal the condition variable
    conditions[lockNum][conditionNum]++;
    interruptEnable();
}
コード例 #14
0
extern void threadLock(int lockNum) {
    interruptDisable();
    threadLockInternal(lockNum);
    interruptEnable();
}