@@ -33,6 +33,9 @@ LOG_MODULE_REGISTER(modem_ublox_sara_r4, CONFIG_MODEM_LOG_LEVEL);
33
33
enum mdm_control_pins {
34
34
MDM_POWER = 0 ,
35
35
MDM_RESET ,
36
+ #if defined(DT_UBLOX_SARA_R4_0_MDM_VINT_GPIOS_CONTROLLER )
37
+ MDM_VINT ,
38
+ #endif
36
39
};
37
40
38
41
static struct modem_pin modem_pins [] = {
@@ -44,6 +47,11 @@ static struct modem_pin modem_pins[] = {
44
47
MODEM_PIN (DT_INST_0_UBLOX_SARA_R4_MDM_RESET_GPIOS_CONTROLLER ,
45
48
DT_INST_0_UBLOX_SARA_R4_MDM_RESET_GPIOS_PIN , GPIO_DIR_OUT ),
46
49
50
+ #if defined(DT_UBLOX_SARA_R4_0_MDM_VINT_GPIOS_CONTROLLER )
51
+ /* MDM_VINT */
52
+ MODEM_PIN (DT_INST_0_UBLOX_SARA_R4_MDM_VINT_GPIOS_CONTROLLER ,
53
+ DT_INST_0_UBLOX_SARA_R4_MDM_VINT_GPIOS_PIN , GPIO_DIR_IN ),
54
+ #endif
47
55
};
48
56
49
57
#define MDM_UART_DEV_NAME DT_INST_0_UBLOX_SARA_R4_BUS_NAME
@@ -52,10 +60,14 @@ static struct modem_pin modem_pins[] = {
52
60
#define MDM_POWER_DISABLE 0
53
61
#define MDM_RESET_NOT_ASSERTED 1
54
62
#define MDM_RESET_ASSERTED 0
63
+ #if defined(DT_UBLOX_SARA_R4_0_MDM_VINT_GPIOS_CONTROLLER )
64
+ #define MDM_VINT_ENABLE 1
65
+ #define MDM_VINT_DISABLE 0
66
+ #endif
55
67
56
68
#define MDM_CMD_TIMEOUT K_SECONDS(10)
57
69
#define MDM_REGISTRATION_TIMEOUT K_SECONDS(180)
58
- #define MDM_PROMPT_CMD_DELAY K_MSEC(10 )
70
+ #define MDM_PROMPT_CMD_DELAY K_MSEC(75 )
59
71
60
72
#define MDM_MAX_DATA_LENGTH 1024
61
73
#define MDM_RECV_MAX_BUF 30
@@ -255,7 +267,7 @@ static int send_socket_data(struct modem_socket *sock,
255
267
256
268
/* slight pause per spec so that @ prompt is received */
257
269
k_sleep (MDM_PROMPT_CMD_DELAY );
258
-
270
+ #if defined( CONFIG_MODEM_UBLOX_SARA_R4 )
259
271
/*
260
272
* HACK: Apparently, enabling HEX transmit mode also
261
273
* affects the BINARY send method. We need to encode
@@ -266,6 +278,9 @@ static int send_socket_data(struct modem_socket *sock,
266
278
snprintk (send_buf , sizeof (send_buf ), "%02x" , buf [i ]);
267
279
mctx .iface .write (& mctx .iface , send_buf , 2U );
268
280
}
281
+ #else
282
+ mctx .iface .write (& mctx .iface , buf , buf_len );
283
+ #endif
269
284
270
285
if (timeout == K_NO_WAIT ) {
271
286
ret = 0 ;
@@ -367,6 +382,7 @@ MODEM_CMD_DEFINE(on_cmd_atcmdinfo_imei)
367
382
LOG_INF ("IMEI: %s" , log_strdup (mdata .mdm_imei ));
368
383
}
369
384
385
+ #if !defined(CONFIG_MODEM_UBLOX_SARA_U2 )
370
386
/*
371
387
* Handler: +CESQ: <rxlev>[0],<ber>[1],<rscp>[2],<ecn0>[3],<rsrq>[4],<rsrp>[5]
372
388
*/
@@ -383,6 +399,27 @@ MODEM_CMD_DEFINE(on_cmd_atcmdinfo_rssi_cesq)
383
399
384
400
LOG_INF ("RSRP: %d" , mctx .data_rssi );
385
401
}
402
+ #endif
403
+
404
+ #if defined(CONFIG_MODEM_UBLOX_SARA_U2 )
405
+ /* Handler: +CSQ: <signal_power>[0],<qual>[1] */
406
+ MODEM_CMD_DEFINE (on_cmd_atcmdinfo_rssi_csq )
407
+ {
408
+ int rssi ;
409
+
410
+ rssi = ATOI (argv [1 ], 0 , "qual" );
411
+ if (rssi == 31 ) {
412
+ mctx .data_rssi = -46 ;
413
+ } else if (rssi >= 0 && rssi <= 31 ) {
414
+ /* FIXME: This value depends on the RAT */
415
+ mctx .data_rssi = -110 + ((rssi * 2 ) + 1 );
416
+ } else {
417
+ mctx .data_rssi = -1000 ;
418
+ }
419
+
420
+ LOG_INF ("QUAL: %d" , mctx .data_rssi );
421
+ }
422
+ #endif
386
423
387
424
/*
388
425
* Modem Socket Command Handlers
@@ -595,31 +632,68 @@ static int pin_init(void)
595
632
596
633
LOG_DBG ("MDM_POWER_PIN -> DISABLE" );
597
634
modem_pin_write (& mctx , MDM_POWER , MDM_POWER_DISABLE );
635
+ #if defined(CONFIG_MODEM_UBLOX_SARA_U2 )
636
+ k_sleep (K_SECONDS (1 ));
637
+ #else
598
638
k_sleep (K_SECONDS (4 ));
639
+ #endif
599
640
LOG_DBG ("MDM_POWER_PIN -> ENABLE" );
600
641
modem_pin_write (& mctx , MDM_POWER , MDM_POWER_ENABLE );
601
642
k_sleep (K_SECONDS (1 ));
602
643
603
644
/* make sure module is powered off */
645
+ #if defined(DT_UBLOX_SARA_R4_0_MDM_VINT_GPIOS_CONTROLLER )
646
+ LOG_DBG ("Waiting for MDM_VINT_PIN = 0" );
647
+
648
+ do {
649
+ k_sleep (K_MSEC (100 ));
650
+ } while (modem_pin_read (& mctx , MDM_VINT ) != MDM_VINT_DISABLE );
651
+ #else
604
652
k_sleep (K_SECONDS (8 ));
653
+ #endif
654
+
605
655
LOG_DBG ("MDM_POWER_PIN -> DISABLE" );
656
+
657
+ unsigned int irq_lock_key = irq_lock ();
658
+
606
659
modem_pin_write (& mctx , MDM_POWER , MDM_POWER_DISABLE );
660
+ #if defined(CONFIG_MODEM_UBLOX_SARA_U2 )
661
+ k_usleep (50 ); /* 50-80 microseconds */
662
+ #else
607
663
k_sleep (K_SECONDS (1 ));
608
- LOG_DBG ( "MDM_POWER_PIN -> ENABLE" );
664
+ #endif
609
665
modem_pin_write (& mctx , MDM_POWER , MDM_POWER_ENABLE );
666
+
667
+ irq_unlock (irq_lock_key );
668
+
669
+ LOG_DBG ("MDM_POWER_PIN -> ENABLE" );
670
+
671
+ #if defined(DT_UBLOX_SARA_R4_0_MDM_VINT_GPIOS_CONTROLLER )
672
+ LOG_DBG ("Waiting for MDM_VINT_PIN = 1" );
673
+ do {
674
+ k_sleep (K_MSEC (100 ));
675
+ } while (modem_pin_read (& mctx , MDM_VINT ) != MDM_VINT_ENABLE );
676
+ #else
610
677
k_sleep (K_SECONDS (10 ));
678
+ #endif
611
679
612
680
modem_pin_config (& mctx , MDM_POWER , GPIO_DIR_IN );
681
+
613
682
LOG_INF ("... Done!" );
614
683
615
684
return 0 ;
616
685
}
617
686
618
687
static void modem_rssi_query_work (struct k_work * work )
619
688
{
620
- struct modem_cmd cmd = MODEM_CMD ("+CESQ: " , on_cmd_atcmdinfo_rssi_cesq ,
621
- 6U , "," );
689
+ struct modem_cmd cmd =
690
+ #if defined(CONFIG_MODEM_UBLOX_SARA_U2 )
691
+ MODEM_CMD ("+CSQ: " , on_cmd_atcmdinfo_rssi_csq , 2U , "," );
692
+ static char * send_cmd = "AT+CSQ" ;
693
+ #else
694
+ MODEM_CMD ("+CESQ: " , on_cmd_atcmdinfo_rssi_cesq , 6U , "," );
622
695
static char * send_cmd = "AT+CESQ" ;
696
+ #endif
623
697
int ret ;
624
698
625
699
/* query modem RSSI */
@@ -668,6 +742,18 @@ static void modem_reset(void)
668
742
SETUP_CMD_NOHANDLE ("AT+CFUN=1" ),
669
743
};
670
744
745
+ #if defined(CONFIG_MODEM_UBLOX_SARA_U2 )
746
+ static struct setup_cmd u2_setup_cmds [] = {
747
+ /* set the APN */
748
+ SETUP_CMD_NOHANDLE ("AT+UPSD=0,1,\""
749
+ CONFIG_MODEM_UBLOX_SARA_R4_MANUAL_MCCMNO "\"" ),
750
+ /* set dynamic IP */
751
+ SETUP_CMD_NOHANDLE ("AT+UPSD=0,7,\"0.0.0.0\"" ),
752
+ /* activate the GPRS connection */
753
+ SETUP_CMD_NOHANDLE ("AT+UPSDA=0,3" ),
754
+ };
755
+ #endif
756
+
671
757
/* bring down network interface */
672
758
atomic_clear_bit (mdata .net_iface -> if_dev -> flags , NET_IF_UP );
673
759
@@ -767,6 +853,17 @@ static void modem_reset(void)
767
853
goto restart ;
768
854
}
769
855
856
+ #if defined(CONFIG_MODEM_UBLOX_SARA_U2 )
857
+ ret = modem_cmd_handler_setup_cmds (& mctx .iface , & mctx .cmd_handler ,
858
+ u2_setup_cmds ,
859
+ ARRAY_SIZE (u2_setup_cmds ),
860
+ & mdata .sem_response ,
861
+ MDM_REGISTRATION_TIMEOUT );
862
+ if (ret < 0 ) {
863
+ goto error ;
864
+ }
865
+ #endif
866
+
770
867
LOG_INF ("Network is ready." );
771
868
772
869
/* Set iface up */
0 commit comments