Anda di halaman 1dari 9

FUNCII C IMPORTANTE I EXEMPLE

LUCRUL CU UART!!! (DSP RELATED)


1. Hi look into the \VisualDSP 4.0\Blackfin\EZ-KITs\ADSP-BF561\Examples\UART RS-232 HyperTerminal session\Core A\ directory of your VisualDSP instalation. there is the UART_Library.c its the asm code portet to c you need the funktions: UART_init, UART_waitForTransferCompletion, UART_putc, UART_puts, Calculate your divisor which: BAUD RATE = SCLK/(16 x Divisor) so eg for SCLK 118.8 Mhz and a wonted baud rate of 115200 you need a divisor of 64 UART_init(64); UART_puts("helo world"); tada and dont forget that you need a 1:1 cable not a crossed nullmodem one beetween the bord and the pc dennis calculate your divisor which the formula

2.

Try digging thru here: http://cvs.sourceforge.jp/cgibin/viewcvs.cgi/toppersjsp4bf/blackfin/bf533/uart.c Also try "uart bf533" on google.

VIDEO
Look at the training video : Rapid Development of a Blackfin-based Video Application (May 2006) http://www.demosondemand.com/clients/analogdevices/001/page/

FOPEN Synopsis #include <stdio.h> FILE *fopen(const char *filename, const char *mode); Description 1
DSP

The fopen function initializes the data structures that are required for reading or writing to a file. The files name is identified by filename, with the access type required specified by the string mode. Valid selections for mode are specified below. If any other mode specification is selected then the behavior is undefined. mode r Selection Open text file for reading. This operation fails if the file has not previously been created. Open text file for writing. If the filename already exists then it will be truncated to zero length with the write starting at the beginning of the file. If the file does not already exist then it is created. Open a text file for appending data. All data will be written to the end of the file specified. As r with the exception that the file can also be written to. As w with the exception that the file can also be read from. As a with the exception that the file can also be read from any position within the file. Data is only written to the end of the file. As r with the exception that the file is opened in binary mode. As w with the exception that the file is opened in binary mode. As a with the exception that the file is opened in binary mode. Open file in binary mode for both reading and writing.

a r+ w+ a+ rb wb ab r+b/rb+

w+b/wb+ Create or truncate to zero length a file for both reading and writing. a+b/ab+ As a+ with the exception that the file is opened in binary mode.

If the call to the fopen function is successful a pointer to the object controlling the stream is returned. Error Conditions If the fopen function is not successful a NULL pointer is returned. Example #include <stdio.h>

FILE *open_output_file(void) 2
DSP

{ /* Open file for writing as binary */ FILE *handle = fopen("output.dat", "wb"); return handle; }

FSCANF #include <stdio.h> int fscanf(FILE *stream, const char *format, /* args */ ...); Description The fscanf function reads from the input file stream, interprets the inputs according to format and stores the results of the conversions (if any) in its arguments. The format is a string containing the control format for the input with the following arguments being pointers to the locations where the converted results are to be written to. The string pointed to by format specifies how the input is to be parsed and, possibly, converted. It may consist of whitespace characters, ordinary characters (apart from the % character), and conversion specifications. A sequence of whitespace characters causes fscanf to continue to parse the input until either there is no more input or until it find a non-whitespace character. If the format specification contains a sequence of ordinary characters, then fscanf will continue to read the next characters in the input stream until the input data does not match the sequence of characters in the format. At this point fscanf will fail, and the differing and subsequent characters in the input stream will not be read. The % character in the format string introduces a conversion specification. A conversion specification has the following form: % [*] [width] [length] type A conversion specification always starts with the % character. It may optionally be followed by an asterisk (*) character, which indicates that the result of the conversion is not to be saved. In this context the asterisk character is known as the assignment-suppressing character. The optional token width represents a non-zero decimal number and specifies the maximum field width. The fscanf function will not read any more than width characters while performing the conversion specified by type.

DSP

The length token can be used to define a length modifier. The length modifier can be used to specify the size of the argument. The length modifiers should only precede one of the d, e, f, g, i, o, u, x or n conversion specifiers unless other conversion specifiers are detailed. Length h hh j l ll L t z Action The argument should be interpreted as a short int. The argument should be interpreted as a char. The argument should be interpreted as intmax_t or uintmax_t. The argument should be interpreted as a long int. The argument should be interpreted as a long long int. The argument should be interpreted as a long double argument. This length modifier should precede one of the a, A, e, E, f, F, g, or G conversion specifiers. The argument should be interpreted as ptrdiff_t. The argument should be interpreted as size_t.

Note that the hh, j, t and z size specifiers, as described in the C99 (ISO/IEC 9899:1999) standard, are only available if the -full-io option has been selected. A conversion specification terminates with a conversion specifier that defines how the input data is to be converted. The valid conversion specifiers can be found in the following table. Specifier aAeEfF gG c d i n o p s u xX Conversion floating point, optionally preceded by a sign and optionally followed by an e or E character single character, including whitespace signed decimal integer with optional sign signed integer with optional sign No input is consumed. The number of characters read so far will be written to the corresponding argument. This specifier does not affect the function result returned by fscanf unsigned octal pointer to void string of characters up to a whitespace character unsigned decimal integer hexadecimal integer with optional sign 4
DSP

[ %

a non-empty sequence of characters referred to as the scanset a single % character with no conversion or assignment

The [ conversion specifier should be followed by a sequence of characters, referred to as the scanset, with a terminating ] character and so will take the form [scanset]. The conversion specifier copies into an array, which is the corresponding argument, until a character that does not match any of the scanset is read. If the scanset begins with a ^ character, then the scanning will match against characters not defined in the scanset. If the scanset is to include the ] character, then this character must immediately follow the [ character or the ^ character (if specified). Each input item is converted to a type appropriate to the conversion character, as specified in the table above. The result of the conversion is placed into the object pointed to by the next argument that has not already been the recipient of a conversion. If the suppression character has been specified then no data shall be placed into the object with the next conversion using the object to store its result. The fscanf function returns the number of items successfully read. Error Conditions If the fscanf function is not successful before any conversion then EOF is returned. Example #include <stdio.h>

void fscanf_example(FILE *fp) { short int day, month, year; float f1, f2, f3; char string[20];

/* Scan a date with any separator, eg, 1-1-2006 or 1/1/2006 */ fscanf (fp, "%hd%*c%hd%*c%hd", &day, &month, &year);

/* Scan float values separated by "abc", for example 5


DSP

1.234e+6abc1.234abc235.06abc

*/

fscanf (fp, "%fabc%gabc%eabc", &f1, &f2, &f3);

/* For input "alphabet", string will contain "a" */ fscanf (fp, "%[aeiou]", string);

/* For input "drying", string will contain "dry" */ fscanf (fp, "%[^aeiou]", string); }

EXEMPLE GETTING STARTED!!! /* * Getting Started With the ADSP-BF537 EZ-KIT Lite * Part 1, Exercise 3 */ #include <stdlib.h> #include <stdio.h> #include <ccblkfn.h> #include <cdefbf537.h> #include <sysreg.h> #include <time.h> #include <services/adi_pwr.h> #define NUM_ITERATIONS 50000 #define ARRAY_LENGTH 128 /* Helper function to enable the real-time clock and reset it to time "zero" */ #define WAIT_FOR_RTC_WRITE_COMPLETE() { while ( ! ( *pRTC_ISTAT & 0x8000 ) ); } void start_real_time_clock () { if ( !*pRTC_PREN ) { *pRTC_PREN = 1; 6
DSP

WAIT_FOR_RTC_WRITE_COMPLETE(); } *pRTC_STAT = 0; WAIT_FOR_RTC_WRITE_COMPLETE(); } /* Helper function to get the number of seconds since zero time. * Only works up to one hour of time. */ unsigned int get_real_time_clock_in_seconds () { unsigned int clock = *pRTC_STAT; /* seconds */ unsigned int seconds = ( clock & 0x3f ); /* minutes */ seconds += 60 * ( ( clock & 0xfc0 ) >> 6 ); return seconds; } /* Initialize two arrays to the same set of random values */ void randomize_arrays ( int *v1, int *v2, unsigned int length ) { unsigned int i; for ( i = 0; i < length; ++i ) { v1[ i ] = v2[ i ] = rand () % 1024; } } /* A standard bubble sort algorithm, O(n^2) */ void bubble_sort ( int *v, unsigned int length ) { unsigned int i, j; for ( i = 0; i < length - 1; ++i ) { for ( j = i + 1; j < length; ++j ) { if ( v[ i ] > v[ j ] ) { int temp = v[ i ]; v[ i ] = v[ j ]; v[ j ] = temp; } } } 7
DSP

} /* A standard quick sort algorithm, O(n*log(n)) */ void quick_sort ( int *v, unsigned int p, unsigned int r ) { if ( p < r ) { unsigned int x, i, j, q; x = v[ p ]; i = p - 1; j = r + 1; for ( ;; ) { do { --j; } while ( v[ j ] > x ); do { ++i; } while ( v[ i ] < x ); if ( i < j ) { int temp = v[ i ]; v[ i ] = v[ j ]; v[ j ] = temp; } else { q = j; break; } } quick_sort ( v, p, q ); quick_sort ( v, q + 1, r ); } } int out_b[ ARRAY_LENGTH ]; int out_m[ ARRAY_LENGTH ]; ADI_PWR_COMMAND_PAIR ezkit_init[] = { /*600Mhz ADSP-BF537 EZ-KIT Lite */ {ADI_PWR_CMD_SET_EZKIT, (void*)ADI_PWR_EZKIT_BF537_600MHZ}, /* command to terminate the table */ {ADI_PWR_CMD_END,0 } }; typedef struct { ADI_PWR_VLEV v; 8
DSP

const char *n; } voltage_levels_type; voltage_levels_type voltage_levels[] = { { ADI_PWR_VLEV_085, "0.85" }, { ADI_PWR_VLEV_095, "0.95" }, { ADI_PWR_VLEV_105, "1.05" }, { ADI_PWR_VLEV_125, "1.25" }, }; void main () { unsigned long long cycles_begin, cycles_end; unsigned long seconds_begin, seconds_end; unsigned long display_cycles_end; volatile unsigned int time_end; int i, v; adi_pwr_Init(ezkit_init); srand ( 22 ); printf("%20s%20s%20s\n","Voltage","Seconds","Cycles (x 1m)"); for ( v = 0; v < sizeof ( voltage_levels ) / sizeof ( voltage_levels_type ); ++v ) { adi_pwr_SetMaxFreqForVolt ( voltage_levels[ v ].v ); start_real_time_clock (); cycles_begin = clock (); for ( i = 0; i < NUM_ITERATIONS; ++i ) { randomize_arrays ( out_b, out_m, ARRAY_LENGTH ); bubble_sort ( out_b, ARRAY_LENGTH ); quick_sort ( out_m, 0, ARRAY_LENGTH - 1 ); } cycles_end = clock () - cycles_begin; display_cycles_end = (unsigned long)(cycles_end / 1000000); time_end = get_real_time_clock_in_seconds (); printf ( "%20s%20u%20u\n", voltage_levels[ v ].n, time_end, display_cycles_end ); } }

DSP

Anda mungkin juga menyukai