This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

BB-Black入门



1、中国版BB-Black硬件资源

2、BB-Black开发环境搭建

 

入门:http://beagleboard.org/Getting%20Started

CCS linux版本下载:http://processors.wiki.ti.com/index.php/Download_CCS

VMware Tools安装:

3、连接调试

方法一:使用SecrueCRT连接调试

1)      安装SecureCRT软件,SecureCRT是一款不错的工具,大家可以下载绿色版使用,或者按照下列的信息填写“许可向导”完成注册。

名字:Windows

公司:IC

序列号:03-50-006248

许可密钥:ADPUSB W3DQ5B ZC35EJ 99AG3T ACM47V SAK5W6 8CD1YZ GJU7JK

发布日期:27-06-2006

2)  打开后输入BB的地址192.168.7.2,协议选SSH2,前提是给BB上电并连接好网线

3)      输入用户名Root

4)      口令默认为空

5) 点击确定,就连接上BB-Black了,接下来就可以调试了

方法二:串口连接调试

BB-Black板卡上提供了调试串口,为了能在PC机上调试,我们需要一个RS232模块和一个串口线或一个USB转串口线。其中PIN1为GND,PIN4为RX,PIN5为TX,TTL转RS232模块的TTL端接BB-Black的调试串口,另一端与PC机相连。

2) 为了方便,我们还是基于上面使用的SecureCRT讲解,点击“连接”弹出连接对话框,点击“New Session”,然后选择Serial继续“下一步”,设置好端口和波特率,点击“下一步”、“完成”、“连接”。

 

3)给BB-Black上电就可以打印信息了。相关设置如下:

4、相关帖子链接

1)      虚拟机下Ubuntu10.04自带有gcc(http://www.deyisupport.com/question_answer/dsp_arm/omap_l1x/f/54/t/70303.aspx

2)      相关资料分享(http://www.deyisupport.com/question_answer/dsp_arm/sitara_arm/f/25/t/11199.aspx

3)      ti-sdk-am335x-evm-07.00.00.00-Linux-x86-Install.bin安装

http://www.deyisupport.com/question_answer/dsp_arm/sitara_arm/f/25/t/73468.aspx

  • Word版资料请查看附件。

    BB-Black入门.docx
  • Symbol for AM335x:

    http://www.ti.com/product/am3359#symbols

    Other Support Links

    For EVM schematic and PCB Layout.
    – Beaglebone http://beagleboard.org/hardware/design/
    – Beaglebone-Black http://beagleboard.org/Products/BeagleBone%20Black
    – GP EVM http://www.ti.com/tool/tmdxevm3358
    – StarterKit http://www.ti.com.cn/tool/cn/tmdssk3358

    Hardware Design Guide
    • Schematic & PCB layout checklist
    http://processors.wiki.ti.com/index.php/AM335x_Schematic_Checklist
    http://processors.wiki.ti.com/index.php/AM335x_Layout_Checklist
    • DDR2/3 design & layout guide
    – More detail in AM335x Datasheet.
    • Multiple options to choose Power management Chips based on Cost
    Feature requirements.
    http://processors.wiki.ti.com/index.php/Device:AM335x:Device_Evaluation#Power

    Power Solution for AM355x
    • We have provided power-consumption summary
    http://processors.wiki.ti.com/index.php/AM335x_Power_Consumption_Summary
    • Power Estimation Tool
    http://processors.wiki.ti.com/index.php/AM335x_Power_Estimation_Tool

    Hardware Migration Guide
    • AM37x to AM335x Hardware Migration Guide
    http://processors.wiki.ti.com/index.php/AM37x_To_AM335x_Hardware_Migration_Guide
    • AM35x to AM335x Hardware Migration Guide
    http://processors.wiki.ti.com/index.php/AM35x_To_AM335x_Hardware_Migration_Guide
    • AM18x to AM335x Hardware Migration Guide
    http://processors.wiki.ti.com/index.php/AM18x_To_AM335x_Hardware_Migration_Guide
    • AM387x to AM335x Hardware Migration Guide
    http://processors.wiki.ti.com/index.php/AM387x_To_AM335x_Hardware_Migration_Guide

     

  • RTC模块为设备提供一个长的记时模式。基本上是每秒一次。时间可以设定为 12 或 24 小时模式 。时间寄存器有缓冲区,不会因为更改设定值而影响记时的准确性。而且可以设置中断来响应CPU事件,在某一特定的时间间隔如每分钟或每天中断一次。可编程的记时周期等,
    对它的寄存器定义我们可以查看库的RTC.h头文件。

           使用RTC模块的步骤:
    1、 为 RTC 配置主系统时钟。如果需要,需要开启其端口的多路复用功能。
    2、RTC 寄存器一般是写保护的。若要禁用此写保护,编程 RTC 寄存器,必须写入一个特定值到KICK寄存器 (KICK0 和 KICK1)。要执行此操作可以使用 RTCWriteProtectDisable() 这个 API函数。
    3、调用 RTC32KClkSourceSelect() API 函数传递相应的参数,以选择使用内部时钟源或提供 32 KHz 时钟 的外部时钟源。我们的开发板就是外接的32K时钟,如下图所示


    4、调用 RTC32KClkClockControl() API函数传递适当的参数以使能 RTC选择从上一部选定的时钟源输入。
    5、调用 RTCEnable() 来启用 RTC模块。这可确保输入到 RTC 的 32 KHz 时钟有效。
    6、我们可以使用 RTCTimeSet() 函数来设定时间。我们要设定的时间作为一个参数传递给此函数。此函数设置有关寄存器如分钟、 小时、 AM 或 PM。也有 单独的API函数设置这些值。
    7、调用 RTCRun() 后应立即调用 API RTCTimeSet() 来启动时钟,这样可以减少误差。
    8、使用 RTCCalendarSet() 可以设置指定的日期信息。日期信息作为一个参数传递给此函数。此函数设置天、 月份和年份值。也有 Api 来单独设置这些值。
    9、可以通过调用 RTCTimeGet() 和 RTCCalendarGet() 从有关寄存器分别读取当前时间和日期信息。
    10、用户还可以使能在发生特定事件时产生中断。使用 RTCIntTimerEnable() 启用中断。中断事件可以是一秒、 分钟、 小时或一天。
    11、RTC模块也可以在它达到一定的时间或读取日期时生成中断。这些称为报警中断,如果想启用它们使用 RTCIntAlarmEnable() 函数将报警时间写入 RTC 的报警寄存器。


    从以上说明可见RTC模块的强大,完全可以作为一个全功能的时钟使用。

    下面这份例程运行时在串口要求用户输入时间和日期,并把他们写入RTC相关寄存器,然后就会在串口同步显示出当前日期信息

    1. #include "evmskAM335x.h"
    2. #include "soc_AM335x.h"
    3. #include "interrupt.h"
    4. #include "uartStdio.h"
    5. #include "cache.h"
    6. #include "rtc.h"
    7. #include "mmu.h"
    8. /*****************************************************************************
    9. **                 INTERNAL MACRO DEFINITIONS
    10. *****************************************************************************/
    11. #define MASK_HOUR               (0xFF000000u)
    12. #define MASK_MINUTE             (0x00FF0000u)
    13. #define MASK_SECOND             (0x0000FF00u)
    14. #define MASK_MERIDIEM           (0x000000FFu)
    15. #define HOUR_SHIFT              (24u)
    16. #define MINUTE_SHIFT            (16u)
    17. #define SECOND_SHIFT            (8u)
    18. #define MASK_DAY                (0xFF000000u)
    19. #define MASK_MONTH              (0x00FF0000u)
    20. #define MASK_YEAR               (0x0000FF00u)
    21. #define MASK_DOTW               (0x000000FFu)
    22. #define DAY_SHIFT               (24u)
    23. #define MONTH_SHIFT             (16u)
    24. #define YEAR_SHIFT              (8u)
    25. #define RTC_INST_BASE           (SOC_RTC_0_REGS)
    26. #define RTC_INT_NUM             (SYS_INT_RTCINT)
    27. /* Definitions related to MMU Configuration. */
    28. #define START_ADDR_DDR          (0x80000000u)
    29. #define START_ADDR_DEV          (0x44000000u)
    30. #define START_ADDR_OCMC         (0x40300000u)
    31. #define NUM_SECTIONS_DDR        (512u)
    32. #define NUM_SECTIONS_DEV        (960u)
    33. #define NUM_SECTIONS_OCMC       (1u)
    34. /******************************************************************************
    35. **                 INTERNAL FUNCTION PROTOTYPES
    36. ******************************************************************************/
    37. static void CalendarResolve(unsigned int calendarValue);
    38. static unsigned char ASCIIToInt(unsigned char byte);
    39. static unsigned int IntToASCII(unsigned char byte);
    40. static void TimeResolve(unsigned int timeValue);
    41. static unsigned int UserCalendarInfoGet(void);
    42. static unsigned int UserTimeInfoGet(void);
    43. static void MMUConfigAndEnable(void);
    44. static void RTCINTCConfigure(void);
    45. static void RTCIsr(void);
    46. /******************************************************************************
    47. **                 INTERNAL VARIABLE DEFINITIONS
    48. ******************************************************************************/
    49. /* Page tables start must be aligned in 16K boundary */
    50. #ifdef __TMS470__
    51. #pragma DATA_ALIGN(pageTable, MMU_PAGETABLE_ALIGN_SIZE);
    52. static volatile unsigned int pageTable[MMU_PAGETABLE_NUM_ENTRY];
    53. #elif defined(__IAR_SYSTEMS_ICC__)
    54. #pragma data_alignment=MMU_PAGETABLE_ALIGN_SIZE
    55. static volatile unsigned int pageTable[MMU_PAGETABLE_NUM_ENTRY];
    56. #elif defined(gcc)
    57. static volatile unsigned int pageTable[MMU_PAGETABLE_NUM_ENTRY]
    58. __attribute__((aligned(MMU_PAGETABLE_ALIGN_SIZE)));
    59. #else
    60. #error "Unsupported Compiler. \r\n"
    61. #endif
    62. /******************************************************************************
    63. **                 INTERNAL FUNCTION DEFINITIONS
    64. ******************************************************************************/
    65. /*
    66. ** This function will setup the MMU. The function maps three regions -
    67. ** 1. DDR
    68. ** 2. OCMC RAM
    69. ** 3. Device memory
    70. ** The function also enables the MMU.
    71. */
    72. static void MMUConfigAndEnable(void)
    73. {
    74.     /*
    75.     ** Define DDR memory region of AM335x. DDR can be configured as Normal
    76.     ** memory with R/W access in user/privileged modes. The cache attributes
    77.     ** specified here are,
    78.     ** Inner - Write through, No Write Allocate
    79.     ** Outer - Write Back, Write Allocate
    80.     */
    81.     REGION regionDdr = {
    82.                         MMU_PGTYPE_SECTION, START_ADDR_DDR, NUM_SECTIONS_DDR,
    83.                         MMU_MEMTYPE_NORMAL_NON_SHAREABLE(MMU_CACHE_WT_NOWA,
    84.                                                          MMU_CACHE_WB_WA),
    85.                         MMU_REGION_NON_SECURE, MMU_AP_PRV_RW_USR_RW,
    86.                         (unsigned int*)pageTable
    87.                        };
    88.     /*
    89.     ** Define OCMC RAM region of AM335x. Same Attributes of DDR region given.
    90.     */
    91.     REGION regionOcmc = {
    92.                          MMU_PGTYPE_SECTION, START_ADDR_OCMC, NUM_SECTIONS_OCMC,
    93.                          MMU_MEMTYPE_NORMAL_NON_SHAREABLE(MMU_CACHE_WT_NOWA,
    94.                                                           MMU_CACHE_WB_WA),
    95.                          MMU_REGION_NON_SECURE, MMU_AP_PRV_RW_USR_RW,
    96.                          (unsigned int*)pageTable
    97.                         };
    98.     /*
    99.     ** Define Device Memory Region. The region between OCMC and DDR is
    100.     ** configured as device memory, with R/W access in user/privileged modes.
    101.     ** Also, the region is marked 'Execute Never'.
    102.     */
    103.     REGION regionDev = {
    104.                         MMU_PGTYPE_SECTION, START_ADDR_DEV, NUM_SECTIONS_DEV,
    105.                         MMU_MEMTYPE_DEVICE_SHAREABLE,
    106.                         MMU_REGION_NON_SECURE,
    107.                         MMU_AP_PRV_RW_USR_RW  | MMU_SECTION_EXEC_NEVER,
    108.                         (unsigned int*)pageTable
    109.                        };
    110.     /* Initialize the page table and MMU */
    111.     MMUInit((unsigned int*)pageTable);
    112.     /* Map the defined regions */
    113.     MMUMemRegionMap(®ionDdr);
    114.     MMUMemRegionMap(®ionOcmc);
    115.     MMUMemRegionMap(®ionDev);
    116.     /* Now Safe to enable MMU */
    117.     MMUEnable((unsigned int*)pageTable);
    118. }
    119. /*
    120. ** Main function.
    121. */
    122. int main(void)
    123. {
    124.     unsigned int userCalendar = 0;
    125.     unsigned int userTime = 0;
    126.     /* Configure and enable the MMU. */
    127.     MMUConfigAndEnable();
    128.     /* Enable all levels of Cache. */
    129.     CacheEnable(CACHE_ALL);
    130.    
    131.     /* Configuring the UART STDIO instance. */
    132.     UARTStdioInit();
    133.     /* Performing the System Clock configuration for RTC. */
    134.     RTCModuleClkConfig();
    135.    
    136.     /* Disabling Write Protection for RTC registers.*/
    137.     RTCWriteProtectDisable(RTC_INST_BASE);
    138.     /* Selecting Internal Clock source for RTC. */
    139.     RTC32KClkSourceSelect(RTC_INST_BASE, RTC_INTERNAL_CLK_SRC_SELECT);
    140.     /* Enabling RTC to receive the Clock inputs. */
    141.     RTC32KClkClockControl(RTC_INST_BASE, RTC_32KCLK_ENABLE);
    142.     /* Enable the RTC module. */
    143.     RTCEnable(RTC_INST_BASE);
    144.     UARTPuts("StarterWare AM335x RTC Application.\r\n", -2);
    145.     /* Receiving Time related information from the user. */
    146.     userTime = UserTimeInfoGet();
    147.     /* Receiving Calendar related information from the user. */
    148.     userCalendar = UserCalendarInfoGet();
    149.    
    150.     /* Programming calendar information in the Calendar registers. */
    151.     RTCCalendarSet(RTC_INST_BASE, userCalendar);
    152.     /* Programming the time information in the Time registers. */
    153.     RTCTimeSet(RTC_INST_BASE, userTime);
    154.    
    155.     /* Set the 32KHz counter to run. */
    156.     RTCRun(RTC_INST_BASE);
    157.     UARTPuts("\r\n\r\n", -2);
    158.     UARTPuts("Current Time And Date:\r\n", -1);
    159.     /* Enabling IRQ in CPSR of ARM processor. */
    160.     IntMasterIRQEnable();
    161.     /* Configure the AINTC to receive RTC interrupts. */
    162.     RTCINTCConfigure();
    163.     /* Enabling RTC interrupts. Configuring RTC to interrupt every second.*/
    164.     RTCIntTimerEnable(RTC_INST_BASE, RTC_INT_EVERY_SECOND);
    165.     while(1);
    166. }
    167. /*
    168. ** This function receives time related information from the user.
    169. */
    170. static unsigned int UserTimeInfoGet()
    171. {
    172.     unsigned char minute[2] = {0};
    173.     unsigned char second[2] = {0};
    174.     unsigned char hour[2] = {0};
    175.     unsigned int hourTime = 0;
    176.     unsigned int minTime = 0;
    177.     unsigned int secTime = 0;
    178.     unsigned int lIndex = 0;
    179.     unsigned int time = 0;
    180.     UARTPuts("\nEnter the time in 24 hour format.\r\n", -1);
    181.     UARTPuts("Example (hh:mm:ss) 20:15:09\r\n", -1);
    182.     UARTPuts("\r\nEnter Hours: \r\n", -2);
    183.     /*
    184.     ** Collecting the 'Hour' information. The values collected shall be in
    185.     ** the ASCII form of the numbers entered.
    186.     */
    187.     do
    188.     {
    189.         hour[lIndex] = UARTGetc();
    190.         UARTPutc(hour[lIndex]);
    191.         lIndex++;
    192.     }while((lIndex < 2) && (hour[lIndex - 1] != '\r'));
    193.     UARTPuts("\r\nEnter Minutes:\r\n", -2);
    194.     lIndex = 0;
    195.     /*
    196.     ** Collecting the 'Minute' information. The values collected shall be in
    197.     ** the ASCII form of the numbers entered.
    198.     */
    199.     do
    200.     {
    201.         minute[lIndex] = UARTGetc();
    202.         UARTPutc(minute[lIndex]);
    203.         lIndex++;
    204.     }while((lIndex < 2) && (minute[lIndex - 1] != '\r'));
    205.     UARTPuts("\r\nEnter Seconds:\r\n", -1);
    206.     lIndex = 0;
    207.     /*
    208.     ** Collecting the 'Second' information. The values collected shall be in
    209.     ** the ASCII form of the numbers entered.
    210.     */
    211.     do
    212.     {
    213.         second[lIndex] = UARTGetc();
    214.         UARTPutc(second[lIndex]);
    215.         lIndex++;
    216.     }while((lIndex < 2) && (second[lIndex - 1] != '\r'));
    217.     /* Converting the ASCII value of 'Hours' to its equivalent decimal value. */
    218.     if(hour[0] != '\r')
    219.     {
    220.         hourTime = (ASCIIToInt(hour[0]) << 0x04);
    221.         if(hour[1] != '\r')
    222.         {
    223.             hourTime |= ASCIIToInt(hour[1]);
    224.         }
    225.         else
    226.         {
    227.             hourTime = hourTime >> 0x04;
    228.         }
    229.     }
    230.     /* Converting the ASCII value of 'Minutes' to its equivalent decimal value. */
    231.     if(minute[0] != '\r')
    232.     {
    233.         minTime = (ASCIIToInt(minute[0]) << 0x04);
    234.         if(minute[1] != '\r')
    235.         {
    236.             minTime |= ASCIIToInt(minute[1]);
    237.         }
    238.         else
    239.         {
    240.             minTime = minTime >> 0x04;
    241.         }
    242.     }
    243.     /* Converting the ASCII value of 'Seconds' to its equivalent decimal value. */
    244.     if(second[0] != '\r')
    245.     {
    246.         secTime = (ASCIIToInt(second[0]) << 0x04);
    247.         if(second[1] != '\r')
    248.         {
    249.             secTime |= ASCIIToInt(second[1]);
    250.         }
    251.         else
    252.         {
    253.             secTime = secTime >> 0x04;
    254.         }
    255.     }
    256.     /*
    257.     ** Consolidating the decimal values of Hours, Minutes and Seconds to
    258.     ** obtain the Time.
    259.     */
    260.     time = (hourTime << HOUR_SHIFT);
    261.     time |= (minTime << MINUTE_SHIFT);
    262.     time |= (secTime << SECOND_SHIFT);
    263.     return time;
    264. }
    265. /*
    266. ** This function receives calendar related information from the user.
    267. */
    268. static unsigned int UserCalendarInfoGet()
    269. {
    270.     unsigned char monthArr[2] = {0};
    271.     unsigned char yearArr[2] = {0};
    272.     unsigned char dotwArr[2] = {0};
    273.     unsigned char dayArr[2] = {0};
    274.     unsigned int calendar = 0;
    275.     unsigned int lIndex = 0;
    276.     unsigned int month = 0;
    277.     unsigned int year = 0;
    278.     unsigned int dotw = 0;
    279.     unsigned int day = 0;
    280.     UARTPuts("\r\n\r\nEnter the calendar information.\r\n", -2);
    281.     UARTPuts("Example (DD:MM:YY) 31:03:73\r\n", -2);
    282.    
    283.     UARTPuts("\r\nEnter the day of the month: \r\n", -2);
    284.    
    285.     /*
    286.     ** Collecting the 'Day of the Month' information. The values collected
    287.     ** shall be in the ASCII form of the numbers entered.
    288.     */
    289.     do
    290.     {
    291.         dayArr[lIndex] = UARTGetc();
    292.         UARTPutc(dayArr[lIndex]);
    293.         lIndex++;
    294.     }while((lIndex < 2) && (dayArr[lIndex - 1] != '\r'));
    295.     UARTPuts("\r\nEnter the month (Jan=01, Dec=12):\r\n", -2);
    296.     lIndex = 0;
    297.     /*
    298.     ** Collecting the 'Month' information. The values collected
    299.     ** shall be in the ASCII form of the numbers entered.
    300.     */
    301.     do
    302.     {
    303.         monthArr[lIndex] = UARTGetc();
    304.         UARTPutc(monthArr[lIndex]);
    305.         lIndex++;        
    306.     }while((lIndex < 2) && (monthArr[lIndex - 1] != '\r'));
    307.     UARTPuts("\r\nEnter the year (Ex: 2010=10, 1987=87:):\r\n", -1);
    308.     lIndex = 0;
    309.     /*
    310.     ** Collecting the 'Year' information. The values collected
    311.     ** shall be in the ASCII form of the numbers entered.
    312.     */
    313.     do
    314.     {
    315.         yearArr[lIndex] = UARTGetc();
    316.         UARTPutc(yearArr[lIndex]);
    317.         lIndex++;
    318.     }while((lIndex < 2) && (yearArr[lIndex - 1] != '\r'));
    319.     UARTPuts("\r\nEnter the Day of the Week (Ex:Sun=00, Sat=06):\r\n", -3);
    320.     lIndex = 0;
    321.     /*
    322.     ** Collecting the 'Day of the Week' information. The values collected
    323.     ** shall be in the ASCII form of the numbers entered.
    324.     */
    325.     do
    326.     {
    327.         dotwArr[lIndex] = UARTGetc();
    328.         UARTPutc(dotwArr[lIndex]);
    329.         lIndex++;
    330.     }while((lIndex < 2) && (dotwArr[lIndex - 1] != '\r'));
    331.     /*
    332.     ** Converting the ASCII value of 'Day of the Month' to its equivalent
    333.     ** decimal value.
    334.     */
    335.     if(dayArr[0] != '\r')
    336.     {
    337.         day = (ASCIIToInt(dayArr[0]) << 0x04);
    338.         if(dayArr[1] != '\r')
    339.         {
    340.             day |= ASCIIToInt(dayArr[1]);
    341.         }
    342.         else
    343.         {
    344.             day = day  >> 0x04;
    345.         }
    346.     }
    347.     /* Converting the ASCII value of 'Month' to its equivalent decimal value. */
    348.     if(monthArr[0] != '\r')
    349.     {
    350.         month = (ASCIIToInt(monthArr[0]) << 0x04);
    351.         if(monthArr[1] != '\r')
    352.         {
    353.             month |= ASCIIToInt(monthArr[1]);
    354.         }
    355.         else
    356.         {
    357.             month = month >> 0x04;
    358.         }
    359.     }
    360.     /* Converting the ASCII value of 'Year' to its equivalent decimal value. */
    361.     if(yearArr[0] != '\r')
    362.     {
    363.         year = (ASCIIToInt(yearArr[0]) << 0x04);
    364.         if(yearArr[1] != '\r')
    365.         {
    366.             year |= ASCIIToInt(yearArr[1]);
    367.         }
    368.         else
    369.         {
    370.             year = year >> 0x04;
    371.         }
    372.     }
    373.     /*
    374.     ** Converting the ASCII value of 'Day of the Week' to its equivalent
    375.     ** decimal value.
    376.     */
    377.     if(dotwArr[0] != '\r')
    378.     {
    379.         dotw = (ASCIIToInt(dotwArr[0]) << 0x04);
    380.         if(dotwArr[1] != '\r')
    381.         {
    382.             dotw |= ASCIIToInt(dotwArr[1]);
    383.         }
    384.         else
    385.         {
    386.             dotw = dotw >> 0x04;
    387.         }
    388.     }
    389.     /*
    390.     ** Consolidating the decimal values of Day of the Month, Month, Year
    391.     ** and Day of the Week to obtain the Date.
    392.     */
    393.     calendar =  day << DAY_SHIFT;     
    394.     calendar |= month << MONTH_SHIFT;
    395.     calendar |= year << YEAR_SHIFT;
    396.     calendar |= dotw;
    397.     return calendar;
    398. }  
    399. /*
    400. ** This function prints the current time read from the RTC registers.
    401. */
    402. static void TimeResolve(unsigned int timeValue)
    403. {
    404.     unsigned char timeArray[3] = {0};              
    405.     unsigned char bytePrint[2] = {0};
    406.     unsigned int asciiTime = 0;
    407.     unsigned int lIndex = 0;
    408.     unsigned int count = 0;
    409.    
    410.     /*
    411.     ** The variable 'timeValue' will have the time in the format
    412.     ** . Now, obtaining the individual fields
          ** to facilitate their display.
    413.     */
    414.     timeArray[0] = (unsigned char)((timeValue & MASK_HOUR) >> HOUR_SHIFT);
    415.     timeArray[1] = (unsigned char)((timeValue & MASK_MINUTE) >> MINUTE_SHIFT);
    416.     timeArray[2] = (unsigned char)((timeValue & MASK_SECOND) >> SECOND_SHIFT);
    417.     /* Prints the time in the format: . */
          while(count < 3)
    418.     {
    419.         lIndex = 0;
    420.         asciiTime = IntToASCII(timeArray[count]);
    421.         bytePrint[0] = (unsigned char)((asciiTime & 0x0000FF00) >> 0x08);
    422.         bytePrint[1] = (unsigned char)(asciiTime & 0x000000FF);
    423.         while(lIndex < 2)
    424.         {   
    425.             UARTPutc(bytePrint[lIndex]);
    426.             lIndex++;
    427.         }
    428.         count++;
    429.         if(count != 3)
    430.         {
    431.             UARTPutc(':');
    432.         }
    433.         else
    434.         {
    435.             UARTPutc(' ');
    436.         }
    437.     }
    438. }
    439. /*
    440. ** This function prints the calendar information read from the RTC registers.
    441. */
    442. static void CalendarResolve(unsigned int calendarValue)
    443. {
    444.     unsigned char calendarArray[3] = {0};
    445.     unsigned char dotwString[4] = {0};
    446.     unsigned char bytePrint[2] = {0};
    447.     unsigned int asciiCalendar = 0;
    448.     unsigned int dotwValue = 0;
    449.     unsigned int lIndex = 0;
    450.     unsigned int count = 0;
    451.     /*
    452.     ** The variable 'calendarValue' will have the date in the format
    453.     ** . Now, obtaining the individual fields
          ** to facilitate their display.
    454.     */
    455.     calendarArray[0] = (unsigned char)((calendarValue & MASK_DAY) >> DAY_SHIFT);
    456.     calendarArray[1] = (unsigned char)((calendarValue & MASK_MONTH) >> MONTH_SHIFT);
    457.     calendarArray[2] = (unsigned char)((calendarValue & MASK_YEAR) >> YEAR_SHIFT);
    458.     dotwValue = (calendarValue & MASK_DOTW);
    459.     switch(dotwValue)
    460.     {
    461.         case 0x00:
    462.              dotwString[0] = 'S';
    463.              dotwString[1] = 'u';
    464.              dotwString[2] = 'n';
    465.              dotwString[3] = '\0';
    466.         break;
    467.         case 0x01:
    468.              dotwString[0] = 'M';
    469.              dotwString[1] = 'o';
    470.              dotwString[2] = 'n';
    471.              dotwString[3] = '\0';
    472.         break;
    473.         case 0x02:
    474.              dotwString[0] = 'T';
    475.              dotwString[1] = 'u';
    476.              dotwString[2] = 'e';
    477.              dotwString[3] = '\0';
    478.         break;
    479.         case 0x03:
    480.              dotwString[0] = 'W';
    481.              dotwString[1] = 'e';
    482.              dotwString[2] = 'd';
    483.              dotwString[3] = '\0';
    484.         break;
    485.         case 0x04:
    486.              dotwString[0] = 'T';
    487.              dotwString[1] = 'h';
    488.              dotwString[2] = 'u';
    489.              dotwString[3] = '\0';
    490.         break;
    491.         case 0x05:
    492.              dotwString[0] = 'F';
    493.              dotwString[1] = 'r';
    494.              dotwString[2] = 'i';
    495.              dotwString[3] = '\0';
    496.         break;
    497.         case 0x06:
    498.              dotwString[0] = 'S';
    499.              dotwString[1] = 'a';
    500.              dotwString[2] = 't';
    501.              dotwString[3] = '\0';
    502.         default:
    503.         break;
    504.     }
    505.    
    506.     /* Prints the date in the format: . */
          while(count < 3)
    507.     {
    508.         lIndex = 0;
    509.         asciiCalendar = IntToASCII(calendarArray[count]);
    510.         bytePrint[0] = (unsigned char)((asciiCalendar & 0x0000FF00) >> 0x08);
    511.         bytePrint[1] = (unsigned char)(asciiCalendar & 0x000000FF);
    512.         while(lIndex < 2)
    513.         {
    514.             UARTPutc(bytePrint[lIndex]);
    515.             lIndex++;
    516.         }
    517.         count++;
    518.         if(count != 3)
    519.         {
    520.             UARTPutc('-');
    521.         }
    522.         else
    523.         {
    524.             UARTPutc(' ');
    525.         }
    526.     }  
    527.     UARTPuts((char *)dotwString, -2);
    528. }
    529. /*
    530. ** This function converts the nibbles of an 8-bit number to their ASCII
    531. ** equivalent value. The 8-bit number is passed as a parameter to this
    532. ** function.
    533. ** For Example, if a number 19 is given to this function, this function
    534. ** returns 0x3139. Here, 0x31 is the ASCII value of 1 and 0x39 is the
    535. ** ASCII value of 9.
    536. */
    537. static unsigned int IntToASCII(unsigned char byte)
    538. {
    539.     unsigned char highNibble = 0;
    540.     unsigned char lowNibble = 0;
    541.     unsigned int retVal = 0;
    542.     lowNibble = (byte & 0x0F);
    543.     highNibble = (byte & 0xF0) >> 0x04;
    544.     retVal = (lowNibble + 0x30);
    545.     retVal |= ((highNibble + 0x30) << 0x08);
    546.     return retVal;
    547. }
    548. /*
    549. ** This function converts the ASCII value of a hexadecimal number to its
    550. ** corresponding hexadecimal value.
    551. */
    552. static unsigned char ASCIIToInt(unsigned char byte)
    553. {
    554.     unsigned char retVal = 0;
    555.     /* For numbers from 0x0 to 0x9.*/
    556.     if((byte >= 0x30) && (byte <= 0x39))
    557.     {
    558.         retVal = byte - 0x30;
    559.     }
    560.     /* For alphabets from A to F.*/
    561.     else if((byte >= 0x41) && (byte <= 0x46))
    562.     {
    563.         retVal = byte - 0x37;
    564.     }
    565.    
    566.     return retVal;
    567. }
    568. /*
    569. ** This function configures the Interrupt Controller(INTC) to receive
    570. ** RTC interrupts.
    571. */
    572. static void RTCINTCConfigure(void)
    573. {
    574.     /* Initializing the ARM Interrupt Controller. */
    575.     IntAINTCInit();
    576.     /* Registering the Interrupt Service Routine(ISR). */
    577.     IntRegister(RTC_INT_NUM, RTCIsr);
    578.     /* Setting the priority for the system interrupt in AINTC. */
    579.     IntPrioritySet(RTC_INT_NUM, 0, AINTC_HOSTINT_ROUTE_IRQ);
    580.     /* Enabling the system interrupt in AINTC. */
    581.     IntSystemEnable(RTC_INT_NUM);   
    582. }
    583. /*
    584. ** This is the Interrupt Service Routine(ISR) for RTC.
    585. */
    586. static void RTCIsr(void)
    587. {
    588.     unsigned int calendarValue = 0;   
    589.     unsigned int timeValue = 0;
    590.         
    591.     /* Read the current time from RTC time registers. */
    592.     timeValue = RTCTimeGet(RTC_INST_BASE);
    593.     /* Decode the time in 'timeValue' and display it on console.*/
    594.     TimeResolve(timeValue);
    595.     /* Read the current date from the RTC calendar registers. */
    596.     calendarValue = RTCCalendarGet(RTC_INST_BASE);
    597.    
    598.     UARTPuts("   ", -2);
    599.     /* Decode  the date in 'calendarValue' and display it on console.*/
    600.     CalendarResolve(calendarValue);
    601.     UARTPuts("\r", -2);   
    602. }