Commit Graph
451 Commits
Author SHA1 Message Date
René van Dorst f364f61c65 docs: Update SWTG024AS with the right gpio numbering.
See #16 with new gpio information, commands etc.

Added GPIO table and notes.
Also found some LEDs but need more investigation how to control them.
2025-09-07 23:32:58 +02:00
René van Dorst 7a2e568fcc Make a helper isnumber(), replace all same patterns. 2025-09-07 17:22:13 +02:00
René van Dorst bde8454449 isletter(): optimized version
Less instructions and jumps.
Saves 39 bytes.

```patch
1634,1651c1621,1628
<       mov     r7,a
<       mov     r6,a
< ;     cmd_parser.c:63: return (l >= 'a' && l <= 'z') || (l >= 'A' && l <= 'Z');
<       cjne    r7,#0x61,00326$
< 00326$:
<       mov     _parse_vlan_sloc0_1_0,c
<       jc      00153$
<       mov     a,r7
<       add     a,#0xff - 0x7a
<       mov     _parse_vlan_sloc0_1_0,c
<       jnc     00149$
< 00153$:
<       cjne    r6,#0x41,00329$
< 00329$:
<       mov     _parse_vlan_sloc0_1_0,c
<       jc      00132$
<       mov     a,r6
<       add     a,#0xff - 0x5a
---
> ;     cmd_parser.c:66: l |= 0x20;
> ;     cmd_parser.c:67: l -= 'A';
>       orl     a,#0x20
> ;     cmd_parser.c:68: return (l <= ('Z'-'A'));
>       add     a,#0xbf
>       add     a,#0xff - 0x19
>       cpl     c
> ;     cmd_parser.c:245: if (cmd_words_b[2] > 0 && isletter(cmd_buffer[cmd_words_b[2]])) {
1653,1654c1630
<       jc      00132$
< 00149$:
---
>       jnc     00132$
```
2025-09-07 17:04:46 +02:00
René van Dorst 54ab915557 cmd: reg{get,set}: more small refactor
Refactor some value checking.
Simplified hexvalue to addr.
Updated some comments.
Remove extra debug prints and EOL after the command.
2025-09-07 16:52:51 +02:00
René van Dorst 4cad857ad5 fix: cmd: regset: need add offset when we have less then 8 hex numbers 2025-09-07 16:33:01 +02:00
René van Dorst 1b578405c0 Remove unused and not related to GPIO define 2025-09-07 14:56:13 +02:00
René van Dorst 074c89cf27 cmd: convert reg to regget and regset.
We want to stick close to the origonal commands.
See: https://github.com/up-n-atom/SWTG118AS?tab=readme-ov-file#commands
2025-09-07 14:50:50 +02:00
René van Dorst 7e729c626c cmd: add reg read and write.
like:
* `reg w 04`
* `reg w 04 00023678`
2025-09-07 01:03:15 +02:00
René van Dorst e0864f811f cmd: move gpio status to a function print_gpio_status() 2025-09-06 17:05:16 +02:00
René van Dorst 74b8280d80 gpio: SOC only has 64 gpio not 96.
Remove BANK_A
Rename BANK_B to GPIO_00_31
Rename BACK_C to GPIO_32_63

Added also _INPUT, _DIRECTIOn registers
2025-09-06 17:04:25 +02:00
René van Dorst f812970ca0 docs: SWTG024AS_v2.0 document power rails. 2025-09-06 12:41:13 +02:00
René van Dorst e6d90f7a8a docs: SWTG024AS reword/reformat was parts 2025-09-06 12:13:53 +02:00
René van Dorst 0d63b08f89 Docs: Add SWTG024AS-v2.0-unmanaged version
Pinout Spreedsheet, photos and wiki about my findings.

GPIO number may be has endian problem.
2025-09-06 10:23:09 +02:00
René van Dorst 8e9cababfb gpio: show also bit changes vs last gpio cmd 2025-09-05 00:10:18 +02:00
René van Dorst f481d1fbe4 add cmd gpio 2025-09-04 23:49:17 +02:00
logicog 8b91646b83 Merge pull request #14 from logicog/smaller_image
Fix issues with smaller image size
2025-09-04 22:59:05 +02:00
logicog b85d57b32b Demagic memory locations 2025-09-04 22:23:02 +02:00
logicog 2669262240 Demagic memory locations 2025-09-04 21:04:57 +02:00
logicog 395f05c27d Remove unnecessary variable 2025-09-04 21:04:42 +02:00
logicog e72585865c Merge pull request #11 from logicog/smaller_image
Smaller image
2025-09-04 20:57:59 +02:00
logicog 5635ad835e Add support for ip, gw and netmask commands 2025-09-03 20:32:57 +02:00
logicog e5146e0857 Use 512kB image size for now 2025-09-03 20:32:30 +02:00
logicog 8765a9ba17 Fix int arguments for file-size and location of added data 2025-09-03 20:32:04 +02:00
logicog fa62eecb97 Merge pull request #9 from vDorst/feat_phy_modify
add phy_modify()
2025-09-03 06:33:03 +02:00
René van Dorst 71eba81421 Add rtlplaygroud.mem also exclude the file in .gitignore.
See PR #10 about mem usage
2025-09-02 22:25:07 +02:00
René van Dorst 001c52ef39 Use phy_modify().
This saves 210 bytes.
2025-09-02 22:23:02 +02:00
René van Dorst c5995a4184 Add: phy_modify() to modify phy_registers.
Makes it easier to modify set/clear bit in a phy register.
Simulair like Linux PHY-core: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/net/phy/phy-core.c#n551
2025-09-02 22:23:02 +02:00
René van Dorst 5316ae9495 Merge pull request #8 from vDorst/feat_gitignore
Add .gitignore
2025-09-02 20:21:11 +00:00
René van Dorst 7bc3d2cf49 Add .gitignore 2025-09-02 10:32:40 +02:00
logicog 3392b588b2 Merge pull request #6 from vDorst/sfr16
Combine two sfr-pairs into a single sfr16 define, so make it less error prone to use and optimize better.
2025-09-01 18:10:06 +02:00
René van Dorst bcf4ae316c fix SFR_DATA_U16: must use sfr a6a7 not sfr a4a5! 2025-09-01 16:47:57 +02:00
René van Dorst 22dccbad8c Replace phy_write_mask(0x1 with phy_write(0x00.
Also added define `RTL8224_PHY_ID` for RTL8224 phy_id.
So it is more clear that we want to talk to that phy.
Replaced in the function which contains `8224` in the name the
`phy_write(0x00, ...)` with `phy_write(RTL8224_PHY_ID, ...)`, same for the
`phy_read(0x00, ...)` with `phy_read(RTL8224_PHY_ID, ...)`.

Removed the extra `phy_read()` in `rtl8224_phy_enable()`.
2025-09-01 12:26:27 +02:00
René van Dorst cc132a8734 phy_write(): also use SFR_DATA_U16 and SFR_SMI_REG_U16
Was added by pr#7.
2025-09-01 09:59:41 +02:00
René van Dorst 689d208ff1 phy: fix whitespace and comments alinement 2025-09-01 09:59:06 +02:00
René van Dorst d865862625 phy: fix or/and-opperation conversion errors 2025-09-01 09:27:28 +02:00
René van Dorst 94cf079fcb PHY: also use SFR_DATA_U16.
Again less error prone and easier to read.

Also see a lot of better optimalizations.
A snipped.

390c390
< ;pval          Allocated to registers r3 r4
---
> ;pval          Allocated to registers
838,852c838,844
< ;     rtl837x_phy.c:181: pval = SFR_DATA_8 & 0xbf;
<       mov     r7,_SFR_DATA_8
<       anl     ar7,#0xbf
< ;     rtl837x_phy.c:182: pval <<= 8;
<       mov     ar4,r7
<       mov     r7,#0x00
< ;     rtl837x_phy.c:183: pval |= SFR_DATA_0;
<       mov     r2,_SFR_DATA_0
<       mov     r3,#0x00
<       mov     a,r2
<       orl     a,r7
<       mov     _phy_write_PARM_4,a
<       mov     a,r3
<       orl     a,r4
<       mov     (_phy_write_PARM_4 + 1),a
---
> ;     rtl837x_phy.c:181: pval = SFR_DATA_U16 & 0xbfff;
>       mov     r4,((_SFR_DATA_U16 >> 0) & 0xFF)
>       mov     a,#0xbf
>       anl     a,((_SFR_DATA_U16 >> 8) & 0xFF)
>       mov     r7,a
>       mov     _phy_write_PARM_4,r4
>       mov     (_phy_write_PARM_4 + 1),r7
864c856
<       mov     _phy_write_PARM_3,r7
---
>       mov     _phy_write_PARM_3,#0x00
2025-09-01 09:25:33 +02:00
René van Dorst b8928a8bcd Replace manual SFR_DATA_0 and SFR_DATA_8 pair read and write with SFR_DATA_U16.
Also added SFR_SMI_REG_U16.

Doing pval = reg_h; pval <<= 8; pval |= reg_l; dont always optimized by the compiler a some places, not all.

A snipped of the diff between two .asm files.

5414,5424c5414,5416
< ;     rtlplayground.c:1382: uint16_t pval = SFR_DATA_8;
< ;     rtlplayground.c:1383: pval <<= 8;
<       mov     r7,_SFR_DATA_8
<       mov     r6,#0x00
< ;     rtlplayground.c:1384: pval |= SFR_DATA_0;
<       mov     r4,_SFR_DATA_0
<       mov     r5,#0x00
<       mov     a,r6
<       orl     ar4,a
<       mov     a,r7
<       orl     ar5,a
---
> ;     rtlplayground.c:1382: uint16_t pval = SFR_DATA_U16;
>       mov     r6,((_SFR_DATA_U16 >> 0) & 0xFF)
>       mov     r7,((_SFR_DATA_U16 >> 8) & 0xFF)
2025-09-01 09:20:36 +02:00
René van Dorst 9dafeab490 Added SFR_NIC_DATA_U16LE and SFR_NIC_RING_U16LE.
Let's use sfr16 for NIC data and ring.
SFR define can so reordered to it does the BE to LE swap for us.
2025-09-01 09:20:36 +02:00
René van Dorst af0135bcce Add sfr16 SFR_REG_ADDR_U16.
So instead do it manual split a uint16_t in to two uint8_t.
The compiler can do it, so reduces user error.
Note: compiler writes the lower/LSB part first.
      When that is importent this can´t be used.

Assembly is still the same except note above.
2025-09-01 09:20:36 +02:00
logicog 250beae09b Merge pull request #7 from vDorst/phy_write_main
bit_mask lookup before calling phy_write() is expensive.
2025-09-01 08:10:21 +02:00
logicog a939e2e92b Fix protocol structure and filling 2025-09-01 07:45:33 +02:00
René van Dorst 7ff028303d Add phy_write() with bit_mask lookup inside the function.
Move the lookup saves a lot of instructions for every phy_write() call.

Assembly diff for one change.
< ;     rtl837x_phy.c:240: phy_write_mask(bit_mask[port], 0x07, 0x00, 0x3200);  // Enable AN
<       mov     dpl,r5
<       mov     dph,r6
---
> ;     rtl837x_phy.c:240: phy_write(port, 0x07, 0x00, 0x3200); // Enable AN
>       mov     _phy_write_PARM_2,#0x07
1345,1359c1019,1024
<       movc    a,@a+dptr
<       mov     r5,a
<       inc     dptr
<       clr     a
<       movc    a,@a+dptr
<       mov     r6,a
<       mov     _phy_write_mask_PARM_2,#0x07
<       clr     a
<       mov     _phy_write_mask_PARM_3,a
<       mov     (_phy_write_mask_PARM_3 + 1),a
<       mov     _phy_write_mask_PARM_4,a
<       mov     (_phy_write_mask_PARM_4 + 1),#0x32
<       mov     dpl, r5
<       mov     dph, r6
<       lcall   _phy_write_mask
---
>       mov     _phy_write_PARM_3,a
>       mov     (_phy_write_PARM_3 + 1),a
>       mov     _phy_write_PARM_4,a
>       mov     (_phy_write_PARM_4 + 1),#0x32
>       mov     dpl, r7
>       lcall   _phy_write

Replace all phy_write_mask(bit_mask[<var>], ...) to phy phy_write(<var>, ...).
2025-09-01 00:12:12 +02:00
René van Dorst d6ea9be4c0 rename phy_write() to phy_write_mask().
It seems that bit_mask[phy] lookup is expensive and it used in many places.
But most of the time we only addressing a single phy.
2025-09-01 00:07:27 +02:00
logicog e499007666 Merge pull request #5 from vDorst/compfix1
fix: comp. warning 283: function declarator with no prototype.
2025-08-31 17:54:13 +02:00
René van Dorst 3d80f73383 fix: comp. warning 283: function declarator with no prototype. 2025-08-30 22:51:19 +02:00
logicog 546d385bf1 Add RLDP setup 2025-08-30 18:44:17 +02:00
logicog 829fbf707a Use uip for mac-address, enable STP packages 2025-08-30 18:43:31 +02:00
logicog 326d94f48d Add support for STP 2025-08-30 18:42:46 +02:00
logicog 83dcd22863 Add STP packet identification 2025-08-30 08:29:25 +02:00
logicog 963d53335c Add initial IGMP handling via ASIC 2025-08-29 17:23:14 +02:00