328 | | |
329 | | |
330 | | |
| 328 | '''Allocating Memory''' |
| 329 | |
| 330 | Create a buffer of Desired WIDTH and HEIGHT. |
| 331 | Use Bufmalloc from that buffer. |
| 332 | Also free into that buffer. |
| 333 | |
| 334 | ''Tips '' |
| 335 | |
| 336 | 1) Ensure that for every allocation, there |
| 337 | is a corresponding free. |
| 338 | |
| 339 | 2) If the WIDTH and HEIGHT values are too |
| 340 | high, their will be a compilation error !! |
| 341 | |
| 342 | 3) Every time we do a malloc, capture |
| 343 | the Status Message returned and print |
| 344 | it out. |
| 345 | |
| 346 | Some useful ''code snippet'' for the above: |
| 347 | |
| 348 | #define BUFWIDTH 45 |
| 349 | #define BUFHEIGHT 2096 |
| 350 | static membuf_t mbuft; |
| 351 | char membuf[BUFWIDTH][BUFHEIGHT] __attribute__ ((aligned(4))); |
332 | | |
| 353 | ''Creating the Buffer'' |
| 354 | |
| 355 | int var; |
| 356 | var = bufcreate (&mbuft, membuf, BUFWIDTH, BUFHEIGHT); |
| 357 | if (var == -1){ |
| 358 | xil_printf ("Error while creating memory pool. Errno: %d.\r\r\n", errno); |
| 359 | ; |
| 360 | } |
| 361 | |
| 362 | ''Destroying the Buffer'' |
| 363 | |
| 364 | bufdestroy (mbuft); |
| 365 | |
| 366 | ''Allocation Example and Capturing'' |
| 367 | |
| 368 | data = (unsigned char*)bufmalloc(mbuft,sizeof(char) * (data length)); |
| 369 | if (data == 0) { |
| 370 | xil_printf ("Error allocating Errno: %d.\r\n", errno); |
| 371 | ; |
| 372 | } |
| 373 | |
| 374 | ''Deallocation'' : Again using mbuft |
| 375 | |
| 376 | buffree(mbuft,data); |
| 377 | |
| 378 | |
| 379 | '''Printing out stuff on the Terminal''' |
| 380 | |
| 381 | We can use any terminal display for that. |
| 382 | |
| 383 | 1) Ensure it is connected to the the right Serial Port. |
| 384 | (COMM1 / COMM2) |
| 385 | |
| 386 | 2) Use the baud rate of 57600, else you will |
| 387 | see SYMBOLS instead of alphanumerics |
| 388 | |
| 389 | 3) Making LOGS: When priting out huge stuff, |
| 390 | use File->Log of the Terminal. You can pause |
| 391 | the logging process in between. |
| 392 | |
| 393 | 4) use xil_printf(), it has the same parameters |
| 394 | %d %x %c etc like printf. For NEWLINE, use both |
| 395 | \r\n. |
| 396 | |
| 397 | |
| 398 | '''Using Buttons on the Board''' for triggering Interrupt, |
| 399 | sp that we can see things .. |
| 400 | |
| 401 | B3 |
| 402 | B2 B1 B5 |
| 403 | B4 |
| 404 | |
| 405 | see the code of pb_handler() |
| 406 | |
| 407 | |
| 408 | |
| 409 | |
| 410 | |