Ejemplo n.º 1
0
/**
 * @brief   Initialize the standard part of a @p MACDriver structure.
 *
 * @param[in] macp      pointer to the @p MACDriver object
 */
void macObjectInit(MACDriver *macp) {

  chSemInit(&macp->md_tdsem, 0);
  chSemInit(&macp->md_rdsem, 0);
#if CH_USE_EVENTS
  chEvtInit(&macp->md_rdevent);
#endif
}
Ejemplo n.º 2
0
/**
 * @brief   Initializes a Mailbox object.
 *
 * @param[out] mbp      the pointer to the Mailbox structure to be initialized
 * @param[in] buf       the circular messages buffer
 * @param[in] n         the buffer size as number of @p msg_t
 *
 * @init
 */
void chMBInit(Mailbox *mbp, msg_t *buf, cnt_t n) {

  chDbgCheck((mbp != NULL) && (buf != NULL) && (n > 0), "chMBInit");

  mbp->mb_buffer = mbp->mb_wrptr = mbp->mb_rdptr = buf;
  mbp->mb_top = &buf[n];
  chSemInit(&mbp->mb_emptysem, n);
  chSemInit(&mbp->mb_fullsem, 0);
}
Ejemplo n.º 3
0
/**
 * @brief   Initialize the standard part of a @p MACDriver structure.
 *
 * @param[out] macp     pointer to the @p MACDriver object
 *
 * @init
 */
void macObjectInit(MACDriver *macp) {

  macp->state  = MAC_STOP;
  macp->config = NULL;
  chSemInit(&macp->tdsem, 0);
  chSemInit(&macp->rdsem, 0);
#if MAC_USE_EVENTS
  chEvtInit(&macp->rdevent);
#endif
}
Ejemplo n.º 4
0
/**
 * @brief   Initializes the standard part of a @p CANDriver structure.
 *
 * @param[out] canp     pointer to the @p CANDriver object
 *
 * @init
 */
void canObjectInit(CANDriver *canp) {

  canp->state    = CAN_STOP;
  canp->config   = NULL;
  chSemInit(&canp->txsem, 0);
  chSemInit(&canp->rxsem, 0);
  chEvtInit(&canp->rxfull_event);
  chEvtInit(&canp->txempty_event);
  chEvtInit(&canp->error_event);
  canp->status = 0;
#if CAN_USE_SLEEP_MODE
  chEvtInit(&canp->sleep_event);
  chEvtInit(&canp->wakeup_event);
#endif /* CAN_USE_SLEEP_MODE */
}
Ejemplo n.º 5
0
void DataListener< datatype >::init(datatype * listener_buf, uint32_t max_len){
	len = max_len;
	chSemInit(&sem, 0);
	buf_head = listener_buf;
	rd_head = buf_head;
	wr_head = buf_head;
}
Ejemplo n.º 6
0
/**
 * @brief   Initializes the standard part of a @p I2CDriver structure.
 *
 * @param[out] i2cp     pointer to the @p I2CDriver object
 *
 * @init
 */
void i2cObjectInit(I2CDriver *i2cp) {

    i2cp->id_state  = I2C_STOP;
    i2cp->id_config = NULL;
    i2cp->rxbuff_p = NULL;
    i2cp->txbuff_p = NULL;
    i2cp->rxbuf = NULL;
    i2cp->txbuf = NULL;
    i2cp->id_slave_config = NULL;

#if I2C_USE_WAIT
    i2cp->id_thread   = NULL;
#endif /* I2C_USE_WAIT */

#if I2C_USE_MUTUAL_EXCLUSION
#if CH_USE_MUTEXES
    chMtxInit(&i2cp->id_mutex);
#else
    chSemInit(&i2cp->id_semaphore, 1);
#endif /* CH_USE_MUTEXES */
#endif /* I2C_USE_MUTUAL_EXCLUSION */

#if defined(I2C_DRIVER_EXT_INIT_HOOK)
    I2C_DRIVER_EXT_INIT_HOOK(i2cp);
#endif
}
Ejemplo n.º 7
0
/**
 * @brief   Initializes an input queue.
 * @details A Semaphore is internally initialized and works as a counter of
 *          the bytes contained in the queue.
 * @note    The callback is invoked from within the S-Locked system state,
 *          see @ref system_states.
 *
 * @param[out] iqp      pointer to an @p InputQueue structure
 * @param[in] bp        pointer to a memory area allocated as queue buffer
 * @param[in] size      size of the queue buffer
 * @param[in] infy      pointer to a callback function that is invoked when
 *                      data is read from the queue. The value can be @p NULL.
 *
 * @init
 */
void chIQInit(InputQueue *iqp, uint8_t *bp, size_t size, qnotify_t infy) {

  iqp->q_buffer = iqp->q_rdptr = iqp->q_wrptr = bp;
  iqp->q_top = bp + size;
  iqp->q_notify = infy;
  chSemInit(&iqp->q_sem, 0);
}
Ejemplo n.º 8
0
/**
 * @brief   Initializes an output queue.
 * @details A Semaphore is internally initialized and works as a counter of
 *          the free bytes in the queue.
 * @note    The callback is invoked from within the S-Locked system state,
 *          see @ref system_states.
 *
 * @param[out] oqp      pointer to an @p OutputQueue structure
 * @param[in] bp        pointer to a memory area allocated as queue buffer
 * @param[in] size      size of the queue buffer
 * @param[in] onfy      pointer to a callback function that is invoked when
 *                      data is written to the queue. The value can be @p NULL.
 *
 * @init
 */
void chOQInit(OutputQueue *oqp, uint8_t *bp, size_t size, qnotify_t onfy) {

  oqp->q_buffer = oqp->q_rdptr = oqp->q_wrptr = bp;
  oqp->q_top = bp + size;
  oqp->q_notify = onfy;
  chSemInit(&oqp->q_sem, (cnt_t)size);
}
Ejemplo n.º 9
0
	bool_t gdispInit(void) {
		bool_t		res;
		unsigned	i;

		/* Mark all the Messages as free */
		for(i=0; i < GDISP_QUEUE_SIZE; i++)
			gdispMsgs[i].action = GDISP_LLD_MSG_NOP;

		/* Initialise our Mailbox, Mutex's and Counting Semaphore.
		 * 	A Mutex is required as well as the Mailbox and Thread because some calls have to be synchronous.
		 *	Synchronous calls get handled by the calling thread, asynchronous by our worker thread.
		 */
		chMBInit(&gdispMailbox, gdispMailboxQueue, sizeof(gdispMailboxQueue)/sizeof(gdispMailboxQueue[0]));
		chMtxInit(&gdispMutex);
		chMtxInit(&gdispMsgsMutex);
		chSemInit(&gdispMsgsSem, GDISP_QUEUE_SIZE);

		lldThread = chThdCreateStatic(waGDISPThread, sizeof(waGDISPThread), NORMALPRIO, GDISPThreadHandler, NULL);

		/* Initialise driver - synchronous */
		chMtxLock(&gdispMutex);
		res = gdisp_lld_init();
		chMtxUnlock();

		return res;
	}
Ejemplo n.º 10
0
void _heap_init(void) {

#if CH_USE_MUTEXES
  chMtxInit(&hmtx);
#else
  chSemInit(&hsem, 1);
#endif
}
Ejemplo n.º 11
0
bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count)
{
   //Initialize the semaphore object
   chSemInit(semaphore, count);

   //Semaphore successfully created
   return TRUE;
}
Ejemplo n.º 12
0
/**
 * @brief   Initializes the default heap.
 *
 * @notapi
 */
void _heap_init(void) {
  default_heap.h_provider = chCoreAlloc;
  default_heap.h_free.h.u.next = (union heap_header *)NULL;
  default_heap.h_free.h.size = 0;
#if CH_USE_MUTEXES || defined(__DOXYGEN__)
  chMtxInit(&default_heap.h_mtx);
#else
  chSemInit(&default_heap.h_sem, 1);
#endif
}
Ejemplo n.º 13
0
/**
 * @brief   Initializes the standard part of a @p ADCDriver structure.
 *
 * @param[in] adcp      pointer to the @p ADCDriver object
 */
void adcObjectInit(ADCDriver *adcp) {

    adcp->ad_state    = ADC_STOP;
    adcp->ad_config   = NULL;
    adcp->ad_callback = NULL;
    adcp->ad_samples  = NULL;
    adcp->ad_depth    = 0;
    adcp->ad_grpp     = NULL;
    chSemInit(&adcp->ad_sem, 0);
}
Ejemplo n.º 14
0
void
vexAudioPlaySound( int freq, int amplitude, int timems )
{
    static int current_amplitude = DEFAULT_AMPLITUDE;
    int f1, f2;

    // Not available on the Olimex eval card
#if defined (STM32F10X_HD)

    // init first time
    if( vslThread == NULL )
        {
        VSL_Init();
        // init counting semaphore with a value of 0
        chSemInit( &vslSem, 0 );
        vslThread = chThdCreateFromHeap(NULL, AUDIO_WA_SIZE, NORMALPRIO, vexAudioTask, (void *)NULL );
        }

    // try and stop pops
    // a frequency of 0 means silence
    if( freq == 0 )
        {
        freq = 1000;
        amplitude = 0;
        }

    // create waveform
    if( amplitude != current_amplitude )
        {
        VSL_CreateSineWave( amplitude );
        current_amplitude = amplitude;
        }

    // limit range of frequencies 200Hz to 10KHz
    if( freq <   200 ) freq =   200;
    if( freq > 10000 ) freq = 10000;
    
    // calculate prescale and period for the timer
    VSL_Factorize( 72000000L / (32 * freq), &f1, &f2 );

    // ReInit timer
    VSL_InitTimer(f1, f2);

    // Enable DMA for the DAC
    DAC->CR |= (DAC_CR_EN1 << DAC_Channel_1);
    
    /* TIM7 enable counter */
    TIM7->CR1 |= TIM_CR1_CEN;

    // stop after time
    VSL_Counter = timems;
    // this will wake audio thread if necessary
    chSemReset(&vslSem, 0);
#endif
}
//-----------------------------------------------------------------------------------------------------------------------
void chSetup() {
  // initialize the counting semaphore to zero i.e.TAKEN
  chSemInit(&sem, 0);

  // start high priority thread
  chThdCreateStatic(waThread1, sizeof(waThread1),
    NORMALPRIO+2, Thread1, NULL);

  // start lower priority thread
  chThdCreateStatic(waThread2, sizeof(waThread2),
    NORMALPRIO+1, Thread2, NULL);
}
Ejemplo n.º 16
0
void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit)
{
	if (val > limit)
		val = limit;

	psem->limit = limit;
	
	#if CH_KERNEL_MAJOR == 2
		chSemInit(&psem->sem, val);
	#elif CH_KERNEL_MAJOR == 3
		chSemObjectInit(&psem->sem, val);
	#endif
}
Ejemplo n.º 17
0
err_t sys_sem_new(sys_sem_t *sem, u8_t count) {

  *sem = chHeapAlloc(NULL, sizeof(Semaphore));
  if (*sem == 0) {
    SYS_STATS_INC(sem.err);
    return ERR_MEM;
  }
  else {
    chSemInit(*sem, (cnt_t)count);
    SYS_STATS_INC_USED(sem);
    return ERR_OK;
  }
}
Ejemplo n.º 18
0
/**
 * @brief   Initializes a memory heap from a static memory area.
 * @pre     Both the heap buffer base and the heap size must be aligned to
 *          the @p stkalign_t type size.
 * @pre     In order to use this function the option @p CH_USE_MALLOC_HEAP
 *          must be disabled.
 *
 * @param[out] heapp    pointer to the memory heap descriptor to be initialized
 * @param[in] buf       heap buffer base
 * @param[in] size      heap size
 *
 * @init
 */
void chHeapInit(MemoryHeap *heapp, void *buf, size_t size) {
  union heap_header *hp;

  chDbgCheck(MEM_IS_ALIGNED(buf) && MEM_IS_ALIGNED(size), "chHeapInit");

  heapp->h_provider = (memgetfunc_t)NULL;
  heapp->h_free.h.u.next = hp = buf;
  heapp->h_free.h.size = 0;
  hp->h.u.next = NULL;
  hp->h.size = size - sizeof(union heap_header);
#if CH_USE_MUTEXES || defined(__DOXYGEN__)
  chMtxInit(&heapp->h_mtx);
#else
  chSemInit(&heapp->h_sem, 1);
#endif
}
Ejemplo n.º 19
0
/**
 * @brief   Initializes the standard part of a @p I2CDriver structure.
 *
 * @param[out] i2cp     pointer to the @p I2CDriver object
 *
 * @init
 */
void i2cObjectInit(I2CDriver *i2cp) {

  i2cp->state  = I2C_STOP;
  i2cp->config = NULL;

#if I2C_USE_MUTUAL_EXCLUSION
#if CH_USE_MUTEXES
  chMtxInit(&i2cp->mutex);
#else
  chSemInit(&i2cp->semaphore, 1);
#endif /* CH_USE_MUTEXES */
#endif /* I2C_USE_MUTUAL_EXCLUSION */

#if defined(I2C_DRIVER_EXT_INIT_HOOK)
  I2C_DRIVER_EXT_INIT_HOOK(i2cp);
#endif
}
Ejemplo n.º 20
0
/**
 * @brief   Initializes the standard part of a @p DACDriver structure.
 *
 * @param[out] dacp     pointer to the @p DACDriver object
 *
 * @init
 */
void dacObjectInit(DACDriver *dacp) {

  dacp->state = DAC_STOP;
  dacp->config = NULL;
#if DAC_USE_WAIT
  dacp->thread = NULL;
#endif /* DAC_USE_WAIT */
#if DAC_USE_MUTUAL_EXCLUSION
#if CH_USE_MUTEXES
  chMtxInit(&dacp->mutex);
#else
  chSemInit(&dacp->semaphore, 1);
#endif
#endif /* DAC_USE_MUTUAL_EXCLUSION */
#if defined(DAC_DRIVER_EXT_INIT_HOOK)
  DAC_DRIVER_EXT_INIT_HOOK(dacp);
#endif
}
/**
 * @brief   Initializes the standard part of a @p SPIDriver structure.
 *
 * @param[out] spip     pointer to the @p SPIDriver object
 *
 * @init
 */
void spiObjectInit(SPIDriver *spip) {

  spip->state = SPI_STOP;
  spip->config = NULL;
#if SPI_USE_WAIT
  spip->thread = NULL;
#endif /* SPI_USE_WAIT */
#if SPI_USE_MUTUAL_EXCLUSION
#if CH_USE_MUTEXES
  chMtxInit(&spip->mutex);
#else
  chSemInit(&spip->semaphore, 1);
#endif
#endif /* SPI_USE_MUTUAL_EXCLUSION */
#if defined(SPI_DRIVER_EXT_INIT_HOOK)
  SPI_DRIVER_EXT_INIT_HOOK(spip);
#endif
}
Ejemplo n.º 22
0
/*
 * Application entry point.
 */
int main(void) {
  halInit();
  chSysInit();

  /*
   * Serial port initialization.
   */
  sdStart(&SD1, NULL); 
  chprintf((BaseSequentialStream *)&SD1, "Main (SD1 started)\r\n");

   /*
  *Semaphore Initialization
  */
  chSemInit(&mySemaphore, 1);

  /*
   * Set mode of PINES
   */

  palSetPadMode(GPIO0_PORT, GPIO0_PAD, PAL_MODE_INPUT);   //Input T1
  palSetPadMode(GPIO1_PORT, GPIO1_PAD, PAL_MODE_INPUT);   //Input T2
  palSetPadMode(GPIO4_PORT, GPIO4_PAD, PAL_MODE_INPUT);   //Input T3
  palSetPadMode(GPIO17_PORT, GPIO17_PAD, PAL_MODE_INPUT); //Input T4
  
  palSetPadMode(GPIO18_PORT, GPIO18_PAD, PAL_MODE_OUTPUT); //Output T1
  palSetPadMode(GPIO22_PORT, GPIO22_PAD, PAL_MODE_OUTPUT); //Output T2
  palSetPadMode(GPIO23_PORT, GPIO23_PAD, PAL_MODE_OUTPUT); //Output T3
  palSetPadMode(GPIO24_PORT, GPIO24_PAD, PAL_MODE_OUTPUT); //Output T4
  
  /*
   * Creates the blinker thread.
   */
  chThdCreateStatic(waTh1, sizeof(waTh1), NORMALPRIO, Th1, NULL);
  chThdCreateStatic(waTh2, sizeof(waTh2), NORMALPRIO, Th2, NULL);
  chThdCreateStatic(waTh3, sizeof(waTh3), NORMALPRIO, Th3, NULL);
  chThdCreateStatic(waTh4, sizeof(waTh4), NORMALPRIO, Th4, NULL);
  
  /*
   * Events servicing loop.
   */
  chThdWait(chThdSelf());

  return 0;
}
Ejemplo n.º 23
0
void setup_uart(void)
{
	/*
	 * Initialize the Semaphore
	 */
	chSemInit(&uart_sem, 1);

	/*
	 * Activate USART1 and USART3
	 * TODO: I would enable USART2, as well, but for some reason it doesn't
	 * work when I2C1 is enabled.
	 */
	uartStart(&UARTD1, &uart1cfg);
	uartStart(&UARTD3, &uart3cfg);

	palSetPadMode(GPIOB, 6, PAL_MODE_ALTERNATE(7));   // USART1 TX
	palSetPadMode(GPIOB, 7, PAL_MODE_ALTERNATE(7));   // USART1 RX
	palSetPadMode(GPIOB, 10, PAL_MODE_ALTERNATE(7));   // USART3 TX
	palSetPadMode(GPIOB, 11, PAL_MODE_ALTERNATE(7));   // USART3 RX
}
Ejemplo n.º 24
0
/**
 * @brief   Initializes the standard part of a @p ADCDriver structure.
 *
 * @param[out] adcp     pointer to the @p ADCDriver object
 *
 * @init
 */
void adcObjectInit(ADCDriver *adcp) {

  adcp->state    = ADC_STOP;
  adcp->config   = NULL;
  adcp->samples  = NULL;
  adcp->depth    = 0;
  adcp->grpp     = NULL;
#if ADC_USE_WAIT
  adcp->thread   = NULL;
#endif /* ADC_USE_WAIT */
#if ADC_USE_MUTUAL_EXCLUSION
#if CH_USE_MUTEXES
  chMtxInit(&adcp->mutex);
#else
  chSemInit(&adcp->semaphore, 1);
#endif
#endif /* ADC_USE_MUTUAL_EXCLUSION */
#if defined(ADC_DRIVER_EXT_INIT_HOOK)
  ADC_DRIVER_EXT_INIT_HOOK(adcp);
#endif
}
Ejemplo n.º 25
0
/*------------------------------------------------------------------------*
 * chibios_rt::CounterSemaphore                                           *
 *------------------------------------------------------------------------*/
CounterSemaphore::CounterSemaphore(cnt_t n) {

    chSemInit(&sem, n);
}
Ejemplo n.º 26
0
static void bmk7_setup(void) {

  chSemInit(&sem1, 0);
}
Ejemplo n.º 27
0
  /*------------------------------------------------------------------------*
   * chibios_rt::Semaphore                                                  *
   *------------------------------------------------------------------------*/
  Semaphore::Semaphore(cnt_t n) {

    chSemInit(&sem, n);
  }
Ejemplo n.º 28
0
void geventListenerInit(GListener *pl) {
	chSemInit(&pl->waitqueue, 0);			// Next wait'er will block
	chBSemInit(&pl->eventlock, FALSE);		// Only one thread at a time looking at the event buffer
	pl->callback = 0;						// No callback active
	pl->event.type = GEVENT_NULL;			// Always safety
}
Ejemplo n.º 29
0
static void bmk11_setup(void) {

  chSemInit(&sem1, 1);
}
Ejemplo n.º 30
0
/**
 * @brief   Initializes a Mail Pool.
 * @note    The number of the mail objects in the mail pool should be at
 *          least <b>2+size(mailbox)</b>, this considering one writer and
 *          one reader, add one element for each extra reader or writer in
 *          order to avoid waiting on the mail pool. A smaller number of
 *          elements can be specified if waiting on the pool is acceptable.
 *
 * @param[out] mlp      pointer to a @p MailPool structure
 * @param[in] size      the size of the mail objects to be placed in the pool
 * @param[in] p         pointer to the mail objects array first element
 * @param[in] n         number of elements in the mail objects array
 *
 * @init
 */
void mailInit(MailPool *mlp, size_t size, void *p, size_t n) {

  chPoolInit(&mlp->pool, size, NULL);
  chPoolLoadArray(&mlp->pool, p, n);
  chSemInit(&mlp->sem, (cnt_t)n);
}