mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-04-19 21:11:57 -04:00
Update demo to include a test of nesting interrupt accessing queues.
This commit is contained in:
parent
684b898abc
commit
0965823a67
|
@ -69,9 +69,9 @@
|
||||||
#define configCPU_CLOCK_HZ ( ( unsigned portLONG ) 72000000UL )
|
#define configCPU_CLOCK_HZ ( ( unsigned portLONG ) 72000000UL )
|
||||||
#define configPERIPHERAL_CLOCK_HZ ( ( unsigned portLONG ) 36000000UL )
|
#define configPERIPHERAL_CLOCK_HZ ( ( unsigned portLONG ) 36000000UL )
|
||||||
#define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 5 )
|
#define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 5 )
|
||||||
#define configMINIMAL_STACK_SIZE ( 210 )
|
#define configMINIMAL_STACK_SIZE ( 200 )
|
||||||
#define configISR_STACK_SIZE ( 400 )
|
#define configISR_STACK_SIZE ( 400 )
|
||||||
#define configTOTAL_HEAP_SIZE ( ( size_t ) 25000 )
|
#define configTOTAL_HEAP_SIZE ( ( size_t ) 28000 )
|
||||||
#define configMAX_TASK_NAME_LEN ( 8 )
|
#define configMAX_TASK_NAME_LEN ( 8 )
|
||||||
#define configUSE_TRACE_FACILITY 0
|
#define configUSE_TRACE_FACILITY 0
|
||||||
#define configUSE_16_BIT_TICKS 0
|
#define configUSE_16_BIT_TICKS 0
|
||||||
|
@ -86,13 +86,14 @@
|
||||||
/* Set the following definitions to 1 to include the API function, or zero
|
/* Set the following definitions to 1 to include the API function, or zero
|
||||||
to exclude the API function. */
|
to exclude the API function. */
|
||||||
|
|
||||||
#define INCLUDE_vTaskPrioritySet 1
|
#define INCLUDE_vTaskPrioritySet 1
|
||||||
#define INCLUDE_uxTaskPriorityGet 1
|
#define INCLUDE_uxTaskPriorityGet 1
|
||||||
#define INCLUDE_vTaskDelete 0
|
#define INCLUDE_vTaskDelete 0
|
||||||
#define INCLUDE_vTaskCleanUpResources 0
|
#define INCLUDE_vTaskCleanUpResources 0
|
||||||
#define INCLUDE_vTaskSuspend 1
|
#define INCLUDE_vTaskSuspend 1
|
||||||
#define INCLUDE_vTaskDelayUntil 1
|
#define INCLUDE_vTaskDelayUntil 1
|
||||||
#define INCLUDE_vTaskDelay 1
|
#define INCLUDE_vTaskDelay 1
|
||||||
|
#define INCLUDE_uxTaskGetStackHighWaterMark 1
|
||||||
|
|
||||||
/* The priority at which the tick interrupt runs. This should probably be
|
/* The priority at which the tick interrupt runs. This should probably be
|
||||||
kept at 1. */
|
kept at 1. */
|
||||||
|
|
117
Demo/PIC32MX_MPLAB/IntQueueTimer.c
Normal file
117
Demo/PIC32MX_MPLAB/IntQueueTimer.c
Normal file
|
@ -0,0 +1,117 @@
|
||||||
|
/*
|
||||||
|
FreeRTOS.org V5.0.0 - Copyright (C) 2003-2008 Richard Barry.
|
||||||
|
|
||||||
|
This file is part of the FreeRTOS.org distribution.
|
||||||
|
|
||||||
|
FreeRTOS.org is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
FreeRTOS.org is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with FreeRTOS.org; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
A special exception to the GPL can be applied should you wish to distribute
|
||||||
|
a combined work that includes FreeRTOS.org, without being obliged to provide
|
||||||
|
the source code for any proprietary components. See the licensing section
|
||||||
|
of http://www.FreeRTOS.org for full details of how and when the exception
|
||||||
|
can be applied.
|
||||||
|
|
||||||
|
***************************************************************************
|
||||||
|
***************************************************************************
|
||||||
|
* *
|
||||||
|
* SAVE TIME AND MONEY! We can port FreeRTOS.org to your own hardware, *
|
||||||
|
* and even write all or part of your application on your behalf. *
|
||||||
|
* See http://www.OpenRTOS.com for details of the services we provide to *
|
||||||
|
* expedite your project. *
|
||||||
|
* *
|
||||||
|
***************************************************************************
|
||||||
|
***************************************************************************
|
||||||
|
|
||||||
|
Please ensure to read the configuration and relevant port sections of the
|
||||||
|
online documentation.
|
||||||
|
|
||||||
|
http://www.FreeRTOS.org - Documentation, latest information, license and
|
||||||
|
contact details.
|
||||||
|
|
||||||
|
http://www.SafeRTOS.com - A version that is certified for use in safety
|
||||||
|
critical systems.
|
||||||
|
|
||||||
|
http://www.OpenRTOS.com - Commercial support, development, porting,
|
||||||
|
licensing and training services.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "FreeRTOS.h"
|
||||||
|
#include "IntQueueTimer.h"
|
||||||
|
#include "IntQueue.h"
|
||||||
|
|
||||||
|
#define timerINTERRUPT3_FREQUENCY ( 2000UL )
|
||||||
|
#define timerINTERRUPT4_FREQUENCY ( 2001UL )
|
||||||
|
|
||||||
|
void vT3InterruptHandler( void );
|
||||||
|
void vT4InterruptHandler( void );
|
||||||
|
|
||||||
|
void __attribute__( (interrupt(ipl0), vector(_TIMER_3_VECTOR))) vT3InterruptWrapper( void );
|
||||||
|
void __attribute__( (interrupt(ipl0), vector(_TIMER_4_VECTOR))) vT4InterruptWrapper( void );
|
||||||
|
|
||||||
|
void vInitialiseTimerForIntQueueTest( void )
|
||||||
|
{
|
||||||
|
/* Timer 1 is used for the tick interrupt, timer 2 is used for the high
|
||||||
|
frequency interrupt test. This file therefore uses timers 3 and 4. */
|
||||||
|
|
||||||
|
T3CON = 0;
|
||||||
|
TMR3 = 0;
|
||||||
|
PR3 = ( unsigned portSHORT ) ( configPERIPHERAL_CLOCK_HZ / timerINTERRUPT3_FREQUENCY );
|
||||||
|
|
||||||
|
/* Setup timer 3 interrupt priority to be above the kernel priority. */
|
||||||
|
ConfigIntTimer3( T3_INT_ON | ( configMAX_SYSCALL_INTERRUPT_PRIORITY - 1 ) );
|
||||||
|
|
||||||
|
/* Clear the interrupt as a starting condition. */
|
||||||
|
IFS0bits.T3IF = 0;
|
||||||
|
|
||||||
|
/* Enable the interrupt. */
|
||||||
|
IEC0bits.T3IE = 1;
|
||||||
|
|
||||||
|
/* Start the timer. */
|
||||||
|
T3CONbits.TON = 1;
|
||||||
|
|
||||||
|
|
||||||
|
/* Do the same for timer 4. */
|
||||||
|
T4CON = 0;
|
||||||
|
TMR4 = 0;
|
||||||
|
PR4 = ( unsigned portSHORT ) ( configPERIPHERAL_CLOCK_HZ / timerINTERRUPT4_FREQUENCY );
|
||||||
|
|
||||||
|
/* Setup timer 4 interrupt priority to be above the kernel priority. */
|
||||||
|
ConfigIntTimer4( T4_INT_ON | ( configMAX_SYSCALL_INTERRUPT_PRIORITY ) );
|
||||||
|
|
||||||
|
/* Clear the interrupt as a starting condition. */
|
||||||
|
IFS0bits.T4IF = 0;
|
||||||
|
|
||||||
|
/* Enable the interrupt. */
|
||||||
|
IEC0bits.T4IE = 1;
|
||||||
|
|
||||||
|
/* Start the timer. */
|
||||||
|
T4CONbits.TON = 1;
|
||||||
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
void vT3InterruptHandler( void )
|
||||||
|
{
|
||||||
|
IFS0bits.T3IF = 0;
|
||||||
|
portEND_SWITCHING_ISR( xFirstTimerHandler() );
|
||||||
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
void vT4InterruptHandler( void )
|
||||||
|
{
|
||||||
|
IFS0bits.T4IF = 0;
|
||||||
|
portEND_SWITCHING_ISR( xSecondTimerHandler() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
58
Demo/PIC32MX_MPLAB/IntQueueTimer.h
Normal file
58
Demo/PIC32MX_MPLAB/IntQueueTimer.h
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
/*
|
||||||
|
FreeRTOS.org V5.0.0 - Copyright (C) 2003-2008 Richard Barry.
|
||||||
|
|
||||||
|
This file is part of the FreeRTOS.org distribution.
|
||||||
|
|
||||||
|
FreeRTOS.org is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
FreeRTOS.org is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with FreeRTOS.org; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
A special exception to the GPL can be applied should you wish to distribute
|
||||||
|
a combined work that includes FreeRTOS.org, without being obliged to provide
|
||||||
|
the source code for any proprietary components. See the licensing section
|
||||||
|
of http://www.FreeRTOS.org for full details of how and when the exception
|
||||||
|
can be applied.
|
||||||
|
|
||||||
|
***************************************************************************
|
||||||
|
***************************************************************************
|
||||||
|
* *
|
||||||
|
* SAVE TIME AND MONEY! We can port FreeRTOS.org to your own hardware, *
|
||||||
|
* and even write all or part of your application on your behalf. *
|
||||||
|
* See http://www.OpenRTOS.com for details of the services we provide to *
|
||||||
|
* expedite your project. *
|
||||||
|
* *
|
||||||
|
***************************************************************************
|
||||||
|
***************************************************************************
|
||||||
|
|
||||||
|
Please ensure to read the configuration and relevant port sections of the
|
||||||
|
online documentation.
|
||||||
|
|
||||||
|
http://www.FreeRTOS.org - Documentation, latest information, license and
|
||||||
|
contact details.
|
||||||
|
|
||||||
|
http://www.SafeRTOS.com - A version that is certified for use in safety
|
||||||
|
critical systems.
|
||||||
|
|
||||||
|
http://www.OpenRTOS.com - Commercial support, development, porting,
|
||||||
|
licensing and training services.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef INT_QUEUE_TIMER_H
|
||||||
|
#define INT_QUEUE_TIMER_H
|
||||||
|
|
||||||
|
void vInitialiseTimerForIntQueueTest( void );
|
||||||
|
portBASE_TYPE xTimer0Handler( void );
|
||||||
|
portBASE_TYPE xTimer1Handler( void );
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -94,7 +94,6 @@
|
||||||
|
|
||||||
/* Demo application includes. */
|
/* Demo application includes. */
|
||||||
#include "partest.h"
|
#include "partest.h"
|
||||||
#include "integer.h"
|
|
||||||
#include "blocktim.h"
|
#include "blocktim.h"
|
||||||
#include "flash.h"
|
#include "flash.h"
|
||||||
#include "semtest.h"
|
#include "semtest.h"
|
||||||
|
@ -103,6 +102,7 @@
|
||||||
#include "lcd.h"
|
#include "lcd.h"
|
||||||
#include "comtest2.h"
|
#include "comtest2.h"
|
||||||
#include "timertest.h"
|
#include "timertest.h"
|
||||||
|
#include "IntQueue.h"
|
||||||
|
|
||||||
#pragma config FPLLMUL = MUL_18, FPLLIDIV = DIV_2, FPLLODIV = DIV_1, FWDTEN = OFF
|
#pragma config FPLLMUL = MUL_18, FPLLIDIV = DIV_2, FPLLODIV = DIV_1, FWDTEN = OFF
|
||||||
#pragma config POSCMOD = HS, FNOSC = PRIPLL, FPBDIV = DIV_2
|
#pragma config POSCMOD = HS, FNOSC = PRIPLL, FPBDIV = DIV_2
|
||||||
|
@ -206,17 +206,17 @@ int main( void )
|
||||||
vStartLEDFlashTasks( tskIDLE_PRIORITY );
|
vStartLEDFlashTasks( tskIDLE_PRIORITY );
|
||||||
vCreateBlockTimeTasks();
|
vCreateBlockTimeTasks();
|
||||||
vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
|
vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
|
||||||
vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );
|
|
||||||
vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
|
vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
|
||||||
vStartQueuePeekTasks();
|
vStartQueuePeekTasks();
|
||||||
vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
|
vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
|
||||||
|
vStartInterruptQueueTasks();
|
||||||
|
|
||||||
/* Create the tasks defined within this file. */
|
/* Create the tasks defined within this file. */
|
||||||
xTaskCreate( prvTestTask1, "Tst1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
|
xTaskCreate( prvTestTask1, "Tst1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
|
||||||
xTaskCreate( prvTestTask2, "Tst2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
|
xTaskCreate( prvTestTask2, "Tst2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
|
||||||
|
|
||||||
/* prvCheckTask uses sprintf so requires more stack. */
|
/* prvCheckTask uses sprintf so requires more stack. */
|
||||||
xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE * 2, NULL, mainCHECK_TASK_PRIORITY, NULL );
|
xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
|
||||||
|
|
||||||
/* Finally start the scheduler. */
|
/* Finally start the scheduler. */
|
||||||
vTaskStartScheduler();
|
vTaskStartScheduler();
|
||||||
|
@ -351,11 +351,11 @@ xLCDMessage xMessage = { ( 200 / portTICK_RATE_MS ), cStringBuffer };
|
||||||
ulTicksToWait = mainERROR_PERIOD;
|
ulTicksToWait = mainERROR_PERIOD;
|
||||||
xMessage.pcMessage = "Error: Sem test";
|
xMessage.pcMessage = "Error: Sem test";
|
||||||
}
|
}
|
||||||
else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
|
else if( xAreIntQueueTasksStillRunning() != pdTRUE )
|
||||||
{
|
{
|
||||||
ulTicksToWait = mainERROR_PERIOD;
|
ulTicksToWait = mainERROR_PERIOD;
|
||||||
xMessage.pcMessage = "Error: Int math";
|
xMessage.pcMessage = "Error: Int queue";
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write the max jitter time to the string buffer. It will only be
|
/* Write the max jitter time to the string buffer. It will only be
|
||||||
displayed if no errors have been detected. */
|
displayed if no errors have been detected. */
|
||||||
|
@ -379,3 +379,5 @@ void _general_exception_handler( unsigned portLONG ulCause, unsigned portLONG ul
|
||||||
should be handled here. */
|
should be handled here. */
|
||||||
for( ;; );
|
for( ;; );
|
||||||
}
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
286
Demo/PIC32MX_MPLAB/printf-stdarg.c
Normal file
286
Demo/PIC32MX_MPLAB/printf-stdarg.c
Normal file
|
@ -0,0 +1,286 @@
|
||||||
|
/*
|
||||||
|
Copyright 2001, 2002 Georges Menie (www.menie.org)
|
||||||
|
stdarg version contributed by Christian Ettinger
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
putchar is the only external dependency for this file,
|
||||||
|
if you have a working putchar, leave it commented out.
|
||||||
|
If not, uncomment the define below and
|
||||||
|
replace outbyte(c) by your own function call.
|
||||||
|
|
||||||
|
#define putchar(c) outbyte(c)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
static void printchar(char **str, int c)
|
||||||
|
{
|
||||||
|
extern int putchar(int c);
|
||||||
|
|
||||||
|
if (str) {
|
||||||
|
**str = c;
|
||||||
|
++(*str);
|
||||||
|
}
|
||||||
|
else (void)putchar(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define PAD_RIGHT 1
|
||||||
|
#define PAD_ZERO 2
|
||||||
|
|
||||||
|
static int prints(char **out, const char *string, int width, int pad)
|
||||||
|
{
|
||||||
|
register int pc = 0, padchar = ' ';
|
||||||
|
|
||||||
|
if (width > 0) {
|
||||||
|
register int len = 0;
|
||||||
|
register const char *ptr;
|
||||||
|
for (ptr = string; *ptr; ++ptr) ++len;
|
||||||
|
if (len >= width) width = 0;
|
||||||
|
else width -= len;
|
||||||
|
if (pad & PAD_ZERO) padchar = '0';
|
||||||
|
}
|
||||||
|
if (!(pad & PAD_RIGHT)) {
|
||||||
|
for ( ; width > 0; --width) {
|
||||||
|
printchar (out, padchar);
|
||||||
|
++pc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for ( ; *string ; ++string) {
|
||||||
|
printchar (out, *string);
|
||||||
|
++pc;
|
||||||
|
}
|
||||||
|
for ( ; width > 0; --width) {
|
||||||
|
printchar (out, padchar);
|
||||||
|
++pc;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* the following should be enough for 32 bit int */
|
||||||
|
#define PRINT_BUF_LEN 12
|
||||||
|
|
||||||
|
static int printi(char **out, int i, int b, int sg, int width, int pad, int letbase)
|
||||||
|
{
|
||||||
|
char print_buf[PRINT_BUF_LEN];
|
||||||
|
register char *s;
|
||||||
|
register int t, neg = 0, pc = 0;
|
||||||
|
register unsigned int u = i;
|
||||||
|
|
||||||
|
if (i == 0) {
|
||||||
|
print_buf[0] = '0';
|
||||||
|
print_buf[1] = '\0';
|
||||||
|
return prints (out, print_buf, width, pad);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sg && b == 10 && i < 0) {
|
||||||
|
neg = 1;
|
||||||
|
u = -i;
|
||||||
|
}
|
||||||
|
|
||||||
|
s = print_buf + PRINT_BUF_LEN-1;
|
||||||
|
*s = '\0';
|
||||||
|
|
||||||
|
while (u) {
|
||||||
|
t = u % b;
|
||||||
|
if( t >= 10 )
|
||||||
|
t += letbase - '0' - 10;
|
||||||
|
*--s = t + '0';
|
||||||
|
u /= b;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (neg) {
|
||||||
|
if( width && (pad & PAD_ZERO) ) {
|
||||||
|
printchar (out, '-');
|
||||||
|
++pc;
|
||||||
|
--width;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
*--s = '-';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return pc + prints (out, s, width, pad);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int print( char **out, const char *format, va_list args )
|
||||||
|
{
|
||||||
|
register int width, pad;
|
||||||
|
register int pc = 0;
|
||||||
|
char scr[2];
|
||||||
|
|
||||||
|
for (; *format != 0; ++format) {
|
||||||
|
if (*format == '%') {
|
||||||
|
++format;
|
||||||
|
width = pad = 0;
|
||||||
|
if (*format == '\0') break;
|
||||||
|
if (*format == '%') goto out;
|
||||||
|
if (*format == '-') {
|
||||||
|
++format;
|
||||||
|
pad = PAD_RIGHT;
|
||||||
|
}
|
||||||
|
while (*format == '0') {
|
||||||
|
++format;
|
||||||
|
pad |= PAD_ZERO;
|
||||||
|
}
|
||||||
|
for ( ; *format >= '0' && *format <= '9'; ++format) {
|
||||||
|
width *= 10;
|
||||||
|
width += *format - '0';
|
||||||
|
}
|
||||||
|
if( *format == 's' ) {
|
||||||
|
register char *s = (char *)va_arg( args, int );
|
||||||
|
pc += prints (out, s?s:"(null)", width, pad);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if( *format == 'd' ) {
|
||||||
|
pc += printi (out, va_arg( args, int ), 10, 1, width, pad, 'a');
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if( *format == 'x' ) {
|
||||||
|
pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'a');
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if( *format == 'X' ) {
|
||||||
|
pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'A');
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if( *format == 'u' ) {
|
||||||
|
pc += printi (out, va_arg( args, int ), 10, 0, width, pad, 'a');
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if( *format == 'c' ) {
|
||||||
|
/* char are converted to int then pushed on the stack */
|
||||||
|
scr[0] = (char)va_arg( args, int );
|
||||||
|
scr[1] = '\0';
|
||||||
|
pc += prints (out, scr, width, pad);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
out:
|
||||||
|
printchar (out, *format);
|
||||||
|
++pc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (out) **out = '\0';
|
||||||
|
va_end( args );
|
||||||
|
return pc;
|
||||||
|
}
|
||||||
|
|
||||||
|
int printf(const char *format, ...)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
|
||||||
|
va_start( args, format );
|
||||||
|
return print( 0, format, args );
|
||||||
|
}
|
||||||
|
|
||||||
|
int sprintf(char *out, const char *format, ...)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
|
||||||
|
va_start( args, format );
|
||||||
|
return print( &out, format, args );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int snprintf( char *buf, unsigned int count, const char *format, ... )
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
|
||||||
|
( void ) count;
|
||||||
|
|
||||||
|
va_start( args, format );
|
||||||
|
return print( &buf, format, args );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef TEST_PRINTF
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
char *ptr = "Hello world!";
|
||||||
|
char *np = 0;
|
||||||
|
int i = 5;
|
||||||
|
unsigned int bs = sizeof(int)*8;
|
||||||
|
int mi;
|
||||||
|
char buf[80];
|
||||||
|
|
||||||
|
mi = (1 << (bs-1)) + 1;
|
||||||
|
printf("%s\n", ptr);
|
||||||
|
printf("printf test\n");
|
||||||
|
printf("%s is null pointer\n", np);
|
||||||
|
printf("%d = 5\n", i);
|
||||||
|
printf("%d = - max int\n", mi);
|
||||||
|
printf("char %c = 'a'\n", 'a');
|
||||||
|
printf("hex %x = ff\n", 0xff);
|
||||||
|
printf("hex %02x = 00\n", 0);
|
||||||
|
printf("signed %d = unsigned %u = hex %x\n", -3, -3, -3);
|
||||||
|
printf("%d %s(s)%", 0, "message");
|
||||||
|
printf("\n");
|
||||||
|
printf("%d %s(s) with %%\n", 0, "message");
|
||||||
|
sprintf(buf, "justif: \"%-10s\"\n", "left"); printf("%s", buf);
|
||||||
|
sprintf(buf, "justif: \"%10s\"\n", "right"); printf("%s", buf);
|
||||||
|
sprintf(buf, " 3: %04d zero padded\n", 3); printf("%s", buf);
|
||||||
|
sprintf(buf, " 3: %-4d left justif.\n", 3); printf("%s", buf);
|
||||||
|
sprintf(buf, " 3: %4d right justif.\n", 3); printf("%s", buf);
|
||||||
|
sprintf(buf, "-3: %04d zero padded\n", -3); printf("%s", buf);
|
||||||
|
sprintf(buf, "-3: %-4d left justif.\n", -3); printf("%s", buf);
|
||||||
|
sprintf(buf, "-3: %4d right justif.\n", -3); printf("%s", buf);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if you compile this file with
|
||||||
|
* gcc -Wall $(YOUR_C_OPTIONS) -DTEST_PRINTF -c printf.c
|
||||||
|
* you will get a normal warning:
|
||||||
|
* printf.c:214: warning: spurious trailing `%' in format
|
||||||
|
* this line is testing an invalid % at the end of the format string.
|
||||||
|
*
|
||||||
|
* this should display (on 32bit int machine) :
|
||||||
|
*
|
||||||
|
* Hello world!
|
||||||
|
* printf test
|
||||||
|
* (null) is null pointer
|
||||||
|
* 5 = 5
|
||||||
|
* -2147483647 = - max int
|
||||||
|
* char a = 'a'
|
||||||
|
* hex ff = ff
|
||||||
|
* hex 00 = 00
|
||||||
|
* signed -3 = unsigned 4294967293 = hex fffffffd
|
||||||
|
* 0 message(s)
|
||||||
|
* 0 message(s) with %
|
||||||
|
* justif: "left "
|
||||||
|
* justif: " right"
|
||||||
|
* 3: 0003 zero padded
|
||||||
|
* 3: 3 left justif.
|
||||||
|
* 3: 3 right justif.
|
||||||
|
* -3: -003 zero padded
|
||||||
|
* -3: -3 left justif.
|
||||||
|
* -3: -3 right justif.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* To keep linker happy. */
|
||||||
|
int write( int i, char* c, int n)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@
|
||||||
/* The maximum value the 16bit timer can contain. */
|
/* The maximum value the 16bit timer can contain. */
|
||||||
#define timerMAX_COUNT 0xffff
|
#define timerMAX_COUNT 0xffff
|
||||||
|
|
||||||
/* The timer 1 interrupt handler. */
|
/* The timer 2 interrupt handler. */
|
||||||
void __attribute__( (interrupt(ipl0), vector(_TIMER_2_VECTOR))) vT2InterruptWrapper( void );
|
void __attribute__( (interrupt(ipl0), vector(_TIMER_2_VECTOR))) vT2InterruptWrapper( void );
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
Loading…
Reference in a new issue