📄 led_blink.c
字号:
return ( FALSE ) ;
}
//* EndIf
}
//* EndIf
}
//* EndIf
}
//* EndIf
}
//* EndIf
*rc = rc_save ;
//* Return True
return ( TRUE ) ;
}
//* End
//*P
//*----------------------------------------------------------------------------
//* Function Name : delay_microsec
//* Object : Run the specified handler after a defined delay in
//* : micro-seconds.
//* Input Parameters : <timer_id> = the channel number to use
//* : <period> = period in micro-seconds
//* : <repeat> = if True, handler is run at each period
//* : <handler> = the handler to run after the delay
//* Output Parameters : True if the arguments are correct, otherwise False
//* Functions called : none
//*----------------------------------------------------------------------------
_REFERENCE (INT32U my_delay_microsec ( INT32U timer_id, //2
INT32U period, //100000
INT32U repeat )) //TRUE
// TypeTCHandler handler ))
#ifdef CORPS
//* Begin
{
StructTC *tc_pt ;
INT32U ra, rb, rc ;
INT32U mode ;
//* If timer index is too high, return False
if ( timer_id >= NB_TIMER ) return ( FALSE ) ;
//* Define the Timer Counter Channel Pointer
tc_pt = &(ConstTimer[timer_id].TCBBase->
TC[ConstTimer[timer_id].ChannelId]) ;
//* Compute registers value for maximum precision, if error return False
//* Define RB as the period to enable stop on Load RB
ra = 0 ;
rb = period ;
rc = period ;
if ( compute_register ( &mode, &ra, &rb, &rc ) != TRUE ) return ( FALSE ) ;
//* Define as pio the pins reserved for the Channel
my_define_as_pio ( ConstTimer[timer_id].PioCtrl, // =0
ConstTimer[timer_id].PioPin ) ; // =(7<<6)
//* Save the handler in the table
// TCHandlerTable[timer_id] = handler ;
//* Initialize the mode of the timer
tc_pt->TC_CMR = mode | WAVE | (repeat ? CPCTRG : CPCDIS) ;
//* Initialize the RC Register value
tc_pt->TC_RC = rc ;
//* Enable the RC Compare interrupt
tc_pt->TC_IER = CPCS ;
//* Enable the clock of the timer
tc_pt->TC_CCR = CLKEN ;
//* Trig the timer
tc_pt->TC_CCR = SWTRG ;
//* Return True
return ( TRUE ) ;
}
//* End
#endif
//*P
//*----------------------------------------------------------------------------
//* Function Name : read_timer_status
//* Object : Read the Status of a Timer Counter Channel
//* Input Parameters : <timer_id> = the channel number
//* Output Parameters : the status value, or 0 if the timer id is out of range
//* Functions called : none
//*----------------------------------------------------------------------------
_REFERENCE (INT32U my_read_timer_status ( INT32U timer_id ))
#ifdef CORPS
//* Begin
{
//* If timer_id is out of range, return False
if ( timer_id >= NB_TIMER ) return ( FALSE ) ;
//* Return the value of the Status Register
return ( ConstTimer[timer_id].TCBBase->
TC[ConstTimer[timer_id].ChannelId].TC_SR ) ;
}
//* End
#endif
//*P
//*----------------------------------------------------------------------------
//* Function Name : init_timer_irq
//* Object : Initialize the Timer Counter Handlers
//* Input Parameters : none
//* Output Parameters : none
//* Functions called : none
//*----------------------------------------------------------------------------
_REFERENCE (void my_init_timer_2_irq ( void ))
#ifdef CORPS
//* Begin
{
// INT32U tc_id=2 ;
//* For each timer counter channel
// for ( tc_id = 0 ; tc_id < NB_TIMER ; tc_id ++ )
// {
//* Initialise the default handler address
// TCHandlerTable[tc_id] = no_handler_tc ;
//* Enable the interrupt on the Interrupt controller for Timer Counter
init_interrupt ( (INT8U)TC2IRQ, // 6
(INT8U)TC2_IRQ_PRIORITY, // 3
(INT8U)EdgeTriggered , // (1<<5)
timer_2_isr ) ;
// }
//* EndFor
}
//* End
#endif
//*P
//*-----------------------------------------------------------------------------
//* Function Name : define_as_pio
//* Object : Define pins as managed by the PIO controller
//* Input Parameters : <mask> defines the pins to managed by the PIO
//* Output Parameters : the value of the PIO Status Register
//* Functions called : none
//*-----------------------------------------------------------------------------
_REFERENCE (INT32U my_define_as_pio ( INT32U pio_ctrl_id, INT32U mask ))
#ifdef CORPS
//* Begin
{
//* If PIO Controller index is correct
if ( pio_ctrl_id > NB_PIO_CTRL ) return ( FALSE ) ;
//* Write the argument mask in the PIO Enable Register
ConstPio[pio_ctrl_id].PioBase->PIO_PER = mask ;
//* Return the value of the PIO Status Register
return ( ConstPio[pio_ctrl_id].PioBase->PIO_PSR ) ;
}
//* End
#endif
//*P
//*-----------------------------------------------------------------------------
//* Function Name : define_as_output
//* Object : Define pins as output if managed by the parallel IO
//* Input Parameters : <mask> defines the pins to be defined as output
//* Output Parameters : a mask showing the pins really defined as output
//* : bit is set if corresponding pin is an output
//* Functions called : none
//*-----------------------------------------------------------------------------
_REFERENCE (INT32U my_define_as_output ( INT32U pio_ctrl_id, INT32U mask ))
#ifdef CORPS
//* Begin
{
//* If PIO Controller index is correct
if ( pio_ctrl_id > NB_PIO_CTRL ) return ( FALSE ) ;
//* Write the argument mask in the Output Enable Register
ConstPio[pio_ctrl_id].PioBase->PIO_OER = mask ;
//* Return PIO Status Register AND PIO Direction Status Register
return ( ConstPio[pio_ctrl_id].PioBase->PIO_PSR &
ConstPio[pio_ctrl_id].PioBase->PIO_OSR ) ;
}
//* End
#endif
//*P
//*-----------------------------------------------------------------------------
//* Function Name : set_pio_output
//* Object : Set an output if mnaged by the PIO and defined as
//* : output
//* Input Parameters : <mask> defines the pins to be set
//* Output Parameters : the state of the 32 pins ( on the pads )
//* Functions called : none
//*-----------------------------------------------------------------------------
_REFERENCE (INT32U my_set_pio_output ( INT32U pio_ctrl_id, INT32U mask ))
#ifdef CORPS
//* Begin
{
//* If PIO Controller index is correct
if ( pio_ctrl_id > NB_PIO_CTRL ) return ( FALSE ) ;
//* Write the argument mask in the Set Output Data Register
ConstPio[pio_ctrl_id].PioBase->PIO_SODR = mask ;
//* Return the Pin Data Status Register
return ( ConstPio[pio_ctrl_id].PioBase->PIO_PDSR ) ;
}
//* End
#endif
//*P
//*-----------------------------------------------------------------------------
//* Function Name : clear_pio_output
//* Object : Clear an output if managed by the PIO and defined as
//* : output
//* Input Parameters : <mask> defines the pins to be cleared
//* Output Parameters : the state of the 32 pins ( on the pads )
//* Functions called : none
//*-----------------------------------------------------------------------------
_REFERENCE (INT32U my_clear_pio_output ( INT32U pio_ctrl_id, INT32U mask ))
#ifdef CORPS
//* Begin
{
//* If PIO Controller index is correct
if ( pio_ctrl_id > NB_PIO_CTRL ) return ( FALSE ) ;
//* Write the argument mask in the Clear Output Data Register
ConstPio[pio_ctrl_id].PioBase->PIO_CODR = mask ;
//* Return the Pin Data Status Register
return ( ConstPio[pio_ctrl_id].PioBase->PIO_PDSR ) ;
}
//* End
#endif
/*
* Task running at the highest priority.
*/
void
Task1(void *i)
{
INT8U Reply;
// INT32U m,n;
my_delay_microsec ( 2, 100000, TRUE ); //, timer_irq ) ;
ARMEnableInt();
for (;;)
{
// OSTimeDly(8);
if(FlagTask1==TRUE)
{
my_clear_pio_output ( 0, LED3 ) ;
FlagTask1=FALSE;
}
else
{
my_set_pio_output ( 0, LED3 ) ;
FlagTask1=TRUE;
}
/* wait for the semaphore */
OSSemPend(Sem2, 0, &Reply);
/* wait a short while */
// for(m=0;m<1000;m++)
// for(n=0;n<100;n++);
/* signal the semaphore */
// OSSemPost(Sem1);
}
}
void
Task2(void *i)
{
// INT8U Reply;
// INT32U m,n;
for (;;)
{
if(FlagSwi==TRUE)
{
my_clear_pio_output ( 0, LED2 ) ;
FlagSwi=FALSE;
}
else
{
my_set_pio_output ( 0, LED2 ) ;
FlagSwi=TRUE;
}
// for(m=0;m<1000;m++)
// for(n=0;n<100;n++);
/* wait for the semaphore */
// OSSemPend(Sem1, 0, &Reply);
// uHALr_printf("[");
/* wait a short while */
OSTimeDly(16);
// uHALr_printf("2]");
/* signal the semaphore */
OSSemPost(Sem2);
}
}
void timer_irq ( StructTC *tc_pt )
{
my_read_timer_status ( 2 ) ;
if(FlagIrq==TRUE)
{
my_clear_pio_output ( 0, LED1 ) ;
FlagIrq=FALSE;
}
else
{
my_set_pio_output ( 0, LED1 ) ;
FlagIrq=TRUE;
}
}
void swi_irq ( void )
{
if(FlagSwi==TRUE)
{
my_clear_pio_output ( 0, LED2 ) ;
FlagSwi=FALSE;
}
else
{
my_set_pio_output ( 0, LED2 ) ;
FlagSwi=TRUE;
}
}
//*P
//*-----------------------------------------------------------------------------
//* Function Name : main
//* Object : Main function of the test "delay"
//* Input Parameters : none
//* Output Parameters :
//* Functions called :
//*-----------------------------------------------------------------------------
_REFERENCE (int MainApplication( void ))
#ifdef CORPS
//* Begin
{
// int i,j;
need_to_swap_context = 0 ;
FlagIrq=TRUE;
FlagSwi=TRUE;
FlagTask1=TRUE;
my_define_as_pio ( 0 , LED1|LED2|LED3 );
my_define_as_output ( 0, LED1|LED2|LED3 );
my_set_pio_output ( 0, LED1|LED2|LED3 ) ;
my_read_timer_status ( 2 ) ;
// init_timer_irq () ;
my_init_timer_2_irq();
/* init_interrupt ( SWIRQ,
SW_IRQ_PRIORITY,
EdgeTriggered ,
// swi_interrupt_handler) ;
OS_TASK_SW);
*/
/* needed by uC/OS */
OSInit();
/*
* create the tasks in uC/OS and assign decreasing
* priority to them
*/
Sem2 = OSSemCreate(0); /* Random number semaphore */
OSTaskCreate(Task1, (void*)0, (OS_STK *)&Stack1[STACKSIZE - 1], 21);
OSTaskCreate(Task2, (void*)0, (OS_STK *)&Stack2[STACKSIZE - 1], 22);
/* start the game */
OSStart();
return 0;
//* End
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -