本文整理匯總了C++中EndCritical函數的典型用法代碼示例。如果您正苦於以下問題:C++ EndCritical函數的具體用法?C++ EndCritical怎麽用?C++ EndCritical使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了EndCritical函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: OS_AddThread
// -------------------------- OS_AddThread ---------------------------
int OS_AddThread(void(*task)(void), unsigned long stackSize, unsigned long priority){
long status;
int i = 0;
status = StartCritical();
while((thread[i].id != 0) && (i < NUMTHREADS)){
i++;
};
if (thread[i].id != 0){
EndCritical(status);
return 0;
}
SetInitialStack(i, task);
thread[i].id = i + 1;
thread[i].priority = priority;
thread[i].blockSt = 0;
thread[i].sleepSt = 0;
linkTCB(&Actives, &thread[i]);
EndCritical(status);
return 1; //successfully added thread
}
示例2: Task_WindOut
void Task_WindOut(void)
{
BSET(AWS_DDR, AWS_PIN);
BeginCritical();
// Fast PWM 8 bit
TCCR1A = BV(COM1A1) | BV(COM1B1) | BV(WGM10);
TCCR1B = BV(WGM12) | BV(CS11);
// Enable PWM pins
AWA_DDR |= BV(AWA_DDR_COS) | BV(AWA_DDR_SIN);
EndCritical();
for (;;) {
delay_ms(80);
//
// Dimension for 5 ms pulses (100 Hz) at 60 Kts
// 60 kts - 100 revs /
if (Nav_AWS < 5)
windPulse = 0;
else
windPulse = 2000 / Nav_AWS;
register int deg = Nav_AWA/10;
BeginCritical();
AWA_SIN = trigint_sin8u(deg * 45 + (deg * 51 / 100));
deg = (90 - deg + 360) % 360;
AWA_COS = trigint_sin8u(deg * 45 + (deg * 51 / 100));
EndCritical();
}
}
示例3: OS_AddThread
int OS_AddThread(void(*task)(void), unsigned long stackSize, unsigned long priority) {
long status;
int i;
int index;
status = StartCritical();
if(NumThreads == 0) {
// First thread no TCBs yet
tcbs[0].next = &tcbs[0];
tcbs[0].prev = &tcbs[0];
Head = &tcbs[0];
Tail = &tcbs[0];
index = 0;
} else {
// Look for open spot in tcbs array
for(i = 0; i < MAXTHREADS; i++) {
if(tcbs[i].valid == INVALID) {
index = i;
i = MAXTHREADS; // Exit loop
} else {
index = -1; // Sentinel to detect no invalid spots
}
}
if(index == -1) {
EndCritical(status);
return FAILURE; // No space in tcbs
}
tcbs[index].next = Head; // New tcb points to head
tcbs[index].prev = Tail; // Point back to current tail
(*Tail).next = &tcbs[index]; // Tail now points to new tcb
Tail = &tcbs[index]; // New tcb becomes the tail
(*Head).prev = &tcbs[index]; // Head now points backwards to new tcb
}
// Initilizing the stack for debugging
setInitialStack(index);
// Set PC for stack to point to function to run
tcbs[index].stack[STACKSIZE - 2] = (long) (task);
// Set inital values for sleep status and id
tcbs[index].sleepState = 0;
tcbs[index].priority = priority;
tcbs[index].blockedState = '\0';
tcbs[index].id = index;
tcbs[index].valid = VALID;
NumThreads++;
EndCritical(status);
return SUCCESS;
}
示例4: uartRx
uint8_t uartRx(uint8_t uartId, bool block) {
uint8_t recvd = 0xFF;
StartCritical();
while((cBufGetChar(&rxBuffer[uartId], (char *)&recvd) > 0) && block) {
EndCritical();
//give the interrupt a chance to run
StartCritical();
}
EndCritical();
return recvd;
}
示例5: OS_InitSemaphore
// ----------------------- OS_InitSemaphore --------------------------
void OS_InitSemaphore(Sema4Type *semaPt, long value){
long status;
status = StartCritical();
(*semaPt).Value = value;
semaPt->Blocked = 0;
EndCritical(status);
}
示例6: Timer5A_Handler
void Timer5A_Handler(void){
unsigned long sr;
TIMER5_ICR_R = TIMER_ICR_TATOCINT;// acknowledge timer2A timeout
if(counter == 50)
{
counter = 1;
sr = StartCritical();
// GPIO_PORTB_AFSEL_R &= ~0x40; // regular port function
// GPIO_PORTB_DIR_R |= 0x40; // make PD3-0 out
// GPIO_PORTB_PCTL_R = (GPIO_PORTB_PCTL_R&0xF0FFFFFF)+0x00000000;
// PB7 = 0x00;
// PB7 = 0x80;
// Timer4A_Wait(800); // 10 us
// PB7 = 0x00;
PA0 = 0x00;
PA0 = 0x40;
Timer4A_Wait(800); // 10 us
PA0 = 0x00;
// GPIO_PORTB_DIR_R &= ~0x40; // make PB6 in
// GPIO_PORTB_AFSEL_R |= 0x40; // enable alt funct on PB6
// GPIO_PORTB_PCTL_R = (GPIO_PORTB_PCTL_R&0xF0FFFFFF)+0x07000000;
EndCritical(sr);
}
else {
counter++;
}
}
示例7: Init_Timer5A
void Init_Timer5A(uint32_t period) {
long sr;
volatile unsigned long delay;
sr = StartCritical();
counter = 0;
SYSCTL_RCGCTIMER_R |= 0x20;
delay = SYSCTL_RCGCTIMER_R;
delay = SYSCTL_RCGCTIMER_R;
TIMER5_CTL_R &= ~TIMER_CTL_TAEN; // 1) disable timer1A during setup
// 2) configure for 32-bit timer mode
TIMER5_CFG_R = TIMER_CFG_32_BIT_TIMER;
// 3) configure for periodic mode, default down-count settings
TIMER5_TAMR_R = TIMER_TAMR_TAMR_PERIOD;
TIMER5_TAILR_R = period - 1; // 4) reload value
// 5) clear timer1A timeout flag
TIMER5_ICR_R = TIMER_ICR_TATOCINT;
TIMER5_IMR_R |= TIMER_IMR_TATOIM;// 6) arm timeout interrupt
// 7) priority shifted to bits 31-29 for timer2A
NVIC_PRI23_R = (NVIC_PRI23_R&0xFFFFFF00)|(1 << 5);
NVIC_EN2_R = NVIC_EN2_INT92; // 8) enable interrupt 23 in NVIC
TIMER5_TAPR_R = 0;
TIMER5_CTL_R |= TIMER_CTL_TAEN; // 9) enable timer2A
//page 155
//page 104 //interrupt number 92 = priority 23
EndCritical(sr);
}
示例8: linkTCB
void linkTCB(tcbList* list, tcbPt target){
tcbPt head = *list;
tcbPt current;
long status;
status = StartCritical();
if (head == 0){
*list = target;
target->next = target;
target->prev = target;
} else {
current = head;
if (target->priority < head->priority){
*list = target;
} else {
current = current->next;
while ((target->priority >= current->priority) && (current != head)){
current = current->next;
}
}
(current->prev)->next = target;
target->prev = current->prev;
target->next = current;
current->prev = target;
}
EndCritical(status);
}
示例9: TimerCapture_Init3
void TimerCapture_Init3(void){long sr; //Timer 3 (Clock thing)
sr = StartCritical();
P10SEL0 |= 0x10;
P10SEL1 &= ~0x10; // configure P10.4 as TA0CCP0
P10DIR &= ~0x10; // make P10.4 in
P8SEL0 |= 0x04;
P8SEL1 &= ~0x04; // configure 8.2 as TA0CCP
P8DIR &= ~0x04;
TA3CTL &= ~0x0030; // halt Timer A3
TA3CTL = 0x0200;
TA3CCTL0 = 0x8910;
TA3CCTL2 = 0x49C0;
TA3EX0 &= ~0x0007; // configure for input clock divider /1
NVIC_IPR3 |= (NVIC_IPR3&0xFFFFFF00)|0x04040000; // priority 2
// interrupts enabled in the main program after all devices initialized
NVIC_ISER0 |= 0x00006000; // enable interrupt 8 in NVIC
TA3CTL |= 0x0024; // reset and start Timer A1 in continuous up mode
EndCritical(sr);
}
示例10: OS_ClearMsTime
// ******** OS_ClearMsTime ************
// sets the system time to zero from Lab 1)
// Inputs: none
// Outputs: none
// You are free to change how this works
void OS_ClearMsTime(void){
int status;
status=StartCritical();
TIMELORD=0;
EndCritical(status);
return;
}
示例11: TimerCapture_Init01
void TimerCapture_Init01(void(*task)(uint16_t time), void(*task2)(uint16_t time)){long sr; //Timer 1 (Wheel encoders)
sr = StartCritical();
CaptureTask = task; // user function
CaptureTask2 = task2; // user function
P8SEL0 |= 0x01;
P8SEL1 &= ~0x01; // configure P8.0 as TA0CCP0
P8DIR &= ~0x01; // make P8.0 in RIGHT?
P7SEL0 |= 0x10;
P7SEL1 &= ~0x10; // configure P7.4 as TA0CCP0
P7DIR &= ~0x10; // make P7.4 in LEFT?
TA1CTL &= ~0x0030; // halt Timer A1
TA1CTL = 0x0200;
TA1CCTL0 = 0x4910;
TA1CCTL4 = 0x4910;
TA1EX0 &= ~0x0003; // configure for input clock divider /1
NVIC_IPR2 |= (NVIC_IPR2&0xFFFFFF00)|0x04040000; // priority 2
// interrupts enabled in the main program after all devices initialized
NVIC_ISER0 = 0x00000C00; // enable interrupt 8 in NVIC
TA1CTL |= 0x0024; // reset and start Timer A1 in continuous up mode
// these also work NVIC_IPR2 |= (NVIC_IPR2&0xFFFFFF00)|0x00000040; NVIC_ISER0 |= 0x00000100;
EndCritical(sr);
}
示例12: OS_bSignal
// ******** OS_bSignal ************
// set semaphore to 1, wakeup blocked thread if appropriate
// input: pointer to a binary semaphore
// output: none
void OS_bSignal(Sema4Type *semaPt) {
long status;
tcbType (*tempPt);
status = StartCritical();
if((*semaPt).Value != 1) {
(*semaPt).Value++;
if((*semaPt).Value <= 0) {
tempPt = RunPt;
while((*tempPt).blockedState != semaPt) {
tempPt = (*tempPt).next;
}
(*tempPt).blockedState = '\0';
}
}
EndCritical(status);
}
示例13: CAN0_Open
// Initialize CAN port
void CAN0_Open(void){
uint32_t volatile delay;
int32_t sr;
sr = StartCritical();
MailFlag = false;
SYSCTL_RCGCCAN_R |= 0x00000001; // CAN0 enable bit 0
SYSCTL_RCGCGPIO_R |= 0x00000010; // RCGC2 portE bit 4
for(delay=0; delay<10; delay++){};
GPIO_PORTE_AFSEL_R |= 0x30; //PORTE AFSEL bits 5,4
// PORTE PCTL 88 into fields for pins 5,4
GPIO_PORTE_PCTL_R = (GPIO_PORTE_PCTL_R&0xFF00FFFF)|0x00880000;
GPIO_PORTE_DEN_R |= 0x30;
GPIO_PORTE_DIR_R |= 0x20;
CANInit(CAN0_BASE);
CANBitRateSet(CAN0_BASE, 80000000, CAN_BITRATE);
CANEnable(CAN0_BASE);
// make sure to enable STATUS interrupts
CANIntEnable(CAN0_BASE, CAN_INT_MASTER | CAN_INT_ERROR | CAN_INT_STATUS);
// Set up filter to receive these IDs
// in this case there is just one type, but you could accept multiple ID types
CAN0_Setup_Message_Object(Ping1_ID, MSG_OBJ_RX_INT_ENABLE, 4, NULL, Ping1_ID, MSG_OBJ_TYPE_RX);
CAN0_Setup_Message_Object(Ping2_ID, MSG_OBJ_RX_INT_ENABLE, 4, NULL, Ping2_ID, MSG_OBJ_TYPE_RX);
CAN0_Setup_Message_Object(Ping3_ID, MSG_OBJ_RX_INT_ENABLE, 4, NULL, Ping3_ID, MSG_OBJ_TYPE_RX);
CAN0_Setup_Message_Object(Ping4_ID, MSG_OBJ_RX_INT_ENABLE, 4, NULL, Ping4_ID, MSG_OBJ_TYPE_RX);
CAN0_Setup_Message_Object(Button1_ID, MSG_OBJ_RX_INT_ENABLE, 4, NULL, Button1_ID, MSG_OBJ_TYPE_RX);
CAN0_Setup_Message_Object(Button2_ID, MSG_OBJ_RX_INT_ENABLE, 4, NULL, Button2_ID, MSG_OBJ_TYPE_RX);
CAN0_Setup_Message_Object(IR_ID, MSG_OBJ_RX_INT_ENABLE, 4, NULL, IR_ID, MSG_OBJ_TYPE_RX);
NVIC_EN1_R = (1 << (INT_CAN0 - 48)); //IntEnable(INT_CAN0);
EndCritical(sr);
return;
}
示例14: OS_Wait
// ******** OS_Wait ************
// decrement semaphore and spin/block if less than zero
// input: pointer to a counting semaphore
// output: none
void OS_Wait(Sema4Type *s){
//new way (Lab3)
long status; //the i bit, used to save and reload it
status=StartCritical(); //Save Ibit
s->Value = s->Value-1; //Decriment semaphore counter
if(s->Value < 0){ //If counter < 0 block
//BLOCK!!!
NUMBLOCKEDTHREADS++;
RUNPT->blockedOn=s; //set in TCB what sema4 its blocked on (for debug info)
if(s->blockedThreads[(s->bIndex+1)%NUMTHREADS]==EMPTY){
s->bIndex=(s->bIndex+1)%NUMTHREADS;
s->blockedThreads[(s->bIndex)%NUMTHREADS]=RUNPT; //add thread to array of blocked threads
NVIC_ST_CURRENT_R = 0;
//EndCritical(status);
OS_SysTick_Handler(); //trigger thread switch
}
}
EndCritical(status); //Reenable I bit
//old way (Lab2)
/* DisableInterrupts()
while( s->Value <= 0){
//TODO: implement Blocking
EnableInterrupts();
DisableInterrupts();
}
s->Value--;
EnableInterrupts();
*/
}
示例15: OS_Signal
// ******** OS_Signal ************
// increment semaphore, wakeup blocked thread if appropriate
// input: pointer to a counting semaphore
// output: none
void OS_Signal(Sema4Type *s){
long status;
status=StartCritical();
s->Value++;
EndCritical(status);
//TODO: wakeup blocked thread
}