本文整理汇总了C++中chMtxLock函数的典型用法代码示例。如果您正苦于以下问题:C++ chMtxLock函数的具体用法?C++ chMtxLock怎么用?C++ chMtxLock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了chMtxLock函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: debugPut
size_t debugPut(const uint8_t *block, size_t n)
/*
truncate any block > 255 bytes
returns # of characters actually output (including the trailing newline)
*/
{
if (n) {
chMtxLock(&debugOutLock);
size_t space = chOQGetEmptyI(&debugOutQ);
if (space) {
if (n >= space)
n = space - 1;
if (n) {
if (n > 255)
n = 255;
chOQPutTimeout( &debugOutQ, n, TIME_IMMEDIATE);
chOQWriteTimeout( &debugOutQ, block, n, TIME_IMMEDIATE);
resumeReader();
n++;
}
}else
n = 0;
chMtxUnlock();
}else
if (debugPutc('\n') >= 0)
n = 1;
return n;
}
开发者ID:brentr,项目名称:charger,代码行数:28,代码来源:debugput.c
示例2: state
void state( uint8_t index, uint32_t * val )
{
// Mutex protected.
chMtxLock( &mutex );
*val = ins[index];
chMtxUnlock();
}
开发者ID:z80,项目名称:IPM,代码行数:7,代码来源:i2c_ctrl.c
示例3: gdispInit
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 = lld_gdisp_init();
chMtxUnlock();
return res;
}
开发者ID:etmatrix,项目名称:ChibiOS-GFX,代码行数:26,代码来源:gdisp.c
示例4: ledsThread
static msg_t ledsThread( void *arg )
{
(void)arg;
chRegSetThreadName( "ld" );
while ( 1 )
{
static uint32_t arg;
chMtxLock( &mutex );
arg = value;
if ( arg & 1 )
palTogglePad( LED_0_PORT, LED_0_PIN );
else
palClearPad( LED_0_PORT, LED_0_PIN );
if ( arg & 2 )
palTogglePad( LED_1_PORT, LED_1_PIN );
else
palClearPad( LED_1_PORT, LED_1_PIN );
chMtxUnlock();
chThdSleepMilliseconds( DURATION_MS );
processDfu( DURATION_MS );
}
return 0;
}
开发者ID:z80,项目名称:digitizer,代码行数:25,代码来源:led_ctrl.c
示例5: mtx5_execute
static void mtx5_execute(void) {
bool_t b;
tprio_t prio;
prio = chThdGetPriority();
b = chMtxTryLock(&m1);
test_assert(1, b, "already locked");
b = chMtxTryLock(&m1);
test_assert(2, !b, "not locked");
chSysLock();
chMtxUnlockS();
chSysUnlock();
test_assert(3, isempty(&m1.m_queue), "queue not empty");
test_assert(4, m1.m_owner == NULL, "still owned");
test_assert(5, chThdGetPriority() == prio, "wrong priority level");
chMtxLock(&m1);
chMtxUnlockAll();
test_assert(6, isempty(&m1.m_queue), "queue not empty");
test_assert(7, m1.m_owner == NULL, "still owned");
}
开发者ID:ColonelPanic42,项目名称:ChibiOS-RPi,代码行数:25,代码来源:testmtx.c
示例6: THD_FUNCTION
static THD_FUNCTION(thread4b, p) {
(void)p;
chThdSleepMilliseconds(150);
chMtxLock(&m1);
chMtxUnlock(&m1);
}
开发者ID:MultiCalorNV,项目名称:verventa-web_Int,代码行数:7,代码来源:testmtx.c
示例7: EM411Update
/*
* Read and update the current GPS data.
*/
void EM411Update(void)
{
int count=0;
/*
* Get message
*/
while((curMsg[count] = chIOGet(&SD2)) != '\n' && count < EMEA_BUFFER_SIZE) {
//curMsg[count] = chIOGet(&SD2);
count++;
}
/*
* Copy message to output buffer
* Also fill data structure.
*/
chMtxLock(&em411mtx);
strncpy(lastMsg, curMsg, EMEA_BUFFER_SIZE-1);
EM411Decode(lastMsg);
chMtxUnlock();
/*
* Clear buffer.
*/
memset(curMsg, 0, EMEA_BUFFER_SIZE);
}
开发者ID:Ankhbayar,项目名称:mlab-chibios,代码行数:29,代码来源:fc_em411.c
示例8: rfhelp_rf_status
int rfhelp_rf_status(void) {
chMtxLock(&rf_mutex);
int s = rf_status();
chMtxUnlock();
return s;
}
开发者ID:devilholk,项目名称:bldc,代码行数:7,代码来源:rfhelp.c
示例9: lastTemp
uint16_t lastTemp( void )
{
chMtxLock( &mutex );
uint16_t t = temperature;
chMtxUnlock();
return t;
}
开发者ID:z80,项目名称:digitizer,代码行数:7,代码来源:temp_ctrl.c
示例10: rfhelp_read_rx_data
/**
* Read data from the RX fifo
*
* @param data
* Pointer to the array in which to store the data.
*
* @param len
* Pointer to variable storing the data length.
*
* @param pipe
* Pointer to the pipe on which the data was received. Can be 0.
*
* @return
* 1: Read OK, more data to read.
* 0: Read OK
* -1: No RX data
* -2: Wrong length read. Something is likely wrong.
*/
int rfhelp_read_rx_data(char *data, int *len, int *pipe) {
int retval = -1;
chMtxLock(&rf_mutex);
int s = rf_status();
int pipe_n = NRF_STATUS_GET_RX_P_NO(s);
if (pipe_n != 7) {
*len = rf_get_payload_width();
if (pipe) {
*pipe = pipe_n;
}
if (*len <= 32 && *len >= 0) {
rf_read_rx_payload(data, *len);
rf_clear_rx_irq();
s = rf_status();
if (NRF_STATUS_GET_RX_P_NO(s) == 7) {
retval = 0;
} else {
retval = 1;
}
} else {
*len = 0;
retval = -2;
}
}
chMtxUnlock();
return retval;
}
开发者ID:devilholk,项目名称:bldc,代码行数:51,代码来源:rfhelp.c
示例11: rand
/**
* Blocking read of the random number generator.
*/
uint32_t rand(void)
{
chMtxLock(&randMtx);
uint32_t r = 0;
int randGood = FALSE;
while (!randGood) {
uint32_t rLast = r;
RNG->CR |= RNG_CR_RNGEN;
while ((RNG->SR & RNG_SR_DRDY) == 0) {
continue;
}
uint32_t status = RNG->SR;
r = RNG->DR;
if (status & RNG_SR_SEIS) {
/* Seed error */
} else if (status & RNG_SR_CEIS) {
/* Clock error */
return FALSE;
} else if ((rLast != 0) && (r != rLast)) {
randGood = TRUE;
}
}
chMtxUnlock();
return r;
}
开发者ID:johnhowe,项目名称:sparkleParty,代码行数:29,代码来源:main.c
示例12: debugPrint
size_t debugPrint(const char *fmt, ...)
/*
printf style debugging output
outputs a trailing newline
*/
{
va_list ap;
va_start(ap, fmt);
NullStream lenStream = {&nullVmt, 0};
chvprintf((BaseSequentialStream *) &lenStream, fmt, ap);
size_t len = lenStream.len;
if (len) {
chMtxLock(&debugOutLock);
size_t qspace = chOQGetEmptyI(&debugOutQ);
if (qspace) {
if (len >= qspace)
len = qspace - 1; //truncate string if it won't fit in queue
if (len) {
if (len > 255)
len = 255;
qStream dbgStream = {&qVmt, len};
chOQPutTimeout(&debugOutQ, len, TIME_IMMEDIATE);
chvprintf((BaseSequentialStream *) &dbgStream, fmt, ap);
resumeReader();
len++;
}
}else
len=0;
chMtxUnlock();
}else
if (debugPutc('\n') >= 0)
len=1;
va_end(ap);
return len;
}
开发者ID:brentr,项目名称:charger,代码行数:35,代码来源:debugput.c
示例13: motor_get_duty_cycle
float motor_get_duty_cycle(void)
{
chMtxLock(&_mutex);
float ret = _state.dc_actual;
chMtxUnlock();
return ret;
}
开发者ID:JarryChou,项目名称:sapog,代码行数:7,代码来源:motor.c
示例14: uart_put_buffer
/**
* Uart transmit buffer implementation
*/
void uart_put_buffer(struct uart_periph *p, long fd, const uint8_t *data, uint16_t len)
{
struct SerialInit *init_struct = (struct SerialInit*)(p->init_struct);
if (fd == 0) {
// if fd is zero, assume the driver is not already locked
// and available space should be checked
chMtxLock(init_struct->tx_mtx);
int16_t space = p->tx_extract_idx - p->tx_insert_idx;
if (space <= 0) {
space += UART_TX_BUFFER_SIZE;
}
if ((uint16_t)(space - 1) < len) {
chMtxUnlock(init_struct->tx_mtx);
return; // no room
}
}
// insert data into buffer
int i;
for (i = 0; i < len; i++) {
p->tx_buf[p->tx_insert_idx] = data[i];
p->tx_insert_idx = (p->tx_insert_idx + 1) % UART_TX_BUFFER_SIZE;
}
// unlock if needed
if (fd == 0) {
chMtxUnlock(init_struct->tx_mtx);
// send signal to start transmission
chSemSignal (init_struct->tx_sem);
}
}
开发者ID:enacuavlab,项目名称:paparazzi,代码行数:32,代码来源:uart_arch.c
示例15: motor_get_control_mode
enum motor_control_mode motor_get_control_mode(void)
{
chMtxLock(&_mutex);
enum motor_control_mode ret = _state.mode;
chMtxUnlock();
return ret;
}
开发者ID:JarryChou,项目名称:sapog,代码行数:7,代码来源:motor.c
示例16: mtx5_execute
static void mtx5_execute(void) {
#if !CH_CFG_USE_MUTEXES_RECURSIVE
bool b;
tprio_t prio = chThdGetPriorityX();
b = chMtxTryLock(&m1);
test_assert(1, b, "already locked");
b = chMtxTryLock(&m1);
test_assert(2, !b, "not locked");
chSysLock();
chMtxUnlockS(&m1);
chSysUnlock();
test_assert(3, queue_isempty(&m1.m_queue), "queue not empty");
test_assert(4, m1.m_owner == NULL, "still owned");
test_assert(5, chThdGetPriorityX() == prio, "wrong priority level");
#endif /* !CH_CFG_USE_MUTEXES_RECURSIVE */
chMtxLock(&m1);
chMtxUnlockAll();
test_assert(6, queue_isempty(&m1.m_queue), "queue not empty");
test_assert(7, m1.m_owner == NULL, "still owned");
}
开发者ID:MultiCalorNV,项目名称:verventa-web_Int,代码行数:26,代码来源:testmtx.c
示例17: motor_is_running
bool motor_is_running(void)
{
chMtxLock(&_mutex);
bool ret = motor_rtctl_get_state() == MOTOR_RTCTL_STATE_RUNNING;
chMtxUnlock();
return ret;
}
开发者ID:JarryChou,项目名称:sapog,代码行数:7,代码来源:motor.c
示例18: OscAutosendThread
static msg_t OscAutosendThread(void *arg)
{
UNUSED(arg);
uint8_t i;
const OscNode* node;
OscChannelData* chd;
while (!chThdShouldTerminate()) {
if (osc.autosendDestination == NONE) {
sleep(250);
}
else {
chd = oscGetChannelByType(osc.autosendDestination);
i = 0;
node = oscRoot.children[i++];
chMtxLock(&chd->lock);
while (node != 0) {
if (node->autosender != 0)
node->autosender(osc.autosendDestination);
node = oscRoot.children[i++];
}
oscSendPendingMessages(osc.autosendDestination);
chMtxUnlock();
sleep(osc.autosendPeriod);
}
}
return 0;
}
开发者ID:YTakami,项目名称:makecontroller,代码行数:28,代码来源:osc.c
示例19: motor_is_idle
bool motor_is_idle(void)
{
chMtxLock(&_mutex);
bool ret = motor_rtctl_get_state() == MOTOR_RTCTL_STATE_IDLE;
chMtxUnlock();
return ret;
}
开发者ID:JarryChou,项目名称:sapog,代码行数:7,代码来源:motor.c
示例20: toggleLeds
void toggleLeds( uint32_t arg )
{
chMtxLock( &mutex );
value = ( value & ( ~arg ) ) |
( (value ^ arg ) & (arg & 0x07) );
chMtxUnlock();
}
开发者ID:z80,项目名称:digitizer,代码行数:7,代码来源:led_ctrl.c
注:本文中的chMtxLock函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论