Advertisement
Guest User

RDS on R0

a guest
Sep 25th, 2012
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.35 KB | None | 0 0
  1. *** THIS IS THE WAY USING KERNEL'S IRQ CALLBACK ***
  2.  
  3. #ifdef HAVE_RDS_CAP
  4.  
  5. /* Low-level RDS Support */
  6. static struct semaphore rds_sema;
  7. static uint32_t rds_stack[DEFAULT_STACK_SIZE / sizeof(uint32_t)];
  8.  
  9. static void rds_callback(void) {
  10.    semaphore_release(&rds_sema); // called when gpio falls to LOW...for 5 ms!
  11. }
  12.  
  13. /* Captures RDS data and processes it */
  14. static void NORETURN_ATTR rds_thread(void)
  15. {
  16.    uint16_t rds_data[4];
  17.    
  18.    while (true)
  19.    {
  20.        semaphore_wait(&rds_sema, TIMEOUT_BLOCK);
  21.        if (si4700_rds_read_raw(rds_data) && rds_process(rds_data))
  22.            si4700_rds_set_event();
  23.       // usleep(10); //need that otherwise it's unstable
  24.     }
  25. }
  26.  
  27. /* true after full radio power up, and false before powering down */
  28. void si4700_rds_powerup(bool on)
  29. {
  30.     (void)on;
  31.     /*
  32.     if(on)
  33.     {
  34.         gpio_control(DEV_CTRL_GPIO_SET_MUX, GPIO_FM_SEARCH, CONFIG_GPIO, CONFIG_GPIO);
  35.         gpio_control(DEV_CTRL_GPIO_SET_TYPE, GPIO_FM_SEARCH, CONFIG_GPIO, CONFIG_GPIO);
  36.         gpio_control(DEV_CTRL_GPIO_SET_INPUT, GPIO_FM_SEARCH, CONFIG_GPIO, CONFIG_GPIO);
  37.         gpio_control(DEV_CTRL_GPIO_SET_HIGH, GPIO_FM_SEARCH, CONFIG_GPIO, CONFIG_GPIO);
  38.     }
  39.     else
  40.     {
  41.         gpio_control(DEV_CTRL_GPIO_UNSET_MUX, GPIO_FM_SEARCH, CONFIG_GPIO, CONFIG_GPIO);
  42.     }
  43.     */
  44. }
  45.  
  46. /* One-time RDS init at startup */
  47. void si4700_rds_init(void)
  48. {
  49.     rds_init();
  50.     semaphore_init(&rds_sema, 1, 0);
  51.     create_thread(rds_thread, rds_stack, sizeof(rds_stack), 0, "rds"
  52.         IF_PRIO(, PRIORITY_REALTIME) IF_COP(, CPU));
  53.     sSi4709_irq_addr_t r = { .addr = &rds_callback };
  54.     //TODO: cleanup this...
  55.     radiodev_open();
  56.     ioctl(radio_dev, IOCTL_SI4709_IRQ_CALLBACK, &r);
  57.     radiodev_close();
  58.  
  59. }
  60. #endif /* HAVE_RDS_CAP */
  61.  
  62. *** END ***
  63.  
  64. *** START OF ANOTHER ATTEMPT: this time reading chip's registers ***
  65. WARNING: shitty-quicktesty code!!!! ;)
  66.  
  67. #ifdef HAVE_RDS_CAP
  68.  
  69. /* Low-level RDS Support */
  70. //static struct semaphore rds_sema;
  71. static uint32_t rds_stack[DEFAULT_STACK_SIZE / sizeof(uint32_t)];
  72. static bool rds_poll_enabled = false;
  73.  
  74. static void rds_callback(void) {
  75.    //semaphore_release(&rds_sema);
  76. }
  77. #define STATUSRSSI  0xA
  78. #define STATUSRSSI_RDSR     (0x1 << 15) /* x */
  79. /* Captures RDS data and processes it */
  80. static void NORETURN_ATTR rds_thread(void)
  81. {
  82.    uint16_t rds_data[4];
  83.    struct si4700_dbg_info nfo;
  84.    
  85.    while (true)
  86.    {
  87.        if (rds_poll_enabled) {
  88.            si4700_dbg_info(&nfo);
  89. //            printf("%i\n", nfo.regs[STATUSRSSI_RDSR]);
  90.            if ((nfo.regs[STATUSRSSI] & STATUSRSSI_RDSR) >> 8) { //if a RDS packet has been received
  91.                if (si4700_rds_read_raw(rds_data) && rds_process(rds_data))
  92.                    si4700_rds_set_event();
  93.            }
  94.        }
  95.        sleep(1);
  96.    }
  97. }
  98.  
  99. /* true after full radio power up, and false before powering down */
  100. void si4700_rds_powerup(bool on)
  101. {
  102.    rds_poll_enabled = on;
  103. }
  104.  
  105. /* One-time RDS init at startup */
  106. void si4700_rds_init(void)
  107. {
  108.    rds_init();
  109.    create_thread(rds_thread, rds_stack, sizeof(rds_stack), 0, "rds"
  110.        IF_PRIO(, PRIORITY_REALTIME) IF_COP(, CPU));
  111.    sSi4709_irq_addr_t r = { .addr = &rds_callback };
  112.    //TODO: cleanup this...
  113.    radiodev_open();
  114.    ioctl(radio_dev, IOCTL_SI4709_IRQ_CALLBACK, &r);
  115.    radiodev_close();
  116.  
  117. }
  118. #endif /* HAVE_RDS_CAP */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement